-
Notifications
You must be signed in to change notification settings - Fork 454
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
test: add tests for non-unilateral DCUtR over TCP #1932
Conversation
Implements the [DCUtR protocol](https://github.com/libp2p/specs/blob/master/relay/DCUtR.md). Only supports TCP Simultaneous Connect since there is no QUIC support yet
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.
self review and some comments/questions for @achingbrain
packages/libp2p/src/dcutr/dcutr.ts
Outdated
// TODO: Why is this outbound? This is supposed to be A, handling an incoming connection from B | ||
// which means on A, data.connection.direction should be 'inbound' |
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.
@achingbrain this is confusing. maybe i'm misunderstanding how registrar and topology works. Is this supposed to be handleOutgoingUpgrade
?
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.
When you register a protocol handler with the registrar, it's invoked when a stream for that protocol is opened by the remote peer.
To do it in the other direction you'd call connection.openStream(multicodec)
if you already have a connection or libp2p.dialProtocol(peer, multicodec)
if you don't.
The actual connection direction isn't taken into account, but in this case the protocol is clear on which end opens the stream.
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.
I'm still confused why we're calling handleIncomingUpgrade
when direction === outbound. that direction implies that the current node is B.. I'm missing something and could probably benefit from a live chat
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.
Why is this outbound? This is supposed to be A, handling an incoming connection from B
The spec says:
B opens a stream to A using the /libp2p/dcutr protocol
So this is A, handling the incoming stream opened by B.
The connection was originally opened in the other direction, from A to B.
The Incoming
in handleIncomingUpgrade
refers to what's happening in the protocol, not the connection direction.
packages/libp2p/src/dcutr/dcutr.ts
Outdated
// Upon observing the new connection, the inbound peer (here B) checks the | ||
// addresses advertised by A via identify. | ||
// | ||
// If that set includes public addresses, then A may be reachable by a direct | ||
// connection, in which case B attempts a unilateral connection upgrade by | ||
// initiating a direct connection to A. | ||
if (await this.attemptUnilateralConnectionUpgrade(relayedConnection)) { | ||
if (await this.attemptUnilateralConnectionUpgrade(connection)) { | ||
debugLog('unilateral connection upgrade succeeded') | ||
return | ||
} |
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.
Moved this into the dcutr proto registration's onConnect instead of in the DCUtR process itself, since the spec also breaks this step out as something to be attempted prior to DCUtR instead of as a part of the DCUtR process.
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.
The onConnectAttempt
function is bound to this
and set as the onConnect
topology callback - it's an async function but onConnect
's signature is sync.
This is flagged by the linter.
const logA = logger('libp2p:dcutr:A') | ||
const logB = logger('libp2p:dcutr:B') |
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.
I found these to be much more helpful in debugging than prefixing with "A this" "B that" because we know who the one in control of operations is when we logA
or logB
, no matter what we put in the message.
packages/libp2p/src/dcutr/dcutr.ts
Outdated
|
||
const log = logger('libp2p:dcutr') | ||
const logA = logger('libp2p:dcutr:A') | ||
const logB = logger('libp2p:dcutr:B') | ||
const debugLog = logger('libp2p:dcutr:debug') |
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.
why doesn't libp2p/logger let us call .extend()
to add debug...? log{A,B}.debug
would be much more useful
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.
Usually you use .trace
for debug-level logging.
Please can you replace all instances of debugLog
with debug.trace
and log happy-path messages with .trace
, errors with .error
and anything notable with debug()
.
To see the trace-level logging you have to turn it on explicitly with DEBUG=*:trace
.
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.
I believe this is done but let me know if I misused the logs
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.
packages/libp2p/src/dcutr/dcutr.ts
Outdated
await relayedConnection.close(options) | ||
logB('closed relayed connection') | ||
// stop the for loop. | ||
break; |
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.
If the connection here is successful, there is no further need to retry, so we need to break out of the loop.
two other things:
Based on ipfs/helia#182 (comment), it seems like we could just enable/disable some transports on each node to get the effect we want, but I don't believe the third item in that comment is accurate
In the spec, and in this code, both of the following are true (B=browser, A=gateway):
|
The scenario is:
|
This comment was marked as outdated.
This comment was marked as outdated.
242fd96
to
bca8d6e
Compare
This change builds on top of #1928 and adds a lot more debugging output that is
probably not as necessary for someone more familiar (aka @achingbrain)