|
|
@@ -9,7 +9,10 @@ import (
|
|
9
|
9
|
"github.com/9seconds/mtg/wrappers/rwc"
|
|
10
|
10
|
)
|
|
11
|
11
|
|
|
12
|
|
-const cloakTimeout = 5 * time.Second
|
|
|
12
|
+const (
|
|
|
13
|
+ cloakLastActivityTimeout = 5 * time.Second
|
|
|
14
|
+ cloakMaxTimeout = 30 * time.Second
|
|
|
15
|
+)
|
|
13
|
16
|
|
|
14
|
17
|
func cloak(one, another io.ReadWriteCloser) {
|
|
15
|
18
|
defer func() {
|
|
|
@@ -41,17 +44,23 @@ func cloak(one, another io.ReadWriteCloser) {
|
|
41
|
44
|
}()
|
|
42
|
45
|
|
|
43
|
46
|
go func() {
|
|
44
|
|
- timer := time.NewTimer(cloakTimeout)
|
|
45
|
|
- defer timer.Stop()
|
|
|
47
|
+ lastActivityTimer := time.NewTimer(cloakLastActivityTimeout)
|
|
|
48
|
+ defer lastActivityTimer.Stop()
|
|
|
49
|
+
|
|
|
50
|
+ maxTimer := time.NewTimer(cloakMaxTimeout)
|
|
|
51
|
+ defer maxTimer.Stop()
|
|
46
|
52
|
|
|
47
|
53
|
for {
|
|
48
|
54
|
select {
|
|
49
|
55
|
case <-channelPing:
|
|
50
|
|
- timer.Stop()
|
|
51
|
|
- timer = time.NewTimer(cloakTimeout)
|
|
|
56
|
+ lastActivityTimer.Stop()
|
|
|
57
|
+ lastActivityTimer = time.NewTimer(cloakLastActivityTimeout)
|
|
52
|
58
|
case <-ctx.Done():
|
|
53
|
59
|
return
|
|
54
|
|
- case <-timer.C:
|
|
|
60
|
+ case <-lastActivityTimer.C:
|
|
|
61
|
+ cancel()
|
|
|
62
|
+ return
|
|
|
63
|
+ case <-maxTimer.C:
|
|
55
|
64
|
cancel()
|
|
56
|
65
|
return
|
|
57
|
66
|
}
|