-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gbn: split out config values into a config struct
- Loading branch information
1 parent
6776e47
commit 1f2aec4
Showing
6 changed files
with
132 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package gbn | ||
|
||
import "time" | ||
|
||
// config holds the configuration values for an instance of GoBackNConn. | ||
type config struct { | ||
// n is the window size. The sender can send a maximum of n packets | ||
// before requiring an ack from the receiver for the first packet in | ||
// the window. The value of n is chosen by the client during the | ||
// GoBN handshake. | ||
n uint8 | ||
|
||
// s is the maximum sequence number used to label packets. Packets | ||
// are labelled with incrementing sequence numbers modulo s. | ||
// s must be strictly larger than the window size, n. This | ||
// is so that the receiver can tell if the sender is resending the | ||
// previous window (maybe the sender did not receive the acks) or if | ||
// they are sending the next window. If s <= n then there would be | ||
// no way to tell. | ||
s uint8 | ||
|
||
// maxChunkSize is the maximum payload size in bytes allowed per | ||
// message. If the payload to be sent is larger than maxChunkSize then | ||
// the payload will be split between multiple packets. | ||
// If maxChunkSize is zero then it is disabled and data won't be split | ||
// between packets. | ||
maxChunkSize int | ||
|
||
// resendTimeout is the duration that will be waited before resending | ||
// the packets in the current queue. | ||
resendTimeout time.Duration | ||
|
||
// recvFromStream is the function that will be used to acquire the next | ||
// available packet. | ||
recvFromStream recvBytesFunc | ||
|
||
// sendToStream is the function that will be used to send over our next | ||
// packet. | ||
sendToStream sendBytesFunc | ||
|
||
// handshakeTimeout is the time after which the server or client | ||
// will abort and restart the handshake if the expected response is | ||
// not received from the peer. | ||
handshakeTimeout time.Duration | ||
|
||
pingTime time.Duration | ||
pongTime time.Duration | ||
} | ||
|
||
// newConfig constructs a new config struct. | ||
func newConfig(sendFunc sendBytesFunc, recvFunc recvBytesFunc, | ||
n uint8) *config { | ||
|
||
return &config{ | ||
n: n, | ||
s: n + 1, | ||
recvFromStream: recvFunc, | ||
sendToStream: sendFunc, | ||
resendTimeout: defaultResendTimeout, | ||
handshakeTimeout: defaultHandshakeTimeout, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.