Browse Source

fix neth. fix issue w/udp listening to 30303.

cl-refactor
subtly 10 years ago
parent
commit
88fa483055
  1. 9
      libp2p/Host.cpp
  2. 4
      libp2p/Host.h
  3. 34
      libp2p/Network.h
  4. 2
      neth/main.cpp

9
libp2p/Host.cpp

@ -316,12 +316,12 @@ void Host::determinePublic()
ep = Network::traverseNAT(ifAddresses, m_netPrefs.listenPort, natIFAddr);
if (lset && natIFAddr != laddr)
// if listen address is set we use it, even if upnp returns different
// if listen address is set, Host will use it, even if upnp returns different
clog(NetWarn) << "Listen address" << laddr << "differs from local address" << natIFAddr << "returned by UPnP!";
if (pset && ep.address() != paddr)
{
// if public address is set we advertise it, even if upnp returns different
// if public address is set, Host will advertise it, even if upnp returns different
clog(NetWarn) << "Specified public address" << paddr << "differs from external address" << ep.address() << "returned by UPnP!";
ep.address(paddr);
}
@ -635,10 +635,9 @@ void Host::startedWorking()
runAcceptor();
}
else
clog(NetNote) << "p2p.start.notice id:" << id().abridged() << "Listen port is invalid or unavailable. Node Table using default port (30303).";
clog(NetNote) << "p2p.start.notice id:" << id().abridged() << "TCP Listen port is invalid or unavailable.";
// this doesn't work unless local-networking is enabled because the port is -1
m_nodeTable.reset(new NodeTable(m_ioService, m_alias, bi::address::from_string(listenAddress()), listenPort() > 0 ? listenPort() : 30303));
m_nodeTable.reset(new NodeTable(m_ioService, m_alias, bi::address::from_string(listenAddress()), listenPort()));
m_nodeTable->setEventHandler(new HostNodeTableHandler(*this));
restoreNetwork(&m_restoreNetwork);

4
libp2p/Host.h

@ -124,10 +124,10 @@ public:
size_t peerCount() const;
/// Get the address we're listening on currently.
std::string listenAddress() const { return m_tcpPublic.address().to_string(); }
std::string listenAddress() const { return m_netPrefs.listenIPAddress.empty() ? "0.0.0.0" : m_netPrefs.listenIPAddress; }
/// Get the port we're listening on currently.
unsigned short listenPort() const { return m_tcpPublic.port(); }
unsigned short listenPort() const { return m_netPrefs.listenPort; }
/// Serialise the set of known peers.
bytes saveNetwork() const;

34
libp2p/Network.h

@ -37,7 +37,22 @@ namespace dev
namespace p2p
{
struct NetworkPreferences;
struct NetworkPreferences
{
// Default Network Preferences
NetworkPreferences(unsigned short lp = 30303): listenPort(lp) {}
// Network Preferences with specific Listen IP
NetworkPreferences(std::string l, unsigned short lp = 30303, bool u = true): publicIPAddress(), listenIPAddress(l), listenPort(lp), traverseNAT(u) {}
// Network Preferences with intended Public IP
NetworkPreferences(std::string publicIP, std::string l = std::string(), unsigned short lp = 30303, bool u = true): publicIPAddress(publicIP), listenIPAddress(l), listenPort(lp), traverseNAT(u) { if (!publicIPAddress.empty() && !isPublicAddress(publicIPAddress)) BOOST_THROW_EXCEPTION(InvalidPublicIPAddress()); }
std::string publicIPAddress;
std::string listenIPAddress;
unsigned short listenPort = 30303;
bool traverseNAT = true;
};
/**
* @brief Network Class
@ -59,22 +74,5 @@ public:
static bi::tcp::endpoint resolveHost(ba::io_service& _ioService, std::string const& _host);
};
struct NetworkPreferences
{
// Default Network Preferences
NetworkPreferences(unsigned short lp = 30303): listenPort(lp) {}
// Network Preferences with specific Listen IP
NetworkPreferences(std::string l, unsigned short lp = 30303, bool u = true): publicIPAddress(), listenIPAddress(l), listenPort(lp), traverseNAT(u) {}
// Network Preferences with intended Public IP
NetworkPreferences(std::string publicIP, std::string l = std::string(), unsigned short lp = 30303, bool u = true): publicIPAddress(publicIP), listenIPAddress(l), listenPort(lp), traverseNAT(u) { if (!publicIPAddress.empty() && !isPublicAddress(publicIPAddress)) BOOST_THROW_EXCEPTION(InvalidPublicIPAddress()); }
std::string publicIPAddress;
std::string listenIPAddress;
unsigned short listenPort = 30303;
bool traverseNAT = true;
};
}
}

2
neth/main.cpp

@ -544,7 +544,7 @@ int main(int argc, char** argv)
StructuredLogger::get().initialize(structuredLogging, structuredLoggingFormat);
VMFactory::setKind(jit ? VMKind::JIT : VMKind::Interpreter);
NetworkPreferences netPrefs(publicIP, listenIP ,listenPort, upnp);
auto netPrefs = publicIP.empty() ? NetworkPreferences(listenIP ,listenPort, upnp) : NetworkPreferences(publicIP, listenIP ,listenPort, upnp);
auto nodesState = contents((dbPath.size() ? dbPath : getDataDir()) + "/network.rlp");
std::string clientImplString = "NEthereum(++)/" + clientName + "v" + dev::Version + "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM) + (jit ? "/JIT" : "");
dev::WebThreeDirect web3(

Loading…
Cancel
Save