@@ -35,7 +35,7 @@ import (
35
35
type Remote struct {
36
36
LocalHost , LocalPort , LocalProto string
37
37
RemoteHost , RemotePort , RemoteProto string
38
- Socks , Reverse , Stdio bool
38
+ Socks , Reverse , Stdio , ProxyProto bool
39
39
}
40
40
41
41
const revPrefix = "R:"
@@ -129,6 +129,9 @@ func DecodeRemote(s string) (*Remote, error) {
129
129
if r .Stdio && r .Reverse {
130
130
return nil , errors .New ("stdio cannot be reversed" )
131
131
}
132
+ if r .ProxyProto && ! r .Reverse {
133
+ return nil , errors .New ("cannot use proxy protocol for a non-reversed remote" )
134
+ }
132
135
return r , nil
133
136
}
134
137
@@ -153,7 +156,7 @@ func isHost(s string) bool {
153
156
154
157
var l4Proto = regexp .MustCompile (`(?i)\/(tcp|udp)$` )
155
158
156
- //L4Proto extacts the layer-4 protocol from the given string
159
+ // L4Proto extacts the layer-4 protocol from the given string
157
160
func L4Proto (s string ) (head , proto string ) {
158
161
if l4Proto .MatchString (s ) {
159
162
l := len (s )
@@ -162,7 +165,7 @@ func L4Proto(s string) (head, proto string) {
162
165
return s , ""
163
166
}
164
167
165
- //implement Stringer
168
+ // implement Stringer
166
169
func (r Remote ) String () string {
167
170
sb := strings.Builder {}
168
171
if r .Reverse {
@@ -177,7 +180,7 @@ func (r Remote) String() string {
177
180
return sb .String ()
178
181
}
179
182
180
- //Encode remote to a string
183
+ // Encode remote to a string
181
184
func (r Remote ) Encode () string {
182
185
if r .LocalPort == "" {
183
186
r .LocalPort = r .RemotePort
@@ -193,7 +196,7 @@ func (r Remote) Encode() string {
193
196
return local + ":" + remote
194
197
}
195
198
196
- //Local is the decodable local portion
199
+ // Local is the decodable local portion
197
200
func (r Remote ) Local () string {
198
201
if r .Stdio {
199
202
return "stdio"
@@ -204,7 +207,7 @@ func (r Remote) Local() string {
204
207
return r .LocalHost + ":" + r .LocalPort
205
208
}
206
209
207
- //Remote is the decodable remote portion
210
+ // Remote is the decodable remote portion
208
211
func (r Remote ) Remote () string {
209
212
if r .Socks {
210
213
return "socks"
@@ -215,16 +218,16 @@ func (r Remote) Remote() string {
215
218
return r .RemoteHost + ":" + r .RemotePort
216
219
}
217
220
218
- //UserAddr is checked when checking if a
219
- //user has access to a given remote
221
+ // UserAddr is checked when checking if a
222
+ // user has access to a given remote
220
223
func (r Remote ) UserAddr () string {
221
224
if r .Reverse {
222
225
return "R:" + r .LocalHost + ":" + r .LocalPort
223
226
}
224
227
return r .RemoteHost + ":" + r .RemotePort
225
228
}
226
229
227
- //CanListen checks if the port can be listened on
230
+ // CanListen checks if the port can be listened on
228
231
func (r Remote ) CanListen () bool {
229
232
//valid protocols
230
233
switch r .LocalProto {
@@ -253,7 +256,7 @@ func (r Remote) CanListen() bool {
253
256
254
257
type Remotes []* Remote
255
258
256
- //Filter out forward reversed/non-reversed remotes
259
+ // Filter out forward reversed/non-reversed remotes
257
260
func (rs Remotes ) Reversed (reverse bool ) Remotes {
258
261
subset := Remotes {}
259
262
for _ , r := range rs {
@@ -265,7 +268,7 @@ func (rs Remotes) Reversed(reverse bool) Remotes {
265
268
return subset
266
269
}
267
270
268
- //Encode back into strings
271
+ // Encode back into strings
269
272
func (rs Remotes ) Encode () []string {
270
273
s := make ([]string , len (rs ))
271
274
for i , r := range rs {
0 commit comments