-
Notifications
You must be signed in to change notification settings - Fork 42
fix: call InterceptSecured earlier; drop conn. #156
Conversation
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 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) { |
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.
Fixed a potential nil pointer panic here.
ma "github.com/multiformats/go-multiaddr" | ||
) | ||
|
||
func BenchmarkInterceptSecured(b *testing.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.
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
Fixes #155.