Browse Source

update CLI and AZ UI for replacing local-networking with explicit --listen-ip

cl-refactor
subtly 10 years ago
parent
commit
bb261e553a
  1. 73
      alethzero/Main.ui
  2. 13
      alethzero/MainWin.cpp
  3. 19
      eth/main.cpp
  4. 6
      libp2p/Common.cpp
  5. 14
      libp2p/Network.h
  6. 1
      libp2p/Peer.h
  7. 24
      neth/main.cpp
  8. 6
      test/peer.cpp

73
alethzero/Main.ui

@ -118,7 +118,7 @@
<x>0</x>
<y>0</y>
<width>1617</width>
<height>24</height>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="menu_File">
@ -135,7 +135,6 @@
<addaction name="separator"/>
<addaction name="upnp"/>
<addaction name="usePast"/>
<addaction name="localNetworking"/>
<addaction name="net"/>
<addaction name="connect"/>
</widget>
@ -284,6 +283,26 @@
</widget>
<widget class="QWidget" name="layoutWidget">
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>&amp;Listen on</string>
</property>
<property name="buddy">
<cstring>port</cstring>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QSpinBox" name="idealPeers">
<property name="minimum">
<number>1</number>
</property>
<property name="value">
<number>5</number>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QSpinBox" name="port">
<property name="minimum">
@ -297,8 +316,18 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>&amp;Client Name</string>
</property>
<property name="buddy">
<cstring>clientName</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="forceAddress">
<widget class="QLineEdit" name="listenIP">
<property name="inputMask">
<string/>
</property>
@ -310,13 +339,10 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>&amp;Listen on</string>
</property>
<property name="buddy">
<cstring>port</cstring>
<item row="2" column="1" colspan="2">
<widget class="QLineEdit" name="clientName">
<property name="placeholderText">
<string>Anonymous</string>
</property>
</widget>
</item>
@ -330,30 +356,17 @@
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QSpinBox" name="idealPeers">
<property name="minimum">
<number>1</number>
</property>
<property name="value">
<number>5</number>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QLineEdit" name="clientName">
<item row="3" column="1">
<widget class="QLineEdit" name="forcePublicIP">
<property name="placeholderText">
<string>Anonymous</string>
<string>Automatic</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_4">
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>&amp;Client Name</string>
</property>
<property name="buddy">
<cstring>clientName</cstring>
<string>Public IP</string>
</property>
</widget>
</item>
@ -1694,7 +1707,7 @@ font-size: 14pt</string>
<tabstop>tabWidget</tabstop>
<tabstop>urlEdit</tabstop>
<tabstop>idealPeers</tabstop>
<tabstop>forceAddress</tabstop>
<tabstop>listenIP</tabstop>
<tabstop>port</tabstop>
<tabstop>clientName</tabstop>
<tabstop>transactionQueue</tabstop>

13
alethzero/MainWin.cpp

@ -251,7 +251,8 @@ void Main::addNewId(QString _ids)
NetworkPreferences Main::netPrefs() const
{
return NetworkPreferences(ui->port->value(), ui->forceAddress->text().toStdString(), ui->upnp->isChecked(), ui->localNetworking->isChecked());
return NetworkPreferences(ui->forcePublicIP->text().toStdString(), ui->listenIP->text().toStdString(), ui->port->value(), ui->upnp->isChecked());
// return NetworkPreferences(ui->port->value(), ui->forceAddress->text().toStdString(), ui->upnp->isChecked(), ui->localNetworking->isChecked());
}
void Main::onKeysChanged()
@ -675,9 +676,10 @@ void Main::writeSettings()
}
s.setValue("upnp", ui->upnp->isChecked());
s.setValue("forceAddress", ui->forceAddress->text());
#warning fixme
// s.setValue("forceAddress", ui->forceAddress->text());
s.setValue("usePast", ui->usePast->isChecked());
s.setValue("localNetworking", ui->localNetworking->isChecked());
// s.setValue("localNetworking", ui->localNetworking->isChecked());
s.setValue("forceMining", ui->forceMining->isChecked());
s.setValue("paranoia", ui->paranoia->isChecked());
s.setValue("natSpec", ui->natSpec->isChecked());
@ -744,9 +746,10 @@ void Main::readSettings(bool _skipGeometry)
}
ui->upnp->setChecked(s.value("upnp", true).toBool());
ui->forceAddress->setText(s.value("forceAddress", "").toString());
#warning fixme
// ui->forceAddress->setText(s.value("forceAddress", "").toString());
ui->usePast->setChecked(s.value("usePast", true).toBool());
ui->localNetworking->setChecked(s.value("localNetworking", true).toBool());
// ui->localNetworking->setChecked(s.value("localNetworking", true).toBool());
ui->forceMining->setChecked(s.value("forceMining", false).toBool());
on_forceMining_triggered();
ui->paranoia->setChecked(s.value("paranoia", false).toBool());

19
eth/main.cpp

@ -121,8 +121,9 @@ void help()
<< " --json-rpc-port Specify JSON-RPC server port (implies '-j', default: " << SensibleHttpPort << ")." << endl
#endif
<< " -K,--kill-blockchain First kill the blockchain." << endl
<< " -l,--listen <port> Listen on the given port for incoming connected (default: 30303)." << endl
<< " -L,--local-networking Use peers whose addresses are local." << endl
<< " --listen-ip <port> Listen on the given port for incoming connections (default: 30303)." << endl
<< " -l,--listen <ip> Listen on the given IP for incoming connections (default: 0.0.0.0)." << endl
<< " -u,--public-ip <ip> Force public ip to given (default: auto)." << endl
<< " -m,--mining <on/off/number> Enable mining, optionally for a specified number of blocks (Default: off)" << endl
<< " -n,--upnp <on/off> Use upnp for NAT (default: on)." << endl
<< " -o,--mode <full/peer> Start a full node or a peer node (Default: full)." << endl
@ -131,7 +132,6 @@ void help()
<< " -r,--remote <host> Connect to remote host (default: none)." << endl
<< " -s,--secret <secretkeyhex> Set the secret key for use with send command (default: auto)." << endl
<< " -t,--miners <number> Number of mining threads to start (Default: " << thread::hardware_concurrency() << ")" << endl
<< " -u,--public-ip <ip> Force public ip to given (default; auto)." << endl
<< " -v,--verbosity <0 - 9> Set the log verbosity from 0 to 9 (Default: 8)." << endl
<< " -x,--peers <number> Attempt to connect to given number of peers (Default: 5)." << endl
<< " -V,--version Show the version and exit." << endl
@ -199,7 +199,9 @@ enum class NodeMode
int main(int argc, char** argv)
{
string listenIP;
unsigned short listenPort = 30303;
string publicIP;
string remoteHost;
unsigned short remotePort = 30303;
string dbPath;
@ -211,10 +213,8 @@ int main(int argc, char** argv)
#if ETH_JSONRPC
int jsonrpc = -1;
#endif
string publicIP;
bool bootstrap = false;
bool upnp = true;
bool useLocal = false;
bool forceMining = false;
bool killChain = false;
bool jit = false;
@ -250,7 +250,9 @@ int main(int argc, char** argv)
for (int i = 1; i < argc; ++i)
{
string arg = argv[i];
if ((arg == "-l" || arg == "--listen" || arg == "--listen-port") && i + 1 < argc)
if (arg == "--listen-ip" && i + 1 < argc)
listenIP = argv[++i];
else if ((arg == "-l" || arg == "--listen" || arg == "--listen-port") && i + 1 < argc)
listenPort = (short)atoi(argv[++i]);
else if ((arg == "-u" || arg == "--public-ip" || arg == "--public") && i + 1 < argc)
publicIP = argv[++i];
@ -271,8 +273,6 @@ int main(int argc, char** argv)
return -1;
}
}
else if (arg == "-L" || arg == "--local-networking")
useLocal = true;
else if (arg == "-K" || arg == "--kill-blockchain")
killChain = true;
else if ((arg == "-c" || arg == "--client-name") && i + 1 < argc)
@ -421,7 +421,8 @@ int main(int argc, char** argv)
StructuredLogger::get().initialize(structuredLogging, structuredLoggingFormat);
VMFactory::setKind(jit ? VMKind::JIT : VMKind::Interpreter);
NetworkPreferences netPrefs(listenPort, publicIP, upnp, useLocal);
#warning fixme
NetworkPreferences netPrefs(listenPort);
auto nodesState = contents((dbPath.size() ? dbPath : getDataDir()) + "/network.rlp");
std::string clientImplString = "Ethereum(++)/" + clientName + "v" + dev::Version + "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM) + (jit ? "/JIT" : "");
dev::WebThreeDirect web3(

6
libp2p/Common.cpp

@ -28,7 +28,7 @@ const unsigned dev::p2p::c_protocolVersion = 3;
bool p2p::isPublicAddress(std::string const& _addressToCheck)
{
return isPublicAddress(bi::address::from_string(_addressToCheck));
return _addressToCheck.empty() ? false : isPublicAddress(bi::address::from_string(_addressToCheck));
}
bool p2p::isPublicAddress(bi::address const& _addressToCheck)
@ -67,7 +67,7 @@ bool p2p::isPrivateAddress(bi::address const& _addressToCheck)
bool p2p::isPrivateAddress(std::string const& _addressToCheck)
{
return isPrivateAddress(bi::address::from_string(_addressToCheck));
return _addressToCheck.empty() ? false : isPrivateAddress(bi::address::from_string(_addressToCheck));
}
// Helper function to determine if an address is localhost
@ -86,7 +86,7 @@ bool p2p::isLocalHostAddress(bi::address const& _addressToCheck)
bool p2p::isLocalHostAddress(std::string const& _addressToCheck)
{
return isLocalHostAddress(bi::address::from_string(_addressToCheck));
return _addressToCheck.empty() ? false : isLocalHostAddress(bi::address::from_string(_addressToCheck));
}
std::string p2p::reasonOf(DisconnectReason _r)

14
libp2p/Network.h

@ -58,16 +58,18 @@ public:
struct NetworkPreferences
{
// Network Preferences with unspecified Public IP
NetworkPreferences(unsigned short p = 30303, std::string i = std::string(), bool u = true, bool l = false): listenPort(p), listenIPAddress(i), publicIPAddress(), traverseNAT(u) {}
// 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, unsigned short p = 30303, std::string i = std::string(), bool u = true, bool l = false): listenPort(p), listenIPAddress(i), publicIPAddress(publicIP), traverseNAT(u) { if (!publicIPAddress.empty() && !isPublicAddress(publicIPAddress)) BOOST_THROW_EXCEPTION(InvalidPublicIPAddress()); }
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()); }
unsigned short listenPort = 30303;
std::string listenIPAddress;
std::string publicIPAddress;
std::string listenIPAddress;
unsigned short listenPort = 30303;
bool traverseNAT = true;
};

1
libp2p/Peer.h

@ -47,7 +47,6 @@ namespace p2p
* those peers. Modifying these properties via a storage backend alleviates
* Host of the responsibility. (&& remove save/restoreNetwork)
* @todo reimplement recording of historical session information on per-transport basis
* @todo rebuild nodetable when localNetworking is enabled/disabled
* @todo move attributes into protected
*/
class Peer: public Node

24
neth/main.cpp

@ -84,8 +84,9 @@ void help()
<< " --json-rpc-port Specify JSON-RPC server port (implies '-j', default: 8080)." << endl
#endif
<< " -K,--kill-blockchain First kill the blockchain." << endl
<< " -l,--listen <port> Listen on the given port for incoming connected (default: 30303)." << endl
<< " -L,--local-networking Use peers whose addresses are local." << endl
<< " --listen-ip <ip> Listen on the given IP for incoming connections (default: 0.0.0.0)." << endl
<< " -l,--listen <port> Listen on the given port for incoming connections (default: 30303)." << endl
<< " -u,--public-ip <ip> Force public ip to given (default; auto)." << endl
<< " -m,--mining <on/off> Enable mining (default: off)" << endl
<< " -n,--upnp <on/off> Use upnp for NAT (default: on)." << endl
<< " -o,--mode <full/peer> Start a full node or a peer node (Default: full)." << endl
@ -94,7 +95,6 @@ void help()
<< " -r,--remote <host> Connect to remote host (default: none)." << endl
<< " -s,--secret <secretkeyhex> Set the secret key for use with send command (default: auto)." << endl
<< " -t,--miners <number> Number of mining threads to start (Default: " << thread::hardware_concurrency() << ")" << endl
<< " -u,--public-ip <ip> Force public ip to given (default; auto)." << endl
<< " -v,--verbosity <0..9> Set the log verbosity from 0 to 9 (tmp forced to 1)." << endl
<< " -x,--peers <number> Attempt to connect to given number of peers (default: 5)." << endl
<< " -V,--version Show the version and exit." << endl
@ -321,7 +321,9 @@ enum class NodeMode
int main(int argc, char** argv)
{
string listenIP;
unsigned short listenPort = 30303;
string publicIP;
string remoteHost;
unsigned short remotePort = 30303;
string dbPath;
@ -332,10 +334,8 @@ int main(int argc, char** argv)
#if ETH_JSONRPC
int jsonrpc = 8080;
#endif
string publicIP;
bool bootstrap = false;
bool upnp = true;
bool useLocal = false;
bool forceMining = false;
bool killChain = false;
bool jit = false;
@ -371,7 +371,9 @@ int main(int argc, char** argv)
for (int i = 1; i < argc; ++i)
{
string arg = argv[i];
if ((arg == "-l" || arg == "--listen" || arg == "--listen-port") && i + 1 < argc)
if (arg == "--listen-ip" && i + 1 < argc)
listenIP = argv[++i];
else if ((arg == "-l" || arg == "--listen" || arg == "--listen-port") && i + 1 < argc)
listenPort = (short)atoi(argv[++i]);
else if ((arg == "-u" || arg == "--public-ip" || arg == "--public") && i + 1 < argc)
publicIP = argv[++i];
@ -392,8 +394,6 @@ int main(int argc, char** argv)
return -1;
}
}
else if (arg == "-L" || arg == "--local-networking")
useLocal = true;
else if (arg == "-K" || arg == "--kill-blockchain")
killChain = true;
else if ((arg == "-c" || arg == "--client-name") && i + 1 < argc)
@ -535,6 +535,8 @@ int main(int argc, char** argv)
}
}
if (!clientName.empty())
clientName += "/";
@ -542,7 +544,7 @@ int main(int argc, char** argv)
StructuredLogger::get().initialize(structuredLogging, structuredLoggingFormat);
VMFactory::setKind(jit ? VMKind::JIT : VMKind::Interpreter);
NetworkPreferences netPrefs(listenPort, publicIP, upnp, useLocal);
NetworkPreferences netPrefs(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(
@ -687,7 +689,9 @@ int main(int argc, char** argv)
{
unsigned port;
iss >> port;
web3.setNetworkPreferences(NetworkPreferences((short)port, publicIP, upnp));
if (port)
netPrefs.listenPort = port;
web3.setNetworkPreferences(netPrefs);
web3.startNetwork();
}
else if (cmd == "connect")

6
test/peer.cpp

@ -35,8 +35,8 @@ BOOST_AUTO_TEST_CASE(host)
auto oldLogVerbosity = g_logVerbosity;
g_logVerbosity = 10;
NetworkPreferences host1prefs(30301, "127.0.0.1", false, true);
NetworkPreferences host2prefs(30302, "127.0.0.1", false, true);
NetworkPreferences host1prefs("127.0.0.1", 30301, false);
NetworkPreferences host2prefs("127.0.0.1", 30302, false);
Host host1("Test", host1prefs);
host1.start();
@ -62,7 +62,7 @@ BOOST_AUTO_TEST_CASE(save_nodes)
std::list<Host*> hosts;
for (auto i:{0,1,2,3,4,5})
{
Host* h = new Host("Test", NetworkPreferences(30300 + i, "127.0.0.1", false, true));
Host* h = new Host("Test", NetworkPreferences("127.0.0.1", 30300 + i, false));
h->setIdealPeerCount(10);
// starting host is required so listenport is available
h->start();

Loading…
Cancel
Save