Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p
Commits
613ed7ed
Commit
613ed7ed
authored
Mar 15, 2017
by
Hector Sanjuan
Browse files
net/mock: Make golint happier
License: MIT Signed-off-by:
Hector Sanjuan
<
hector@protocol.ai
>
parent
040c881b
Changes
4
Show whitespace changes
Inline
Side-by-side
p2p/net/mock/interface.go
View file @
613ed7ed
...
...
@@ -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
...
...
p2p/net/mock/mock_net.go
View file @
613ed7ed
...
...
@@ -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
{},
...
...
p2p/net/mock/mock_stream.go
View file @
613ed7ed
...
...
@@ -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
,
...
...
p2p/net/mock/ratelimiter.go
View file @
613ed7ed
...
...
@@ -17,7 +17,7 @@ type ratelimiter struct {
duration
time
.
Duration
// total delay introduced due to rate limiting
}
//
C
reates a new ratelimiter with bandwidth (in bytes/sec)
//
NewRatelimiter c
reates a new ratelimiter with bandwidth (in bytes/sec)
func
NewRatelimiter
(
bandwidth
float64
)
*
ratelimiter
{
// convert bandwidth to bytes per nanosecond
b
:=
bandwidth
/
float64
(
time
.
Second
)
...
...
@@ -47,7 +47,7 @@ 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
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment