73 return _addressToCheck.empty() ?
false :
isPublicAddress(bi::address::from_string(_addressToCheck));
86 if (_addressToCheck.is_v4())
88 bi::address_v4 v4Address = _addressToCheck.to_v4();
89 bi::address_v4::bytes_type bytesToCheck = v4Address.to_bytes();
90 if (bytesToCheck[0] == 10 || bytesToCheck[0] == 127)
92 if (bytesToCheck[0] == 172 && (bytesToCheck[1] >= 16 && bytesToCheck[1] <= 31))
94 if (bytesToCheck[0] == 192 && bytesToCheck[1] == 168)
97 else if (_addressToCheck.is_v6())
99 bi::address_v6 v6Address = _addressToCheck.to_v6();
100 bi::address_v6::bytes_type bytesToCheck = v6Address.to_bytes();
101 if (bytesToCheck[0] == 0xfd && bytesToCheck[1] == 0)
103 if (!bytesToCheck[0] && !bytesToCheck[1] && !bytesToCheck[2] && !bytesToCheck[3] && !bytesToCheck[4] && !bytesToCheck[5] && !bytesToCheck[6] && !bytesToCheck[7]
104 && !bytesToCheck[8] && !bytesToCheck[9] && !bytesToCheck[10] && !bytesToCheck[11] && !bytesToCheck[12] && !bytesToCheck[13] && !bytesToCheck[14] && (bytesToCheck[15] == 0 || bytesToCheck[15] == 1))
112 return _addressToCheck.empty() ?
false :
isPrivateAddress(bi::address::from_string(_addressToCheck));
119 static const set<bi::address> c_rejectAddresses = {
120 {bi::address_v4::from_string(
"127.0.0.1")},
121 {bi::address_v4::from_string(
"0.0.0.0")},
122 {bi::address_v6::from_string(
"::1")},
123 {bi::address_v6::from_string(
"::")}
126 return find(c_rejectAddresses.begin(), c_rejectAddresses.end(), _addressToCheck) != c_rejectAddresses.end();
131 return _addressToCheck.empty() ?
false :
isLocalHostAddress(bi::address::from_string(_addressToCheck));
139 case TCPError:
return "Low-level TCP communication error.";
141 case UselessPeer:
return "Peer had no use for this node.";
142 case TooManyPeers:
return "Peer had too many connections.";
149 case UserReason:
return "Subprotocol reason.";
150 case NoDisconnect:
return "(No disconnect has happened.)";
151 default:
return "Unknown reason.";
157 if (_append == StreamList)
165 _s << udpPort << tcpPort;
168 void NodeIPEndpoint::interpretRLP(
RLP const& _r)
170 if (_r[0].
size() == 4)
171 address = bi::address_v4(*(bi::address_v4::bytes_type*)_r[0].toBytes().
data());
172 else if (_r[0].
size() == 16)
173 address = bi::address_v6(*(bi::address_v6::bytes_type*)_r[0].toBytes().
data());
176 udpPort = _r[1].
toInt<uint16_t>();
177 tcpPort = _r[2].
toInt<uint16_t>();
180 void DeadlineOps::reap()
186 std::vector<DeadlineOp>::iterator t = m_timers.begin();
187 while (t != m_timers.end())
191 t = m_timers.erase(t);
196 m_timers.emplace_back(m_io, m_reapIntervalMs, [
this](boost::system::error_code
const& ec)
198 if (!ec && !m_stopped)
205 endpoint(_s.nodeIPEndpoint()),
212 if (m_address.substr(0, 8) ==
"enode://" && m_address.find(
'@') == 136)
215 m_address = m_address.substr(137);
217 size_t colon = m_address.find_first_of(
":");
218 if (colon != string::npos)
220 string ports = m_address.substr(colon + 1);
221 m_address = m_address.substr(0, colon);
222 size_t p2 = ports.find_first_of(
".");
223 if (p2 != string::npos)
225 m_udpPort = stoi(ports.substr(p2 + 1));
226 m_tcpPort = stoi(ports.substr(0, p2));
229 m_tcpPort = m_udpPort = stoi(ports);
240 string ret = m_address;
243 if (m_udpPort && m_tcpPort != m_udpPort)
251 return "enode://" + m_id.hex() +
"@" + ret;
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
bool isPrivateAddress(bi::address const &_addressToCheck)
bool isLocalHostAddress(bi::address const &_addressToCheck)
bool isPublicAddress(bi::address const &_addressToCheck)
std::hash for asio::adress
const unsigned c_protocolVersion
Peer network protocol version.
std::string toString(string32 const &_s)
Make normal string from fixed-length string.
std::string reasonOf(DisconnectReason _r)
std::lock_guard< std::mutex > Guard
std::vector< byte > bytes
const Node UnspecifiedNode
vector_ref< byte const > bytesConstRef
RLPStream & appendList(size_t _items)
Appends a list.
NodeIPEndpoint nodeIPEndpoint() const
static bi::tcp::endpoint resolveHost(std::string const &_host)
Resolve "host:port" string as TCP endpoint. Returns unspecified endpoint on failure.
virtual NodeID const & address() const
uint8_t const size_t const size
const unsigned c_defaultIPPort
std::string enode() const
struct evm_uint160be address(struct evm_env *env)
std::ostream & operator<<(std::ostream &_out, NodeTable const &_nodeTable)
_T toInt(int _flags=Strict) const
Converts to int of type given; if isString(), decodes as big-endian bytestream.
Class for writing to an RLP bytestream.
const NodeIPEndpoint UnspecifiedNodeIPEndpoint
Class for interpreting Recursive Linear-Prefix Data.
static bool test_allowLocal
Setting true causes isAllowed to return true for all addresses. (Used by test fixtures) ...