Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-unixfs
Commits
9d0736bc
Commit
9d0736bc
authored
Jan 05, 2015
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
peer+mocknet: sorting for determinism.
parent
ce367ee7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
0 deletions
+26
-0
p2p/net/mock/mock_net.go
p2p/net/mock/mock_net.go
+19
-0
p2p/peer/peer.go
p2p/peer/peer.go
+7
-0
No files found.
p2p/net/mock/mock_net.go
View file @
9d0736bc
...
...
@@ -2,6 +2,7 @@ package mocknet
import
(
"fmt"
"sort"
"sync"
"time"
...
...
@@ -90,6 +91,7 @@ func (mn *mocknet) Peers() []peer.ID {
for
_
,
n
:=
range
mn
.
nets
{
cp
=
append
(
cp
,
n
.
peer
)
}
sort
.
Sort
(
peer
.
IDSlice
(
cp
))
return
cp
}
...
...
@@ -115,6 +117,8 @@ func (mn *mocknet) Hosts() []host.Host {
for
_
,
h
:=
range
mn
.
hosts
{
cp
=
append
(
cp
,
h
)
}
sort
.
Sort
(
hostSlice
(
cp
))
return
cp
}
...
...
@@ -126,6 +130,7 @@ func (mn *mocknet) Nets() []inet.Network {
for
_
,
n
:=
range
mn
.
nets
{
cp
=
append
(
cp
,
n
)
}
sort
.
Sort
(
netSlice
(
cp
))
return
cp
}
...
...
@@ -339,3 +344,17 @@ func (mn *mocknet) LinkDefaults() LinkOptions {
defer
mn
.
RUnlock
()
return
mn
.
linkDefaults
}
// netSlice for sorting by peer
type
netSlice
[]
inet
.
Network
func
(
es
netSlice
)
Len
()
int
{
return
len
(
es
)
}
func
(
es
netSlice
)
Swap
(
i
,
j
int
)
{
es
[
i
],
es
[
j
]
=
es
[
j
],
es
[
i
]
}
func
(
es
netSlice
)
Less
(
i
,
j
int
)
bool
{
return
string
(
es
[
i
]
.
LocalPeer
())
<
string
(
es
[
j
]
.
LocalPeer
())
}
// hostSlice for sorting by peer
type
hostSlice
[]
host
.
Host
func
(
es
hostSlice
)
Len
()
int
{
return
len
(
es
)
}
func
(
es
hostSlice
)
Swap
(
i
,
j
int
)
{
es
[
i
],
es
[
j
]
=
es
[
j
],
es
[
i
]
}
func
(
es
hostSlice
)
Less
(
i
,
j
int
)
bool
{
return
string
(
es
[
i
]
.
ID
())
<
string
(
es
[
j
]
.
ID
())
}
p2p/peer/peer.go
View file @
9d0736bc
...
...
@@ -130,3 +130,10 @@ type PeerInfo struct {
ID
ID
Addrs
[]
ma
.
Multiaddr
}
// IDSlice for sorting peers
type
IDSlice
[]
ID
func
(
es
IDSlice
)
Len
()
int
{
return
len
(
es
)
}
func
(
es
IDSlice
)
Swap
(
i
,
j
int
)
{
es
[
i
],
es
[
j
]
=
es
[
j
],
es
[
i
]
}
func
(
es
IDSlice
)
Less
(
i
,
j
int
)
bool
{
return
string
(
es
[
i
])
<
string
(
es
[
j
])
}
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