From 613ed7edf803504345e1187e46393c5037f71ed1 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Wed, 15 Mar 2017 18:07:03 +0100 Subject: [PATCH] net/mock: Make golint happier License: MIT Signed-off-by: Hector Sanjuan --- p2p/net/mock/interface.go | 4 ++++ p2p/net/mock/mock_net.go | 1 + p2p/net/mock/mock_stream.go | 1 + p2p/net/mock/ratelimiter.go | 12 ++++++------ 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/p2p/net/mock/interface.go b/p2p/net/mock/interface.go index e62fc4d..0e03b55 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 fb12a61..59a69fe 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 2529651..962b48b 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 0b21c9a..4acec57 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 } -- GitLab