test relay server
All checks were successful
Create and publish a Docker image 🚀 / build-and-push-image (push) Successful in 2m1s
All checks were successful
Create and publish a Docker image 🚀 / build-and-push-image (push) Successful in 2m1s
This commit is contained in:
85
old-test-main.go
Normal file
85
old-test-main.go
Normal file
@@ -0,0 +1,85 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
|
||||
"github.com/caddyserver/certmagic"
|
||||
"github.com/okdaichi/gomoqt/moqt"
|
||||
"github.com/okdaichi/gomoqt/quic"
|
||||
)
|
||||
|
||||
func main() {
|
||||
domain := "qgo-server.quizer.space"
|
||||
email := "serverussnap@outlook.com"
|
||||
|
||||
// 1. Настройка CertMagic
|
||||
certmagic.DefaultACME.Email = email
|
||||
certmagic.DefaultACME.Agreed = true
|
||||
certmagic.Default.Storage = &certmagic.FileStorage{Path: "/root/.local/share/certmagic"}
|
||||
|
||||
// Создаем TLS конфигурацию
|
||||
tlsConfig, err := certmagic.TLS([]string{domain})
|
||||
if err != nil {
|
||||
slog.Error("failed to setup TLS", "error", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Поддержка протоколов для браузера и MoQ
|
||||
tlsConfig.NextProtos = []string{"h3"}
|
||||
tlsConfig.MinVersion = tls.VersionTLS13
|
||||
|
||||
// 2. Инициализация MoQ сервера
|
||||
moqServer := moqt.Server{
|
||||
Addr: ":443",
|
||||
TLSConfig: tlsConfig,
|
||||
QUICConfig: &quic.Config{
|
||||
Allow0RTT: true,
|
||||
EnableDatagrams: true,
|
||||
},
|
||||
}
|
||||
|
||||
path := "/relay"
|
||||
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Alt-Svc", `h3=":443"; ma=2592000`)
|
||||
|
||||
if r.URL.Path == path {
|
||||
err := moqServer.HandleWebTransport(w, r)
|
||||
if err != nil {
|
||||
slog.Error("WebTransport error", "error", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
fmt.Fprintf(w, "MoQ Server is active at %s", path)
|
||||
})
|
||||
|
||||
moqt.HandleFunc(path, func(w moqt.SetupResponseWriter, r *moqt.SetupRequest) {
|
||||
sess, err := moqt.Accept(w, r, nil)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
go handleSession(sess)
|
||||
})
|
||||
|
||||
slog.Info("Starting MoQ server", "url", "https://"+domain)
|
||||
|
||||
go func() {
|
||||
err := certmagic.HTTPS([]string{domain}, http.DefaultServeMux)
|
||||
if err != nil {
|
||||
slog.Error("TCP/HTTPS Server failed", "error", err)
|
||||
}
|
||||
}()
|
||||
|
||||
if err := moqServer.ListenAndServe(); err != nil {
|
||||
slog.Error("MoQ UDP Server failed", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func handleSession(sess *moqt.Session) {
|
||||
slog.Info("MoQ session established", "remote", sess.RemoteAddr())
|
||||
<-sess.Context().Done()
|
||||
slog.Info("MoQ session closed")
|
||||
}
|
||||
Reference in New Issue
Block a user