13 #include <shared_mutex>
24 #include <boost/asio.hpp>
25 #include <boost/asio/ip/tcp.hpp>
26 #include <boost/asio/steady_timer.hpp>
29 namespace ba = boost::asio;
30 namespace bi = ba::ip;
55 bool isAllowedAddress(
bool _allowLocalDiscovery, bi::address
const& _addressToCheck);
69 #define NET_GLOBAL_LOGGER(NAME, SEVERITY) \
70 BOOST_LOG_INLINE_GLOBAL_LOGGER_CTOR_ARGS( \
71 g_##NAME##Logger, boost::log::sources::severity_channel_logger_mt<>, \
72 (boost::log::keywords::severity = SEVERITY)(boost::log::keywords::channel = "net"))
75 #define cnetnote LOG(dev::p2p::g_netnoteLogger::get())
77 #define cnetlog LOG(dev::p2p::g_netlogLogger::get())
79 #define cnetdetails LOG(dev::p2p::g_netdetailsLogger::get())
116 using CapDesc = std::pair<std::string, unsigned>;
187 NodeSpec(std::string
const& _addr, uint16_t _port,
int _udpPort = -1)
194 std::string
enode()
const;
218 explicit operator bool()
const {
return static_cast<bool>(
id); }
233 inline boost::log::formatting_ostream&
operator<<(boost::log::formatting_ostream& _strm,
Node const& _node) {
237 inline boost::log::formatting_ostream&
operator<<(boost::log::formatting_ostream& _strm,
Node& _node) {
238 auto const& constValue = _node;
248 inline boost::log::formatting_ostream&
operator<<(boost::log::formatting_ostream& _strm,
250 _strm << _peerSessionInfo.
id <<
"|" << _peerSessionInfo.
clientVersion <<
"|" << _peerSessionInfo.
host <<
"|"
251 << _peerSessionInfo.
port <<
"|";
252 for (
auto const& cap : _peerSessionInfo.
caps) _strm <<
"(" << cap.first <<
"," << cap.second <<
")";
262 #if !defined(BOOST_ASIO_HAS_STD_HASH)
265 struct hash<bi::address> {
267 if (_a.is_v4())
return std::hash<unsigned long>()(_a.to_v4().to_ulong());
269 auto const& range = _a.to_v6().to_bytes();
270 return boost::hash_range(range.begin(), range.end());
272 if (_a.is_unspecified())
273 return static_cast<size_t>(0x3487194039229152ull);
275 return std::hash<std::string>()(_a.to_string());
std::string abridged() const
Definition: FixedHash.h:167
Class for writing to an RLP bytestream.
Definition: RLP.h:484
Node(Node const &)
Definition: Common.cpp:148
std::atomic< PeerType > peerType
Definition: Common.h:229
std::atomic< uint16_t > external_udp_port
Definition: Common.h:230
Node(Public _publicKey, NodeIPEndpoint const &_ip, PeerType _peerType=PeerType::Optional)
Definition: Common.h:209
NodeID const id
Definition: Common.h:221
NodeID const & address() const
Definition: Common.h:213
std::shared_mutex endpoint_mu_
Definition: Common.h:225
void set_endpoint(NodeIPEndpoint endpoint)
Definition: Common.cpp:158
NodeIPEndpoint endpoint_
Definition: Common.h:224
NodeIPEndpoint get_endpoint() const
Definition: Common.cpp:153
IPv4,UDP/TCP endpoints.
Definition: Common.h:140
void setUdpPort(uint16_t _udp)
Definition: Common.h:168
void interpretRLP(RLP const &_r)
Definition: Common.cpp:137
uint16_t tcpPort() const
Definition: Common.h:170
void streamRLP(RLPStream &_s, RLPAppend _append=StreamList) const
Definition: Common.cpp:126
void setAddress(bi::address _addr)
Definition: Common.h:164
bool operator!=(NodeIPEndpoint const &_cmp) const
Definition: Common.h:157
uint16_t m_udpPort
Definition: Common.h:176
uint16_t udpPort() const
Definition: Common.h:166
NodeIPEndpoint(RLP const &_r)
Definition: Common.h:147
bi::address m_address
Definition: Common.h:175
void setTcpPort(uint16_t _tcp)
Definition: Common.h:172
RLPAppend
Definition: Common.h:142
@ StreamList
Definition: Common.h:142
@ StreamInline
Definition: Common.h:142
bi::address address() const
Definition: Common.h:162
NodeIPEndpoint(bi::address _addr, uint16_t _udp, uint16_t _tcp)
Definition: Common.h:145
bool operator==(NodeIPEndpoint const &_cmp) const
Definition: Common.h:154
uint16_t m_tcpPort
Definition: Common.h:177
#define NET_GLOBAL_LOGGER(NAME, SEVERITY)
Definition: Common.h:69
std::vector< CapDesc > CapDescs
Definition: Common.h:117
std::string clientVersion
Definition: Common.h:126
ostream & operator<<(ostream &_out, NodeIPEndpoint const &_ep)
Definition: Common.cpp:205
HandshakeFailureReason
Definition: Common.h:105
std::set< CapDesc > caps
Definition: Common.h:130
std::string host
Definition: Common.h:127
NodeID id
Definition: Common.h:125
std::pair< std::string, unsigned > CapDesc
Definition: Common.h:116
std::chrono::steady_clock::duration lastPing
Definition: Common.h:129
std::vector< PeerSessionInfo > PeerSessionInfos
Definition: Common.h:133
bool isLocalHostAddress(bi::address const &_addressToCheck)
Definition: Common.cpp:77
const Node UnspecifiedNode
Definition: Common.cpp:17
bool isPublicAddress(string const &_addressToCheck)
Definition: Common.cpp:34
constexpr unsigned c_protocolVersion
Peer network protocol version.
Definition: Common.h:40
string reasonOf(DisconnectReason _r)
Definition: Common.cpp:93
char const * p2pPacketTypeToString(P2pPacketType _packetType)
Definition: Common.cpp:19
bool isPrivateAddress(bi::address const &_addressToCheck)
Definition: Common.cpp:52
unsigned short port
Definition: Common.h:128
bool isAllowedEndpoint(bool _allowLocalDiscovery, NodeIPEndpoint const &_endpointToCheck)
Definition: Common.cpp:46
DisconnectReason
Definition: Common.h:85
@ NoDisconnect
Definition: Common.h:99
@ UserReason
Definition: Common.h:98
@ LocalIdentity
Definition: Common.h:96
@ DisconnectRequested
Definition: Common.h:86
@ DuplicatePeer
Definition: Common.h:91
@ PingTimeout
Definition: Common.h:97
@ IncompatibleProtocol
Definition: Common.h:92
@ UnexpectedIdentity
Definition: Common.h:95
@ ClientQuit
Definition: Common.h:94
@ TCPError
Definition: Common.h:87
@ TooManyPeers
Definition: Common.h:90
@ NullIdentity
Definition: Common.h:93
@ UselessPeer
Definition: Common.h:89
@ BadProtocol
Definition: Common.h:88
P2pPacketType
Definition: Common.h:81
@ UserPacket
Definition: Common.h:81
@ PongPacket
Definition: Common.h:81
@ PingPacket
Definition: Common.h:81
@ DisconnectPacket
Definition: Common.h:81
@ HelloPacket
Definition: Common.h:81
bool isAllowedAddress(bool _allowLocalDiscovery, bi::address const &_addressToCheck)
Definition: Common.cpp:42
PeerType
Definition: Common.h:135
const NodeIPEndpoint UnspecifiedNodeIPEndpoint
Definition: Common.cpp:16
@ VerbosityInfo
Definition: Log.h:48
@ VerbosityDebug
Definition: Log.h:49
@ VerbosityTrace
Definition: Log.h:50
FixedHash< 64 > h512
Definition: FixedHash.h:452
std::hash for asio::adress
Definition: FixedHash.h:483
Base class for all exceptions.
Definition: Exceptions.h:21
The ECDHE agreement failed during RLPx handshake.
Definition: Common.h:67
The Host class Capabilities should be registered prior to startNetwork, since m_capabilities is not t...
Definition: Host.h:69
bool isValid() const
Definition: Common.cpp:203
NodeID id() const
Definition: Common.h:190
NodeIPEndpoint nodeIPEndpoint() const
Definition: Common.cpp:185
NodeID m_id
Definition: Common.h:202
uint16_t m_tcpPort
Definition: Common.h:200
NodeSpec(std::string const &_user)
std::string enode() const
Definition: Common.cpp:189
NodeSpec()
Definition: Common.h:181
NodeSpec(std::string const &_addr, uint16_t _port, int _udpPort=-1)
Definition: Common.h:187
std::string m_address
Definition: Common.h:199
uint16_t m_udpPort
Definition: Common.h:201
The Session class.
Definition: Session.h:32
size_t operator()(bi::address const &_a) const
Definition: Common.h:266