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

fix: call InterceptSecured earlier; drop conn. #156

Closed
wants to merge 2 commits into from

Conversation

raulk
Copy link
Member

@raulk raulk commented May 21, 2020

Fixes #155.

Copy link
Collaborator

@marten-seemann marten-seemann left a comment

Choose a reason for hiding this comment

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

This would fix the bug for QUIC, but not for TLS.
In #155 (comment) I've argued that InterceptSecured belongs in the security layer, not in the transport layer. What are your thoughts on that?

@@ -50,8 +50,7 @@ func (c *filteredConn) ReadFrom(b []byte) (n int, addr net.Addr, rerr error) {
}

connAddrs := &connAddrs{lmAddr: c.lmAddr, rmAddr: rmAddr}

if c.gater.InterceptAccept(connAddrs) {
if c.gater != nil && c.gater.InterceptAccept(connAddrs) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed a potential nil pointer panic here.

ma "github.com/multiformats/go-multiaddr"
)

func BenchmarkInterceptSecured(b *testing.B) {
Copy link
Member Author

Choose a reason for hiding this comment

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

@marten-seemann @Stebalien

Figured we might as well write a little benchmark to know how much state is being constructed by QUIC after a successful handshake, which we could prevent by blocking denied connections earlier.

TL;DR: we're looking at a 20% difference in allocs (1000+ allocs), and 10% difference in bytes (50kB per op).

This PR

goos: darwin
goarch: amd64
pkg: github.com/libp2p/go-libp2p-quic-transport
BenchmarkInterceptSecured
BenchmarkInterceptSecured-8          694       1673938 ns/op      497751 B/op       4394 allocs/op
PASS

Process finished with exit code 0

PR #157

goos: darwin
goarch: amd64
pkg: github.com/libp2p/go-libp2p-quic-transport
BenchmarkInterceptSecured
BenchmarkInterceptSecured-8          670       1760618 ns/op      544251 B/op       5436 allocs/op
PASS

Process finished with exit code 0

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