Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

close the connection when it is refused by InterceptSecured #157

Merged
merged 1 commit into from
May 22, 2020

Conversation

marten-seemann
Copy link
Collaborator

@marten-seemann marten-seemann commented May 21, 2020

Minimally fixes #155. Closes #156.

This is the solution to #155 that's analogous to what we do for other transports: We first finish the cryptographic handshake (which verifies the peer's identity), and then afterwards close the connection when the connection gater doesn't like that peer's ID.

@@ -186,6 +186,7 @@ func (t *transport) Dial(ctx context.Context, raddr ma.Multiaddr, p peer.ID) (tp

connaddrs := &connAddrs{lmAddr: localMultiaddr, rmAddr: remoteMultiaddr}
if t.gater != nil && !t.gater.InterceptSecured(n.DirOutbound, p, connaddrs) {
sess.CloseWithError(0, "")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use a different error code and / or a reason string here. Might help debugging, but then this would be something QUIC-specific as afaik we don't have any close reasons for TCP-based transports.

Copy link
Member

@raulk raulk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this create more overhead than #156?

@marten-seemann
Copy link
Collaborator Author

Overhead in what sense?

@raulk
Copy link
Member

raulk commented May 21, 2020

@marten-seemann creating state in QUIC that doesn't need to exist, which will be immediately available for GC? #156 drops connection the as soon as we authenticate the peer, and will likely perform better in terms of allocs and ns/op. We can benchmark it if you'd like.

@marten-seemann
Copy link
Collaborator Author

quic-go creates almost all of the state needed for a connection when accepting it (not when the handshake completes), so I don't expect a big difference here. For sure, aborting early is almost always more efficient, but since this is not the common case anyway, I don't think it's worth optimizing too much for it. I'd rather be consistent with other transports here.

@raulk
Copy link
Member

raulk commented May 21, 2020

@marten-seemann no other transport does this interception itself. They delegate on the Upgrader, which does it ASAP (as soon as the crypto handshake is done, and before the multiplexer is negotiated). We push the gater down to the transport precisely so that each transport can gate in the most efficient way, i.e. the goal is to specialise, not to normalise. I think the other PR achieves this in the most efficient and cleanest way possible.

Copy link
Member

@raulk raulk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should go with #156.

@raulk
Copy link
Member

raulk commented May 21, 2020

I don't think this is the right way to do this, @Stebalien. Please look at #156 and discussion.

@Stebalien
Copy link
Member

Sorry, I looked at the code instead of reading the discussion. I agree with @raulk here. We should reject the connection as early as we can.

@Stebalien
Copy link
Member

Ok, I need to read the full discussion before commenting. Continuing in #155.

@Stebalien
Copy link
Member

Given that this PR is a strict bug fix while the other PR bundles an optimization, I'm going to merge this and let the debate continue.

@Stebalien Stebalien merged commit 51f45f6 into master May 22, 2020
@Stebalien Stebalien mentioned this pull request May 26, 2020
77 tasks
@marten-seemann marten-seemann deleted the close-when-gated branch May 31, 2020 08:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

connection is not closed when rejected by InterceptSecured
3 participants