Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/stellar-core_example.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ NETWORK_PASSPHRASE="Public Global Stellar Network ; September 2015"
# The port other instances of stellar-core can connect to you on.
PEER_PORT=11625

# PEER_LISTEN_IP (string) default "" (bind to 0.0.0.0)
# The IP address other instances of stellar-core can connect to you on.
PEER_LISTEN_IP=""

# TARGET_PEER_CONNECTIONS (Integer) default 8
# This controls how aggressively the server will connect to other peers.
# It will send outbound connection attempts until it is at this
Expand Down
2 changes: 2 additions & 0 deletions src/main/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,8 @@ Config::processConfig(std::shared_ptr<cpptoml::table> t)
#endif
{"PEER_PORT",
[&]() { PEER_PORT = readInt<unsigned short>(item, 1); }},
{"PEER_LISTEN_IP",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth doing validation that the IP is reasonable here. Although, we can only really check that the IP is properly formatted, and we'll get similar asio errors in PeerDoor::start for an invalid address and an address we can't bind to.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does asio expose a function that validates IP addresses? I agree it would be nice to fail early here if it's easy enough.

[&]() { PEER_LISTEN_IP = readString(item); }},
{"HTTP_PORT",
[&]() { HTTP_PORT = readInt<unsigned short>(item); }},
{"HTTP_QUERY_PORT",
Expand Down
1 change: 1 addition & 0 deletions src/main/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@ class Config : public std::enable_shared_from_this<Config>

// overlay config
unsigned short PEER_PORT;
std::string PEER_LISTEN_IP; // IP address to listen on (empty = 0.0.0.0)
unsigned short TARGET_PEER_CONNECTIONS;
unsigned short MAX_PENDING_CONNECTIONS;
int MAX_ADDITIONAL_PEER_CONNECTIONS;
Expand Down
4 changes: 2 additions & 2 deletions src/overlay/OverlayManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ class OverlayManager
virtual bool acceptAuthenticatedPeer(Peer::pointer peer) = 0;

virtual bool isPreferred(Peer* peer) const = 0;
virtual bool isPossiblyPreferred(std::string const& ip) const = 0;
virtual bool haveSpaceForConnection(std::string const& ip) const = 0;
virtual bool isPossiblyPreferred(asio::ip::address const& ip) const = 0;
virtual bool haveSpaceForConnection(asio::ip::address const& ip) const = 0;

// Return the current in-memory set of inbound pending peers.
virtual std::vector<Peer::pointer> const&
Expand Down
6 changes: 3 additions & 3 deletions src/overlay/OverlayManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ OverlayManagerImpl::maybeAddInboundConnection(Peer::pointer peer)
}

bool
OverlayManagerImpl::isPossiblyPreferred(std::string const& ip) const
OverlayManagerImpl::isPossiblyPreferred(asio::ip::address const& ip) const
{
return std::any_of(
std::begin(mConfigurationPreferredPeers),
Expand All @@ -915,7 +915,7 @@ OverlayManagerImpl::isPossiblyPreferred(std::string const& ip) const
}

bool
OverlayManagerImpl::haveSpaceForConnection(std::string const& ip) const
OverlayManagerImpl::haveSpaceForConnection(asio::ip::address const& ip) const
{
auto totalAuthenticated = getInboundAuthenticatedPeers().size();
auto totalTracked = *getLiveInboundPeersCounter();
Expand Down Expand Up @@ -947,7 +947,7 @@ OverlayManagerImpl::haveSpaceForConnection(std::string const& ip) const
CLOG_DEBUG(
Overlay,
"Peer rejected - all pending inbound connections are taken: {}",
ip);
ip.to_string());
CLOG_DEBUG(Overlay, "If you wish to allow for more pending "
"inbound connections, please update your "
"MAX_PENDING_CONNECTIONS setting in "
Expand Down
6 changes: 4 additions & 2 deletions src/overlay/OverlayManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,10 @@ class OverlayManagerImpl : public OverlayManager
int availableOutboundAuthenticatedSlots() const;
int nonPreferredAuthenticatedCount() const;

virtual bool isPossiblyPreferred(std::string const& ip) const override;
virtual bool haveSpaceForConnection(std::string const& ip) const override;
virtual bool
isPossiblyPreferred(asio::ip::address const& ip) const override;
virtual bool
haveSpaceForConnection(asio::ip::address const& ip) const override;

void updateSizeCounters();

Expand Down
20 changes: 3 additions & 17 deletions src/overlay/Peer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ static constexpr VirtualClock::time_point PING_NOT_SENT =
VirtualClock::time_point::min();
static constexpr uint32_t QUERY_RESPONSE_MULTIPLIER = 5;

Peer::Peer(Application& app, PeerRole role)
Peer::Peer(Application& app, PeerRole role, PeerBareAddress const& address)
: mAppConnector(app.getAppConnector())
, mNetworkID(app.getNetworkID())
, mFlowControl(
Expand All @@ -145,6 +145,7 @@ Peer::Peer(Application& app, PeerRole role)
, mState(role == WE_CALLED_REMOTE ? CONNECTING : CONNECTED)
, mRemoteOverlayMinVersion(0)
, mRemoteOverlayVersion(0)
, mAddress(address)
, mCreationTime(app.getClock().now())
, mRecurringTimer(app)
, mDelayedExecutionTimer(app)
Expand Down Expand Up @@ -1719,7 +1720,6 @@ void
Peer::updatePeerRecordAfterEcho()
{
releaseAssert(threadIsMain());
releaseAssert(!getAddress().isEmpty());

PeerType type;
if (mAppConnector.getOverlayManager().isPreferred(this))
Expand All @@ -1745,7 +1745,6 @@ void
Peer::updatePeerRecordAfterAuthentication()
{
releaseAssert(threadIsMain());
releaseAssert(!getAddress().isEmpty());

if (mRole == WE_CALLED_REMOTE)
{
Expand Down Expand Up @@ -1801,12 +1800,6 @@ Peer::recvHello(Hello const& elo)
// mAddress is set in TCPPeer::initiate and TCPPeer::accept. It should
// contain valid IP (but not necessarily port yet)
auto ip = mAddress.getIP();
if (ip.empty())
{
drop("failed to determine remote address",
Peer::DropDirection::WE_DROPPED_REMOTE);
return;
}
mAddress =
PeerBareAddress{ip, static_cast<unsigned short>(elo.listeningPort)};

Expand Down Expand Up @@ -1853,7 +1846,7 @@ Peer::recvHello(Hello const& elo)
return;
}

if (elo.listeningPort <= 0 || elo.listeningPort > UINT16_MAX || ip.empty())
if (elo.listeningPort <= 0 || elo.listeningPort > UINT16_MAX)
{
sendErrorAndDrop(ERR_CONF, "bad address");
return;
Expand Down Expand Up @@ -1989,14 +1982,7 @@ Peer::recvPeers(StellarMessage const& msg)
peer.port);
continue;
}
if (peer.ip.type() == IPv6)
{
CLOG_DEBUG(Overlay,
"ignoring received IPv6 address (not yet supported)");
continue;
}

releaseAssert(peer.ip.type() == IPv4);
auto address = PeerBareAddress{peer};

if (address.isPrivate())
Expand Down
2 changes: 1 addition & 1 deletion src/overlay/Peer.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ class Peer : public std::enable_shared_from_this<Peer>,
public:
/* The following functions must all be called from the main thread (they all
* contain releaseAssert(threadIsMain())) */
Peer(Application& app, PeerRole role);
Peer(Application& app, PeerRole role, PeerBareAddress const& address);

void cancelTimers();

Expand Down
Loading
Loading