|
|
@ -677,7 +677,7 @@ struct UPnP |
|
|
|
|
|
|
|
class NoNetworking: public std::exception {}; |
|
|
|
|
|
|
|
PeerServer::PeerServer(std::string const& _clientVersion, BlockChain const& _ch, uint _networkId, short _port, NodeMode _m, string const& _publicAddress): |
|
|
|
PeerServer::PeerServer(std::string const& _clientVersion, BlockChain const& _ch, uint _networkId, short _port, NodeMode _m, string const& _publicAddress, bool _upnp): |
|
|
|
m_clientVersion(_clientVersion), |
|
|
|
m_mode(_m), |
|
|
|
m_listenPort(_port), |
|
|
@ -687,7 +687,7 @@ PeerServer::PeerServer(std::string const& _clientVersion, BlockChain const& _ch, |
|
|
|
m_requiredNetworkId(_networkId) |
|
|
|
{ |
|
|
|
populateAddresses(); |
|
|
|
determinePublic(_publicAddress); |
|
|
|
determinePublic(_publicAddress, _upnp); |
|
|
|
ensureAccepting(); |
|
|
|
if (m_verbosity) |
|
|
|
cout << "Mode: " << (_m == NodeMode::PeerServer ? "PeerServer" : "Full") << endl; |
|
|
@ -714,12 +714,14 @@ PeerServer::~PeerServer() |
|
|
|
delete m_upnp; |
|
|
|
} |
|
|
|
|
|
|
|
void PeerServer::determinePublic(string const& _publicAddress) |
|
|
|
void PeerServer::determinePublic(string const& _publicAddress, bool _upnp) |
|
|
|
{ |
|
|
|
m_upnp = new UPnP; |
|
|
|
if (m_upnp->isValid() && m_peerAddresses.size()) |
|
|
|
if (_upnp) |
|
|
|
m_upnp = new UPnP; |
|
|
|
|
|
|
|
bi::tcp::resolver r(m_ioService); |
|
|
|
if (m_upnp && m_upnp->isValid() && m_peerAddresses.size()) |
|
|
|
{ |
|
|
|
bi::tcp::resolver r(m_ioService); |
|
|
|
cout << "external addr: " << m_upnp->externalIP() << endl; |
|
|
|
int p = m_upnp->addRedirect(m_peerAddresses[0].to_string().c_str(), m_listenPort); |
|
|
|
if (!p) |
|
|
@ -738,6 +740,17 @@ void PeerServer::determinePublic(string const& _publicAddress) |
|
|
|
m_addresses.push_back(m_public.address().to_v4()); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
// No UPnP - fallback on given public address or, if empty, the assumed peer address.
|
|
|
|
if (_publicAddress.size()) |
|
|
|
m_public = r.resolve({_publicAddress, toString(m_listenPort)})->endpoint(); |
|
|
|
else if (m_peerAddresses.size()) |
|
|
|
m_public = r.resolve({m_peerAddresses[0].to_string(), toString(m_listenPort)})->endpoint(); |
|
|
|
else |
|
|
|
m_public = bi::tcp::endpoint(bi::address(), m_listenPort); |
|
|
|
m_addresses.push_back(m_public.address().to_v4()); |
|
|
|
} |
|
|
|
/* int er;
|
|
|
|
UPNPDev* dlist = upnpDiscover(250, 0, 0, 0, 0, &er); |
|
|
|
for (UPNPDev* d = dlist; d; d = dlist->pNext) |
|
|
|