Skip to content

Commit c4a0876

Browse files
committed
gbn: modularise
1 parent c2216e4 commit c4a0876

File tree

10 files changed

+818
-522
lines changed

10 files changed

+818
-522
lines changed

gbn/config.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,6 @@ type config struct {
1010
// GoBN handshake.
1111
n uint8
1212

13-
// s is the maximum sequence number used to label packets. Packets
14-
// are labelled with incrementing sequence numbers modulo s.
15-
// s must be strictly larger than the window size, n. This
16-
// is so that the receiver can tell if the sender is resending the
17-
// previous window (maybe the sender did not receive the acks) or if
18-
// they are sending the next window. If s <= n then there would be
19-
// no way to tell.
20-
s uint8
21-
2213
// maxChunkSize is the maximum payload size in bytes allowed per
2314
// message. If the payload to be sent is larger than maxChunkSize then
2415
// the payload will be split between multiple packets.
@@ -53,7 +44,6 @@ func newConfig(sendFunc sendBytesFunc, recvFunc recvBytesFunc,
5344

5445
return &config{
5546
n: n,
56-
s: n + 1,
5747
recvFromStream: recvFunc,
5848
sendToStream: sendFunc,
5949
resendTimeout: defaultResendTimeout,

gbn/gbn_client.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
// The resendTimeout parameter defines the duration to wait before resending data
1515
// if the corresponding ACK for the data is not received.
1616
func NewClientConn(ctx context.Context, n uint8, sendFunc sendBytesFunc,
17-
receiveFunc recvBytesFunc, opts ...Option) (*GoBackNConn, error) {
17+
receiveFunc recvBytesFunc, opts ...Option) (GBN, error) {
1818

1919
if n == math.MaxUint8 {
2020
return nil, fmt.Errorf("n must be smaller than %d",
@@ -28,14 +28,15 @@ func NewClientConn(ctx context.Context, n uint8, sendFunc sendBytesFunc,
2828
o(cfg)
2929
}
3030

31-
conn := newGoBackNConn(ctx, cfg, "client")
31+
conn := newGBN(ctx, cfg, "client")
3232

3333
if err := conn.clientHandshake(); err != nil {
3434
if err := conn.Close(); err != nil {
3535
conn.log.Errorf("error closing gbn ClientConn: %v", err)
3636
}
3737
return nil, err
3838
}
39+
3940
conn.start()
4041

4142
return conn, nil
@@ -50,7 +51,7 @@ func NewClientConn(ctx context.Context, n uint8, sendFunc sendBytesFunc,
5051
// SYNACK.
5152
// 3b. If the client does not receive SYN from the server within a given
5253
// timeout, then the client restarts the handshake from step 1.
53-
func (g *GoBackNConn) clientHandshake() error {
54+
func (g *gbn) clientHandshake() error {
5455
// Spin off the recv function in a goroutine so that we can use
5556
// a select to choose to timeout waiting for data from the receive
5657
// stream. This is needed instead of a context timeout because the

0 commit comments

Comments
 (0)