Browse Source

Merge branch 'nethosts' into netFix

cl-refactor
subtly 10 years ago
parent
commit
085a0b27ad
  1. 22
      eth/main.cpp
  2. 4
      libp2p/Host.cpp
  3. 20
      libp2p/Host.h
  4. 8
      libp2p/Network.h
  5. 5
      libwebthree/WebThree.cpp
  6. 3
      libwebthree/WebThree.h

22
eth/main.cpp

@ -170,7 +170,9 @@ void help()
<< "Client networking:" << endl << "Client networking:" << endl
<< " --client-name <name> Add a name to your client's version string (default: blank)." << endl << " --client-name <name> Add a name to your client's version string (default: blank)." << endl
<< " -b,--bootstrap Connect to the default Ethereum peerserver." << endl << " -b,--bootstrap Connect to the default Ethereum peerserver." << endl
<< " -x,--peers <number> Attempt to connect to given number of peers (default: 5)." << endl << " -x,--peers <number> Attempt to connect to given number of peers (default: 11)." << endl
<< " --peer-stretch <number> Accepted connection multiplier (default: 7)." << endl
<< " --public-ip <ip> Force public ip to given (default: auto)." << endl << " --public-ip <ip> Force public ip to given (default: auto)." << endl
<< " --listen-ip <ip>(:<port>) Listen on the given IP for incoming connections (default: 0.0.0.0)." << endl << " --listen-ip <ip>(:<port>) Listen on the given IP for incoming connections (default: 0.0.0.0)." << endl
<< " --listen <port> Listen on the given port for incoming connections (default: 30303)." << endl << " --listen <port> Listen on the given port for incoming connections (default: 30303)." << endl
@ -178,11 +180,17 @@ void help()
<< " --port <port> Connect to remote port (default: 30303)." << endl << " --port <port> Connect to remote port (default: 30303)." << endl
<< " --network-id <n> Only connect to other hosts with this network id." << endl << " --network-id <n> Only connect to other hosts with this network id." << endl
<< " --upnp <on/off> Use UPnP for NAT (default: on)." << endl << " --upnp <on/off> Use UPnP for NAT (default: on)." << endl
// << " --peers <filename> Text list of type publickey@host[:port] (default: network)" << endl
// << " Types:" << endl
// << " default Attempt connection when no other peers are available and pinning is disable." << endl
// << " trusted Keep connected at all times." << endl
// << " --trust-peers <filename> Text list of publickeys." << endl
<< " --no-discovery Disable Node discovery." << endl << " --no-discovery Disable Node discovery." << endl
<< " --pin Only connect to required (trusted) peers." << endl << " --pin Only accept or connect to trusted peers." << endl
<< " --hermit Equivalent to --no-discovery --pin." << endl << " --hermit Equivalent to --no-discovery --pin." << endl
<< " --sociable Forces discovery and no pinning." << endl << " --sociable Forces discovery and no pinning." << endl
// << " --require-peers <peers.json> List of required (trusted) peers. (experimental)" << endl
<< endl; << endl;
MinerCLI::streamHelp(cout); MinerCLI::streamHelp(cout);
cout cout
@ -1123,7 +1131,10 @@ int main(int argc, char** argv)
string publicIP; string publicIP;
string remoteHost; string remoteHost;
unsigned short remotePort = 30303; unsigned short remotePort = 30303;
unsigned peers = 11;
HostPeerPreferences hprefs;
unsigned peers = hprefs.idealPeerCount;
unsigned peerStretch = hprefs.stretchPeerCount;
bool bootstrap = false; bool bootstrap = false;
bool disableDiscovery = false; bool disableDiscovery = false;
bool pinning = false; bool pinning = false;
@ -1480,6 +1491,8 @@ int main(int argc, char** argv)
g_logVerbosity = atoi(argv[++i]); g_logVerbosity = atoi(argv[++i]);
else if ((arg == "-x" || arg == "--peers") && i + 1 < argc) else if ((arg == "-x" || arg == "--peers") && i + 1 < argc)
peers = atoi(argv[++i]); peers = atoi(argv[++i]);
else if ((arg == "-x" || arg == "--peer-stretch") && i + 1 < argc)
peerStretch = atoi(argv[++i]);
else if ((arg == "-o" || arg == "--mode") && i + 1 < argc) else if ((arg == "-o" || arg == "--mode") && i + 1 < argc)
{ {
string m = argv[++i]; string m = argv[++i];
@ -1766,6 +1779,7 @@ int main(int argc, char** argv)
cout << ethCredits(); cout << ethCredits();
web3.setIdealPeerCount(peers); web3.setIdealPeerCount(peers);
web3.private_setPeerStretch(peerStretch);
// std::shared_ptr<eth::BasicGasPricer> gasPricer = make_shared<eth::BasicGasPricer>(u256(double(ether / 1000) / etherPrice), u256(blockFees * 1000)); // std::shared_ptr<eth::BasicGasPricer> gasPricer = make_shared<eth::BasicGasPricer>(u256(double(ether / 1000) / etherPrice), u256(blockFees * 1000));
std::shared_ptr<eth::TrivialGasPricer> gasPricer = make_shared<eth::TrivialGasPricer>(askPrice, bidPrice); std::shared_ptr<eth::TrivialGasPricer> gasPricer = make_shared<eth::TrivialGasPricer>(askPrice, bidPrice);
eth::Client* c = nodeMode == NodeMode::Full ? web3.ethereum() : nullptr; eth::Client* c = nodeMode == NodeMode::Full ? web3.ethereum() : nullptr;

4
libp2p/Host.cpp

@ -283,7 +283,7 @@ void Host::startPeerSession(Public const& _id, RLP const& _rlp, RLPXFrameCoder*
return; return;
} }
if (!peerSlotsAvailable(Ingress)) if (!peerSlotsAvailable())
{ {
ps->disconnect(TooManyPeers); ps->disconnect(TooManyPeers);
return; return;
@ -405,7 +405,7 @@ void Host::runAcceptor()
socket->close(); socket->close();
return; return;
} }
if (peerCount() > Ingress * m_idealPeerCount) if (peerCount() > peerSlots(Ingress))
{ {
clog(NetConnect) << "Dropping incoming connect due to maximum peer count (" << Ingress << " * ideal peer count): " << socket->remoteEndpoint(); clog(NetConnect) << "Dropping incoming connect due to maximum peer count (" << Ingress << " * ideal peer count): " << socket->remoteEndpoint();
socket->close(); socket->close();

20
libp2p/Host.h

@ -119,6 +119,16 @@ struct NodeInfo
std::string version; std::string version;
}; };
struct HostPeerPreferences
{
unsigned const idealPeerCount = 11; // Ideal number of peers to be connected to.
unsigned const stretchPeerCount = 7; // Accepted connection multiplier (max peers = ideal*stretch).
// std::list<NodeId> const defaultPeers;
// std::list<NodeId> const requiredPeers;
// std::list<NodeId> const trusted;
};
/** /**
* @brief The Host class * @brief The Host class
* Capabilities should be registered prior to startNetwork, since m_capabilities is not thread-safe. * Capabilities should be registered prior to startNetwork, since m_capabilities is not thread-safe.
@ -173,6 +183,9 @@ public:
/// Set ideal number of peers. /// Set ideal number of peers.
void setIdealPeerCount(unsigned _n) { m_idealPeerCount = _n; } void setIdealPeerCount(unsigned _n) { m_idealPeerCount = _n; }
/// Set multipier for max accepted connections.
void setPeerStretch(unsigned _n) { m_stretchPeers = _n; }
/// Get peer information. /// Get peer information.
PeerSessionInfos peerSessionInfo() const; PeerSessionInfos peerSessionInfo() const;
@ -236,7 +249,9 @@ protected:
void restoreNetwork(bytesConstRef _b); void restoreNetwork(bytesConstRef _b);
private: private:
enum PeerSlotRatio { Egress = 1, Ingress = 4 }; enum PeerSlotType { Egress, Ingress };
unsigned peerSlots(PeerSlotType _type) { return _type == Egress ? m_idealPeerCount : m_idealPeerCount * m_stretchPeers; }
bool havePeerSession(NodeId const& _id) { return !!peerSession(_id); } bool havePeerSession(NodeId const& _id) { return !!peerSession(_id); }
@ -246,7 +261,7 @@ private:
void connect(std::shared_ptr<Peer> const& _p); void connect(std::shared_ptr<Peer> const& _p);
/// Returns true if pending and connected peer count is less than maximum /// Returns true if pending and connected peer count is less than maximum
bool peerSlotsAvailable(PeerSlotRatio _type) { Guard l(x_pendingNodeConns); return peerCount() + m_pendingPeerConns.size() < _type * m_idealPeerCount; } bool peerSlotsAvailable(PeerSlotType _type = Ingress) { Guard l(x_pendingNodeConns); return peerCount() + m_pendingPeerConns.size() < peerSlots(_type); }
/// Ping the peers to update the latency information and disconnect peers which have timed out. /// Ping the peers to update the latency information and disconnect peers which have timed out.
void keepAlivePeers(); void keepAlivePeers();
@ -314,6 +329,7 @@ private:
Mutex x_connecting; ///< Mutex for m_connecting. Mutex x_connecting; ///< Mutex for m_connecting.
unsigned m_idealPeerCount = 11; ///< Ideal number of peers to be connected to. unsigned m_idealPeerCount = 11; ///< Ideal number of peers to be connected to.
unsigned m_stretchPeers = 7; ///< Accepted connection multiplier (max peers = ideal*stretch).
std::map<CapDesc, std::shared_ptr<HostCapabilityFace>> m_capabilities; ///< Each of the capabilities we support. std::map<CapDesc, std::shared_ptr<HostCapabilityFace>> m_capabilities; ///< Each of the capabilities we support.

8
libp2p/Network.h

@ -48,12 +48,18 @@ struct NetworkPreferences
// Network Preferences with intended Public IP // Network Preferences with intended Public IP
NetworkPreferences(std::string const& publicIP, std::string const& 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()); } NetworkPreferences(std::string const& publicIP, std::string const& 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()); }
/// Addressing
std::string publicIPAddress; std::string publicIPAddress;
std::string listenIPAddress; std::string listenIPAddress;
unsigned short listenPort = 30303; unsigned short listenPort = 30303;
/// Preferences
bool traverseNAT = true; bool traverseNAT = true;
bool discovery = true; // Discovery is activated with network. bool discovery = true; // Discovery is activated with network.
bool pin = false; // Only connect to trusted ("required") peers. bool pin = false; // Only accept or connect to trusted peers.
}; };
/** /**

5
libwebthree/WebThree.cpp

@ -118,6 +118,11 @@ void WebThreeDirect::setIdealPeerCount(size_t _n)
return m_net.setIdealPeerCount(_n); return m_net.setIdealPeerCount(_n);
} }
void WebThreeDirect::private_setPeerStretch(size_t _n)
{
return m_net.setPeerStretch(_n);
}
bytes WebThreeDirect::saveNetwork() bytes WebThreeDirect::saveNetwork()
{ {
return m_net.saveNetwork(); return m_net.saveNetwork();

3
libwebthree/WebThree.h

@ -171,6 +171,9 @@ public:
/// Sets the ideal number of peers. /// Sets the ideal number of peers.
void setIdealPeerCount(size_t _n) override; void setIdealPeerCount(size_t _n) override;
/// Sets ceiling for incoming connections to multiple of ideal peer count.
void private_setPeerStretch(size_t _n);
bool haveNetwork() const override { return m_net.haveNetwork(); } bool haveNetwork() const override { return m_net.haveNetwork(); }
p2p::NetworkPreferences const& networkPreferences() const override; p2p::NetworkPreferences const& networkPreferences() const override;

Loading…
Cancel
Save