Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
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
f61f242f
Commit
f61f242f
authored
8 years ago
by
Jeromy
Browse files
Options
Download
Email Patches
Plain Diff
Extract netutil to its own package
parent
5a2b58bc
master
2018-Q4-OKR
docs-improvements
feat/p2p-multiaddr
feat/pnet/working3
feat/protobuf
feat/relay-integrate
feat/udp
feature/standardize-readme
fix/473
fix/no-custom-field
fix/reset-ping-stream
fix/revert-correct-external-addr
gx/update-jccl6u
gx/update-nza0mn
jenkinsfile
kevina/fix-go-vet
multistream-ping
punching
revert-276-update-go-detect-race
v6.0.23
v6.0.22
v6.0.21
v6.0.20
v6.0.19
v6.0.18
v6.0.17
v6.0.16
v6.0.15
v6.0.14
v6.0.13
v6.0.12
v6.0.11
v6.0.10
v6.0.9
v6.0.8
v6.0.7
v6.0.6
v6.0.5
v6.0.4
v6.0.3
v6.0.2
v6.0.1
v6.0.0
v5.0.21
v5.0.20
v5.0.19
v5.0.18
v5.0.17
v5.0.16
v5.0.15
v5.0.14
v5.0.13
v5.0.12
v5.0.11
v5.0.10
v5.0.9
v5.0.8
v5.0.7
v5.0.6
v5.0.5
v5.0.4
v5.0.3
v5.0.2
v5.0.1
v5.0.0
v4.5.5
v4.5.4
v4.5.3
v4.5.2
v4.5.1
v4.5.0
v4.4.5
v4.4.4
v4.4.3
v4.4.2
v4.4.1
v4.4.0
v4.3.12
v4.3.11
v4.3.10
v4.3.9
v4.3.8
v4.3.7
v4.3.6
v4.3.5
v4.3.4
v4.3.3
v4.3.2
v4.3.1
v4.3.0
v4.2.0
No related merge requests found
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
p2p/discovery/mdns_test.go
+5
-3
p2p/discovery/mdns_test.go
p2p/host/basic/basic_host_test.go
+8
-8
p2p/host/basic/basic_host_test.go
p2p/net/mock/mock_net.go
+1
-1
p2p/net/mock/mock_net.go
p2p/protocol/identify/id_test.go
+13
-8
p2p/protocol/identify/id_test.go
p2p/protocol/ping/ping_test.go
+5
-5
p2p/protocol/ping/ping_test.go
p2p/protocol/relay/relay_test.go
+16
-14
p2p/protocol/relay/relay_test.go
p2p/test/backpressure/backpressure_test.go
+8
-6
p2p/test/backpressure/backpressure_test.go
p2p/test/reconnects/reconnect_test.go
+10
-8
p2p/test/reconnects/reconnect_test.go
p2p/test/util/key.go
+0
-164
p2p/test/util/key.go
p2p/test/util/util.go
+0
-41
p2p/test/util/util.go
package.json
+13
-0
package.json
with
79 additions
and
258 deletions
+79
-258
p2p/discovery/mdns_test.go
View file @
f61f242f
...
...
@@ -5,8 +5,10 @@ import (
"testing"
"time"
bhost
"github.com/libp2p/go-libp2p/p2p/host/basic"
host
"github.com/libp2p/go-libp2p-host"
netutil
"github.com/libp2p/go-libp2p
/p2p/test/
util"
netutil
"github.com/libp2p/go-libp2p
-net
util"
pstore
"github.com/libp2p/go-libp2p-peerstore"
)
...
...
@@ -23,8 +25,8 @@ func TestMdnsDiscovery(t *testing.T) {
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
a
:=
netutil
.
Gen
Host
Swarm
(
t
,
ctx
)
b
:=
netutil
.
Gen
Host
Swarm
(
t
,
ctx
)
a
:=
bhost
.
New
(
netutil
.
GenSwarm
Network
(
t
,
ctx
)
)
b
:=
bhost
.
New
(
netutil
.
GenSwarm
Network
(
t
,
ctx
)
)
sa
,
err
:=
NewMdnsService
(
ctx
,
a
,
time
.
Second
)
if
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
p2p/host/basic/basic_host_test.go
View file @
f61f242f
package
basichost
_test
package
basichost
import
(
"bytes"
...
...
@@ -9,15 +9,15 @@ import (
host
"github.com/libp2p/go-libp2p-host"
inet
"github.com/libp2p/go-libp2p-net"
testutil
"github.com/libp2p/go-libp2p-netutil"
protocol
"github.com/libp2p/go-libp2p-protocol"
testutil
"github.com/libp2p/go-libp2p/p2p/test/util"
)
func
TestHostSimple
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
h1
:=
testutil
.
Gen
Host
Swarm
(
t
,
ctx
)
h2
:=
testutil
.
Gen
Host
Swarm
(
t
,
ctx
)
h1
:=
New
(
testutil
.
GenSwarm
Network
(
t
,
ctx
)
)
h2
:=
New
(
testutil
.
GenSwarm
Network
(
t
,
ctx
)
)
defer
h1
.
Close
()
defer
h2
.
Close
()
...
...
@@ -64,8 +64,8 @@ func TestHostSimple(t *testing.T) {
}
func
getHostPair
(
ctx
context
.
Context
,
t
*
testing
.
T
)
(
host
.
Host
,
host
.
Host
)
{
h1
:=
testutil
.
Gen
Host
Swarm
(
t
,
ctx
)
h2
:=
testutil
.
Gen
Host
Swarm
(
t
,
ctx
)
h1
:=
New
(
testutil
.
GenSwarm
Network
(
t
,
ctx
)
)
h2
:=
New
(
testutil
.
GenSwarm
Network
(
t
,
ctx
)
)
h2pi
:=
h2
.
Peerstore
()
.
PeerInfo
(
h2
.
ID
())
if
err
:=
h1
.
Connect
(
ctx
,
h2pi
);
err
!=
nil
{
...
...
@@ -170,8 +170,8 @@ func TestHostProtoPreknowledge(t *testing.T) {
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
h1
:=
testutil
.
Gen
Host
Swarm
(
t
,
ctx
)
h2
:=
testutil
.
Gen
Host
Swarm
(
t
,
ctx
)
h1
:=
New
(
testutil
.
GenSwarm
Network
(
t
,
ctx
)
)
h2
:=
New
(
testutil
.
GenSwarm
Network
(
t
,
ctx
)
)
conn
:=
make
(
chan
protocol
.
ID
,
16
)
handler
:=
func
(
s
inet
.
Stream
)
{
...
...
This diff is collapsed.
Click to expand it.
p2p/net/mock/mock_net.go
View file @
f61f242f
...
...
@@ -8,12 +8,12 @@ import (
host
"github.com/libp2p/go-libp2p-host"
bhost
"github.com/libp2p/go-libp2p/p2p/host/basic"
p2putil
"github.com/libp2p/go-libp2p/p2p/test/util"
"github.com/jbenet/goprocess"
goprocessctx
"github.com/jbenet/goprocess/context"
ic
"github.com/libp2p/go-libp2p-crypto"
inet
"github.com/libp2p/go-libp2p-net"
p2putil
"github.com/libp2p/go-libp2p-netutil"
peer
"github.com/libp2p/go-libp2p-peer"
pstore
"github.com/libp2p/go-libp2p-peerstore"
testutil
"github.com/libp2p/go-testutil"
...
...
This diff is collapsed.
Click to expand it.
p2p/protocol/identify/id_test.go
View file @
f61f242f
...
...
@@ -6,24 +6,27 @@ import (
"time"
ic
"github.com/libp2p/go-libp2p-crypto"
testutil
"github.com/libp2p/go-libp2p-netutil"
peer
"github.com/libp2p/go-libp2p-peer"
identify
"github.com/libp2p/go-libp2p/p2p/protocol/identify"
testutil
"github.com/libp2p/go-libp2p/p2p/test/util"
blhost
"github.com/libp2p/go-libp2p-blankhost"
host
"github.com/libp2p/go-libp2p-host"
ma
"github.com/multiformats/go-multiaddr"
)
func
subtestIDService
(
t
*
testing
.
T
,
postDialWait
time
.
Duration
)
{
// the generated networks should have the id service wired in.
ctx
:=
context
.
Background
()
h1
:=
testutil
.
Gen
Host
Swarm
(
t
,
ctx
)
h2
:=
testutil
.
Gen
Host
Swarm
(
t
,
ctx
)
h1
:=
blhost
.
NewBlankHost
(
testutil
.
GenSwarm
Network
(
t
,
ctx
)
)
h2
:=
blhost
.
NewBlankHost
(
testutil
.
GenSwarm
Network
(
t
,
ctx
)
)
h1p
:=
h1
.
ID
()
h2p
:=
h2
.
ID
()
ids1
:=
identify
.
NewIDService
(
h1
)
ids2
:=
identify
.
NewIDService
(
h2
)
testKnowsAddrs
(
t
,
h1
,
h2p
,
[]
ma
.
Multiaddr
{})
// nothing
testKnowsAddrs
(
t
,
h2
,
h1p
,
[]
ma
.
Multiaddr
{})
// nothing
...
...
@@ -32,11 +35,13 @@ func subtestIDService(t *testing.T, postDialWait time.Duration) {
t
.
Fatal
(
err
)
}
// we need to wait here if Dial returns before ID service is finished.
if
postDialWait
>
0
{
<-
time
.
After
(
postDialWait
)
h1t2c
:=
h1
.
Network
()
.
ConnsToPeer
(
h2p
)
if
len
(
h1t2c
)
==
0
{
t
.
Fatal
(
"should have a conn here"
)
}
ids1
.
IdentifyConn
(
h1t2c
[
0
])
// the IDService should be opened automatically, by the network.
// what we should see now is that both peers know about each others listen addresses.
t
.
Log
(
"test peer1 has peer2 addrs correctly"
)
...
...
@@ -50,7 +55,7 @@ func subtestIDService(t *testing.T, postDialWait time.Duration) {
if
len
(
c
)
<
1
{
t
.
Fatal
(
"should have connection by now at least."
)
}
<-
h2
.
IDService
()
.
Identify
Wait
(
c
[
0
])
ids2
.
Identify
Conn
(
c
[
0
])
addrs
:=
h1
.
Peerstore
()
.
Addrs
(
h1p
)
addrs
=
append
(
addrs
,
c
[
0
]
.
RemoteMultiaddr
())
...
...
This diff is collapsed.
Click to expand it.
p2p/protocol/ping/ping_test.go
View file @
f61f242f
package
ping
import
(
"context"
"testing"
"time"
netutil
"github.com/libp2p/go-libp2p/p2p/test/util"
"context"
netutil
"github.com/libp2p/go-libp2p-netutil"
peer
"github.com/libp2p/go-libp2p-peer"
pstore
"github.com/libp2p/go-libp2p-peerstore"
bhost
"github.com/libp2p/go-libp2p/p2p/host/basic"
)
func
TestPing
(
t
*
testing
.
T
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
h1
:=
netutil
.
Gen
Host
Swarm
(
t
,
ctx
)
h2
:=
netutil
.
Gen
Host
Swarm
(
t
,
ctx
)
h1
:=
bhost
.
New
(
netutil
.
GenSwarm
Network
(
t
,
ctx
)
)
h2
:=
bhost
.
New
(
netutil
.
GenSwarm
Network
(
t
,
ctx
)
)
err
:=
h1
.
Connect
(
ctx
,
pstore
.
PeerInfo
{
ID
:
h2
.
ID
(),
...
...
This diff is collapsed.
Click to expand it.
p2p/protocol/relay/relay_test.go
View file @
f61f242f
package
relay_test
import
(
"context"
"io"
"testing"
"context"
bhost
"github.com/libp2p/go-libp2p/p2p/host/basic"
relay
"github.com/libp2p/go-libp2p/p2p/protocol/relay"
logging
"github.com/ipfs/go-log"
inet
"github.com/libp2p/go-libp2p-net"
testutil
"github.com/libp2p/go-libp2p-netutil"
protocol
"github.com/libp2p/go-libp2p-protocol"
relay
"github.com/libp2p/go-libp2p/p2p/protocol/relay"
testutil
"github.com/libp2p/go-libp2p/p2p/test/util"
msmux
"github.com/whyrusleeping/go-multistream"
)
...
...
@@ -20,9 +22,9 @@ func TestRelaySimple(t *testing.T) {
ctx
:=
context
.
Background
()
// these networks have the relay service wired in already.
n1
:=
testutil
.
Gen
Host
Swarm
(
t
,
ctx
)
n2
:=
testutil
.
Gen
Host
Swarm
(
t
,
ctx
)
n3
:=
testutil
.
Gen
Host
Swarm
(
t
,
ctx
)
n1
:=
bhost
.
New
(
testutil
.
GenSwarm
Network
(
t
,
ctx
)
)
n2
:=
bhost
.
New
(
testutil
.
GenSwarm
Network
(
t
,
ctx
)
)
n3
:=
bhost
.
New
(
testutil
.
GenSwarm
Network
(
t
,
ctx
)
)
n1p
:=
n1
.
ID
()
n2p
:=
n2
.
ID
()
...
...
@@ -103,11 +105,11 @@ func TestRelayAcrossFour(t *testing.T) {
ctx
:=
context
.
Background
()
// these networks have the relay service wired in already.
n1
:=
testutil
.
Gen
Host
Swarm
(
t
,
ctx
)
n2
:=
testutil
.
Gen
Host
Swarm
(
t
,
ctx
)
n3
:=
testutil
.
Gen
Host
Swarm
(
t
,
ctx
)
n4
:=
testutil
.
Gen
Host
Swarm
(
t
,
ctx
)
n5
:=
testutil
.
Gen
Host
Swarm
(
t
,
ctx
)
n1
:=
bhost
.
New
(
testutil
.
GenSwarm
Network
(
t
,
ctx
)
)
n2
:=
bhost
.
New
(
testutil
.
GenSwarm
Network
(
t
,
ctx
)
)
n3
:=
bhost
.
New
(
testutil
.
GenSwarm
Network
(
t
,
ctx
)
)
n4
:=
bhost
.
New
(
testutil
.
GenSwarm
Network
(
t
,
ctx
)
)
n5
:=
bhost
.
New
(
testutil
.
GenSwarm
Network
(
t
,
ctx
)
)
n1p
:=
n1
.
ID
()
n2p
:=
n2
.
ID
()
...
...
@@ -215,9 +217,9 @@ func TestRelayStress(t *testing.T) {
ctx
:=
context
.
Background
()
// these networks have the relay service wired in already.
n1
:=
testutil
.
Gen
Host
Swarm
(
t
,
ctx
)
n2
:=
testutil
.
Gen
Host
Swarm
(
t
,
ctx
)
n3
:=
testutil
.
Gen
Host
Swarm
(
t
,
ctx
)
n1
:=
bhost
.
New
(
testutil
.
GenSwarm
Network
(
t
,
ctx
)
)
n2
:=
bhost
.
New
(
testutil
.
GenSwarm
Network
(
t
,
ctx
)
)
n3
:=
bhost
.
New
(
testutil
.
GenSwarm
Network
(
t
,
ctx
)
)
n1p
:=
n1
.
ID
()
n2p
:=
n2
.
ID
()
...
...
This diff is collapsed.
Click to expand it.
p2p/test/backpressure/backpressure_test.go
View file @
f61f242f
package
backpressure_tests
import
(
"context"
"io"
"math/rand"
"testing"
"time"
"context"
bhost
"github.com/libp2p/go-libp2p/p2p/host/basic"
u
"github.com/ipfs/go-ipfs-util"
logging
"github.com/ipfs/go-log"
host
"github.com/libp2p/go-libp2p-host"
inet
"github.com/libp2p/go-libp2p-net"
testutil
"github.com/libp2p/go-libp2p-netutil"
peer
"github.com/libp2p/go-libp2p-peer"
protocol
"github.com/libp2p/go-libp2p-protocol"
testutil
"github.com/libp2p/go-libp2p/p2p/test/util"
)
var
log
=
logging
.
Logger
(
"backpressure"
)
...
...
@@ -135,8 +137,8 @@ a problem.
// ok that's enough setup. let's do it!
ctx
:=
context
.
Background
()
h1
:=
testutil
.
Gen
Host
Swarm
(
t
,
ctx
)
h2
:=
testutil
.
Gen
Host
Swarm
(
t
,
ctx
)
h1
:=
bhost
.
New
(
testutil
.
GenSwarm
Network
(
t
,
ctx
)
)
h2
:=
bhost
.
New
(
testutil
.
GenSwarm
Network
(
t
,
ctx
)
)
// setup receiver handler
h1
.
SetStreamHandler
(
protocol
.
TestingID
,
receiver
)
...
...
@@ -272,8 +274,8 @@ func TestStBackpressureStreamWrite(t *testing.T) {
// setup the networks
ctx
:=
context
.
Background
()
h1
:=
testutil
.
Gen
Host
Swarm
(
t
,
ctx
)
h2
:=
testutil
.
Gen
Host
Swarm
(
t
,
ctx
)
h1
:=
bhost
.
New
(
testutil
.
GenSwarm
Network
(
t
,
ctx
)
)
h2
:=
bhost
.
New
(
testutil
.
GenSwarm
Network
(
t
,
ctx
)
)
// setup sender handler on 1
h1
.
SetStreamHandler
(
protocol
.
TestingID
,
sender
)
...
...
This diff is collapsed.
Click to expand it.
p2p/test/reconnects/reconnect_test.go
View file @
f61f242f
...
...
@@ -8,13 +8,15 @@ import (
"testing"
"time"
bhost
"github.com/libp2p/go-libp2p/p2p/host/basic"
u
"github.com/ipfs/go-ipfs-util"
logging
"github.com/ipfs/go-log"
host
"github.com/libp2p/go-libp2p-host"
inet
"github.com/libp2p/go-libp2p-net"
testutil
"github.com/libp2p/go-libp2p-netutil"
protocol
"github.com/libp2p/go-libp2p-protocol"
swarm
"github.com/libp2p/go-libp2p-swarm"
testutil
"github.com/libp2p/go-libp2p/p2p/test/util"
ps
"github.com/libp2p/go-peerstream"
)
...
...
@@ -103,8 +105,8 @@ func newSender() (chan sendChans, func(s inet.Stream)) {
// TestReconnect tests whether hosts are able to disconnect and reconnect.
func
TestReconnect2
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
h1
:=
testutil
.
Gen
Host
Swarm
(
t
,
ctx
)
h2
:=
testutil
.
Gen
Host
Swarm
(
t
,
ctx
)
h1
:=
bhost
.
New
(
testutil
.
GenSwarm
Network
(
t
,
ctx
)
)
h2
:=
bhost
.
New
(
testutil
.
GenSwarm
Network
(
t
,
ctx
)
)
hosts
:=
[]
host
.
Host
{
h1
,
h2
}
h1
.
SetStreamHandler
(
protocol
.
TestingID
,
EchoStreamHandler
)
...
...
@@ -123,11 +125,11 @@ func TestReconnect2(t *testing.T) {
// TestReconnect tests whether hosts are able to disconnect and reconnect.
func
TestReconnect5
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
h1
:=
testutil
.
Gen
Host
Swarm
(
t
,
ctx
)
h2
:=
testutil
.
Gen
Host
Swarm
(
t
,
ctx
)
h3
:=
testutil
.
Gen
Host
Swarm
(
t
,
ctx
)
h4
:=
testutil
.
Gen
Host
Swarm
(
t
,
ctx
)
h5
:=
testutil
.
Gen
Host
Swarm
(
t
,
ctx
)
h1
:=
bhost
.
New
(
testutil
.
GenSwarm
Network
(
t
,
ctx
)
)
h2
:=
bhost
.
New
(
testutil
.
GenSwarm
Network
(
t
,
ctx
)
)
h3
:=
bhost
.
New
(
testutil
.
GenSwarm
Network
(
t
,
ctx
)
)
h4
:=
bhost
.
New
(
testutil
.
GenSwarm
Network
(
t
,
ctx
)
)
h5
:=
bhost
.
New
(
testutil
.
GenSwarm
Network
(
t
,
ctx
)
)
hosts
:=
[]
host
.
Host
{
h1
,
h2
,
h3
,
h4
,
h5
}
h1
.
SetStreamHandler
(
protocol
.
TestingID
,
EchoStreamHandler
)
...
...
This diff is collapsed.
Click to expand it.
p2p/test/util/key.go
deleted
100644 → 0
View file @
5a2b58bc
package
testutil
import
(
"bytes"
"io"
"testing"
u
"github.com/ipfs/go-ipfs-util"
logging
"github.com/ipfs/go-log"
ic
"github.com/libp2p/go-libp2p-crypto"
peer
"github.com/libp2p/go-libp2p-peer"
testutil
"github.com/libp2p/go-testutil"
ma
"github.com/multiformats/go-multiaddr"
)
var
log
=
logging
.
Logger
(
"boguskey"
)
// TestBogusPrivateKey is a key used for testing (to avoid expensive keygen)
type
TestBogusPrivateKey
[]
byte
// TestBogusPublicKey is a key used for testing (to avoid expensive keygen)
type
TestBogusPublicKey
[]
byte
func
(
pk
TestBogusPublicKey
)
Verify
(
data
,
sig
[]
byte
)
(
bool
,
error
)
{
log
.
Errorf
(
"TestBogusPublicKey.Verify -- this better be a test!"
)
return
bytes
.
Equal
(
data
,
reverse
(
sig
)),
nil
}
func
(
pk
TestBogusPublicKey
)
Bytes
()
([]
byte
,
error
)
{
return
[]
byte
(
pk
),
nil
}
func
(
pk
TestBogusPublicKey
)
Encrypt
(
b
[]
byte
)
([]
byte
,
error
)
{
log
.
Errorf
(
"TestBogusPublicKey.Encrypt -- this better be a test!"
)
return
reverse
(
b
),
nil
}
// Equals checks whether this key is equal to another
func
(
pk
TestBogusPublicKey
)
Equals
(
k
ic
.
Key
)
bool
{
return
ic
.
KeyEqual
(
pk
,
k
)
}
func
(
pk
TestBogusPublicKey
)
Hash
()
([]
byte
,
error
)
{
return
ic
.
KeyHash
(
pk
)
}
func
(
sk
TestBogusPrivateKey
)
GenSecret
()
[]
byte
{
return
[]
byte
(
sk
)
}
func
(
sk
TestBogusPrivateKey
)
Sign
(
message
[]
byte
)
([]
byte
,
error
)
{
log
.
Errorf
(
"TestBogusPrivateKey.Sign -- this better be a test!"
)
return
reverse
(
message
),
nil
}
func
(
sk
TestBogusPrivateKey
)
GetPublic
()
ic
.
PubKey
{
return
TestBogusPublicKey
(
sk
)
}
func
(
sk
TestBogusPrivateKey
)
Decrypt
(
b
[]
byte
)
([]
byte
,
error
)
{
log
.
Errorf
(
"TestBogusPrivateKey.Decrypt -- this better be a test!"
)
return
reverse
(
b
),
nil
}
func
(
sk
TestBogusPrivateKey
)
Bytes
()
([]
byte
,
error
)
{
return
[]
byte
(
sk
),
nil
}
// Equals checks whether this key is equal to another
func
(
sk
TestBogusPrivateKey
)
Equals
(
k
ic
.
Key
)
bool
{
return
ic
.
KeyEqual
(
sk
,
k
)
}
func
(
sk
TestBogusPrivateKey
)
Hash
()
([]
byte
,
error
)
{
return
ic
.
KeyHash
(
sk
)
}
func
RandTestBogusPrivateKey
()
(
TestBogusPrivateKey
,
error
)
{
r
:=
u
.
NewTimeSeededRand
()
k
:=
make
([]
byte
,
5
)
if
_
,
err
:=
io
.
ReadFull
(
r
,
k
);
err
!=
nil
{
return
nil
,
err
}
return
TestBogusPrivateKey
(
k
),
nil
}
func
RandTestBogusPublicKey
()
(
TestBogusPublicKey
,
error
)
{
k
,
err
:=
RandTestBogusPrivateKey
()
return
TestBogusPublicKey
(
k
),
err
}
func
RandTestBogusPrivateKeyOrFatal
(
t
*
testing
.
T
)
TestBogusPrivateKey
{
k
,
err
:=
RandTestBogusPrivateKey
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
return
k
}
func
RandTestBogusPublicKeyOrFatal
(
t
*
testing
.
T
)
TestBogusPublicKey
{
k
,
err
:=
RandTestBogusPublicKey
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
return
k
}
func
RandTestBogusIdentity
()
(
testutil
.
Identity
,
error
)
{
k
,
err
:=
RandTestBogusPrivateKey
()
if
err
!=
nil
{
return
nil
,
err
}
id
,
err
:=
peer
.
IDFromPrivateKey
(
k
)
if
err
!=
nil
{
return
nil
,
err
}
return
&
identity
{
k
:
k
,
id
:
id
,
a
:
testutil
.
RandLocalTCPAddress
(),
},
nil
}
func
RandTestBogusIdentityOrFatal
(
t
*
testing
.
T
)
testutil
.
Identity
{
k
,
err
:=
RandTestBogusIdentity
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
return
k
}
// identity is a temporary shim to delay binding of PeerNetParams.
type
identity
struct
{
k
TestBogusPrivateKey
id
peer
.
ID
a
ma
.
Multiaddr
}
func
(
p
*
identity
)
ID
()
peer
.
ID
{
return
p
.
id
}
func
(
p
*
identity
)
Address
()
ma
.
Multiaddr
{
return
p
.
a
}
func
(
p
*
identity
)
PrivateKey
()
ic
.
PrivKey
{
return
p
.
k
}
func
(
p
*
identity
)
PublicKey
()
ic
.
PubKey
{
return
p
.
k
.
GetPublic
()
}
func
reverse
(
a
[]
byte
)
[]
byte
{
b
:=
make
([]
byte
,
len
(
a
))
for
i
:=
0
;
i
<
len
(
a
);
i
++
{
b
[
i
]
=
a
[
len
(
a
)
-
1
-
i
]
}
return
b
}
This diff is collapsed.
Click to expand it.
p2p/test/util/util.go
deleted
100644 → 0
View file @
5a2b58bc
package
testutil
import
(
"context"
"testing"
bhost
"github.com/libp2p/go-libp2p/p2p/host/basic"
metrics
"github.com/libp2p/go-libp2p-metrics"
inet
"github.com/libp2p/go-libp2p-net"
pstore
"github.com/libp2p/go-libp2p-peerstore"
swarm
"github.com/libp2p/go-libp2p-swarm"
tu
"github.com/libp2p/go-testutil"
ma
"github.com/multiformats/go-multiaddr"
)
func
GenSwarmNetwork
(
t
*
testing
.
T
,
ctx
context
.
Context
)
*
swarm
.
Network
{
p
:=
tu
.
RandPeerNetParamsOrFatal
(
t
)
ps
:=
pstore
.
NewPeerstore
()
ps
.
AddPubKey
(
p
.
ID
,
p
.
PubKey
)
ps
.
AddPrivKey
(
p
.
ID
,
p
.
PrivKey
)
n
,
err
:=
swarm
.
NewNetwork
(
ctx
,
[]
ma
.
Multiaddr
{
p
.
Addr
},
p
.
ID
,
ps
,
metrics
.
NewBandwidthCounter
())
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
ps
.
AddAddrs
(
p
.
ID
,
n
.
ListenAddresses
(),
pstore
.
PermanentAddrTTL
)
return
n
}
func
DivulgeAddresses
(
a
,
b
inet
.
Network
)
{
id
:=
a
.
LocalPeer
()
addrs
:=
a
.
Peerstore
()
.
Addrs
(
id
)
b
.
Peerstore
()
.
AddAddrs
(
id
,
addrs
,
pstore
.
PermanentAddrTTL
)
}
func
GenHostSwarm
(
t
*
testing
.
T
,
ctx
context
.
Context
)
*
bhost
.
BasicHost
{
n
:=
GenSwarmNetwork
(
t
,
ctx
)
return
bhost
.
New
(
n
)
}
var
RandPeerID
=
tu
.
RandPeerID
This diff is collapsed.
Click to expand it.
package.json
View file @
f61f242f
...
...
@@ -226,6 +226,18 @@
"hash"
:
"QmPpncQ3L4bC3rnwLBrgEomygs5RbnFejb68GgsecxbMiL"
,
"name"
:
"go-libp2p-nat"
,
"version"
:
"0.0.0"
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"QmcDTquYLTYirqj71RRWKUWEEw3nJt11Awzun5ep8kfY7W"
,
"name"
:
"go-libp2p-netutil"
,
"version"
:
"0.1.0"
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"QmYjDhB1VkuP5ATkqjdnPHfA2huyfcydNMXoGdtEvTNcYL"
,
"name"
:
"go-libp2p-blankhost"
,
"version"
:
"0.1.0"
}
],
"gxVersion"
:
"0.4.0"
,
...
...
@@ -235,3 +247,4 @@
"releaseCmd"
:
"git commit -a -m
\"
gx publish $VERSION
\"
"
,
"version"
:
"4.1.0"
}
This diff is collapsed.
Click to expand it.
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
Menu
Projects
Groups
Snippets
Help