Browse Source

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)
cl-refactor
Daniel Hams 11 years ago
parent
commit
42986e83a2
  1. 14
      libethereum/PeerNetwork.cpp
  2. 16
      libethereum/PeerNetwork.h

14
libethereum/PeerNetwork.cpp

@ -80,7 +80,7 @@ bool eth::isPrivateAddress(bi::address _addressToCheck)
return false; 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_server(_s),
m_socket(std::move(_socket)), m_socket(std::move(_socket)),
m_reqNetworkId(_rNId), m_reqNetworkId(_rNId),
@ -137,7 +137,7 @@ bool PeerSession::interpret(RLP const& _r)
m_networkId = _r[2].toInt<uint>(); m_networkId = _r[2].toInt<uint>();
auto clientVersion = _r[3].toString(); auto clientVersion = _r[3].toString();
m_caps = _r[4].toInt<uint>(); m_caps = _r[4].toInt<uint>();
m_listenPort = _r[5].toInt<short>(); m_listenPort = _r[5].toInt<ushort>();
m_id = _r[6].toHash<h512>(); m_id = _r[6].toHash<h512>();
clogS(NetMessageSummary) << "Hello: " << clientVersion << "V[" << m_protocolVersion << "/" << m_networkId << "]" << m_id.abridged() << showbase << hex << m_caps << dec << m_listenPort; 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_clientVersion(_clientVersion),
m_mode(_m), m_mode(_m),
m_listenPort(_port), 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): PeerServer::PeerServer(std::string const& _clientVersion, uint _networkId, NodeMode _m):
m_clientVersion(_clientVersion), m_clientVersion(_clientVersion),
m_mode(_m), m_mode(_m),
m_listenPort(-1), m_listenPort(0),
m_acceptor(m_ioService, bi::tcp::endpoint(bi::tcp::v4(), 0)), m_acceptor(m_ioService, bi::tcp::endpoint(bi::tcp::v4(), 0)),
m_socket(m_ioService), m_socket(m_ioService),
m_key(KeyPair::create()), m_key(KeyPair::create()),
@ -746,7 +746,7 @@ void PeerServer::populateAddresses()
bi::address ad(bi::address::from_string(addrStr)); bi::address ad(bi::address::from_string(addrStr));
m_addresses.push_back(ad.to_v4()); m_addresses.push_back(ad.to_v4());
bool isLocal = std::find(c_rejectAddresses.begin(), c_rejectAddresses.end(), ad) != c_rejectAddresses.end(); 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()); m_peerAddresses.push_back(ad.to_v4());
clog(NetNote) << "Address: " << ac << " = " << m_addresses.back() << (isLocal ? " [LOCAL]" : " [PEER]"); 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 try
{ {
@ -866,7 +866,7 @@ void PeerServer::connect(bi::tcp::endpoint const& _ep)
else else
{ {
auto p = make_shared<PeerSession>(this, std::move(*s), m_requiredNetworkId, _ep.address(), _ep.port()); auto p = make_shared<PeerSession>(this, std::move(*s), m_requiredNetworkId, _ep.address(), _ep.port());
clog(NetNote) << "Connected to " << p->endpoint(); clog(NetNote) << "Connected to " << _ep;
p->start(); p->start();
} }
delete s; delete s;

16
libethereum/PeerNetwork.h

@ -82,7 +82,7 @@ struct PeerInfo
{ {
std::string clientVersion; std::string clientVersion;
std::string host; std::string host;
short port; ushort port;
std::chrono::steady_clock::duration lastPing; std::chrono::steady_clock::duration lastPing;
}; };
@ -91,7 +91,7 @@ class PeerSession: public std::enable_shared_from_this<PeerSession>
friend class PeerServer; friend class PeerServer;
public: 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(); ~PeerSession();
void start(); void start();
@ -127,7 +127,7 @@ private:
uint m_protocolVersion; uint m_protocolVersion;
uint m_networkId; uint m_networkId;
uint m_reqNetworkId; 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; uint m_caps;
std::chrono::steady_clock::time_point m_ping; std::chrono::steady_clock::time_point m_ping;
@ -147,7 +147,7 @@ enum class NodeMode
PeerServer PeerServer
}; };
struct UPnP; class UPnP;
class PeerServer class PeerServer
{ {
@ -155,13 +155,13 @@ class PeerServer
public: public:
/// Start server, listening for connections on the given port. /// 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. /// Start server, but don't listen.
PeerServer(std::string const& _clientVersion, uint _networkId, NodeMode _m = NodeMode::Full); PeerServer(std::string const& _clientVersion, uint _networkId, NodeMode _m = NodeMode::Full);
~PeerServer(); ~PeerServer();
/// Connect to a peer explicitly. /// 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); 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. /// 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(); void pingAll();
/// Get the port we're listening on currently. /// 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; bytes savePeers() const;
void restorePeers(bytesConstRef _b); void restorePeers(bytesConstRef _b);
@ -209,7 +209,7 @@ private:
std::string m_clientVersion; std::string m_clientVersion;
NodeMode m_mode = NodeMode::Full; NodeMode m_mode = NodeMode::Full;
short m_listenPort; ushort m_listenPort;
BlockChain const* m_chain = nullptr; BlockChain const* m_chain = nullptr;
ba::io_service m_ioService; ba::io_service m_ioService;

Loading…
Cancel
Save