7
7
"encoding/hex"
8
8
"encoding/json"
9
9
"fmt"
10
- "io"
11
10
"net"
12
11
"net/http"
13
12
"net/netip"
@@ -16,7 +15,6 @@ import (
16
15
"time"
17
16
18
17
"github.com/briandowns/spinner"
19
- "github.com/google/uuid"
20
18
"golang.org/x/xerrors"
21
19
"golang.zx2c4.com/wireguard/conn"
22
20
"golang.zx2c4.com/wireguard/device"
@@ -28,29 +26,20 @@ import (
28
26
"github.com/coder/coder/cryptorand"
29
27
)
30
28
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
-
38
29
type Tunnel struct {
39
30
URL string
40
31
Listener net.Listener
41
32
}
42
33
43
34
type Config struct {
44
35
Version int `json:"version"`
45
- ID uuid.UUID `json:"id"`
46
36
PrivateKey device.NoisePrivateKey `json:"private_key"`
47
37
PublicKey device.NoisePublicKey `json:"public_key"`
48
38
49
39
Tunnel Node `json:"tunnel"`
50
40
}
51
41
type configExt struct {
52
42
Version int `json:"-"`
53
- ID uuid.UUID `json:"id"`
54
43
PrivateKey device.NoisePrivateKey `json:"-"`
55
44
PublicKey device.NoisePublicKey `json:"public_key"`
56
45
@@ -181,22 +170,9 @@ func sendConfigToServer(ctx context.Context, cfg Config) (ServerResponse, error)
181
170
return ServerResponse {}, xerrors .Errorf ("marshal config: %w" , err )
182
171
}
183
172
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 )
200
176
}
201
177
202
178
res , err := http .DefaultClient .Do (req )
@@ -206,23 +182,9 @@ func sendConfigToServer(ctx context.Context, cfg Config) (ServerResponse, error)
206
182
defer res .Body .Close ()
207
183
208
184
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 )
226
188
}
227
189
228
190
return resp , nil
0 commit comments