Skip to content

Commit

Permalink
add mini relay
Browse files Browse the repository at this point in the history
  • Loading branch information
navigaid committed Apr 13, 2024
1 parent 1c5c176 commit 22ef08d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
38 changes: 38 additions & 0 deletions apps/mini/mini.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package mini

import (
"log/slog"
"net"
"net/http"

"github.com/webteleport/relay"
"github.com/webteleport/ufo/apps/relay/envs"
"github.com/webteleport/utils"
)

func listenHTTP(handler http.Handler) error {
slog.Info("listening on HTTP http://" + envs.HOST + envs.HTTP_PORT)
ln, err := net.Listen("tcp4", envs.HTTP_PORT)
if err != nil {
return err
}
return http.Serve(ln, handler)
}

func Run([]string) (err error) {
sm := relay.NewSessionManager(envs.HOST)

var dsm http.Handler = sm
// Set the Alt-Svc header for UDP port discovery && http3 bootstrapping
dsm = AltSvcMiddleware(dsm)
dsm = utils.GinLoggerMiddleware(dsm)

return listenHTTP(dsm)
}

func AltSvcMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Alt-Svc", envs.ALT_SVC)
next.ServeHTTP(w, r)
})
}
2 changes: 2 additions & 0 deletions cmd/ufo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/webteleport/ufo/apps/intercept"
"github.com/webteleport/ufo/apps/ip"
"github.com/webteleport/ufo/apps/login"
"github.com/webteleport/ufo/apps/mini"
"github.com/webteleport/ufo/apps/mmdb"
"github.com/webteleport/ufo/apps/multi"
"github.com/webteleport/ufo/apps/naive"
Expand Down Expand Up @@ -122,6 +123,7 @@ var cmdRun multicall.RunnerFuncMap = map[string]multicall.RunnerFunc{
// relay
"hub": relay.Run,
"relay": relay.Run,
"mini": mini.Run,
// version info
"version": version.Run,
// binary upgrade
Expand Down

0 comments on commit 22ef08d

Please sign in to comment.