Skip to content

Commit

Permalink
remove late packet handling in packet handler map
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Nov 17, 2018
1 parent bd6567a commit f0a7b6e
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions packet_handler_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (h *packetHandlerMap) CloseServer() {
h.server = nil
var wg sync.WaitGroup
for id, handler := range h.handlers {
if handler != nil && handler.GetPerspective() == protocol.PerspectiveServer {
if handler.GetPerspective() == protocol.PerspectiveServer {
wg.Add(1)
go func(id string, handler packetHandler) {
// session.Close() blocks until the CONNECTION_CLOSE has been sent and the run-loop has stopped
Expand Down Expand Up @@ -156,21 +156,17 @@ func (h *packetHandlerMap) handlePacket(addr net.Addr, data []byte) error {
var sentBy protocol.Perspective
var version protocol.VersionNumber
var handlePacket func(*receivedPacket)
if ok && handler == nil {
// Late packet for closed session
return nil
}
if !ok {
if ok { // existing session
sentBy = handler.GetPerspective().Opposite()
version = handler.GetVersion()
handlePacket = handler.handlePacket
} else { // no session found
if server == nil { // no server set
return fmt.Errorf("received a packet with an unexpected connection ID %s", iHdr.DestConnectionID)
}
handlePacket = server.handlePacket
sentBy = protocol.PerspectiveClient
version = iHdr.Version
} else {
sentBy = handler.GetPerspective().Opposite()
version = handler.GetVersion()
handlePacket = handler.handlePacket
}

hdr, err := iHdr.Parse(r, sentBy, version)
Expand Down

0 comments on commit f0a7b6e

Please sign in to comment.