Skip to content

Commit a387887

Browse files
committed
Merge pull request #1021 from sipa/ipv6
IPv6 node support
2 parents c052719 + 8f10a28 commit a387887

14 files changed

+347
-119
lines changed

bitcoin-qt.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ TEMPLATE = app
22
TARGET =
33
VERSION = 0.6.99
44
INCLUDEPATH += src src/json src/qt
5-
DEFINES += QT_GUI BOOST_THREAD_USE_LIB
5+
DEFINES += QT_GUI BOOST_THREAD_USE_LIB USE_IPV6
66
CONFIG += no_include_pwd
77

88
# for boost 1.37, add -mt to the boost libraries

doc/build-osx.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ sudo port install qrencode
4444
4. Now you should be able to build bitcoind:
4545

4646
cd bitcoin/src
47-
make -f makefile.osx
47+
make -f makefile.osx USE_IPV6=1
4848

4949
Run:
5050
./bitcoind --help # for a list of command-line options.

doc/build-unix.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ your package manager. Set USE_QRCODE to control this:
4343
USE_QRCODE=0 (the default) No QRCode support - libarcode not required
4444
USE_QRCODE=1 QRCode support enabled
4545

46+
IPv6 support may be enabled by setting
47+
USE_IPV6=1 Enable IPv6 support
48+
4649
Licenses of statically linked libraries:
4750
Berkeley DB New BSD license with additional requirement that linked
4851
software must be free open source
@@ -80,7 +83,7 @@ emerge -av1 --noreplace boost glib openssl sys-libs/db:4.8
8083

8184
Take the following steps to build (no UPnP support):
8285
cd ${BITCOIN_DIR}/src
83-
make -f makefile.unix USE_UPNP= BDB_INCLUDE_PATH='/usr/include/db4.8'
86+
make -f makefile.unix USE_UPNP= USE_IPV6=1 BDB_INCLUDE_PATH='/usr/include/db4.8'
8487
strip bitcoind
8588

8689

src/init.cpp

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,18 @@ bool AppInit(int argc, char* argv[])
119119
return fRet;
120120
}
121121

122+
bool static Bind(const CService &addr) {
123+
if (IsLimited(addr))
124+
return false;
125+
std::string strError;
126+
if (!BindListenPort(addr, strError))
127+
{
128+
ThreadSafeMessageBox(strError, _("Bitcoin"), wxOK | wxMODAL);
129+
return false;
130+
}
131+
return true;
132+
}
133+
122134
bool AppInit2(int argc, char* argv[])
123135
{
124136
#ifdef _MSC_VER
@@ -180,6 +192,7 @@ bool AppInit2(int argc, char* argv[])
180192
" -timeout=<n> \t " + _("Specify connection timeout (in milliseconds)") + "\n" +
181193
" -proxy=<ip:port> \t " + _("Connect through socks proxy") + "\n" +
182194
" -socks=<n> \t " + _("Select the version of socks proxy to use (4 or 5, 5 is default)") + "\n" +
195+
" -noproxy=<net> \t " + _("Do not use proxy for connections to network net (ipv4 or ipv6)") + "\n" +
183196
" -dns \t " + _("Allow DNS lookups for -addnode, -seednode and -connect") + "\n" +
184197
" -proxydns \t " + _("Pass DNS requests to (SOCKS5) proxy") + "\n" +
185198
" -port=<port> \t\t " + _("Listen for connections on <port> (default: 8333 or testnet: 18333)") + "\n" +
@@ -188,9 +201,11 @@ bool AppInit2(int argc, char* argv[])
188201
" -connect=<ip> \t\t " + _("Connect only to the specified node") + "\n" +
189202
" -seednode=<ip> \t\t " + _("Connect to a node to retrieve peer addresses, and disconnect") + "\n" +
190203
" -externalip=<ip> \t " + _("Specify your own public address") + "\n" +
204+
" -blocknet=<net> \t " + _("Do not connect to addresses in network net (ipv4, ipv6)") + "\n" +
191205
" -discover \t " + _("Try to discover public IP address (default: 1)") + "\n" +
192206
" -irc \t " + _("Find peers using internet relay chat (default: 0)") + "\n" +
193207
" -listen \t " + _("Accept connections from outside (default: 1)") + "\n" +
208+
" -bind=<addr> \t " + _("Bind to given address. Use [host]:port notation for IPv6") + "\n" +
194209
#ifdef QT_GUI
195210
" -lang=<lang> \t\t " + _("Set language, for example \"de_DE\" (default: system locale)") + "\n" +
196211
#endif
@@ -532,9 +547,25 @@ bool AppInit2(int argc, char* argv[])
532547
}
533548
}
534549

550+
if (mapArgs.count("-noproxy"))
551+
{
552+
BOOST_FOREACH(std::string snet, mapMultiArgs["-noproxy"]) {
553+
enum Network net = ParseNetwork(snet);
554+
if (net == NET_UNROUTABLE) {
555+
ThreadSafeMessageBox(_("Unknown network specified in -noproxy"), _("Bitcoin"), wxOK | wxMODAL);
556+
return false;
557+
}
558+
SetNoProxy(net);
559+
}
560+
}
561+
535562
if (mapArgs.count("-connect"))
536563
SoftSetBoolArg("-dnsseed", false);
537-
564+
565+
// even in Tor mode, if -bind is specified, you really want -listen
566+
if (mapArgs.count("-bind"))
567+
SoftSetBoolArg("-listen", true);
568+
538569
bool fTor = (fUseProxy && addrProxy.GetPort() == 9050);
539570
if (fTor)
540571
{
@@ -547,6 +578,17 @@ bool AppInit2(int argc, char* argv[])
547578
SoftSetBoolArg("-discover", false);
548579
}
549580

581+
if (mapArgs.count("-blocknet")) {
582+
BOOST_FOREACH(std::string snet, mapMultiArgs["-blocknet"]) {
583+
enum Network net = ParseNetwork(snet);
584+
if (net == NET_UNROUTABLE) {
585+
ThreadSafeMessageBox(_("Unknown network specified in -blocknet"), _("Bitcoin"), wxOK | wxMODAL);
586+
return false;
587+
}
588+
SetLimited(net);
589+
}
590+
}
591+
550592
fNameLookup = GetBoolArg("-dns");
551593
fProxyNameLookup = GetBoolArg("-proxydns");
552594
if (fProxyNameLookup)
@@ -563,14 +605,23 @@ bool AppInit2(int argc, char* argv[])
563605
const char* pszP2SH = "/P2SH/";
564606
COINBASE_FLAGS << std::vector<unsigned char>(pszP2SH, pszP2SH+strlen(pszP2SH));
565607

608+
bool fBound = false;
566609
if (!fNoListen)
567610
{
568611
std::string strError;
569-
if (!BindListenPort(strError))
570-
{
571-
ThreadSafeMessageBox(strError, _("Bitcoin"), wxOK | wxMODAL);
572-
return false;
612+
if (mapArgs.count("-bind")) {
613+
BOOST_FOREACH(std::string strBind, mapMultiArgs["-bind"]) {
614+
fBound |= Bind(CService(strBind, GetDefaultPort(), false));
615+
}
616+
} else {
617+
struct in_addr inaddr_any = {s_addr: INADDR_ANY};
618+
fBound |= Bind(CService(inaddr_any, GetDefaultPort()));
619+
#ifdef USE_IPV6
620+
fBound |= Bind(CService(in6addr_any, GetDefaultPort()));
621+
#endif
573622
}
623+
if (!fBound)
624+
return false;
574625
}
575626

576627
if (mapArgs.count("-externalip"))

src/irc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ void ThreadIRCSeed2(void* parg)
246246
return;
247247
}
248248

249-
CNetAddr addrLocal;
249+
CService addrLocal;
250250
string strMyName;
251251
if (GetLocal(addrLocal, &addrConnect))
252252
strMyName = EncodeAddress(GetLocalAddress(&addrConnect));

src/main.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2419,18 +2419,17 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
24192419
}
24202420

24212421
// Store the new addresses
2422+
vector<CAddress> vAddrOk;
24222423
int64 nNow = GetAdjustedTime();
24232424
int64 nSince = nNow - 10 * 60;
24242425
BOOST_FOREACH(CAddress& addr, vAddr)
24252426
{
24262427
if (fShutdown)
24272428
return true;
2428-
// ignore IPv6 for now, since it isn't implemented anyway
2429-
if (!addr.IsIPv4())
2430-
continue;
24312429
if (addr.nTime <= 100000000 || addr.nTime > nNow + 10 * 60)
24322430
addr.nTime = nNow - 5 * 24 * 60 * 60;
24332431
pfrom->AddAddressKnown(addr);
2432+
bool fReachable = IsReachable(addr);
24342433
if (addr.nTime > nSince && !pfrom->fGetAddr && vAddr.size() <= 10 && addr.IsRoutable())
24352434
{
24362435
// Relay to a limited number of other nodes
@@ -2455,13 +2454,16 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
24552454
hashKey = Hash(BEGIN(hashKey), END(hashKey));
24562455
mapMix.insert(make_pair(hashKey, pnode));
24572456
}
2458-
int nRelayNodes = 2;
2457+
int nRelayNodes = fReachable ? 2 : 1; // limited relaying of addresses outside our network(s)
24592458
for (multimap<uint256, CNode*>::iterator mi = mapMix.begin(); mi != mapMix.end() && nRelayNodes-- > 0; ++mi)
24602459
((*mi).second)->PushAddress(addr);
24612460
}
24622461
}
2462+
// Do not store addresses outside our network
2463+
if (fReachable)
2464+
vAddrOk.push_back(addr);
24632465
}
2464-
addrman.Add(vAddr, pfrom->addr, 2 * 60 * 60);
2466+
addrman.Add(vAddrOk, pfrom->addr, 2 * 60 * 60);
24652467
if (vAddr.size() < 1000)
24662468
pfrom->fGetAddr = false;
24672469
if (pfrom->fOneShot)

src/makefile.linux-mingw

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ LIBS= \
2727
-l ssl \
2828
-l crypto
2929

30-
DEFS=-D_MT -DWIN32 -D_WINDOWS -DBOOST_THREAD_USE_LIB
30+
DEFS=-D_MT -DWIN32 -D_WINDOWS -DBOOST_THREAD_USE_LIB -DUSE_IPV6
3131
DEBUGFLAGS=-g
3232
CFLAGS=-O2 -w -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter $(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS)
3333

src/makefile.mingw

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ LIBS= \
2323
-l ssl \
2424
-l crypto
2525

26-
DEFS=-DWIN32 -D_WINDOWS -DBOOST_THREAD_USE_LIB
26+
DEFS=-DWIN32 -D_WINDOWS -DBOOST_THREAD_USE_LIB -DUSE_IPV6
2727
DEBUGFLAGS=-g
2828
CFLAGS=-mthreads -O2 -w -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter $(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS)
2929

src/makefile.osx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ LIBS += \
5353
TESTDEFS += -DBOOST_TEST_DYN_LINK
5454
endif
5555

56-
DEFS=-DMAC_OSX -DMSG_NOSIGNAL=0
56+
DEFS=-DMAC_OSX -DMSG_NOSIGNAL=0 -DUSE_IPV6
5757

5858
ifdef RELEASE
5959
# Compile for maximum compatibility and smallest size.

src/makefile.unix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
USE_UPNP:=0
66

7-
DEFS=
7+
DEFS=-DUSE_IPV6
88

99
DEFS += $(addprefix -I,$(CURDIR) $(CURDIR)/obj $(BOOST_INCLUDE_PATH) $(BDB_INCLUDE_PATH) $(OPENSSL_INCLUDE_PATH))
1010
LIBS = $(addprefix -L,$(BOOST_LIB_PATH) $(BDB_LIB_PATH) $(OPENSSL_LIB_PATH))

0 commit comments

Comments
 (0)