Skip to content

Commit 19b6958

Browse files
committed
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.
1 parent 3985719 commit 19b6958

File tree

3 files changed

+47
-22
lines changed

3 files changed

+47
-22
lines changed

src/init.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ bool AppInit2(int argc, char* argv[])
187187
" -addnode=<ip> \t " + _("Add a node to connect to and attempt to keep the connection open") + "\n" +
188188
" -connect=<ip> \t\t " + _("Connect only to the specified node") + "\n" +
189189
" -seednode=<ip> \t\t " + _("Connect to a node to retrieve peer addresses, and disconnect") + "\n" +
190+
" -externalip=<ip> \t " + _("Specify your own public address") + "\n" +
191+
" -discover \t " + _("Try to discover public IP address (default: 1)") + "\n" +
190192
" -irc \t " + _("Find peers using internet relay chat (default: 0)") + "\n" +
191193
" -listen \t " + _("Accept connections from outside (default: 1)") + "\n" +
192194
#ifdef QT_GUI
@@ -519,6 +521,9 @@ bool AppInit2(int argc, char* argv[])
519521
}
520522
}
521523

524+
if (mapArgs.count("-connect"))
525+
SoftSetBoolArg("-dnsseed", false);
526+
522527
bool fTor = (fUseProxy && addrProxy.GetPort() == 9050);
523528
if (fTor)
524529
{
@@ -528,6 +533,7 @@ bool AppInit2(int argc, char* argv[])
528533
SoftSetBoolArg("-irc", false);
529534
SoftSetBoolArg("-proxydns", true);
530535
SoftSetBoolArg("-upnp", false);
536+
SoftSetBoolArg("-discover", false);
531537
}
532538

533539
fNameLookup = GetBoolArg("-dns");
@@ -556,6 +562,12 @@ bool AppInit2(int argc, char* argv[])
556562
}
557563
}
558564

565+
if (mapArgs.count("-externalip"))
566+
{
567+
BOOST_FOREACH(string strAddr, mapMultiArgs["-externalip"])
568+
AddLocal(CNetAddr(strAddr, fNameLookup), LOCAL_MANUAL);
569+
}
570+
559571
if (mapArgs.count("-paytxfee"))
560572
{
561573
if (!ParseMoney(mapArgs["-paytxfee"], nTransactionFee))

src/net.cpp

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -973,19 +973,21 @@ void ThreadMapPort2(void* parg)
973973
r = UPNP_GetValidIGD(devlist, &urls, &data, lanaddr, sizeof(lanaddr));
974974
if (r == 1)
975975
{
976-
char externalIPAddress[40];
977-
r = UPNP_GetExternalIPAddress(urls.controlURL, data.first.servicetype, externalIPAddress);
978-
if(r != UPNPCOMMAND_SUCCESS)
979-
printf("UPnP: GetExternalIPAddress() returned %d\n", r);
980-
else
981-
{
982-
if(externalIPAddress[0])
976+
if (GetBoolArg("-discover", true)) {
977+
char externalIPAddress[40];
978+
r = UPNP_GetExternalIPAddress(urls.controlURL, data.first.servicetype, externalIPAddress);
979+
if(r != UPNPCOMMAND_SUCCESS)
980+
printf("UPnP: GetExternalIPAddress() returned %d\n", r);
981+
else
983982
{
984-
printf("UPnP: ExternalIPAddress = %s\n", externalIPAddress);
985-
AddLocal(CNetAddr(externalIPAddress), LOCAL_UPNP);
983+
if(externalIPAddress[0])
984+
{
985+
printf("UPnP: ExternalIPAddress = %s\n", externalIPAddress);
986+
AddLocal(CNetAddr(externalIPAddress), LOCAL_UPNP);
987+
}
988+
else
989+
printf("UPnP: GetExternalIPAddress failed.\n");
986990
}
987-
else
988-
printf("UPnP: GetExternalIPAddress failed.\n");
989991
}
990992

991993
string strDesc = "Bitcoin " + FormatFullVersion();
@@ -1695,18 +1697,10 @@ bool BindListenPort(string& strError)
16951697
return true;
16961698
}
16971699

1698-
void StartNode(void* parg)
1700+
void static Discover()
16991701
{
1700-
#ifdef USE_UPNP
1701-
#if USE_UPNP
1702-
fUseUPnP = GetBoolArg("-upnp", true);
1703-
#else
1704-
fUseUPnP = GetBoolArg("-upnp", false);
1705-
#endif
1706-
#endif
1707-
1708-
if (pnodeLocalHost == NULL)
1709-
pnodeLocalHost = new CNode(INVALID_SOCKET, CAddress(CService("127.0.0.1", 0), nLocalServices));
1702+
if (!GetBoolArg("-discover", true))
1703+
return;
17101704

17111705
#ifdef WIN32
17121706
// Get local host ip
@@ -1764,6 +1758,22 @@ void StartNode(void* parg)
17641758
{
17651759
CreateThread(ThreadGetMyExternalIP, NULL);
17661760
}
1761+
}
1762+
1763+
void StartNode(void* parg)
1764+
{
1765+
#ifdef USE_UPNP
1766+
#if USE_UPNP
1767+
fUseUPnP = GetBoolArg("-upnp", true);
1768+
#else
1769+
fUseUPnP = GetBoolArg("-upnp", false);
1770+
#endif
1771+
#endif
1772+
1773+
if (pnodeLocalHost == NULL)
1774+
pnodeLocalHost = new CNode(INVALID_SOCKET, CAddress(CService("127.0.0.1", 0), nLocalServices));
1775+
1776+
Discover();
17671777

17681778
//
17691779
// Start threads

src/net.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ enum
4949
LOCAL_UPNP,
5050
LOCAL_IRC,
5151
LOCAL_HTTP,
52+
LOCAL_MANUAL,
53+
54+
LOCAL_MAX
5255
};
5356

5457
bool AddLocal(const CNetAddr& addr, int nScore = LOCAL_NONE);

0 commit comments

Comments
 (0)