From 2d8f05f966faaea247ff8f629175e304612c435a Mon Sep 17 00:00:00 2001 From: gopherfarm Date: Tue, 10 Sep 2024 17:13:54 +0800 Subject: [PATCH] fix: use quic.Version instead of the deprecated quic.VersionNumber (#2955) --- p2p/transport/quic/listener.go | 4 ++-- p2p/transport/quic/transport.go | 2 +- p2p/transport/quic/virtuallistener.go | 12 ++++++------ p2p/transport/quicreuse/config.go | 2 +- p2p/transport/quicreuse/connmgr.go | 2 +- p2p/transport/quicreuse/quic_multiaddr.go | 6 +++--- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/p2p/transport/quic/listener.go b/p2p/transport/quic/listener.go index 0c69741358..f90bdf53f0 100644 --- a/p2p/transport/quic/listener.go +++ b/p2p/transport/quic/listener.go @@ -23,11 +23,11 @@ type listener struct { rcmgr network.ResourceManager privKey ic.PrivKey localPeer peer.ID - localMultiaddrs map[quic.VersionNumber]ma.Multiaddr + localMultiaddrs map[quic.Version]ma.Multiaddr } func newListener(ln quicreuse.Listener, t *transport, localPeer peer.ID, key ic.PrivKey, rcmgr network.ResourceManager) (listener, error) { - localMultiaddrs := make(map[quic.VersionNumber]ma.Multiaddr) + localMultiaddrs := make(map[quic.Version]ma.Multiaddr) for _, addr := range ln.Multiaddrs() { if _, err := addr.ValueForProtocol(ma.P_QUIC_V1); err == nil { localMultiaddrs[quic.Version1] = addr diff --git a/p2p/transport/quic/transport.go b/p2p/transport/quic/transport.go index f0862d22e9..4d3d9e551d 100644 --- a/p2p/transport/quic/transport.go +++ b/p2p/transport/quic/transport.go @@ -327,7 +327,7 @@ func (t *transport) Listen(addr ma.Multiaddr) (tpt.Listener, error) { acceptRunner = &acceptLoopRunner{ acceptSem: make(chan struct{}, 1), - muxer: make(map[quic.VersionNumber]chan acceptVal), + muxer: make(map[quic.Version]chan acceptVal), } } diff --git a/p2p/transport/quic/virtuallistener.go b/p2p/transport/quic/virtuallistener.go index 8aa2a0c1e6..7927225567 100644 --- a/p2p/transport/quic/virtuallistener.go +++ b/p2p/transport/quic/virtuallistener.go @@ -16,7 +16,7 @@ const acceptBufferPerVersion = 4 type virtualListener struct { *listener udpAddr string - version quic.VersionNumber + version quic.Version t *transport acceptRunnner *acceptLoopRunner acceptChan chan acceptVal @@ -46,11 +46,11 @@ type acceptLoopRunner struct { acceptSem chan struct{} muxerMu sync.Mutex - muxer map[quic.VersionNumber]chan acceptVal + muxer map[quic.Version]chan acceptVal muxerClosed bool } -func (r *acceptLoopRunner) AcceptForVersion(v quic.VersionNumber) chan acceptVal { +func (r *acceptLoopRunner) AcceptForVersion(v quic.Version) chan acceptVal { r.muxerMu.Lock() defer r.muxerMu.Unlock() @@ -64,7 +64,7 @@ func (r *acceptLoopRunner) AcceptForVersion(v quic.VersionNumber) chan acceptVal return ch } -func (r *acceptLoopRunner) RmAcceptForVersion(v quic.VersionNumber, err error) { +func (r *acceptLoopRunner) RmAcceptForVersion(v quic.Version, err error) { r.muxerMu.Lock() defer r.muxerMu.Unlock() @@ -98,7 +98,7 @@ func (r *acceptLoopRunner) sendErrAndClose(err error) { // innerAccept is the inner logic of the Accept loop. Assume caller holds the // acceptSemaphore. May return both a nil conn and nil error if it didn't find a // conn with the expected version -func (r *acceptLoopRunner) innerAccept(l *listener, expectedVersion quic.VersionNumber, bufferedConnChan chan acceptVal) (tpt.CapableConn, error) { +func (r *acceptLoopRunner) innerAccept(l *listener, expectedVersion quic.Version, bufferedConnChan chan acceptVal) (tpt.CapableConn, error) { select { // Check if we have a buffered connection first from an earlier Accept call case v, ok := <-bufferedConnChan: @@ -150,7 +150,7 @@ func (r *acceptLoopRunner) innerAccept(l *listener, expectedVersion quic.Version return nil, nil } -func (r *acceptLoopRunner) Accept(l *listener, expectedVersion quic.VersionNumber, bufferedConnChan chan acceptVal) (tpt.CapableConn, error) { +func (r *acceptLoopRunner) Accept(l *listener, expectedVersion quic.Version, bufferedConnChan chan acceptVal) (tpt.CapableConn, error) { for { var conn tpt.CapableConn var err error diff --git a/p2p/transport/quicreuse/config.go b/p2p/transport/quicreuse/config.go index 92c881ef7c..62f8919c8b 100644 --- a/p2p/transport/quicreuse/config.go +++ b/p2p/transport/quicreuse/config.go @@ -12,7 +12,7 @@ var quicConfig = &quic.Config{ MaxStreamReceiveWindow: 10 * (1 << 20), // 10 MB MaxConnectionReceiveWindow: 15 * (1 << 20), // 15 MB KeepAlivePeriod: 15 * time.Second, - Versions: []quic.VersionNumber{quic.Version1}, + Versions: []quic.Version{quic.Version1}, // We don't use datagrams (yet), but this is necessary for WebTransport EnableDatagrams: true, } diff --git a/p2p/transport/quicreuse/connmgr.go b/p2p/transport/quicreuse/connmgr.go index 8e4c61b0bc..c3aa0fa046 100644 --- a/p2p/transport/quicreuse/connmgr.go +++ b/p2p/transport/quicreuse/connmgr.go @@ -232,7 +232,7 @@ func (c *ConnManager) DialQUIC(ctx context.Context, raddr ma.Multiaddr, tlsConf if v == quic.Version1 { // The endpoint has explicit support for QUIC v1, so we'll only use that version. - quicConf.Versions = []quic.VersionNumber{quic.Version1} + quicConf.Versions = []quic.Version{quic.Version1} } else { return nil, errors.New("unknown QUIC version") } diff --git a/p2p/transport/quicreuse/quic_multiaddr.go b/p2p/transport/quicreuse/quic_multiaddr.go index 3da4721b5b..85b282df2e 100644 --- a/p2p/transport/quicreuse/quic_multiaddr.go +++ b/p2p/transport/quicreuse/quic_multiaddr.go @@ -13,7 +13,7 @@ var ( quicV1MA = ma.StringCast("/quic-v1") ) -func ToQuicMultiaddr(na net.Addr, version quic.VersionNumber) (ma.Multiaddr, error) { +func ToQuicMultiaddr(na net.Addr, version quic.Version) (ma.Multiaddr, error) { udpMA, err := manet.FromNetAddr(na) if err != nil { return nil, err @@ -26,8 +26,8 @@ func ToQuicMultiaddr(na net.Addr, version quic.VersionNumber) (ma.Multiaddr, err } } -func FromQuicMultiaddr(addr ma.Multiaddr) (*net.UDPAddr, quic.VersionNumber, error) { - var version quic.VersionNumber +func FromQuicMultiaddr(addr ma.Multiaddr) (*net.UDPAddr, quic.Version, error) { + var version quic.Version var partsBeforeQUIC []ma.Multiaddr ma.ForEach(addr, func(c ma.Component) bool { switch c.Protocol().Code {