Skip to content

Commit 2c3076c

Browse files
committed
resolves merge conflicts
2 parents 7df8802 + d9599fe commit 2c3076c

32 files changed

Lines changed: 2164 additions & 354 deletions

api/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Options:
5555
defer cancel()
5656

5757
// drain on sigterm
58-
go func() {
58+
go server.HandleError(func() {
5959
defer cancel()
6060
select {
6161
case <-ctx.Done():
@@ -67,7 +67,7 @@ Options:
6767
case <-time.After(DrainTimeout):
6868
}
6969
}
70-
}()
70+
})
7171

7272
routes := []*router.Route{
7373
router.NewRoute("GET", "/privacy.txt", router.Txt),

connect/connect_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ func testConnect(
488488
settings.ConnectionAnnounceTimeout = 0
489489
// settings.ConnectionRateLimitSettings.MaxTotalConnectionCount = 1000
490490
settings.ConnectionRateLimitSettings.BurstConnectionCount = 1000
491+
// settings.MaximumExchangeMessageByteCount = 2 * int(messageContentSizes[len(messageContentSizes)-1])
491492
connectHandler := NewConnectHandler(ctx, server.NewId(), exchange, settings)
492493

493494
fmt.Printf("create server :%d (:%d :%d)\n", port, settings.ListenH3Port, settings.ListenDnsPort)

connect/main.go

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package main
33
import (
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

Comments
 (0)