@@ -41,13 +41,13 @@ func NewClientConn(ctx context.Context, n uint8, sendFunc sendBytesFunc,
4141
4242// clientHandshake initiates the client side GBN handshake.
4343// The handshake sequence from the client side is as follows:
44- // 1. The client sends SYN to the server along with the N value that the
45- // client wishes to use for the connection.
46- // 2. The client then waits for the server to respond with SYN.
47- // 3a. If the client receives SYN from the server then the client sends back
48- // SYNACK.
44+ // 1. The client sends SYN to the server along with the N value that the
45+ // client wishes to use for the connection.
46+ // 2. The client then waits for the server to respond with SYN.
47+ // 3a. If the client receives SYN from the server, then the client sends back
48+ // SYNACK.
4949// 3b. If the client does not receive SYN from the server within a given
50- // timeout, then the client restarts the handshake from step 1.
50+ // timeout, then the client restarts the handshake from step 1.
5151func (g * GoBackNConn ) clientHandshake () error {
5252 // Spin off the recv function in a goroutine so that we can use
5353 // a select to choose to timeout waiting for data from the receive
@@ -94,7 +94,10 @@ func (g *GoBackNConn) clientHandshake() error {
9494 }
9595 }()
9696
97- var resp Message
97+ var (
98+ resp Message
99+ respSYN * PacketSYN
100+ )
98101handshake:
99102 for {
100103 // start Handshake
@@ -142,8 +145,10 @@ handshake:
142145 }
143146
144147 log .Debugf ("Client got %T" , resp )
145- switch resp .(type ) {
148+ switch r := resp .(type ) {
146149 case * PacketSYN :
150+ respSYN = r
151+
147152 break handshake
148153 default :
149154 }
@@ -155,7 +160,8 @@ handshake:
155160 }
156161
157162 log .Debugf ("Client got SYN" )
158- if resp .(* PacketSYN ).N != g .n {
163+
164+ if respSYN .N != g .n {
159165 return io .EOF
160166 }
161167
0 commit comments