From c9158cb15f8719049b2fdef728fab08ae258b6dd Mon Sep 17 00:00:00 2001 From: Kleissner Date: Sun, 27 Feb 2022 04:11:59 +0100 Subject: [PATCH] UDT: Fix critical bugs: Virtual Connection should not block. Revert close channel from last commit. --- Transfer Virtual Connection.go | 7 ++++--- udt/udtsocket.go | 5 ++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Transfer Virtual Connection.go b/Transfer Virtual Connection.go index a365c07..0d8f20a 100644 --- a/Transfer Virtual Connection.go +++ b/Transfer Virtual Connection.go @@ -44,7 +44,7 @@ func newVirtualPacketConn(peer *PeerInfo, sendData func(data []byte, sequenceNum v = &virtualPacketConn{ peer: peer, sendData: sendData, - incomingData: make(chan []byte, 100), + incomingData: make(chan []byte, 512), outgoingData: make(chan []byte), terminationSignal: make(chan struct{}), } @@ -67,7 +67,7 @@ func (v *virtualPacketConn) writeForward() { } } -// receiveData receives incoming data via an external message. Blocking until a read occurs or the connection is terminated! +// receiveData receives incoming data via an external message. Non-blocking. func (v *virtualPacketConn) receiveData(data []byte) { if v.IsTerminated() { return @@ -77,8 +77,9 @@ func (v *virtualPacketConn) receiveData(data []byte) { select { case v.incomingData <- data: case <-v.terminationSignal: + default: + // packet lost } - // TODO: Add read timeout } // Terminate closes the connection. Do not call this function manually. Use the underlying protocol's function to close the connection. diff --git a/udt/udtsocket.go b/udt/udtsocket.go index 5e791d2..01c3948 100644 --- a/udt/udtsocket.go +++ b/udt/udtsocket.go @@ -302,7 +302,6 @@ func (s *udtSocket) Close() error { } s.isClosed = true - close(s.sockClosed) // closing messageOut was a signal supposed to tell the send code to initiate shutdown. However, it closes too fast before all data is transferred. // The entire UDT code is a piece of !@#$ and needs a rewrite. @@ -713,8 +712,6 @@ func (s *udtSocket) readPacket(m *multiplexer, p packet.Packet) { return } - s.recvEvent <- recvPktEvent{pkt: p, now: now} - switch sp := p.(type) { case *packet.HandshakePacket: // sent by both peers s.readHandshake(m, sp) @@ -724,5 +721,7 @@ func (s *udtSocket) readPacket(m *multiplexer, p packet.Packet) { s.sendEvent <- recvPktEvent{pkt: p, now: now} case *packet.UserDefControlPacket: s.cong.onCustomMsg(*sp) + default: + s.recvEvent <- recvPktEvent{pkt: p, now: now} } }