Browse Source

tcp listener ws wss address (#211)

Signed-off-by: turuslan <turuslan.devbox@gmail.com>
pull/213/head v0.1.12
Ruslan Tushov 1 year ago
committed by GitHub
parent
commit
42982bf471
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      include/libp2p/transport/tcp/tcp_util.hpp
  2. 2
      src/transport/tcp/tcp_listener.cpp
  3. 2
      test/libp2p/protocol_muxer/multiselect_test.cpp

15
include/libp2p/transport/tcp/tcp_util.hpp

@ -17,7 +17,10 @@
namespace libp2p::transport::detail {
template <typename T>
inline outcome::result<multi::Multiaddress> makeAddress(T &&endpoint) {
inline outcome::result<multi::Multiaddress> makeAddress(
T &&endpoint,
const std::vector<std::pair<multi::Protocol, std::string>> *layers =
nullptr) {
try {
auto address = endpoint.address();
auto port = endpoint.port();
@ -32,6 +35,16 @@ namespace libp2p::transport::detail {
s << "/tcp/" << port;
if (layers != nullptr and not layers->empty()) {
auto &protocol = layers->at(0).first.code;
using P = multi::Protocol::Code;
if (protocol == P::WS) {
s << "/ws";
} else if (protocol == P::WSS) {
s << "/wss";
}
}
return multi::Multiaddress::create(s.str());
} catch (const boost::system::system_error &e) {
return e.code();

2
src/transport/tcp/tcp_listener.cpp

@ -63,7 +63,7 @@ namespace libp2p::transport {
if (ec) {
return ec;
}
return detail::makeAddress(endpoint);
return detail::makeAddress(endpoint, &layers_);
}
bool TcpListener::isClosed() const {

2
test/libp2p/protocol_muxer/multiselect_test.cpp

@ -20,7 +20,7 @@ TEST(Multiselect, TmpBufThrows) {
using libp2p::protocol_muxer::multiselect::detail::TmpMsgBuf;
TmpMsgBuf buf;
buf.resize(kMaxMessageSize / 2);
EXPECT_THROW(buf.resize(buf.capacity() + 1), std::bad_alloc);
EXPECT_THROW(buf.resize(buf.capacity() + 1), boost::container::bad_alloc_t);
}
TEST(Multiselect, SingleValidMessages) {

Loading…
Cancel
Save