@@ -23,6 +23,7 @@ const (
2323 defaultHandshakeTimeout = 100 * time .Millisecond
2424 defaultResendTimeout = 100 * time .Millisecond
2525 finSendTimeout = 1000 * time .Millisecond
26+ defaultResendMultiplier = 5
2627 DefaultSendTimeout = math .MaxInt64
2728 DefaultRecvTimeout = math .MaxInt64
2829)
@@ -60,10 +61,21 @@ type GoBackNConn struct {
6061 recvSeq uint8
6162
6263 // resendTimeout is the duration that will be waited before resending
63- // the packets in the current queue.
64+ // the packets in the current queue. The timeout is dynamically set
65+ // during the handshake process, and is set to the time it took for the
66+ // other party to respond, multiplied by the resendMultiplier.
6467 resendTimeout time.Duration
6568 resendTicker * time.Ticker
6669
70+ // resendMultiplier defines the multiplier used when multiplying the
71+ // duration it took for the other party to respond when setting the
72+ // resendTimeout dynamically during the handshake.
73+ resendMultiplier int
74+
75+ // hasSetResendTimeout is used to determine if a resend timeout
76+ // has been manually set when creating a new GoBackNConn.
77+ hasSetResendTimeout bool
78+
6779 recvFromStream recvBytesFunc
6880 sendToStream sendBytesFunc
6981
@@ -164,26 +176,28 @@ func newGoBackNConn(ctx context.Context, sendFunc sendBytesFunc,
164176 ctxc , cancel := context .WithCancel (ctx )
165177
166178 return & GoBackNConn {
167- n : n ,
168- s : n + 1 ,
169- resendTimeout : defaultResendTimeout ,
170- recvFromStream : recvFunc ,
171- sendToStream : sendFunc ,
172- recvDataChan : make (chan * PacketData , n ),
173- sendDataChan : make (chan * PacketData ),
174- isServer : isServer ,
175- sendQueue : newQueue (n + 1 , defaultHandshakeTimeout ),
176- handshakeTimeout : defaultHandshakeTimeout ,
177- recvTimeout : DefaultRecvTimeout ,
178- sendTimeout : DefaultSendTimeout ,
179- receivedACKSignal : make (chan struct {}),
180- resendSignal : make (chan struct {}, 1 ),
181- remoteClosed : make (chan struct {}),
182- awaitedACKSignal : make (chan struct {}, 1 ),
183- awaitedNACKSignal : make (chan struct {}, 1 ),
184- ctx : ctxc ,
185- cancel : cancel ,
186- quit : make (chan struct {}),
179+ n : n ,
180+ s : n + 1 ,
181+ resendTimeout : defaultResendTimeout ,
182+ resendMultiplier : defaultResendMultiplier ,
183+ hasSetResendTimeout : false ,
184+ recvFromStream : recvFunc ,
185+ sendToStream : sendFunc ,
186+ recvDataChan : make (chan * PacketData , n ),
187+ sendDataChan : make (chan * PacketData ),
188+ isServer : isServer ,
189+ sendQueue : newQueue (n + 1 , defaultHandshakeTimeout ),
190+ handshakeTimeout : defaultHandshakeTimeout ,
191+ recvTimeout : DefaultRecvTimeout ,
192+ sendTimeout : DefaultSendTimeout ,
193+ receivedACKSignal : make (chan struct {}),
194+ resendSignal : make (chan struct {}, 1 ),
195+ remoteClosed : make (chan struct {}),
196+ awaitedACKSignal : make (chan struct {}, 1 ),
197+ awaitedNACKSignal : make (chan struct {}, 1 ),
198+ ctx : ctxc ,
199+ cancel : cancel ,
200+ quit : make (chan struct {}),
187201 }
188202}
189203
@@ -920,3 +934,24 @@ func (g *GoBackNConn) proceedAfterTime(catchUpId int64) {
920934 // in the queue would lead to a NACK.
921935 time .AfterFunc (g .resendTimeout , cb )
922936}
937+
938+ // increaseResendTimeout sets the resendTimeout to the passed duration, if the
939+ // passed duration is > than the current set resendTimeout.
940+ // If the resendTimeout has been set manually, this function will be a no op.
941+ func (g * GoBackNConn ) increaseResendTimeout (resendTimeout time.Duration ) {
942+ if g .hasSetResendTimeout {
943+ log .Tracef ("Not increasing resendTimeout as it has been set " +
944+ "manually" )
945+
946+ return
947+ }
948+
949+ if resendTimeout > g .resendTimeout {
950+ log .Tracef ("Increasing resendTimeout to %v" , resendTimeout )
951+ g .resendTimeout = resendTimeout
952+ } else {
953+ log .Tracef ("Not increasing resendTimeout to %v as it is not " +
954+ "greater than the current resendTimeout %v" ,
955+ resendTimeout , g .resendTimeout )
956+ }
957+ }
0 commit comments