Skip to content

Commit 203f9e6

Browse files
Jeff GarzikJeff Garzik
authored andcommitted
Merge branch 'tmp-ipv6' into merge-ipv6
2 parents 82ab06b + 19b6958 commit 203f9e6

File tree

9 files changed

+558
-183
lines changed

9 files changed

+558
-183
lines changed

src/init.cpp

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,17 @@ bool AppInit2(int argc, char* argv[])
178178
" -dbcache=<n> \t\t " + _("Set database cache size in megabytes (default: 25)") + "\n" +
179179
" -dblogsize=<n> \t\t " + _("Set database disk log size in megabytes (default: 100)") + "\n" +
180180
" -timeout=<n> \t " + _("Specify connection timeout (in milliseconds)") + "\n" +
181-
" -proxy=<ip:port> \t " + _("Connect through socks4 proxy") + "\n" +
182-
" -dns \t " + _("Allow DNS lookups for addnode and connect") + "\n" +
181+
" -proxy=<ip:port> \t " + _("Connect through socks proxy") + "\n" +
182+
" -socks=<n> \t " + _("Select the version of socks proxy to use (4 or 5, 5 is default)") + "\n" +
183+
" -dns \t " + _("Allow DNS lookups for -addnode, -seednode and -connect") + "\n" +
184+
" -proxydns \t " + _("Pass DNS requests to (SOCKS5) proxy") + "\n" +
183185
" -port=<port> \t\t " + _("Listen for connections on <port> (default: 8333 or testnet: 18333)") + "\n" +
184186
" -maxconnections=<n>\t " + _("Maintain at most <n> connections to peers (default: 125)") + "\n" +
185187
" -addnode=<ip> \t " + _("Add a node to connect to and attempt to keep the connection open") + "\n" +
186188
" -connect=<ip> \t\t " + _("Connect only to the specified node") + "\n" +
189+
" -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" +
187192
" -irc \t " + _("Find peers using internet relay chat (default: 0)") + "\n" +
188193
" -listen \t " + _("Accept connections from outside (default: 1)") + "\n" +
189194
#ifdef QT_GUI
@@ -527,20 +532,30 @@ bool AppInit2(int argc, char* argv[])
527532
}
528533
}
529534

535+
if (mapArgs.count("-connect"))
536+
SoftSetBoolArg("-dnsseed", false);
537+
530538
bool fTor = (fUseProxy && addrProxy.GetPort() == 9050);
531539
if (fTor)
532540
{
533541
// Use SoftSetBoolArg here so user can override any of these if they wish.
534542
// Note: the GetBoolArg() calls for all of these must happen later.
535543
SoftSetBoolArg("-listen", false);
536544
SoftSetBoolArg("-irc", false);
537-
SoftSetBoolArg("-dnsseed", false);
545+
SoftSetBoolArg("-proxydns", true);
538546
SoftSetBoolArg("-upnp", false);
539-
SoftSetBoolArg("-dns", false);
547+
SoftSetBoolArg("-discover", false);
540548
}
541549

542-
fAllowDNS = GetBoolArg("-dns");
550+
fNameLookup = GetBoolArg("-dns");
551+
fProxyNameLookup = GetBoolArg("-proxydns");
552+
if (fProxyNameLookup)
553+
fNameLookup = true;
543554
fNoListen = !GetBoolArg("-listen", true);
555+
nSocksVersion = GetArg("-socks", 5);
556+
557+
BOOST_FOREACH(string strDest, mapMultiArgs["-seednode"])
558+
AddOneShot(strDest);
544559

545560
// Continue to put "/P2SH/" in the coinbase to monitor
546561
// BIP16 support.
@@ -558,15 +573,10 @@ bool AppInit2(int argc, char* argv[])
558573
}
559574
}
560575

561-
if (mapArgs.count("-addnode"))
576+
if (mapArgs.count("-externalip"))
562577
{
563-
BOOST_FOREACH(string strAddr, mapMultiArgs["-addnode"])
564-
{
565-
CAddress addr(CService(strAddr, GetDefaultPort(), fAllowDNS));
566-
addr.nTime = 0; // so it won't relay unless successfully connected
567-
if (addr.IsValid())
568-
addrman.Add(addr, CNetAddr("127.0.0.1"));
569-
}
578+
BOOST_FOREACH(string strAddr, mapMultiArgs["-externalip"])
579+
AddLocal(CNetAddr(strAddr, fNameLookup), LOCAL_MANUAL);
570580
}
571581

572582
if (mapArgs.count("-paytxfee"))

src/irc.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ using namespace std;
1212
using namespace boost;
1313

1414
int nGotIRCAddresses = 0;
15-
bool fGotExternalIP = false;
1615

1716
void ThreadIRCSeed2(void* parg);
1817

@@ -216,7 +215,6 @@ void ThreadIRCSeed2(void* parg)
216215
printf("ThreadIRCSeed started\n");
217216
int nErrorWait = 10;
218217
int nRetryWait = 10;
219-
bool fNameInUse = false;
220218

221219
while (!fShutdown)
222220
{
@@ -248,9 +246,10 @@ void ThreadIRCSeed2(void* parg)
248246
return;
249247
}
250248

249+
CNetAddr addrLocal;
251250
string strMyName;
252-
if (addrLocalHost.IsRoutable() && !fUseProxy && !fNameInUse)
253-
strMyName = EncodeAddress(addrLocalHost);
251+
if (GetLocal(addrLocal, &addrConnect))
252+
strMyName = EncodeAddress(GetLocalAddress(&addrConnect));
254253
else
255254
strMyName = strprintf("x%u", GetRand(1000000000));
256255

@@ -265,7 +264,6 @@ void ThreadIRCSeed2(void* parg)
265264
if (nRet == 2)
266265
{
267266
printf("IRC name already in use\n");
268-
fNameInUse = true;
269267
Wait(10);
270268
continue;
271269
}
@@ -285,9 +283,8 @@ void ThreadIRCSeed2(void* parg)
285283
if (!fUseProxy && addrFromIRC.IsRoutable())
286284
{
287285
// IRC lets you to re-nick
288-
fGotExternalIP = true;
289-
addrLocalHost.SetIP(addrFromIRC);
290-
strMyName = EncodeAddress(addrLocalHost);
286+
AddLocal(addrFromIRC, LOCAL_IRC);
287+
strMyName = EncodeAddress(GetLocalAddress(&addrConnect));
291288
Send(hSocket, strprintf("NICK %s\r", strMyName.c_str()).c_str());
292289
}
293290
}

src/irc.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@
88
void ThreadIRCSeed(void* parg);
99

1010
extern int nGotIRCAddresses;
11-
extern bool fGotExternalIP;
1211

1312
#endif

src/main.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2312,6 +2312,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
23122312
if (!vRecv.empty())
23132313
vRecv >> pfrom->nStartingHeight;
23142314

2315+
if (pfrom->fInbound && addrMe.IsRoutable())
2316+
{
2317+
pfrom->addrLocal = addrMe;
2318+
SeenLocal(addrMe);
2319+
}
2320+
23152321
// Disconnect if we connected to ourself
23162322
if (nNonce == nLocalHostNonce && nNonce > 1)
23172323
{
@@ -2335,16 +2341,15 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
23352341
if (!pfrom->fInbound)
23362342
{
23372343
// Advertise our address
2338-
if (!fNoListen && !fUseProxy && addrLocalHost.IsRoutable() &&
2339-
!IsInitialBlockDownload())
2344+
if (!fNoListen && !fUseProxy && !IsInitialBlockDownload())
23402345
{
2341-
CAddress addr(addrLocalHost);
2342-
addr.nTime = GetAdjustedTime();
2343-
pfrom->PushAddress(addr);
2346+
CAddress addr = GetLocalAddress(&pfrom->addr);
2347+
if (addr.IsRoutable())
2348+
pfrom->PushAddress(addr);
23442349
}
23452350

23462351
// Get recent addresses
2347-
if (pfrom->nVersion >= CADDR_TIME_VERSION || addrman.size() < 1000)
2352+
if (pfrom->fOneShot || pfrom->nVersion >= CADDR_TIME_VERSION || addrman.size() < 1000)
23482353
{
23492354
pfrom->PushMessage("getaddr");
23502355
pfrom->fGetAddr = true;
@@ -2360,7 +2365,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
23602365

23612366
// Ask the first connected node for block updates
23622367
static int nAskedForBlocks = 0;
2363-
if (!pfrom->fClient &&
2368+
if (!pfrom->fClient && !pfrom->fOneShot &&
23642369
(pfrom->nVersion < NOBLKS_VERSION_START ||
23652370
pfrom->nVersion >= NOBLKS_VERSION_END) &&
23662371
(nAskedForBlocks < 1 || vNodes.size() <= 1))
@@ -2458,6 +2463,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
24582463
addrman.Add(vAddr, pfrom->addr, 2 * 60 * 60);
24592464
if (vAddr.size() < 1000)
24602465
pfrom->fGetAddr = false;
2466+
if (pfrom->fOneShot)
2467+
pfrom->fDisconnect = true;
24612468
}
24622469

24632470

@@ -2979,11 +2986,11 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
29792986
pnode->setAddrKnown.clear();
29802987

29812988
// Rebroadcast our address
2982-
if (!fNoListen && !fUseProxy && addrLocalHost.IsRoutable())
2989+
if (!fNoListen && !fUseProxy)
29832990
{
2984-
CAddress addr(addrLocalHost);
2985-
addr.nTime = GetAdjustedTime();
2986-
pnode->PushAddress(addr);
2991+
CAddress addr = GetLocalAddress(&pnode->addr);
2992+
if (addr.IsRoutable())
2993+
pnode->PushAddress(addr);
29872994
}
29882995
}
29892996
}

0 commit comments

Comments
 (0)