Skip to content

Commit

Permalink
net: ignore ports when comparing I2P addresses
Browse files Browse the repository at this point in the history
From our perspective ports are ignored when connecting to the I2P
network. I.e. `aaa.b32.i2p:1111` is the same as `aaa.b32.i2p:2222`,
so compare them equal to avoid redundant connections to the same node if
ports happen to differ for some reason.

Fixes bitcoin#21389
  • Loading branch information
vasild committed Mar 18, 2021
1 parent 9d67b8e commit 4521677
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/netaddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,14 @@ uint16_t CService::GetPort() const

bool operator==(const CService& a, const CService& b)
{
return static_cast<CNetAddr>(a) == static_cast<CNetAddr>(b) && a.port == b.port;
const bool addr_eq{static_cast<CNetAddr>(a) == static_cast<CNetAddr>(b)};
if (!addr_eq) {
return false;
}
if (a.IsI2P()) {
return true;
}
return a.port == b.port;
}

/**
Expand Down

0 comments on commit 4521677

Please sign in to comment.