From c8447c190ca3bed0528ad421050a692f2da978be Mon Sep 17 00:00:00 2001 From: seelabs Date: Thu, 23 Apr 2015 10:55:38 -0700 Subject: [PATCH] Report the inbound listening port during crawl (RIPD-866) --- src/ripple/overlay/impl/OverlayImpl.cpp | 13 +++++++++++-- src/ripple/peerfinder/Slot.h | 2 ++ src/ripple/peerfinder/impl/Logic.h | 1 + src/ripple/peerfinder/impl/SlotImp.cpp | 2 ++ src/ripple/peerfinder/impl/SlotImp.h | 18 ++++++++++++++++++ 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/ripple/overlay/impl/OverlayImpl.cpp b/src/ripple/overlay/impl/OverlayImpl.cpp index 7d7e51e6e..d7361cd06 100644 --- a/src/ripple/overlay/impl/OverlayImpl.cpp +++ b/src/ripple/overlay/impl/OverlayImpl.cpp @@ -595,12 +595,21 @@ OverlayImpl::crawl() pv[jss::public_key] = beast::base64_encode( sp->getNodePublic().getNodePublic().data(), sp->getNodePublic().getNodePublic().size()); + pv[jss::type] = sp->slot()->inbound() ? + "in" : "out"; if (sp->crawl()) { + pv[jss::ip] = sp->getRemoteAddress().address().to_string(); if (sp->slot()->inbound()) - pv[jss::ip] = sp->getRemoteAddress().address().to_string(); + { + if (auto port = sp->slot()->listening_port()) + pv[jss::port] = *port; + } else - pv[jss::ip] = sp->getRemoteAddress().to_string(); + { + pv[jss::port] = std::to_string( + sp->getRemoteAddress().port()); + } } auto version = sp->getVersion (); if (!version.empty ()) diff --git a/src/ripple/peerfinder/Slot.h b/src/ripple/peerfinder/Slot.h index cc19f26dd..bd3bb590d 100644 --- a/src/ripple/peerfinder/Slot.h +++ b/src/ripple/peerfinder/Slot.h @@ -68,6 +68,8 @@ public: /** The local endpoint of the socket, when known. */ virtual boost::optional const& local_endpoint () const = 0; + virtual boost::optional listening_port () const = 0; + /** The peer's public key, when known. The public key is established when the handshake is complete. */ diff --git a/src/ripple/peerfinder/impl/Logic.h b/src/ripple/peerfinder/impl/Logic.h index 7c446b946..097724527 100644 --- a/src/ripple/peerfinder/impl/Logic.h +++ b/src/ripple/peerfinder/impl/Logic.h @@ -262,6 +262,7 @@ public: } slot.canAccept = true; + slot.set_listening_port (checkedAddress.port ()); if (m_journal.debug) m_journal.debug << beast::leftw (18) << "Logic testing " << checkedAddress << " succeeded"; } diff --git a/src/ripple/peerfinder/impl/SlotImp.cpp b/src/ripple/peerfinder/impl/SlotImp.cpp index 32f9cbca6..a116a5160 100644 --- a/src/ripple/peerfinder/impl/SlotImp.cpp +++ b/src/ripple/peerfinder/impl/SlotImp.cpp @@ -35,6 +35,7 @@ SlotImp::SlotImp (beast::IP::Endpoint const& local_endpoint, , m_state (accept) , m_remote_endpoint (remote_endpoint) , m_local_endpoint (local_endpoint) + , m_listening_port (unknownPort) , checked (false) , canAccept (false) , connectivityCheckInProgress (false) @@ -49,6 +50,7 @@ SlotImp::SlotImp (beast::IP::Endpoint const& remote_endpoint, , m_cluster (false) , m_state (connect) , m_remote_endpoint (remote_endpoint) + , m_listening_port (unknownPort) , checked (true) , canAccept (true) , connectivityCheckInProgress (false) diff --git a/src/ripple/peerfinder/impl/SlotImp.h b/src/ripple/peerfinder/impl/SlotImp.h index fcffb9ad8..b10bde474 100644 --- a/src/ripple/peerfinder/impl/SlotImp.h +++ b/src/ripple/peerfinder/impl/SlotImp.h @@ -22,9 +22,11 @@ #include #include +#include #include #include #include +#include namespace ripple { namespace PeerFinder { @@ -81,6 +83,19 @@ public: return m_public_key; } + boost::optional listening_port () const + { + std::uint32_t const value = m_listening_port; + if (value == unknownPort) + return boost::none; + return value; + } + + void set_listening_port (std::uint16_t port) + { + m_listening_port = port; + } + void local_endpoint (beast::IP::Endpoint const& endpoint) { m_local_endpoint = endpoint; @@ -147,6 +162,9 @@ private: boost::optional m_local_endpoint; boost::optional m_public_key; + static std::int32_t BEAST_CONSTEXPR unknownPort = -1; + std::atomic m_listening_port; + public: // DEPRECATED public data members