Pārlūkot izejas kodu

Add unregistering on telegram conn close

tags/1.0^2
9seconds 6 gadus atpakaļ
vecāks
revīzija
2eba78b0db
2 mainītis faili ar 10 papildinājumiem un 1 dzēšanām
  1. 3
    0
      hub/hub.go
  2. 7
    1
      wrappers/packetack/proxy.go

+ 3
- 0
hub/hub.go Parādīt failu

@@ -54,6 +54,9 @@ func (h *hub) getHub(req *protocol.TelegramRequest) *connectionHub {
54 54
 
55 55
 		rv, ok = h.subs[key]
56 56
 		if !ok {
57
+			h.logger.Debugw("Create new connection hub",
58
+				"dc", req.ClientProtocol.DC(),
59
+				"protocol", req.ClientProtocol.ConnectionProtocol())
57 60
 			rv = newConnectionHub(h.logger.With(
58 61
 				"dc", req.ClientProtocol.DC(),
59 62
 				"protocol", req.ClientProtocol.ConnectionProtocol(),

+ 7
- 1
wrappers/packetack/proxy.go Parādīt failu

@@ -5,6 +5,7 @@ import (
5 5
 	"encoding/binary"
6 6
 	"fmt"
7 7
 	"net"
8
+	"sync"
8 9
 
9 10
 	"github.com/9seconds/mtg/config"
10 11
 	"github.com/9seconds/mtg/conntypes"
@@ -19,6 +20,7 @@ type wrapperProxy struct {
19 20
 	clientIPPort []byte
20 21
 	ourIPPort    []byte
21 22
 	channelRead  hub.ChannelReadCloser
23
+	closeOnce    sync.Once
22 24
 }
23 25
 
24 26
 func (w *wrapperProxy) Write(packet conntypes.Packet, acks *conntypes.ConnectionAcks) error {
@@ -61,7 +63,11 @@ func (w *wrapperProxy) Read(acks *conntypes.ConnectionAcks) (conntypes.Packet, e
61 63
 }
62 64
 
63 65
 func (w *wrapperProxy) Close() error {
64
-	return w.channelRead.Close()
66
+	w.closeOnce.Do(func() {
67
+		w.channelRead.Close()
68
+		hub.Registry.Unregister(w.request.ConnID)
69
+	})
70
+	return nil
65 71
 }
66 72
 
67 73
 func NewProxy(request *protocol.TelegramRequest) conntypes.PacketAckReadWriteCloser {

Notiek ielāde…
Atcelt
Saglabāt