diff --git a/p2p/net/mock/interface.go b/p2p/net/mock/interface.go index e62fc4d7185ce52b0bb6794ac2e23ed6c51693bc..0e03b55426b450209ece75fd98731b6e789966a8 100644 --- a/p2p/net/mock/interface.go +++ b/p2p/net/mock/interface.go @@ -19,6 +19,10 @@ import ( ma "github.com/multiformats/go-multiaddr" ) +// Mocknet is an interface representing a network of peers. Each peer +// has its own net.Network. Mocknet can add and remove peers, +// link different networks and provide a representation of the state +// of the system via LinkMaps. type Mocknet interface { // GenPeer generates a peer and its inet.Network in the Mocknet diff --git a/p2p/net/mock/mock_net.go b/p2p/net/mock/mock_net.go index fb12a61a56582ac4ede5b84c93462663a88a969e..59a69fe41681782bf566be8e407a648e2170083c 100644 --- a/p2p/net/mock/mock_net.go +++ b/p2p/net/mock/mock_net.go @@ -38,6 +38,7 @@ type mocknet struct { sync.Mutex } +// New initializes and returns a default implementation of Mocknet. func New(ctx context.Context) Mocknet { return &mocknet{ nets: map[peer.ID]*peernet{}, diff --git a/p2p/net/mock/mock_stream.go b/p2p/net/mock/mock_stream.go index 25296516b94f1f53f8e52d98000c3809b5beaa75..962b48bf4a45f10b6af2e53a74952db50b6c9ea1 100644 --- a/p2p/net/mock/mock_stream.go +++ b/p2p/net/mock/mock_stream.go @@ -26,6 +26,7 @@ type transportObject struct { arrivalTime time.Time } +// NewStream returns a new mock stream, which implements net.Stream. func NewStream(p net.Conn) *stream { s := &stream{ Pipe: p, diff --git a/p2p/net/mock/ratelimiter.go b/p2p/net/mock/ratelimiter.go index 0b21c9a4d92f0efbb5d5dacdca21ab0f99b16824..4acec572fd6999a33b4c02efea5ac9a75e8d5fcb 100644 --- a/p2p/net/mock/ratelimiter.go +++ b/p2p/net/mock/ratelimiter.go @@ -5,8 +5,8 @@ import ( "time" ) -// A ratelimiter is used by a link to determine how long to wait before sending -// data given a bandwidth cap. +// A ratelimiter is used by a link to determine how long to wait before sending +// data given a bandwidth cap. type ratelimiter struct { lock sync.Mutex bandwidth float64 // bytes per nanosecond @@ -17,7 +17,7 @@ type ratelimiter struct { duration time.Duration // total delay introduced due to rate limiting } -// Creates a new ratelimiter with bandwidth (in bytes/sec) +// NewRatelimiter creates a new ratelimiter with bandwidth (in bytes/sec) func NewRatelimiter(bandwidth float64) *ratelimiter { // convert bandwidth to bytes per nanosecond b := bandwidth / float64(time.Second) @@ -29,7 +29,7 @@ func NewRatelimiter(bandwidth float64) *ratelimiter { } } -// Changes bandwidth of a ratelimiter and resets its allowance +// Changes bandwidth of a ratelimiter and resets its allowance func (r *ratelimiter) UpdateBandwidth(bandwidth float64) { r.lock.Lock() defer r.lock.Unlock() @@ -42,12 +42,12 @@ func (r *ratelimiter) UpdateBandwidth(bandwidth float64) { r.lastUpdate = time.Now() } -// Returns how long to wait before sending data with length 'dataSize' bytes +// Returns how long to wait before sending data with length 'dataSize' bytes func (r *ratelimiter) Limit(dataSize int) time.Duration { r.lock.Lock() defer r.lock.Unlock() // update time - var duration time.Duration = time.Duration(0) + var duration = time.Duration(0) if r.bandwidth == 0 { return duration }