Skip to content

Commit 2cc657b

Browse files
committed
remove all legacy tunnel code
1 parent 04a962a commit 2cc657b

File tree

1 file changed

+6
-44
lines changed

1 file changed

+6
-44
lines changed

coderd/devtunnel/tunnel.go

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"encoding/hex"
88
"encoding/json"
99
"fmt"
10-
"io"
1110
"net"
1211
"net/http"
1312
"net/netip"
@@ -16,7 +15,6 @@ import (
1615
"time"
1716

1817
"github.com/briandowns/spinner"
19-
"github.com/google/uuid"
2018
"golang.org/x/xerrors"
2119
"golang.zx2c4.com/wireguard/conn"
2220
"golang.zx2c4.com/wireguard/device"
@@ -28,29 +26,20 @@ import (
2826
"github.com/coder/coder/cryptorand"
2927
)
3028

31-
var (
32-
v0EndpointHTTPS = "wg-tunnel.coder.app"
33-
34-
v0ServerPublicKey = "+KNSMwed/IlqoesvTMSBNsHFaKVLrmmaCkn0bxIhUg0="
35-
v0ServerIP = netip.AddrFrom16(uuid.MustParse("fcad0000-0000-4000-8000-000000000001"))
36-
)
37-
3829
type Tunnel struct {
3930
URL string
4031
Listener net.Listener
4132
}
4233

4334
type Config struct {
4435
Version int `json:"version"`
45-
ID uuid.UUID `json:"id"`
4636
PrivateKey device.NoisePrivateKey `json:"private_key"`
4737
PublicKey device.NoisePublicKey `json:"public_key"`
4838

4939
Tunnel Node `json:"tunnel"`
5040
}
5141
type configExt struct {
5242
Version int `json:"-"`
53-
ID uuid.UUID `json:"id"`
5443
PrivateKey device.NoisePrivateKey `json:"-"`
5544
PublicKey device.NoisePublicKey `json:"public_key"`
5645

@@ -181,22 +170,9 @@ func sendConfigToServer(ctx context.Context, cfg Config) (ServerResponse, error)
181170
return ServerResponse{}, xerrors.Errorf("marshal config: %w", err)
182171
}
183172

184-
var req *http.Request
185-
switch cfg.Version {
186-
case 0:
187-
req, err = http.NewRequestWithContext(ctx, "POST", "https://"+v0EndpointHTTPS+"/tun", bytes.NewReader(raw))
188-
if err != nil {
189-
return ServerResponse{}, xerrors.Errorf("new request: %w", err)
190-
}
191-
192-
case 1:
193-
req, err = http.NewRequestWithContext(ctx, "POST", "https://"+cfg.Tunnel.HostnameHTTPS+"/tun", bytes.NewReader(raw))
194-
if err != nil {
195-
return ServerResponse{}, xerrors.Errorf("new request: %w", err)
196-
}
197-
198-
default:
199-
return ServerResponse{}, xerrors.Errorf("unknown config version: %d", cfg.Version)
173+
req, err := http.NewRequestWithContext(ctx, "POST", "https://"+cfg.Tunnel.HostnameHTTPS+"/tun", bytes.NewReader(raw))
174+
if err != nil {
175+
return ServerResponse{}, xerrors.Errorf("new request: %w", err)
200176
}
201177

202178
res, err := http.DefaultClient.Do(req)
@@ -206,23 +182,9 @@ func sendConfigToServer(ctx context.Context, cfg Config) (ServerResponse, error)
206182
defer res.Body.Close()
207183

208184
var resp ServerResponse
209-
switch cfg.Version {
210-
case 0:
211-
_, _ = io.Copy(io.Discard, res.Body)
212-
resp.Hostname = fmt.Sprintf("%s.%s", cfg.ID, v0EndpointHTTPS)
213-
resp.ServerIP = v0ServerIP
214-
resp.ServerPublicKey = encodeBase64ToHex(v0ServerPublicKey)
215-
resp.ClientIP = netip.AddrFrom16(cfg.ID)
216-
217-
case 1:
218-
err := json.NewDecoder(res.Body).Decode(&resp)
219-
if err != nil {
220-
return ServerResponse{}, xerrors.Errorf("decode response: %w", err)
221-
}
222-
223-
default:
224-
_, _ = io.Copy(io.Discard, res.Body)
225-
return ServerResponse{}, xerrors.Errorf("unknown config version: %d", cfg.Version)
185+
err = json.NewDecoder(res.Body).Decode(&resp)
186+
if err != nil {
187+
return ServerResponse{}, xerrors.Errorf("decode response: %w", err)
226188
}
227189

228190
return resp, nil

0 commit comments

Comments
 (0)