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-bitswap
Commits
bb3d2abc
Commit
bb3d2abc
authored
Jul 15, 2017
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ensure testnet peers get evenly connected mesh
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
f6230f4f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
3 deletions
+24
-3
testnet/peernet.go
testnet/peernet.go
+2
-2
testnet/virtual.go
testnet/virtual.go
+21
-0
testutils.go
testutils.go
+1
-1
No files found.
testnet/peernet.go
View file @
bb3d2abc
package
bitswap
import
(
context
"context"
"context"
bsnet
"github.com/ipfs/go-ipfs/exchange/bitswap/network"
mockrouting
"github.com/ipfs/go-ipfs/routing/mock"
testutil
"github.com/ipfs/go-ipfs/thirdparty/testutil"
...
...
@@ -37,4 +37,4 @@ func (pn *peernet) HasPeer(p peer.ID) bool {
return
false
}
var
_
Network
=
&
peernet
{}
var
_
Network
=
(
*
peernet
)(
nil
)
testnet/virtual.go
View file @
bb3d2abc
...
...
@@ -9,16 +9,21 @@ import (
mockrouting
"github.com/ipfs/go-ipfs/routing/mock"
delay
"github.com/ipfs/go-ipfs/thirdparty/delay"
testutil
"github.com/ipfs/go-ipfs/thirdparty/testutil"
routing
"gx/ipfs/QmPjTrrSfE6TzLv6ya6VWhGcCgPrUAdcgrDcQyRDX2VyW1/go-libp2p-routing"
logging
"gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
cid
"gx/ipfs/QmTprEaAA2A9bst5XH7exuyi5KzNMK3SEDNN8rBDnKWcUS/go-cid"
peer
"gx/ipfs/QmXYjuNuxVzXKJCfWasQk1RqkhVLDM9jtUKhqc2WPQmFSB/go-libp2p-peer"
)
var
log
=
logging
.
Logger
(
"bstestnet"
)
func
VirtualNetwork
(
rs
mockrouting
.
Server
,
d
delay
.
D
)
Network
{
return
&
network
{
clients
:
make
(
map
[
peer
.
ID
]
bsnet
.
Receiver
),
delay
:
d
,
routingserver
:
rs
,
conns
:
make
(
map
[
string
]
struct
{}),
}
}
...
...
@@ -26,6 +31,7 @@ type network struct {
clients
map
[
peer
.
ID
]
bsnet
.
Receiver
routingserver
mockrouting
.
Server
delay
delay
.
D
conns
map
[
string
]
struct
{}
}
func
(
n
*
network
)
Adapter
(
p
testutil
.
Identity
)
bsnet
.
BitSwapNetwork
{
...
...
@@ -149,7 +155,22 @@ func (nc *networkClient) ConnectTo(_ context.Context, p peer.ID) error {
if
!
nc
.
network
.
HasPeer
(
p
)
{
return
errors
.
New
(
"no such peer in network"
)
}
tag
:=
tagForPeers
(
nc
.
local
,
p
)
if
_
,
ok
:=
nc
.
network
.
conns
[
tag
];
ok
{
log
.
Warning
(
"ALREADY CONNECTED TO PEER (is this a reconnect? test lib needs fixing)"
)
return
nil
}
nc
.
network
.
conns
[
tag
]
=
struct
{}{}
// TODO: add handling for disconnects
nc
.
network
.
clients
[
p
]
.
PeerConnected
(
nc
.
local
)
nc
.
Receiver
.
PeerConnected
(
p
)
return
nil
}
func
tagForPeers
(
a
,
b
peer
.
ID
)
string
{
if
a
<
b
{
return
string
(
a
+
b
)
}
return
string
(
b
+
a
)
}
testutils.go
View file @
bb3d2abc
...
...
@@ -59,7 +59,7 @@ func (g *SessionGenerator) Instances(n int) []Instance {
for
i
,
inst
:=
range
instances
{
for
j
:=
i
+
1
;
j
<
len
(
instances
);
j
++
{
oinst
:=
instances
[
j
]
inst
.
Exchange
.
PeerConnected
(
oinst
.
Peer
)
inst
.
Exchange
.
network
.
ConnectTo
(
context
.
Background
(),
oinst
.
Peer
)
}
}
return
instances
...
...
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