Przeglądaj źródła

Cap max time in cloak mode

tags/v1.0.2^2
9seconds 6 lat temu
rodzic
commit
c5029c706c
1 zmienionych plików z 15 dodań i 6 usunięć
  1. 15
    6
      faketls/cloak.go

+ 15
- 6
faketls/cloak.go Wyświetl plik

9
 	"github.com/9seconds/mtg/wrappers/rwc"
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
 func cloak(one, another io.ReadWriteCloser) {
17
 func cloak(one, another io.ReadWriteCloser) {
15
 	defer func() {
18
 	defer func() {
41
 	}()
44
 	}()
42
 
45
 
43
 	go func() {
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
 		for {
53
 		for {
48
 			select {
54
 			select {
49
 			case <-channelPing:
55
 			case <-channelPing:
50
-				timer.Stop()
51
-				timer = time.NewTimer(cloakTimeout)
56
+				lastActivityTimer.Stop()
57
+				lastActivityTimer = time.NewTimer(cloakLastActivityTimeout)
52
 			case <-ctx.Done():
58
 			case <-ctx.Done():
53
 				return
59
 				return
54
-			case <-timer.C:
60
+			case <-lastActivityTimer.C:
61
+				cancel()
62
+				return
63
+			case <-maxTimer.C:
55
 				cancel()
64
 				cancel()
56
 				return
65
 				return
57
 			}
66
 			}

Ładowanie…
Anuluj
Zapisz