add new tls enctrypt method
All checks were successful
Create and publish a Docker image 🚀 / build-and-push-image (push) Successful in 4m58s
All checks were successful
Create and publish a Docker image 🚀 / build-and-push-image (push) Successful in 4m58s
This commit is contained in:
23
main.go
23
main.go
@@ -1,30 +1,28 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"log"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
|
||||
"github.com/caddyserver/certmagic"
|
||||
"github.com/okdaichi/gomoqt/moqt"
|
||||
"github.com/okdaichi/gomoqt/quic"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// 🔐 Загружаем mkcert сертификат
|
||||
cert, err := tls.LoadX509KeyPair("localhost+3.pem", "localhost+3-key.pem")
|
||||
certmagic.DefaultACME.Email = "your-email@example.com"
|
||||
certmagic.DefaultACME.Agreed = true
|
||||
|
||||
tlsConfig, err := certmagic.TLS([]string{"qgo-server.quizer.space"})
|
||||
if err != nil {
|
||||
log.Fatalf("failed to load server cert and key: %v", err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
tlsConfig := &tls.Config{
|
||||
Certificates: []tls.Certificate{cert},
|
||||
NextProtos: []string{"h3"}, // обязательно для HTTP/3
|
||||
}
|
||||
tlsConfig.NextProtos = append([]string{"h3"}, tlsConfig.NextProtos...)
|
||||
|
||||
// 🚀 MoQ сервер
|
||||
server := moqt.Server{
|
||||
Addr: ":8080",
|
||||
Addr: ":443",
|
||||
TLSConfig: tlsConfig,
|
||||
QUICConfig: &quic.Config{
|
||||
Allow0RTT: true,
|
||||
@@ -34,7 +32,6 @@ func main() {
|
||||
|
||||
path := "/relay"
|
||||
|
||||
// 🌐 WebTransport endpoint
|
||||
http.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
|
||||
slog.Info("Incoming WebTransport request")
|
||||
|
||||
@@ -44,7 +41,6 @@ func main() {
|
||||
}
|
||||
})
|
||||
|
||||
// 📡 MoQ setup handler
|
||||
moqt.HandleFunc(path, func(w moqt.SetupResponseWriter, r *moqt.SetupRequest) {
|
||||
slog.Info("MoQ setup request received")
|
||||
|
||||
@@ -55,8 +51,6 @@ func main() {
|
||||
}
|
||||
|
||||
slog.Info("MoQ session established", "remote", sess.RemoteAddr())
|
||||
|
||||
// ⚠️ НЕ блокируем поток!
|
||||
go handleSession(sess)
|
||||
})
|
||||
|
||||
@@ -71,7 +65,6 @@ func handleSession(sess *moqt.Session) {
|
||||
defer sess.Context().Done()
|
||||
|
||||
for {
|
||||
// Ждём закрытия соединения
|
||||
select {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user