Browse Source

Allow UPnP to be disabled.

cl-refactor
Gav Wood 11 years ago
parent
commit
6fb35aa0f1
  1. 20
      TODO
  2. 16
      eth/main.cpp
  3. 4
      libethereum/Client.cpp
  4. 2
      libethereum/Client.h
  5. 4
      libethereum/Common.cpp
  6. 25
      libethereum/PeerNetwork.cpp
  7. 4
      libethereum/PeerNetwork.h

20
TODO

@ -10,13 +10,14 @@ Crypto stuff:
Better handling of corrupt blocks.
Network:
- Firewall-busting PeerConnections. UPnP?
- Crypto on network. TLS?
- Make work with IPv6
- Consider node addresses
CLI client
- Implement CLI option "--help".
- UPnP should be disablable.
- Should also attempt random port usage.
General:
- Better logging.
@ -25,20 +26,29 @@ General:
### GAV
FOR ALPHA:
For PoC2:
Ubuntu builds
- Raring (branch, local, x64 only :-( )
- Quantal (branch) (Launchpad)
- Saucy (master) (Launchpad)
Server
- Get PoC-2 running on dev server ready for switchover on release.
- Or just run on release @30300?
Network:
* NotInChain will be very bad for new peers - it'll run through until the genesis.
- NotInChain will be very bad for new peers - it'll run through until the genesis.
- Check how many it has first.
UI:
* State panel shouldn't show pending (i.e. post-mined) transactions.
- State panel shouldn't show pending (i.e. post-mined) transactions.
### ERIC
Build:
* Windows build.
- Windows build.
LATER:

16
eth/main.cpp

@ -60,6 +60,7 @@ int main(int argc, char** argv)
NodeMode mode = NodeMode::Full;
unsigned peers = 5;
string publicIP;
bool upnp = true;
// Our address.
KeyPair us = KeyPair::create();
@ -91,6 +92,19 @@ int main(int argc, char** argv)
remoteHost = argv[++i];
else if ((arg == "-p" || arg == "--port") && i + 1 < argc)
remotePort = atoi(argv[++i]);
else if ((arg == "-n" || arg == "--upnp") && i + 1 < argc)
{
string m = argv[++i];
if (m == "on")
upnp = true;
else if (m == "off")
upnp = false;
else
{
cerr << "Invalid UPnP option: " << argv[i] << endl;
return -1;
}
}
else if ((arg == "-a" || arg == "--address" || arg == "--coinbase-address") && i + 1 < argc)
coinbase = h160(fromUserHex(argv[++i]));
else if ((arg == "-s" || arg == "--secret") && i + 1 < argc)
@ -188,7 +202,7 @@ int main(int argc, char** argv)
}
else
{
c.startNetwork(listenPort, remoteHost, remotePort, verbosity, mode, peers, publicIP);
c.startNetwork(listenPort, remoteHost, remotePort, verbosity, mode, peers, publicIP, upnp);
eth::uint n = c.blockChain().details().number;
while (true)
{

4
libethereum/Client.cpp

@ -50,11 +50,11 @@ Client::~Client()
usleep(10000);
}
void Client::startNetwork(short _listenPort, std::string const& _seedHost, short _port, unsigned _verbosity, NodeMode _mode, unsigned _peers, string const& _publicIP)
void Client::startNetwork(short _listenPort, std::string const& _seedHost, short _port, unsigned _verbosity, NodeMode _mode, unsigned _peers, string const& _publicIP, bool _upnp)
{
if (m_net)
return;
m_net = new PeerServer(m_clientVersion, m_bc, 0, _listenPort, _mode, _publicIP);
m_net = new PeerServer(m_clientVersion, m_bc, 0, _listenPort, _mode, _publicIP, _upnp);
m_net->setIdealPeerCount(_peers);
m_net->setVerbosity(_verbosity);
if (_seedHost.size())

2
libethereum/Client.h

@ -60,7 +60,7 @@ public:
std::vector<PeerInfo> peers() { return m_net ? m_net->peers() : std::vector<PeerInfo>(); }
unsigned peerCount() const { return m_net ? m_net->peerCount() : 0; }
void startNetwork(short _listenPort = 30303, std::string const& _seedHost = std::string(), short _port = 30303, unsigned _verbosity = 4, NodeMode _mode = NodeMode::Full, unsigned _peers = 5, std::string const& _publicIP = std::string());
void startNetwork(short _listenPort = 30303, std::string const& _seedHost = std::string(), short _port = 30303, unsigned _verbosity = 4, NodeMode _mode = NodeMode::Full, unsigned _peers = 5, std::string const& _publicIP = std::string(), bool _upnp = true);
void connect(std::string const& _seedHost, short _port = 30303);
void stopNetwork();

4
libethereum/Common.cpp

@ -37,9 +37,9 @@ using namespace std;
using namespace eth;
#if NDEBUG
u256 const eth::c_genesisDifficulty = (u256)1 << 32;
u256 const eth::c_genesisDifficulty = (u256)1 << 22;
#else
u256 const eth::c_genesisDifficulty = (u256)1 << 32; // should be << 32
u256 const eth::c_genesisDifficulty = (u256)1 << 22;
#endif
std::string eth::escaped(std::string const& _s, bool _all)

25
libethereum/PeerNetwork.cpp

@ -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)

4
libethereum/PeerNetwork.h

@ -125,7 +125,7 @@ class PeerServer
public:
/// Start server, listening for connections on the given port.
PeerServer(std::string const& _clientVersion, BlockChain const& _ch, uint _networkId, short _port, NodeMode _m = NodeMode::Full, std::string const& _publicAddress = std::string());
PeerServer(std::string const& _clientVersion, BlockChain const& _ch, uint _networkId, short _port, NodeMode _m = NodeMode::Full, std::string const& _publicAddress = std::string(), bool _upnp = true);
/// Start server, but don't listen.
PeerServer(std::string const& _clientVersion, uint _networkId);
~PeerServer();
@ -161,7 +161,7 @@ public:
private:
void seal(bytes& _b);
void populateAddresses();
void determinePublic(std::string const& _publicAddress);
void determinePublic(std::string const& _publicAddress, bool _upnp);
void ensureAccepting();
std::vector<bi::tcp::endpoint> potentialPeers();

Loading…
Cancel
Save