Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions src/addrman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,28 +750,25 @@ void CAddrMan::ResetI2PPorts()
continue;
}

auto addr_info_newport = addr_info;
// The below changes addr_info_newport.GetKey(), which is used in finding a
// The below changes addr_info.GetKey(), which is used in finding a
// bucket and a position within that bucket. So a re-bucketing may be necessary.
addr_info_newport.port = I2P_SAM31_PORT;
addr_info.port = I2P_SAM31_PORT;

// Reposition entries of vvNew within the same bucket because we don't know the source
// address which led to the decision to store the entry in vvNew[bucket] so we can't
// re-evaluate that decision, but even if we could, CAddrInfo::GetNewBucket() does not
// use CAddrInfo::GetKey() so it would end up in the same bucket as before the port
// change.
const auto i_target = addr_info_newport.GetBucketPosition(nKey, true, bucket);
const auto i_target = addr_info.GetBucketPosition(nKey, true, bucket);

if (i_target == i) { // No need to re-position.
addr_info = addr_info_newport;
continue;
}

// Reposition from i to i_target, removing the entry from i_target (if any).
ClearNew(bucket, i_target);
vvNew[bucket][i_target] = id;
vvNew[bucket][i] = -1;
addr_info = addr_info_newport;
}
}

Expand All @@ -790,16 +787,14 @@ void CAddrMan::ResetI2PPorts()
continue;
}

auto addr_info_newport = addr_info;
// The below changes addr_info_newport.GetKey(), which is used in finding a
// The below changes addr_info.GetKey(), which is used in finding a
// bucket and a position within that bucket. So a re-bucketing may be necessary.
addr_info_newport.port = I2P_SAM31_PORT;
addr_info.port = I2P_SAM31_PORT;

const auto bucket_target = addr_info_newport.GetTriedBucket(nKey, m_asmap);
const auto i_target = addr_info_newport.GetBucketPosition(nKey, false, bucket_target);
const auto bucket_target = addr_info.GetTriedBucket(nKey, m_asmap);
const auto i_target = addr_info.GetBucketPosition(nKey, false, bucket_target);

if (bucket_target == bucket && i_target == i) { // No need to re-position.
addr_info = addr_info_newport;
continue;
}

Expand All @@ -825,7 +820,6 @@ void CAddrMan::ResetI2PPorts()

vvTried[bucket_target][i_target] = id;
vvTried[bucket][i] = -1;
addr_info = addr_info_newport;
}
}
}