Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modular GBN #13

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions gbn/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@ type config struct {
// 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.
Expand Down Expand Up @@ -53,7 +44,6 @@ func newConfig(sendFunc sendBytesFunc, recvFunc recvBytesFunc,

return &config{
n: n,
s: n + 1,
recvFromStream: recvFunc,
sendToStream: sendFunc,
resendTimeout: defaultResendTimeout,
Expand Down
7 changes: 4 additions & 3 deletions gbn/gbn_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
// The resendTimeout parameter defines the duration to wait before resending data
// if the corresponding ACK for the data is not received.
func NewClientConn(ctx context.Context, n uint8, sendFunc sendBytesFunc,
receiveFunc recvBytesFunc, opts ...Option) (*GoBackNConn, error) {
receiveFunc recvBytesFunc, opts ...Option) (GBN, error) {

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

conn := newGoBackNConn(ctx, cfg, "client")
conn := newGBN(ctx, cfg, "client")

if err := conn.clientHandshake(); err != nil {
if err := conn.Close(); err != nil {
conn.log.Errorf("error closing gbn ClientConn: %v", err)
}
return nil, err
}

conn.start()

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