@@ -3,10 +3,11 @@ package main
33import (
44 "context"
55 // "fmt"
6- // "net/http"
76 "net"
7+ "net/http"
88 "os"
99 "strconv"
10+ "strings"
1011 "syscall"
1112 "time"
1213
@@ -16,6 +17,7 @@ import (
1617
1718 "github.com/urnetwork/glog"
1819
20+ "github.com/urnetwork/connect"
1921 "github.com/urnetwork/server"
2022 "github.com/urnetwork/server/model"
2123 "github.com/urnetwork/server/router"
@@ -39,6 +41,9 @@ Options:
3941 panic (err )
4042 }
4143
44+ // use up to a 4gib message pool per instance
45+ connect .ResizeMessagePools (connect .Gib (4 ))
46+
4247 // server.Logger().Printf("%s\n", opts)
4348
4449 quitEvent := server .NewEventWithContext (context .Background ())
@@ -56,8 +61,10 @@ Options:
5661 handlerId := model .CreateNetworkClientHandler (ctx )
5762
5863 connectHandler := NewConnectHandlerWithDefaults (ctx , handlerId , exchange )
64+ proxyConnectHandler := NewProxyConnectHandlerWithDefaults (ctx , handlerId , exchange )
5965 // update the heartbeat
60- go func () {
66+ go server .HandleError (func () {
67+ defer cancel ()
6168 for {
6269 select {
6370 case <- ctx .Done ():
@@ -73,22 +80,38 @@ Options:
7380 }
7481 })
7582 }
76- }( )
83+ })
7784
7885 // drain on sigterm
79- go func () {
86+ go server . HandleError ( func () {
8087 defer cancel ()
8188 select {
8289 case <- ctx .Done ():
83- return
8490 case <- quitEvent .Ctx .Done ():
8591 exchange .Drain ()
8692 }
87- }()
93+ })
94+
95+ connectRouter := func (w http.ResponseWriter , r * http.Request ) {
96+ host := r .Header .Get ("X-Forwarded-Host" )
97+ if host == "" {
98+ host = r .Header .Get ("Host" )
99+ }
100+
101+ sub := strings .SplitAfterN (host , "." , 2 )[0 ]
102+ if sub == "connect" {
103+ // the host is connect.<domain>
104+ connectHandler .Connect (w , r )
105+ } else {
106+ // the host is <auth>.connect.<domain>
107+ proxyConnectHandler .Connect (w , r )
108+ }
109+ }
88110
111+ // FIXME multiplex connectHandler.Connect and proxyConnectHandler.Connect
89112 routes := []* router.Route {
90113 router .NewRoute ("GET" , "/status" , router .WarpStatus ),
91- router .NewRoute ("GET " , "/" , connectHandler . Connect ),
114+ router .NewRoute ("* " , "/" , connectRouter ),
92115 }
93116
94117 port , _ := opts .Int ("--port" )
0 commit comments