fix
All checks were successful
Create and publish a Docker image 🚀 / build-and-push-image (push) Successful in 1m56s
All checks were successful
Create and publish a Docker image 🚀 / build-and-push-image (push) Successful in 1m56s
This commit is contained in:
43
main.go
43
main.go
@@ -65,7 +65,6 @@ func (s *Server) handleSession(roomName string, sess *webtransport.Session) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
go s.handleStream(room, sess, stream)
|
||||
}
|
||||
}
|
||||
@@ -84,14 +83,14 @@ func (s *Server) handleStream(room *Room, sender *webtransport.Session, stream *
|
||||
if conn == sender {
|
||||
continue
|
||||
}
|
||||
go func(c *webtransport.Session) {
|
||||
go func(c *webtransport.Session, data []byte) {
|
||||
out, err := c.OpenStream()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer out.Close()
|
||||
out.Write(buf[:n])
|
||||
}(conn)
|
||||
out.Write(data)
|
||||
}(conn, append([]byte(nil), buf[:n]...))
|
||||
}
|
||||
room.mu.Unlock()
|
||||
}
|
||||
@@ -112,6 +111,7 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Обязательно и h3, и http/1.1
|
||||
tlsConf.NextProtos = []string{"h3", "http/1.1"}
|
||||
tlsConf.MinVersion = tls.VersionTLS13
|
||||
|
||||
@@ -119,7 +119,14 @@ func main() {
|
||||
|
||||
mux := http.NewServeMux()
|
||||
|
||||
wtServer := &webtransport.Server{}
|
||||
// WebTransport server поверх HTTP/3
|
||||
wtServer := &webtransport.Server{
|
||||
H3: &http3.Server{
|
||||
Addr: ":443",
|
||||
TLSConfig: tlsConf,
|
||||
Handler: mux,
|
||||
},
|
||||
}
|
||||
|
||||
mux.HandleFunc("/room/", func(w http.ResponseWriter, r *http.Request) {
|
||||
roomName := strings.TrimPrefix(r.URL.Path, "/room/")
|
||||
@@ -133,27 +140,21 @@ func main() {
|
||||
go server.handleSession(roomName, sess)
|
||||
})
|
||||
|
||||
// HTTP/1.1 server (TCP 443)
|
||||
log.Println("Relay running on https://" + domain + "/room/{room}")
|
||||
|
||||
// Запуск HTTP/3 + WebTransport (UDP 443)
|
||||
go func() {
|
||||
if err := wtServer.ListenAndServe(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Отдельный HTTPS сервер (TCP 443) для ACME challenge
|
||||
httpServer := &http.Server{
|
||||
Addr: ":443",
|
||||
TLSConfig: tlsConf,
|
||||
Handler: mux,
|
||||
}
|
||||
|
||||
// HTTP/3 server (UDP 443)
|
||||
h3Server := &http3.Server{
|
||||
Addr: ":443",
|
||||
TLSConfig: tlsConf,
|
||||
Handler: mux,
|
||||
}
|
||||
|
||||
log.Println("Relay running on https://" + domain + "/room/{room}")
|
||||
|
||||
// Запускаем HTTP/3
|
||||
go func() {
|
||||
log.Fatal(h3Server.ListenAndServe())
|
||||
}()
|
||||
|
||||
// Запускаем HTTPS (TCP)
|
||||
log.Fatal(httpServer.ListenAndServeTLS("", ""))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user