|
|
@@ -4,6 +4,7 @@ import (
|
|
4
|
4
|
"fmt"
|
|
5
|
5
|
"math/rand"
|
|
6
|
6
|
"sync"
|
|
|
7
|
+ "time"
|
|
7
|
8
|
|
|
8
|
9
|
"go.uber.org/zap"
|
|
9
|
10
|
|
|
|
@@ -13,6 +14,8 @@ import (
|
|
13
|
14
|
"github.com/9seconds/mtg/protocol"
|
|
14
|
15
|
)
|
|
15
|
16
|
|
|
|
17
|
+const connectionTTL = time.Hour
|
|
|
18
|
+
|
|
16
|
19
|
type connection struct {
|
|
17
|
20
|
conn conntypes.PacketReadWriteCloser
|
|
18
|
21
|
proxyConns map[string]*ProxyConn
|
|
|
@@ -31,6 +34,9 @@ type connection struct {
|
|
31
|
34
|
func (c *connection) run() {
|
|
32
|
35
|
defer c.Close()
|
|
33
|
36
|
|
|
|
37
|
+ ttl := time.NewTimer(connectionTTL)
|
|
|
38
|
+ defer ttl.Stop()
|
|
|
39
|
+
|
|
34
|
40
|
for {
|
|
35
|
41
|
select {
|
|
36
|
42
|
case <-c.channelDone:
|
|
|
@@ -39,6 +45,9 @@ func (c *connection) run() {
|
|
39
|
45
|
}
|
|
40
|
46
|
|
|
41
|
47
|
return
|
|
|
48
|
+ case <-ttl.C:
|
|
|
49
|
+ c.logger.Debugw("Closing connection by TTL")
|
|
|
50
|
+ c.Close()
|
|
42
|
51
|
case resp := <-c.channelRead:
|
|
43
|
52
|
if channel, ok := c.proxyConns[string(resp.ConnID[:])]; ok {
|
|
44
|
53
|
if resp.Type == rpc.ProxyResponseTypeCloseExt {
|