@@ -36,7 +36,7 @@ type QUICLocalChannel struct {
36
36
}
37
37
38
38
type QUICRemoteChannel struct {
39
- Port int64 `json:"port "`
39
+ Target string `json:"target "`
40
40
Host string `json:"host"`
41
41
}
42
42
@@ -48,20 +48,15 @@ type QUICChannel struct {
48
48
var QUICRemoteForm = forms.Form {
49
49
Fields : []forms.Field {
50
50
{
51
- Name : "host " ,
51
+ Name : "target " ,
52
52
Validators : []forms.Validator {
53
53
forms.IsString {},
54
54
},
55
55
},
56
56
{
57
- Name : "port " ,
57
+ Name : "host " ,
58
58
Validators : []forms.Validator {
59
- forms.IsInteger {
60
- HasMin : true ,
61
- Min : 1 ,
62
- HasMax : true ,
63
- Max : 65535 ,
64
- },
59
+ forms.IsString {},
65
60
},
66
61
},
67
62
},
@@ -80,13 +75,6 @@ var QUICLocalForm = forms.Form{
80
75
},
81
76
},
82
77
},
83
- {
84
- Name : "host" ,
85
- Validators : []forms.Validator {
86
- forms.IsOptional {Default : "0.0.0.0" },
87
- forms.IsString {},
88
- },
89
- },
90
78
},
91
79
}
92
80
@@ -200,16 +188,25 @@ func (q *QUICChannel) server(listener *quic.Listener) {
200
188
bs2 := make ([]byte , 2 )
201
189
202
190
if _ , err := io .ReadFull (stream , bs2 ); err != nil {
203
- hyper .Log .Error ("Cannot read port" )
191
+ hyper .Log .Error ("Cannot read string length" )
192
+ return
193
+ }
194
+
195
+ len := binary .LittleEndian .Uint16 (bs2 )
196
+
197
+ target := make ([]byte , len )
198
+
199
+ if _ , err := io .ReadFull (stream , target ); err != nil {
200
+ hyper .Log .Error ("Cannot read hostame" )
204
201
return
205
202
}
206
203
207
- port := binary . LittleEndian . Uint16 ( bs2 )
204
+ hyper . Log . Info ( "Connecting to target '%s'..." , string ( target ) )
208
205
209
- conn , err := net .Dial ("tcp" , fmt . Sprintf ( "localhost:%d" , port ))
206
+ conn , err := net .Dial ("tcp" , string ( target ))
210
207
211
208
if err != nil {
212
- hyper .Log .Errorf ("Cannot connect to local port %d " , port )
209
+ hyper .Log .Errorf ("Cannot connect to target '%s' " , target )
213
210
stream .Close ()
214
211
return
215
212
}
@@ -263,7 +260,7 @@ func (q *QUICChannel) handle(conn net.Conn, channel *QUICChannelConfig) {
263
260
hyper .Log .Error (err )
264
261
return
265
262
} else {
266
- if err := q .pipe (conn , settings .Address , channel .Remote .Host , channel .Remote .Port ); err != nil {
263
+ if err := q .pipe (conn , settings .Address , channel .Remote .Host , channel .Remote .Target ); err != nil {
267
264
hyper .Log .Errorf ("Cannot connect: %v" , err )
268
265
return
269
266
}
@@ -326,7 +323,7 @@ func pipe(left, right io.ReadWriteCloser, close func()) {
326
323
}
327
324
}
328
325
329
- func (q * QUICChannel ) pipe (conn net.Conn , addr , serverName string , port int64 ) error {
326
+ func (q * QUICChannel ) pipe (conn net.Conn , addr , serverName string , target string ) error {
330
327
331
328
config , err := tls .TLSClientConfig (q .Settings .TLS )
332
329
@@ -357,12 +354,18 @@ func (q *QUICChannel) pipe(conn net.Conn, addr, serverName string, port int64) e
357
354
358
355
bs2 := make ([]byte , 2 )
359
356
360
- binary .LittleEndian .PutUint16 (bs2 , uint16 (port ))
357
+ binary .LittleEndian .PutUint16 (bs2 , uint16 (len ( target ) ))
361
358
359
+ // we write the target length
362
360
if _ , err := stream .Write (bs2 ); err != nil {
363
361
return err
364
362
}
365
363
364
+ // we write the target
365
+ if _ , err := stream .Write ([]byte (target )); err != nil {
366
+ return err
367
+ }
368
+
366
369
hyper .Log .Debugf ("Proxying connection..." )
367
370
368
371
go pipe (stream , conn , close )
0 commit comments