From d3f8b90e32dc98a0e9fc14d361fa09ff92901a2f Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 9 Jul 2020 09:03:04 +0000 Subject: [PATCH] fix first connection --- cmd/telebit/admin.go | 4 ++++ cmd/telebit/telebit.go | 2 +- cmd/wsserve/wsserve.go | 3 +++ examples/run-as-relay.sh | 2 +- mplexer/encoder.go | 5 +++++ table/table.go | 4 ++-- 6 files changed, 16 insertions(+), 4 deletions(-) diff --git a/cmd/telebit/admin.go b/cmd/telebit/admin.go index f2395cc..fc79e1c 100644 --- a/cmd/telebit/admin.go +++ b/cmd/telebit/admin.go @@ -178,6 +178,9 @@ func upgradeWebsocket(w http.ResponseWriter, r *http.Request) { MultiEncoder: telebit.NewEncoder(context.TODO(), wsTun), MultiDecoder: telebit.NewDecoder(wsTun), } + // TODO should this happen at NewEncoder()? + // (or is it even necessary anymore?) + _ = server.MultiEncoder.Start() go func() { // (this listener is also a telebit.Router) @@ -187,6 +190,7 @@ func upgradeWebsocket(w http.ResponseWriter, r *http.Request) { // there's an encoder with a callback between the websocket // and the multiplexer, so it doesn't know to stop listening otherwise _ = wsTun.Close() + // TODO close all clients fmt.Printf("a subscriber stream is done: %q\n", err) }() diff --git a/cmd/telebit/telebit.go b/cmd/telebit/telebit.go index 6ae8013..903968a 100644 --- a/cmd/telebit/telebit.go +++ b/cmd/telebit/telebit.go @@ -359,7 +359,7 @@ func routeSubscribersAndClients(client net.Conn) error { // Match full servername "sub.domain.example.com" if tryToServeName(servername, wconn) { // TODO better non-error - return io.EOF + return nil } // Match wild names diff --git a/cmd/wsserve/wsserve.go b/cmd/wsserve/wsserve.go index 4302f0b..98c7758 100644 --- a/cmd/wsserve/wsserve.go +++ b/cmd/wsserve/wsserve.go @@ -229,6 +229,9 @@ func upgradeWebsocket(w http.ResponseWriter, r *http.Request) { MultiEncoder: telebit.NewEncoder(context.TODO(), wsTun), MultiDecoder: telebit.NewDecoder(wsTun), } + // TODO should this happen at NewEncoder()? + // (or is it even necessary anymore?) + _ = server.MultiEncoder.Start() go func() { // (this listener is also a telebit.Router) diff --git a/examples/run-as-relay.sh b/examples/run-as-relay.sh index 8edd67d..8f00ba6 100644 --- a/examples/run-as-relay.sh +++ b/examples/run-as-relay.sh @@ -16,7 +16,7 @@ ACME_EMAIL="${ACME_EMAIL:-}" ./telebit --acme-agree=true \ --admin-hostname $ADMIN_HOSTNAME \ - --auth-url $AUTH_URL/api \ + --auth-url $AUTH_URL \ --acme-email "$ACME_EMAIL" \ --secret "$SECRET" \ --listen 3020,3030 diff --git a/mplexer/encoder.go b/mplexer/encoder.go index dd19304..9aa2fe2 100644 --- a/mplexer/encoder.go +++ b/mplexer/encoder.go @@ -54,6 +54,11 @@ func (enc *Encoder) Run() error { } } +func (enc *Encoder) Start() error { + go enc.Run() + return nil +} + // Encode adds MPLEXY headers to raw net traffic, and is intended to be used on each client connection func (enc *Encoder) Encode(rin io.Reader, src, dst Addr) error { rx := make(chan []byte) diff --git a/table/table.go b/table/table.go index 477e4c6..77dac02 100644 --- a/table/table.go +++ b/table/table.go @@ -124,8 +124,8 @@ func (s *SubscriberConn) Serve(client net.Conn) error { id := client.RemoteAddr().String() s.Clients.Store(id, client) - fmt.Println("[debug] cancel all the clients") - _ = client.Close() + //fmt.Println("[debug] immediately cancel client to simplify testing / debugging") + //_ = client.Close() // TODO // - Encode each client to the tunnel