From 42986e83a27259a9ca710c6b1b929e55af4304a9 Mon Sep 17 00:00:00 2001 From: Daniel Hams Date: Mon, 17 Feb 2014 11:41:10 +0000 Subject: [PATCH] Little fixes in peer network. (1) Use of unsigned port number (2) Fix of copy pasta error in window isLocal logic (3) On outgoing connection print endpoint instead of peer.endpoint (this fixes 0.0.0.0 appearing in log on OSX as not fully initialised) --- libethereum/PeerNetwork.cpp | 14 +++++++------- libethereum/PeerNetwork.h | 16 ++++++++-------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/libethereum/PeerNetwork.cpp b/libethereum/PeerNetwork.cpp index 89787aa9d..c0e24ddc2 100644 --- a/libethereum/PeerNetwork.cpp +++ b/libethereum/PeerNetwork.cpp @@ -80,7 +80,7 @@ bool eth::isPrivateAddress(bi::address _addressToCheck) return false; } -PeerSession::PeerSession(PeerServer* _s, bi::tcp::socket _socket, uint _rNId, bi::address _peerAddress, short _peerPort): +PeerSession::PeerSession(PeerServer* _s, bi::tcp::socket _socket, uint _rNId, bi::address _peerAddress, ushort _peerPort): m_server(_s), m_socket(std::move(_socket)), m_reqNetworkId(_rNId), @@ -137,7 +137,7 @@ bool PeerSession::interpret(RLP const& _r) m_networkId = _r[2].toInt(); auto clientVersion = _r[3].toString(); m_caps = _r[4].toInt(); - m_listenPort = _r[5].toInt(); + m_listenPort = _r[5].toInt(); m_id = _r[6].toHash(); clogS(NetMessageSummary) << "Hello: " << clientVersion << "V[" << m_protocolVersion << "/" << m_networkId << "]" << m_id.abridged() << showbase << hex << m_caps << dec << m_listenPort; @@ -635,7 +635,7 @@ void PeerSession::doRead() }); } -PeerServer::PeerServer(std::string const& _clientVersion, BlockChain const& _ch, uint _networkId, short _port, NodeMode _m, string const& _publicAddress, bool _upnp): +PeerServer::PeerServer(std::string const& _clientVersion, BlockChain const& _ch, uint _networkId, ushort _port, NodeMode _m, string const& _publicAddress, bool _upnp): m_clientVersion(_clientVersion), m_mode(_m), m_listenPort(_port), @@ -654,7 +654,7 @@ PeerServer::PeerServer(std::string const& _clientVersion, BlockChain const& _ch, PeerServer::PeerServer(std::string const& _clientVersion, uint _networkId, NodeMode _m): m_clientVersion(_clientVersion), m_mode(_m), - m_listenPort(-1), + m_listenPort(0), m_acceptor(m_ioService, bi::tcp::endpoint(bi::tcp::v4(), 0)), m_socket(m_ioService), m_key(KeyPair::create()), @@ -746,7 +746,7 @@ void PeerServer::populateAddresses() bi::address ad(bi::address::from_string(addrStr)); m_addresses.push_back(ad.to_v4()); bool isLocal = std::find(c_rejectAddresses.begin(), c_rejectAddresses.end(), ad) != c_rejectAddresses.end(); - if (isLocal) + if (!isLocal) m_peerAddresses.push_back(ad.to_v4()); clog(NetNote) << "Address: " << ac << " = " << m_addresses.back() << (isLocal ? " [LOCAL]" : " [PEER]"); } @@ -831,7 +831,7 @@ void PeerServer::ensureAccepting() } } -void PeerServer::connect(std::string const& _addr, uint _port) noexcept +void PeerServer::connect(std::string const& _addr, ushort _port) noexcept { try { @@ -866,7 +866,7 @@ void PeerServer::connect(bi::tcp::endpoint const& _ep) else { auto p = make_shared(this, std::move(*s), m_requiredNetworkId, _ep.address(), _ep.port()); - clog(NetNote) << "Connected to " << p->endpoint(); + clog(NetNote) << "Connected to " << _ep; p->start(); } delete s; diff --git a/libethereum/PeerNetwork.h b/libethereum/PeerNetwork.h index 9edfe0cb6..5d44e375e 100644 --- a/libethereum/PeerNetwork.h +++ b/libethereum/PeerNetwork.h @@ -82,7 +82,7 @@ struct PeerInfo { std::string clientVersion; std::string host; - short port; + ushort port; std::chrono::steady_clock::duration lastPing; }; @@ -91,7 +91,7 @@ class PeerSession: public std::enable_shared_from_this friend class PeerServer; public: - PeerSession(PeerServer* _server, bi::tcp::socket _socket, uint _rNId, bi::address _peerAddress, short _peerPort = 0); + PeerSession(PeerServer* _server, bi::tcp::socket _socket, uint _rNId, bi::address _peerAddress, ushort _peerPort = 0); ~PeerSession(); void start(); @@ -127,7 +127,7 @@ private: uint m_protocolVersion; uint m_networkId; uint m_reqNetworkId; - short m_listenPort; ///< Port that the remote client is listening on for connections. Useful for giving to peers. + ushort m_listenPort; ///< Port that the remote client is listening on for connections. Useful for giving to peers. uint m_caps; std::chrono::steady_clock::time_point m_ping; @@ -147,7 +147,7 @@ enum class NodeMode PeerServer }; -struct UPnP; +class UPnP; class PeerServer { @@ -155,13 +155,13 @@ class PeerServer public: /// Start server, listening for connections on the given port. - PeerServer(std::string const& _clientVersion, BlockChain const& _ch, uint _networkId, short _port, NodeMode _m = NodeMode::Full, std::string const& _publicAddress = std::string(), bool _upnp = true); + PeerServer(std::string const& _clientVersion, BlockChain const& _ch, uint _networkId, ushort _port, NodeMode _m = NodeMode::Full, std::string const& _publicAddress = std::string(), bool _upnp = true); /// Start server, but don't listen. PeerServer(std::string const& _clientVersion, uint _networkId, NodeMode _m = NodeMode::Full); ~PeerServer(); /// Connect to a peer explicitly. - void connect(std::string const& _addr, uint _port = 30303) noexcept; + void connect(std::string const& _addr, ushort _port = 30303) noexcept; void connect(bi::tcp::endpoint const& _ep); /// Sync with the BlockChain. It might contain one of our mined blocks, we might have new candidates from the network. @@ -188,7 +188,7 @@ public: void pingAll(); /// Get the port we're listening on currently. - short listenPort() const { return m_public.port(); } + ushort listenPort() const { return m_public.port(); } bytes savePeers() const; void restorePeers(bytesConstRef _b); @@ -209,7 +209,7 @@ private: std::string m_clientVersion; NodeMode m_mode = NodeMode::Full; - short m_listenPort; + ushort m_listenPort; BlockChain const* m_chain = nullptr; ba::io_service m_ioService;