only create a single session for duplicate Initials

This commit is contained in:
Marten Seemann 2020-05-29 15:54:25 +07:00
parent 85c19fbb5a
commit dad30e7c33
6 changed files with 123 additions and 58 deletions

View file

@ -118,6 +118,21 @@ func (h *packetHandlerMap) Add(id protocol.ConnectionID, handler packetHandler)
return true
}
func (h *packetHandlerMap) AddWithConnID(clientDestConnID, newConnID protocol.ConnectionID, fn func() packetHandler) bool {
sid := string(clientDestConnID)
h.mutex.Lock()
defer h.mutex.Unlock()
if _, ok := h.handlers[sid]; ok {
return false
}
sess := fn()
h.handlers[sid] = sess
h.handlers[string(newConnID)] = sess
return true
}
func (h *packetHandlerMap) Remove(id protocol.ConnectionID) {
h.mutex.Lock()
delete(h.handlers, string(id))