github.com/sagernet/sing-box@v1.9.0-rc.20/inbound/naive_quic.go (about) 1 //go:build with_quic 2 3 package inbound 4 5 import ( 6 "github.com/sagernet/quic-go" 7 "github.com/sagernet/quic-go/http3" 8 "github.com/sagernet/sing-quic" 9 E "github.com/sagernet/sing/common/exceptions" 10 ) 11 12 func (n *Naive) configureHTTP3Listener() error { 13 err := qtls.ConfigureHTTP3(n.tlsConfig) 14 if err != nil { 15 return err 16 } 17 18 udpConn, err := n.ListenUDP() 19 if err != nil { 20 return err 21 } 22 23 quicListener, err := qtls.ListenEarly(udpConn, n.tlsConfig, &quic.Config{ 24 MaxIncomingStreams: 1 << 60, 25 Allow0RTT: true, 26 }) 27 if err != nil { 28 udpConn.Close() 29 return err 30 } 31 32 h3Server := &http3.Server{ 33 Port: int(n.listenOptions.ListenPort), 34 Handler: n, 35 } 36 37 go func() { 38 sErr := h3Server.ServeListener(quicListener) 39 udpConn.Close() 40 if sErr != nil && !E.IsClosedOrCanceled(sErr) { 41 n.logger.Error("http3 server serve error: ", sErr) 42 } 43 }() 44 45 n.h3Server = h3Server 46 return nil 47 }