aboutsummaryrefslogtreecommitdiff
path: root/src/net.cpp
diff options
context:
space:
mode:
authorGregory Maxwell <greg@xiph.org>2012-07-01 20:23:26 -0400
committerGregory Maxwell <greg@xiph.org>2012-07-01 20:42:47 -0400
commit19521acfa4499bb50105e13b5ffd63bfd43c73aa (patch)
tree0a5cfa10d2b13dfba749920e383ee830b916e8c3 /src/net.cpp
parent18e8e43715b0704b0e94d60f51bce28d6510ed0d (diff)
downloadbitcoin-19521acfa4499bb50105e13b5ffd63bfd43c73aa.tar.xz
Do not consider inbound peers for outbound network group exclusion.
Bitcoin will not make an outbound connection to a network group (/16 for IPv4) that it is already connected to. This means that if an attacker wants good odds of capturing all a nodes outbound connections he must have hosts on a a large number of distinct groups. Previously both inbound and outbound connections were used to feed this exclusion. The use of inbound connections, which can be controlled by the attacker, actually has the potential of making sibyl attacks _easier_: An attacker can start up hosts in groups which house many honest nodes and make outbound connections to the victim to exclude big swaths of honest nodes. Because the attacker chooses to make the outbound connection he can always beat out honest nodes for the consumption of inbound slots. At _best_ the old behavior increases attacker costs by a single group (e.g. one distinct group to use to fill up all your inbound slots), but at worst it allows the attacker to select whole networks you won't connect to. This commit makes the nodes use only outbound links to exclude network groups for outbound connections. Fancier things could be done, like weaker exclusion for inbound groups... but simplicity is good and I don't believe more complexity is currently needed.
Diffstat (limited to 'src/net.cpp')
-rw-r--r--src/net.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/net.cpp b/src/net.cpp
index 2a09d20dea..2d1f708edc 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -1432,16 +1432,17 @@ void ThreadOpenConnections2(void* parg)
//
CAddress addrConnect;
- // Only connect to one address per a.b.?.? range.
+ // Only connect out to one peer per network group (/16 for IPv4).
// Do this here so we don't have to critsect vNodes inside mapAddresses critsect.
int nOutbound = 0;
set<vector<unsigned char> > setConnected;
{
LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodes) {
- setConnected.insert(pnode->addr.GetGroup());
- if (!pnode->fInbound)
+ if (!pnode->fInbound) {
+ setConnected.insert(pnode->addr.GetGroup());
nOutbound++;
+ }
}
}