MCPcopy
hub / github.com/passteque/gluetun / Run

Method Run

internal/shadowsocks/loop.go:59–145  ·  view source on GitHub ↗
(ctx context.Context, done chan<- struct{})

Source from the content-addressed store, hash-verified

57}
58
59func (l *Loop) Run(ctx context.Context, done chan<- struct{}) {
60 defer close(done)
61
62 crashed := false
63
64 if *l.GetSettings().Enabled {
65 go func() {
66 _, _ = l.SetStatus(ctx, constants.Running)
67 }()
68 }
69
70 select {
71 case <-l.start:
72 case <-ctx.Done():
73 return
74 }
75
76 for ctx.Err() == nil {
77 settings := l.GetSettings()
78 server, err := shadowsockslib.NewServer(settings.Settings, l.logger)
79 if err != nil {
80 crashed = true
81 l.logAndWait(ctx, err)
82 continue
83 }
84
85 shadowsocksCtx, shadowsocksCancel := context.WithCancel(ctx)
86
87 waitError := make(chan error)
88 go func() {
89 waitError <- server.Listen(shadowsocksCtx)
90 }()
91 if err != nil {
92 crashed = true
93 shadowsocksCancel()
94 l.logAndWait(ctx, err)
95 continue
96 }
97
98 isStableTimer := time.NewTimer(time.Second)
99
100 stayHere := true
101 for stayHere {
102 select {
103 case <-ctx.Done():
104 shadowsocksCancel()
105 <-waitError
106 close(waitError)
107 return
108 case <-isStableTimer.C:
109 if !crashed {
110 l.running <- constants.Running
111 crashed = false
112 } else {
113 l.backoffTime = defaultBackoffTime
114 l.state.setStatusWithLock(constants.Running)
115 }
116 case <-l.start:

Callers

nothing calls this directly

Calls 6

GetSettingsMethod · 0.95
SetStatusMethod · 0.95
logAndWaitMethod · 0.95
InfoMethod · 0.65
StopMethod · 0.65
setStatusWithLockMethod · 0.45

Tested by

no test coverage detected