-
Notifications
You must be signed in to change notification settings - Fork 445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: track failed/successful dials per-address #2033
base: main
Are you sure you want to change the base?
Changes from 4 commits
90bfc6d
3b31fdd
cc8196c
7836623
40dd225
3296f11
308097f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,26 +26,51 @@ export async function dedupeFilterAndSortAddresses (peerId: PeerId, filter: Addr | |
continue | ||
} | ||
|
||
const isCertified = addr.isCertified ?? false | ||
const maStr = addr.multiaddr.toString() | ||
const existingAddr = addressMap.get(maStr) | ||
let existingAddr = addressMap.get(maStr) | ||
|
||
if (existingAddr != null) { | ||
addr.isCertified = existingAddr.isCertified || isCertified | ||
} else { | ||
addressMap.set(maStr, { | ||
multiaddr: addr.multiaddr, | ||
isCertified | ||
}) | ||
if (existingAddr == null) { | ||
existingAddr = { | ||
multiaddr: addr.multiaddr | ||
} | ||
|
||
addressMap.set(maStr, existingAddr) | ||
} | ||
|
||
if (addr.isCertified === true) { | ||
existingAddr.isCertified = true | ||
} | ||
|
||
if (addr.lastFailure != null) { | ||
existingAddr.lastFailure = Number(addr.lastFailure) | ||
} | ||
|
||
if (addr.lastSuccess != null) { | ||
existingAddr.lastSuccess = Number(addr.lastSuccess) | ||
Comment on lines
+45
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a good reason to use Number here instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The value is a timestamp, the max value of which can exceed 32 bits so we need to use a 64 bit number in the protobuf to store it, which means we need to represent it as a BigInt, but this is overkill for actual time values. We can refactor this once ipfs/protons#112 is implemented to have protons serialize/deserialize to |
||
} | ||
} | ||
|
||
return [...addressMap.values()] | ||
.sort((a, b) => { | ||
return a.multiaddr.toString().localeCompare(b.multiaddr.toString()) | ||
}) | ||
.map(({ isCertified, multiaddr }) => ({ | ||
isCertified, | ||
multiaddr: multiaddr.bytes | ||
})) | ||
.map(({ isCertified, multiaddr, lastFailure, lastSuccess }) => { | ||
const addr: AddressPB = { | ||
multiaddr: multiaddr.bytes | ||
} | ||
|
||
if (isCertified) { | ||
addr.isCertified = true | ||
} | ||
|
||
if (lastFailure != null) { | ||
addr.lastFailure = BigInt(lastFailure) | ||
} | ||
|
||
if (lastSuccess != null) { | ||
addr.lastSuccess = BigInt(lastSuccess) | ||
} | ||
|
||
return addr | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check implies that we may also attempt to dial peers where peerId == null. Can we log when that is the case, and that we're not marking peer as having a failed dial?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is the case when dialing a multiaddr without a peer id, e.g.
/dnsaddr/bootstrap.libp2p.io
We can't mark the peer as having a failed dial as peer data is keyed on the peer id - if we don't know the peer id we can't mark anything as having failed.