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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
16 additions and
3 deletions
-
include/libp2p/transport/tcp/tcp_util.hpp
-
src/transport/tcp/tcp_listener.cpp
-
test/libp2p/protocol_muxer/multiselect_test.cpp
|
|
@ -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(); |
|
|
|
|
|
@ -63,7 +63,7 @@ namespace libp2p::transport { |
|
|
|
if (ec) { |
|
|
|
return ec; |
|
|
|
} |
|
|
|
return detail::makeAddress(endpoint); |
|
|
|
return detail::makeAddress(endpoint, &layers_); |
|
|
|
} |
|
|
|
|
|
|
|
bool TcpListener::isClosed() const { |
|
|
|
|
|
@ -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) { |
|
|
|