diff --git a/gbn/gbn_client.go b/gbn/gbn_client.go index 6cb43b27..dff43545 100644 --- a/gbn/gbn_client.go +++ b/gbn/gbn_client.go @@ -41,13 +41,17 @@ func NewClientConn(ctx context.Context, n uint8, sendFunc sendBytesFunc, // clientHandshake initiates the client side GBN handshake. // The handshake sequence from the client side is as follows: -// 1. The client sends SYN to the server along with the N value that the +// 1. The client sends SYN to the server along with the N value that the // client wishes to use for the connection. -// 2. The client then waits for the server to respond with SYN. +// 2. The client then waits for the server to respond with SYN. +// // 3a. If the client receives SYN from the server then the client sends back -// SYNACK. +// +// SYNACK. +// // 3b. If the client does not receive SYN from the server within a given -// timeout, then the client restarts the handshake from step 1. +// +// timeout, then the client restarts the handshake from step 1. func (g *GoBackNConn) clientHandshake() error { // Spin off the recv function in a goroutine so that we can use // a select to choose to timeout waiting for data from the receive @@ -94,7 +98,10 @@ func (g *GoBackNConn) clientHandshake() error { } }() - var resp Message + var ( + resp Message + respSYN *PacketSYN + ) handshake: for { // start Handshake @@ -142,8 +149,10 @@ handshake: } log.Debugf("Client got %T", resp) - switch resp.(type) { + switch r := resp.(type) { case *PacketSYN: + respSYN = r + break handshake default: } @@ -155,7 +164,8 @@ handshake: } log.Debugf("Client got SYN") - if resp.(*PacketSYN).N != g.n { + + if respSYN.N != g.n { return io.EOF } diff --git a/gbn/gbn_conn.go b/gbn/gbn_conn.go index ab52bd69..b6108053 100644 --- a/gbn/gbn_conn.go +++ b/gbn/gbn_conn.go @@ -97,7 +97,7 @@ type GoBackNConn struct { pongTicker *IntervalAwareForceTicker pongWait chan struct{} - ctx context.Context + ctx context.Context //nolint:containedctx cancel func() // remoteClosed is closed if the remote party initiated the FIN sequence. diff --git a/mailbox/server.go b/mailbox/server.go index a0a820b0..f810fbc8 100644 --- a/mailbox/server.go +++ b/mailbox/server.go @@ -26,7 +26,7 @@ type Server struct { sid [64]byte - ctx context.Context + ctx context.Context //nolint:containedctx quit chan struct{} cancel func()