2022-08-10 12:19:16 +00:00
|
|
|
//go:build with_quic
|
|
|
|
|
|
|
|
package inbound
|
|
|
|
|
|
|
|
import (
|
2022-08-18 15:02:36 +00:00
|
|
|
"github.com/sagernet/quic-go/http3"
|
2022-08-23 05:22:03 +00:00
|
|
|
E "github.com/sagernet/sing/common/exceptions"
|
2022-08-10 12:19:16 +00:00
|
|
|
)
|
|
|
|
|
2022-08-23 05:22:03 +00:00
|
|
|
func (n *Naive) configureHTTP3Listener() error {
|
2022-09-09 10:45:10 +00:00
|
|
|
tlsConfig, err := n.tlsConfig.Config()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-08-10 12:19:16 +00:00
|
|
|
h3Server := &http3.Server{
|
|
|
|
Port: int(n.listenOptions.ListenPort),
|
2022-09-09 10:45:10 +00:00
|
|
|
TLSConfig: tlsConfig,
|
2022-08-10 12:19:16 +00:00
|
|
|
Handler: n,
|
|
|
|
}
|
|
|
|
|
2022-08-23 05:22:03 +00:00
|
|
|
udpConn, err := n.ListenUDP()
|
2022-08-10 12:19:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
go func() {
|
2022-08-23 05:22:03 +00:00
|
|
|
sErr := h3Server.Serve(udpConn)
|
|
|
|
udpConn.Close()
|
|
|
|
if sErr != nil && !E.IsClosedOrCanceled(sErr) {
|
2022-08-10 12:19:16 +00:00
|
|
|
n.logger.Error("http3 server serve error: ", sErr)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
n.h3Server = h3Server
|
|
|
|
return nil
|
|
|
|
}
|