|
|
@ -52,9 +52,10 @@ static const set<bi::address> c_rejectAddresses = { |
|
|
|
{bi::address_v6::from_string("::")} |
|
|
|
}; |
|
|
|
|
|
|
|
PeerHost::PeerHost(std::string const& _clientVersion, unsigned short _port, string const& _publicAddress, bool _upnp): |
|
|
|
PeerHost::PeerHost(std::string const& _clientVersion, unsigned short _port, string const& _publicAddress, bool _upnp, bool _localNetworking): |
|
|
|
m_clientVersion(_clientVersion), |
|
|
|
m_listenPort(_port), |
|
|
|
m_localNetworking(_localNetworking), |
|
|
|
m_acceptor(m_ioService, bi::tcp::endpoint(bi::tcp::v4(), _port)), |
|
|
|
m_socket(m_ioService), |
|
|
|
m_key(KeyPair::create()) |
|
|
@ -63,12 +64,13 @@ PeerHost::PeerHost(std::string const& _clientVersion, unsigned short _port, stri |
|
|
|
determinePublic(_publicAddress, _upnp); |
|
|
|
ensureAccepting(); |
|
|
|
m_lastPeersRequest = chrono::steady_clock::time_point::min(); |
|
|
|
clog(NetNote) << "Id:" << toHex(m_key.address().ref().cropped(0, 4)); |
|
|
|
clog(NetNote) << "Id:" << m_key.address().abridged(); |
|
|
|
} |
|
|
|
|
|
|
|
PeerHost::PeerHost(std::string const& _clientVersion, string const& _publicAddress, bool _upnp): |
|
|
|
PeerHost::PeerHost(std::string const& _clientVersion, string const& _publicAddress, bool _upnp, bool _localNetworking): |
|
|
|
m_clientVersion(_clientVersion), |
|
|
|
m_listenPort(0), |
|
|
|
m_localNetworking(_localNetworking), |
|
|
|
m_acceptor(m_ioService, bi::tcp::endpoint(bi::tcp::v4(), 0)), |
|
|
|
m_socket(m_ioService), |
|
|
|
m_key(KeyPair::create()) |
|
|
@ -80,7 +82,7 @@ PeerHost::PeerHost(std::string const& _clientVersion, string const& _publicAddre |
|
|
|
determinePublic(_publicAddress, _upnp); |
|
|
|
ensureAccepting(); |
|
|
|
m_lastPeersRequest = chrono::steady_clock::time_point::min(); |
|
|
|
clog(NetNote) << "Id:" << toHex(m_key.address().ref().cropped(0, 4)); |
|
|
|
clog(NetNote) << "Id:" << m_key.address().abridged(); |
|
|
|
} |
|
|
|
|
|
|
|
PeerHost::PeerHost(std::string const& _clientVersion): |
|
|
@ -93,7 +95,7 @@ PeerHost::PeerHost(std::string const& _clientVersion): |
|
|
|
// populate addresses.
|
|
|
|
populateAddresses(); |
|
|
|
m_lastPeersRequest = chrono::steady_clock::time_point::min(); |
|
|
|
clog(NetNote) << "Id:" << toHex(m_key.address().ref().cropped(0, 4)); |
|
|
|
clog(NetNote) << "Id:" << m_key.address().abridged(); |
|
|
|
} |
|
|
|
|
|
|
|
PeerHost::~PeerHost() |
|
|
@ -164,14 +166,14 @@ void PeerHost::determinePublic(string const& _publicAddress, bool _upnp) |
|
|
|
bi::tcp::resolver r(m_ioService); |
|
|
|
if (m_upnp && m_upnp->isValid() && m_peerAddresses.size()) |
|
|
|
{ |
|
|
|
clog(NetNote) << "External addr: " << m_upnp->externalIP(); |
|
|
|
clog(NetNote) << "External addr:" << m_upnp->externalIP(); |
|
|
|
int p = m_upnp->addRedirect(m_peerAddresses[0].to_string().c_str(), m_listenPort); |
|
|
|
if (p) |
|
|
|
clog(NetNote) << "Punched through NAT and mapped local port" << m_listenPort << "onto external port" << p << "."; |
|
|
|
else |
|
|
|
{ |
|
|
|
// couldn't map
|
|
|
|
clog(NetWarn) << "Couldn't punch through NAT (or no NAT in place). Assuming " << m_listenPort << " is local & external port."; |
|
|
|
clog(NetWarn) << "Couldn't punch through NAT (or no NAT in place). Assuming" << m_listenPort << "is local & external port."; |
|
|
|
p = m_listenPort; |
|
|
|
} |
|
|
|
|
|
|
@ -280,7 +282,7 @@ std::map<Public, bi::tcp::endpoint> PeerHost::potentialPeers() |
|
|
|
{ |
|
|
|
auto ep = j->endpoint(); |
|
|
|
// Skip peers with a listen port of zero or are on a private network
|
|
|
|
bool peerOnNet = (j->m_listenPort != 0 && !isPrivateAddress(ep.address())); |
|
|
|
bool peerOnNet = (j->m_listenPort != 0 && (!isPrivateAddress(ep.address()) || m_localNetworking)); |
|
|
|
if (peerOnNet && ep.port() && j->m_id) |
|
|
|
ret.insert(make_pair(i.first, ep)); |
|
|
|
} |
|
|
|