Repository navigation
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
|
Both IPv6 and CJDNS use 16 bytes, so there could be an overlap like with Tor and I2P. The first of those 16 bytes identifies the address as CJDNS. While such an address is also a valid IPv6 address, it is globally unroutable on the public internet. |
| case NET_INTERNAL: key.push_back(6); break; | ||
| case NET_UNROUTABLE: // m_net is never and should not be set to NET_UNROUTABLE | ||
| case NET_MAX: // m_net is never and should not be set to NET_MAX | ||
| AssertUnreachable(); |
There was a problem hiding this comment.
shouldn't this rather be a break and an AssertUnreachable() after the switch for this to be guaranteed exhaustive?
There was a problem hiding this comment.
There are two things here: 1. values for m_net that should never be set and 2. ensure that the switch handles all enum values.
For example here there are two asserts to handle each one of 1. and 2.:
Lines 487 to 501 in edcac28
and here just 1. is checked:
Lines 111 to 136 in edcac28
The new code I added is like in the second example, handling only 1. To handle 2. one must conclude every case with a return so that the assert after the switch becomes unreachable. This is omitted in places where some work has to be done after the switch.
There was a problem hiding this comment.
If you want to add the assert, it would be possible with a lambda, but up to you:
enum class Tabs {
info,
console,
};
int GetInt(Tabs tab)
{
int ret = [&]() {
switch (tab) {
case Tabs::info: return 0;
case Tabs::console: return 1;
} // no default case, so the compiler can warn about missing cases
AssertUnreachable();
}();
LogInfo("Tab %s", ret);
return ret;
}There was a problem hiding this comment.
Cool pattern, I wasn't aware of it. I like it. The surrounding code does not use it though, so for now I will leave it as it is for now.
|
Concept ACK |
| { | ||
| std::vector<unsigned char> key; | ||
|
|
||
| if (include_network) { |
There was a problem hiding this comment.
I think it would be simpler to reuse the BIP155 serialization here, if there is no requirement for compatibility with the old non-include_network format.
if (include_network) {
VectorWriter writer(key, 0);
writer << CNetAddr::V2(*this);
return key;
}This will assert(false); if used on a NET_INTERNAL address, so that may still need to be handled separately if that's a possibility.
There was a problem hiding this comment.
Simpler. Like. NET_INTERNAL works. No need to handle.
Lines 376 to 390 in 0bc1e88
The current version of `CService::GetKey()` is used for addrman bucketing. While on-disk format of `peers.dat` does not depend on it, loading the same `peers.dat` with different bucketing rules will cause many (if not all) addresses to end up in a different bucket and/or position in memory and likely colliding with another address and thus being lost. In some circumstances it may be ok to do that, but it must be justified and definitely must not happen unintentionally. Thus, add tests that would need to be adjusted if this happens.
`CService::GetKey()` didn't include the network in the output. So in theory it would be possible for two I2P and Tor addresses to have the same output from `CService::GetKey()`. This would have unexpected results when used in the per-peer bloom filter of known addresses - we may wrongfully assume that a peer knows `foo.onion` when we have sent to them `foo.i2p`. To make this impossible - include the network in `CService::GetKey()`. Addrman already includes the network separately so it does not need this change. The code would be simplest if addrman also uses `GetKey()` with the network but that would change its in-memory bucketing, resuling in some addresses being collided away on the first load with the new bucketing scheme. So, keep a variant of network-less `GetKey()` for addrman.
f5a425d to
6b6bf6f
Compare
|
I considered including the network unconditionally in new table: 65512 addresses after loading that file with unconditional-with-network-GetKey() the collisions resulted in: new table: 42905 addresses I assume that this is going to be more or less the same for every full addrman and better with addrmans that have less addresses. I think that is too much, so I leave the option to preserve the bucketing (have network-less-GetKey()). |

CService::GetKey()didn't include the network in the output. So in theory it would be possible for two I2P and Tor addresses to have the same output fromCService::GetKey().This would have unexpected results when used in the per-peer bloom filter of known addresses - we may wrongfully assume that a peer knows
foo.onionwhen we have sent to themfoo.i2p.To make this impossible - include the network in
CService::GetKey().Addrman already includes the network separately so it does not need this change. The code would be simplest if addrman also uses
GetKey()with the network but that would mess the positions of addresses in existent databases (peers.dat). So, keep a variant of network-lessGetKey()for addrman.Thanks, l0rinc for pointing me into this. I think it is minor but also the change is minor, so worth fixing IMO.