Skip to content

Commit

Permalink
webtransport: update webtransport-go to v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Nov 17, 2022
1 parent 84ded7d commit 1516247
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ require (
github.com/libp2p/zeroconf/v2 v2.2.0
github.com/lucas-clemente/quic-go v0.31.0
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd
github.com/marten-seemann/webtransport-go v0.2.0
github.com/marten-seemann/webtransport-go v0.3.0
github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b
github.com/minio/sha256-simd v1.0.0
github.com/mr-tron/base58 v1.2.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ github.com/marten-seemann/qtls-go1-19 v0.1.1 h1:mnbxeq3oEyQxQXwI4ReCgW9DPoPR94sN
github.com/marten-seemann/qtls-go1-19 v0.1.1/go.mod h1:5HTDWtVudo/WFsHKRNuOhWlbdjrfs5JHrYb0wIJqGpI=
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd h1:br0buuQ854V8u83wA0rVZ8ttrq5CpaPZdvrK0LP2lOk=
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd/go.mod h1:QuCEs1Nt24+FYQEqAAncTDPJIuGs+LxK1MCiFL25pMU=
github.com/marten-seemann/webtransport-go v0.2.0 h1:987jPVqcyE3vF+CHNIxDhT0P21O+bI4fVF+0NoRujSo=
github.com/marten-seemann/webtransport-go v0.2.0/go.mod h1:XmnWYsWXaxUF7kjeIIzLWPyS+q0OcBY5vA64NuyK0ps=
github.com/marten-seemann/webtransport-go v0.3.0 h1:TqUSf7/qZN8bJyuGrDMz9nDrfMbgH8p7KqV3TYrkBgo=
github.com/marten-seemann/webtransport-go v0.3.0/go.mod h1:4xcfySgZMLP4aG5GBGj1egP7NlpfwgYJ1WJMvPPiVMU=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
Expand Down
2 changes: 1 addition & 1 deletion p2p/transport/webtransport/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (c *conn) allowWindowIncrease(size uint64) bool {
// garbage collection to properly work in this package.
func (c *conn) Close() error {
c.transport.removeConn(c.session)
return c.session.Close()
return c.session.CloseWithError(0, "")
}

func (c *conn) IsClosed() bool { return c.session.Context().Err() != nil }
Expand Down
8 changes: 4 additions & 4 deletions p2p/transport/webtransport/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,22 +137,22 @@ func (l *listener) httpHandler(w http.ResponseWriter, r *http.Request) {
if err != nil {
cancel()
log.Debugw("handshake failed", "error", err)
sess.Close()
sess.CloseWithError(1, "")
connScope.Done()
return
}
cancel()

if l.transport.gater != nil && !l.transport.gater.InterceptSecured(network.DirInbound, sconn.RemotePeer(), sconn) {
// TODO: can we close with a specific error here?
sess.Close()
sess.CloseWithError(errorCodeConnectionGating, "")
connScope.Done()
return
}

if err := connScope.SetPeer(sconn.RemotePeer()); err != nil {
log.Debugw("resource manager blocked incoming connection for peer", "peer", sconn.RemotePeer(), "addr", r.RemoteAddr, "error", err)
sess.Close()
sess.CloseWithError(1, "")
connScope.Done()
return
}
Expand All @@ -163,7 +163,7 @@ func (l *listener) httpHandler(w http.ResponseWriter, r *http.Request) {
case l.queue <- conn:
default:
log.Debugw("accept queue full, dropping incoming connection", "peer", sconn.RemotePeer(), "addr", r.RemoteAddr, "error", err)
sess.Close()
sess.CloseWithError(1, "")
connScope.Done()
}
}
Expand Down
2 changes: 1 addition & 1 deletion p2p/transport/webtransport/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

const (
reset webtransport.ErrorCode = 0
reset webtransport.StreamErrorCode = 0
)

type webtransportStream struct {
Expand Down
7 changes: 4 additions & 3 deletions p2p/transport/webtransport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ var log = logging.Logger("webtransport")

const webtransportHTTPEndpoint = "/.well-known/libp2p-webtransport"

const errorCodeConnectionGating = 0x47415445 // GATE in ASCII

const certValidity = 14 * 24 * time.Hour

type Option func(*transport) error
Expand Down Expand Up @@ -151,13 +153,12 @@ func (t *transport) Dial(ctx context.Context, raddr ma.Multiaddr, p peer.ID) (tp
}
sconn, err := t.upgrade(ctx, sess, p, certHashes)
if err != nil {
sess.Close()
sess.CloseWithError(1, "")
scope.Done()
return nil, err
}
if t.gater != nil && !t.gater.InterceptSecured(network.DirOutbound, p, sconn) {
// TODO: can we close with a specific error here?
sess.Close()
sess.CloseWithError(errorCodeConnectionGating, "")
scope.Done()
return nil, fmt.Errorf("secured connection gated")
}
Expand Down

0 comments on commit 1516247

Please sign in to comment.