Skip to content

Commit

Permalink
Reduce fingerprinting through timestamps in 'addr' messages.
Browse files Browse the repository at this point in the history
Suggested by Jonas Nick.

Rebased-From: 9c27379
Github-Pull: #5860
  • Loading branch information
sipa authored and laanwj committed Mar 17, 2015
1 parent 2c08406 commit ca301bf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/addrman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,9 @@ void CAddrMan::Good_(const CService& addr, int64_t nTime)
// update info
info.nLastSuccess = nTime;
info.nLastTry = nTime;
info.nTime = nTime;
info.nAttempts = 0;
// nTime is not updated here, to avoid leaking information about
// currently-connected peers.

// if it is already in the tried set, don't do anything else
if (info.fInTried)
Expand Down
21 changes: 16 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ struct CBlockReject {
* and we're no longer holding the node's locks.
*/
struct CNodeState {
//! The peer's address
CService address;
//! Whether we have a fully established connection.
bool fCurrentlyConnected;
//! Accumulated misbehaviour score for this peer.
int nMisbehavior;
//! Whether this peer should be disconnected and banned (unless whitelisted).
Expand All @@ -255,6 +259,7 @@ struct CNodeState {
bool fPreferredDownload;

CNodeState() {
fCurrentlyConnected = false;
nMisbehavior = 0;
fShouldBan = false;
pindexBestKnownBlock = NULL;
Expand Down Expand Up @@ -298,6 +303,7 @@ void InitializeNode(NodeId nodeid, const CNode *pnode) {
LOCK(cs_main);
CNodeState &state = mapNodeState.insert(std::make_pair(nodeid, CNodeState())).first->second;
state.name = pnode->addrName;
state.address = pnode->addr;
}

void FinalizeNode(NodeId nodeid) {
Expand All @@ -307,6 +313,10 @@ void FinalizeNode(NodeId nodeid) {
if (state->fSyncStarted)
nSyncStarted--;

if (state->nMisbehavior == 0 && state->fCurrentlyConnected) {
AddressCurrentlyConnected(state->address);
}

BOOST_FOREACH(const QueuedBlock& entry, state->vBlocksInFlight)
mapBlocksInFlight.erase(entry.hash);
EraseOrphansFor(nodeid);
Expand Down Expand Up @@ -3563,6 +3573,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
else if (strCommand == "verack")
{
pfrom->SetRecvVersion(min(pfrom->nVersion, PROTOCOL_VERSION));

// Mark this node as currently connected, so we update its timestamp later.
if (pfrom->fNetworkNode) {
LOCK(cs_main);
State(pfrom->GetId())->fCurrentlyConnected = true;
}
}


Expand Down Expand Up @@ -4207,11 +4223,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
}


// Update the last seen time for this node's address
if (pfrom->fNetworkNode)
if (strCommand == "version" || strCommand == "addr" || strCommand == "inv" || strCommand == "getdata" || strCommand == "ping")
AddressCurrentlyConnected(pfrom->addr);


return true;
}
Expand Down

0 comments on commit ca301bf

Please sign in to comment.