@@ -2,6 +2,70 @@ package gbn
2
2
3
3
import "time"
4
4
5
+ // TimeoutOptions can be used to modify the default timeout values used within
6
+ // the TimeoutManager.
7
+ type TimeoutOptions func (manager * TimeoutManager )
8
+
9
+ // WithStaticResendTimeout is used to set a static resend timeout. This is the
10
+ // time to wait for ACKs before resending the queue.
11
+ func WithStaticResendTimeout (timeout time.Duration ) TimeoutOptions {
12
+ return func (manager * TimeoutManager ) {
13
+ manager .useStaticTimeout = true
14
+ manager .resendTimeout = timeout
15
+ }
16
+ }
17
+
18
+ // WithResendMultiplier is used to set the resend multiplier. This is the
19
+ // multiplier we use when dynamically setting the resend timeout, based on how
20
+ // long it took for other party to respond.
21
+ // Note that when setting the resend timeout manually with the
22
+ // WithStaticResendTimeout option, this option will have no effect.
23
+ // Note that the passed multiplier must be greater than zero or this option will
24
+ // have no effect.
25
+ func WithResendMultiplier (multiplier int ) TimeoutOptions {
26
+ return func (manager * TimeoutManager ) {
27
+ if multiplier > 0 {
28
+ manager .resendMultiplier = multiplier
29
+ }
30
+ }
31
+ }
32
+
33
+ // WithTimeoutUpdateFrequency is used to set the frequency of how many
34
+ // corresponding responses we need to receive until updating the resend timeout.
35
+ // Note that when setting the resend timeout manually with the WithTimeout
36
+ // option, this option will have no effect.
37
+ // Also note that the passed frequency must be greater than zero or this option
38
+ // will have no effect.
39
+ func WithTimeoutUpdateFrequency (frequency int ) TimeoutOptions {
40
+ return func (manager * TimeoutManager ) {
41
+ if frequency > 0 {
42
+ manager .timeoutUpdateFrequency = frequency
43
+ }
44
+ }
45
+ }
46
+
47
+ // WithTMHandshakeTimeout is used to set the timeout used during the handshake.
48
+ // If the timeout is reached without response from the peer then the handshake
49
+ // will be aborted and restarted.
50
+ func WithTMHandshakeTimeout (timeout time.Duration ) TimeoutOptions {
51
+ return func (manager * TimeoutManager ) {
52
+ manager .handshakeTimeout = timeout
53
+ }
54
+ }
55
+
56
+ // WithTMKeepalivePing is used to send a ping packet if no packets have been
57
+ // received from the other side for the given duration. This helps keep the
58
+ // connection alive and also ensures that the connection is closed if the
59
+ // other side does not respond to the ping in a timely manner. After the ping
60
+ // the connection will be closed if the other side does not respond within
61
+ // time duration.
62
+ func WithTMKeepalivePing (ping , pong time.Duration ) TimeoutOptions {
63
+ return func (manager * TimeoutManager ) {
64
+ manager .pingTime = ping
65
+ manager .pongTime = pong
66
+ }
67
+ }
68
+
5
69
// config holds the configuration values for an instance of GoBackNConn.
6
70
type config struct {
7
71
// n is the window size. The sender can send a maximum of n packets
0 commit comments