Просмотр исходного кода

Add unregistering on telegram conn close

tags/1.0^2
9seconds 6 лет назад
Родитель
Сommit
2eba78b0db
2 измененных файлов: 10 добавлений и 1 удалений
  1. 3
    0
      hub/hub.go
  2. 7
    1
      wrappers/packetack/proxy.go

+ 3
- 0
hub/hub.go Просмотреть файл

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

+ 7
- 1
wrappers/packetack/proxy.go Просмотреть файл

5
 	"encoding/binary"
5
 	"encoding/binary"
6
 	"fmt"
6
 	"fmt"
7
 	"net"
7
 	"net"
8
+	"sync"
8
 
9
 
9
 	"github.com/9seconds/mtg/config"
10
 	"github.com/9seconds/mtg/config"
10
 	"github.com/9seconds/mtg/conntypes"
11
 	"github.com/9seconds/mtg/conntypes"
19
 	clientIPPort []byte
20
 	clientIPPort []byte
20
 	ourIPPort    []byte
21
 	ourIPPort    []byte
21
 	channelRead  hub.ChannelReadCloser
22
 	channelRead  hub.ChannelReadCloser
23
+	closeOnce    sync.Once
22
 }
24
 }
23
 
25
 
24
 func (w *wrapperProxy) Write(packet conntypes.Packet, acks *conntypes.ConnectionAcks) error {
26
 func (w *wrapperProxy) Write(packet conntypes.Packet, acks *conntypes.ConnectionAcks) error {
61
 }
63
 }
62
 
64
 
63
 func (w *wrapperProxy) Close() error {
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
 func NewProxy(request *protocol.TelegramRequest) conntypes.PacketAckReadWriteCloser {
73
 func NewProxy(request *protocol.TelegramRequest) conntypes.PacketAckReadWriteCloser {

Загрузка…
Отмена
Сохранить