Skip to content

Commit 928668f

Browse files
committed
ipn/proxies: pause and resume fns
1 parent 3f38c8a commit 928668f

14 files changed

Lines changed: 210 additions & 1 deletion

File tree

intra/backend/ipn_proxies.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ const ( // see ipn/proxies.go
6969

7070
// status of proxies
7171

72+
// proxy paused until resumed; will not dial
73+
TPU = 3
7274
// proxy UP but not responding
7375
TNT = 2
7476
// proxy idle
@@ -140,6 +142,10 @@ type Proxy interface {
140142
Status() int
141143
// Ping pings this proxy.
142144
Ping() bool
145+
// Pause pauses this proxy.
146+
Pause() bool
147+
// Resume resumes this proxy.
148+
Resume() bool
143149
// Stop stops this proxy.
144150
Stop() error
145151
// Refresh re-registers this proxy, if necessary.

intra/ipn/auto.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type auto struct {
2929
NoDNS
3030
ProtoAgnostic
3131
SkipRefresh
32+
CantPause
3233
GW
3334
pxr ProxyProvider
3435
addr string

intra/ipn/base.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type base struct {
2525
NoDNS
2626
ProtoAgnostic
2727
SkipRefresh
28+
CantPause
2829
GW
2930
id string
3031
addr string

intra/ipn/exit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type exit struct {
3131
NoDNS
3232
ProtoAgnostic
3333
SkipRefresh
34+
CantPause
3435
GWNoVia
3536
id string
3637
addr string

intra/ipn/exit64.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,32 @@ func (h *exit64) Status() int {
210210
return h.status.Load()
211211
}
212212

213+
// Since implements x.Proxy.
214+
func (h *exit64) Pause() bool {
215+
st := h.status.Load()
216+
if st == END {
217+
log.W("proxy: exit64: pause called when stopped")
218+
return false
219+
}
220+
221+
ok := h.status.Cas(st, TPU)
222+
log.I("proxy: exit64: paused? %t", ok)
223+
return ok
224+
}
225+
226+
// Resume implements x.Proxy.
227+
func (h *exit64) Resume() bool {
228+
st := h.status.Load()
229+
if st != TPU {
230+
log.W("proxy: exit64: resume called when not paused; status %d", st)
231+
return false
232+
}
233+
234+
ok := h.status.Cas(st, TUP)
235+
log.I("proxy: exit64: resumed? %t", ok)
236+
return ok
237+
}
238+
213239
// Stop implements Proxy.
214240
func (h *exit64) Stop() error {
215241
h.status.Store(END)

intra/ipn/ground.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type ground struct {
1818
ProtoAgnostic
1919
SkipRefresh
2020
GWNoVia
21+
CantPause
2122
addr string
2223
}
2324

intra/ipn/http1.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,32 @@ func (h *http1) Status() int {
209209
return s
210210
}
211211

212+
// Pause implements x.Proxy.
213+
func (h *http1) Pause() bool {
214+
st := h.status.Load()
215+
if st == END {
216+
log.W("proxy: http1: pause called when stopped")
217+
return false
218+
}
219+
220+
ok := h.status.Cas(st, TPU)
221+
log.I("proxy: http1: paused? %t", ok)
222+
return ok
223+
}
224+
225+
// Resume implements x.Proxy.
226+
func (h *http1) Resume() bool {
227+
st := h.status.Load()
228+
if st != TPU {
229+
log.W("proxy: http1: resume called when not paused; status %d", st)
230+
return false
231+
}
232+
233+
ok := h.status.Cas(st, TUP)
234+
log.I("proxy: http1: resumed? %t", ok)
235+
return ok
236+
}
237+
212238
// Stop implements Proxy.
213239
func (h *http1) Stop() error {
214240
h.status.Store(END)

intra/ipn/nop.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ func (SkipRefresh) onNotOK() (didRefresh bool, allOK bool) { return false, true
103103
// Ping implements Proxy.
104104
func (SkipRefresh) Ping() bool { return false }
105105

106+
type CantPause struct{}
107+
108+
// Pause implements Proxy.
109+
func (CantPause) Pause() bool { return false }
110+
111+
// Resume implements Proxy.
112+
func (CantPause) Resume() bool { return false }
113+
106114
// NoFwd is a proxy that does not support listening or forwarding.
107115
type NoFwd struct{}
108116

@@ -139,6 +147,7 @@ type NoProxy struct {
139147
ProtoAgnostic
140148
SkipRefresh
141149
NoFwd
150+
CantPause
142151
GWNoVia
143152
}
144153

intra/ipn/piph2.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,32 @@ func (t *piph2) Status() int {
338338
return st
339339
}
340340

341+
// Since implements x.Proxy.
342+
func (h *piph2) Pause() bool {
343+
st := h.status.Load()
344+
if st == END {
345+
log.W("proxy: piph2: pause called when stopped")
346+
return false
347+
}
348+
349+
ok := h.status.Cas(st, TPU)
350+
log.I("proxy: piph2: paused? %t", ok)
351+
return ok
352+
}
353+
354+
// Resume implements x.Proxy.
355+
func (h *piph2) Resume() bool {
356+
st := h.status.Load()
357+
if st != TPU {
358+
log.W("proxy: piph2: resume called when not paused; status %d", st)
359+
return false
360+
}
361+
362+
ok := h.status.Cas(st, TUP)
363+
log.I("proxy: piph2: resumed? %t", ok)
364+
return ok
365+
}
366+
341367
// Scenario 4: privacypass.github.io/protocol
342368
func (t *piph2) claim(msg string) []string {
343369
if len(t.token) == 0 || len(t.toksig) == 0 {

intra/ipn/pipws.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,32 @@ func (t *pipws) Status() int {
336336
return s
337337
}
338338

339+
// Pause implements x.Proxy.
340+
func (h *pipws) Pause() bool {
341+
st := h.status.Load()
342+
if st == END {
343+
log.W("proxy: pipws: pause called when stopped")
344+
return false
345+
}
346+
347+
ok := h.status.Cas(st, TPU)
348+
log.I("proxy: pipws: paused? %t", ok)
349+
return ok
350+
}
351+
352+
// Resume implements x.Proxy.
353+
func (h *pipws) Resume() bool {
354+
st := h.status.Load()
355+
if st != TPU {
356+
log.W("proxy: pipws: resume called when not paused; status %d", st)
357+
return false
358+
}
359+
360+
ok := h.status.Cas(st, TUP)
361+
log.I("proxy: pipws: resumed? %t", ok)
362+
return ok
363+
}
364+
339365
// Scenario 4: privacypass.github.io/protocol
340366
func (t *pipws) claim(msg string) []string {
341367
if len(t.token) == 0 || len(t.toksig) == 0 {

0 commit comments

Comments
 (0)