moq-rs/server/main.go

74 lines
1.6 KiB
Go
Raw Normal View History

2022-06-29 16:17:02 +00:00
package main
import (
"context"
"crypto/sha256"
"crypto/tls"
"encoding/hex"
2022-06-29 16:17:02 +00:00
"flag"
"fmt"
"log"
"github.com/kixelated/invoker"
"github.com/kixelated/warp/server/internal/warp"
"github.com/kixelated/warp/server/internal/web"
2022-06-29 16:17:02 +00:00
)
func main() {
err := run(context.Background())
2022-12-05 22:07:58 +00:00
if err != nil {
log.Fatal(err)
2022-06-29 16:17:02 +00:00
}
}
func run(ctx context.Context) (err error) {
2022-11-18 23:13:35 +00:00
addr := flag.String("addr", ":4443", "HTTPS server address")
cert := flag.String("tls-cert", "../cert/localhost.crt", "TLS certificate file path")
key := flag.String("tls-key", "../cert/localhost.key", "TLS certificate file path")
2022-06-29 16:17:02 +00:00
logDir := flag.String("log-dir", "", "logs will be written to the provided directory")
dash := flag.String("dash", "../media/playlist.mpd", "DASH playlist path")
2022-06-29 16:17:02 +00:00
flag.Parse()
media, err := warp.NewMedia(*dash)
if err != nil {
return fmt.Errorf("failed to open media: %w", err)
}
tlsCert, err := tls.LoadX509KeyPair(*cert, *key)
if err != nil {
return fmt.Errorf("failed to load TLS certificate: %w", err)
}
warpConfig := warp.Config{
Addr: *addr,
Cert: &tlsCert,
LogDir: *logDir,
Media: media,
2022-06-29 16:17:02 +00:00
}
warpServer, err := warp.New(warpConfig)
2022-06-29 16:17:02 +00:00
if err != nil {
return fmt.Errorf("failed to create warp server: %w", err)
}
hash := sha256.Sum256(tlsCert.Certificate[0])
fingerprint := hex.EncodeToString(hash[:])
2023-03-28 05:57:18 +00:00
fmt.Println(fingerprint)
webConfig := web.Config{
Addr: *addr,
CertFile: *cert,
KeyFile: *key,
Fingerprint: fingerprint,
}
webServer := web.New(webConfig)
2022-06-29 16:17:02 +00:00
log.Printf("listening on %s", *addr)
return invoker.Run(ctx, invoker.Interrupt, warpServer.Run, webServer.Run)
2022-06-29 16:17:02 +00:00
}