Skip to content

Commit ca301bf

Browse files
sipalaanwj
authored andcommitted
Reduce fingerprinting through timestamps in 'addr' messages.
Suggested by Jonas Nick. Rebased-From: 9c27379 Github-Pull: #5860
1 parent 2c08406 commit ca301bf

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/addrman.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,9 @@ void CAddrMan::Good_(const CService& addr, int64_t nTime)
272272
// update info
273273
info.nLastSuccess = nTime;
274274
info.nLastTry = nTime;
275-
info.nTime = nTime;
276275
info.nAttempts = 0;
276+
// nTime is not updated here, to avoid leaking information about
277+
// currently-connected peers.
277278

278279
// if it is already in the tried set, don't do anything else
279280
if (info.fInTried)

src/main.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ struct CBlockReject {
231231
* and we're no longer holding the node's locks.
232232
*/
233233
struct CNodeState {
234+
//! The peer's address
235+
CService address;
236+
//! Whether we have a fully established connection.
237+
bool fCurrentlyConnected;
234238
//! Accumulated misbehaviour score for this peer.
235239
int nMisbehavior;
236240
//! Whether this peer should be disconnected and banned (unless whitelisted).
@@ -255,6 +259,7 @@ struct CNodeState {
255259
bool fPreferredDownload;
256260

257261
CNodeState() {
262+
fCurrentlyConnected = false;
258263
nMisbehavior = 0;
259264
fShouldBan = false;
260265
pindexBestKnownBlock = NULL;
@@ -298,6 +303,7 @@ void InitializeNode(NodeId nodeid, const CNode *pnode) {
298303
LOCK(cs_main);
299304
CNodeState &state = mapNodeState.insert(std::make_pair(nodeid, CNodeState())).first->second;
300305
state.name = pnode->addrName;
306+
state.address = pnode->addr;
301307
}
302308

303309
void FinalizeNode(NodeId nodeid) {
@@ -307,6 +313,10 @@ void FinalizeNode(NodeId nodeid) {
307313
if (state->fSyncStarted)
308314
nSyncStarted--;
309315

316+
if (state->nMisbehavior == 0 && state->fCurrentlyConnected) {
317+
AddressCurrentlyConnected(state->address);
318+
}
319+
310320
BOOST_FOREACH(const QueuedBlock& entry, state->vBlocksInFlight)
311321
mapBlocksInFlight.erase(entry.hash);
312322
EraseOrphansFor(nodeid);
@@ -3563,6 +3573,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
35633573
else if (strCommand == "verack")
35643574
{
35653575
pfrom->SetRecvVersion(min(pfrom->nVersion, PROTOCOL_VERSION));
3576+
3577+
// Mark this node as currently connected, so we update its timestamp later.
3578+
if (pfrom->fNetworkNode) {
3579+
LOCK(cs_main);
3580+
State(pfrom->GetId())->fCurrentlyConnected = true;
3581+
}
35663582
}
35673583

35683584

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

42094225

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

42164227
return true;
42174228
}

0 commit comments

Comments
 (0)