aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2012-02-19 20:44:35 +0100
committerPieter Wuille <pieter.wuille@gmail.com>2012-05-04 16:12:23 +0200
commit19b6958cfd5c5207ffe8259ef48ebbd24ca89725 (patch)
tree454edd591d114938e4f7d19b972bde3b00e609c1 /src
parent39857190dee3ed296112cfcfd79b0a375143b6c6 (diff)
Added -externalip and -discover
-externalip=<ip> can be used to explicitly set the public IP address of your node. -discover=0 can be used to disable the automatic public IP discovery system.
Diffstat (limited to 'src')
-rw-r--r--src/init.cpp12
-rw-r--r--src/net.cpp54
-rw-r--r--src/net.h3
3 files changed, 47 insertions, 22 deletions
diff --git a/src/init.cpp b/src/init.cpp
index f9ea998cee..4696428972 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -187,6 +187,8 @@ bool AppInit2(int argc, char* argv[])
" -addnode=<ip> \t " + _("Add a node to connect to and attempt to keep the connection open") + "\n" +
" -connect=<ip> \t\t " + _("Connect only to the specified node") + "\n" +
" -seednode=<ip> \t\t " + _("Connect to a node to retrieve peer addresses, and disconnect") + "\n" +
+ " -externalip=<ip> \t " + _("Specify your own public address") + "\n" +
+ " -discover \t " + _("Try to discover public IP address (default: 1)") + "\n" +
" -irc \t " + _("Find peers using internet relay chat (default: 0)") + "\n" +
" -listen \t " + _("Accept connections from outside (default: 1)") + "\n" +
#ifdef QT_GUI
@@ -519,6 +521,9 @@ bool AppInit2(int argc, char* argv[])
}
}
+ if (mapArgs.count("-connect"))
+ SoftSetBoolArg("-dnsseed", false);
+
bool fTor = (fUseProxy && addrProxy.GetPort() == 9050);
if (fTor)
{
@@ -528,6 +533,7 @@ bool AppInit2(int argc, char* argv[])
SoftSetBoolArg("-irc", false);
SoftSetBoolArg("-proxydns", true);
SoftSetBoolArg("-upnp", false);
+ SoftSetBoolArg("-discover", false);
}
fNameLookup = GetBoolArg("-dns");
@@ -556,6 +562,12 @@ bool AppInit2(int argc, char* argv[])
}
}
+ if (mapArgs.count("-externalip"))
+ {
+ BOOST_FOREACH(string strAddr, mapMultiArgs["-externalip"])
+ AddLocal(CNetAddr(strAddr, fNameLookup), LOCAL_MANUAL);
+ }
+
if (mapArgs.count("-paytxfee"))
{
if (!ParseMoney(mapArgs["-paytxfee"], nTransactionFee))
diff --git a/src/net.cpp b/src/net.cpp
index 0a78bc445f..c626e49b1b 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -973,19 +973,21 @@ void ThreadMapPort2(void* parg)
r = UPNP_GetValidIGD(devlist, &urls, &data, lanaddr, sizeof(lanaddr));
if (r == 1)
{
- char externalIPAddress[40];
- r = UPNP_GetExternalIPAddress(urls.controlURL, data.first.servicetype, externalIPAddress);
- if(r != UPNPCOMMAND_SUCCESS)
- printf("UPnP: GetExternalIPAddress() returned %d\n", r);
- else
- {
- if(externalIPAddress[0])
+ if (GetBoolArg("-discover", true)) {
+ char externalIPAddress[40];
+ r = UPNP_GetExternalIPAddress(urls.controlURL, data.first.servicetype, externalIPAddress);
+ if(r != UPNPCOMMAND_SUCCESS)
+ printf("UPnP: GetExternalIPAddress() returned %d\n", r);
+ else
{
- printf("UPnP: ExternalIPAddress = %s\n", externalIPAddress);
- AddLocal(CNetAddr(externalIPAddress), LOCAL_UPNP);
+ if(externalIPAddress[0])
+ {
+ printf("UPnP: ExternalIPAddress = %s\n", externalIPAddress);
+ AddLocal(CNetAddr(externalIPAddress), LOCAL_UPNP);
+ }
+ else
+ printf("UPnP: GetExternalIPAddress failed.\n");
}
- else
- printf("UPnP: GetExternalIPAddress failed.\n");
}
string strDesc = "Bitcoin " + FormatFullVersion();
@@ -1695,18 +1697,10 @@ bool BindListenPort(string& strError)
return true;
}
-void StartNode(void* parg)
+void static Discover()
{
-#ifdef USE_UPNP
-#if USE_UPNP
- fUseUPnP = GetBoolArg("-upnp", true);
-#else
- fUseUPnP = GetBoolArg("-upnp", false);
-#endif
-#endif
-
- if (pnodeLocalHost == NULL)
- pnodeLocalHost = new CNode(INVALID_SOCKET, CAddress(CService("127.0.0.1", 0), nLocalServices));
+ if (!GetBoolArg("-discover", true))
+ return;
#ifdef WIN32
// Get local host ip
@@ -1764,6 +1758,22 @@ void StartNode(void* parg)
{
CreateThread(ThreadGetMyExternalIP, NULL);
}
+}
+
+void StartNode(void* parg)
+{
+#ifdef USE_UPNP
+#if USE_UPNP
+ fUseUPnP = GetBoolArg("-upnp", true);
+#else
+ fUseUPnP = GetBoolArg("-upnp", false);
+#endif
+#endif
+
+ if (pnodeLocalHost == NULL)
+ pnodeLocalHost = new CNode(INVALID_SOCKET, CAddress(CService("127.0.0.1", 0), nLocalServices));
+
+ Discover();
//
// Start threads
diff --git a/src/net.h b/src/net.h
index 239971e2ca..a00dd1b8cc 100644
--- a/src/net.h
+++ b/src/net.h
@@ -49,6 +49,9 @@ enum
LOCAL_UPNP,
LOCAL_IRC,
LOCAL_HTTP,
+ LOCAL_MANUAL,
+
+ LOCAL_MAX
};
bool AddLocal(const CNetAddr& addr, int nScore = LOCAL_NONE);