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
p2p
go-p2p-swarm
Commits
b2d941fc
Unverified
Commit
b2d941fc
authored
Nov 14, 2016
by
Jakub Sztandera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert to normal NewNetwork create NewNetworkWithProtector
parent
d9513595
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
4 deletions
+10
-4
swarm_addr_test.go
swarm_addr_test.go
+2
-2
swarm_net.go
swarm_net.go
+7
-1
swarm_net_test.go
swarm_net_test.go
+1
-1
No files found.
swarm_addr_test.go
View file @
b2d941fc
...
@@ -65,11 +65,11 @@ func TestFilterAddrs(t *testing.T) {
...
@@ -65,11 +65,11 @@ func TestFilterAddrs(t *testing.T) {
ps
:=
pstore
.
NewPeerstore
()
ps
:=
pstore
.
NewPeerstore
()
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
if
_
,
err
:=
NewNetwork
(
ctx
,
bad
,
id
,
ps
,
nil
,
metrics
.
NewBandwidthCounter
());
err
==
nil
{
if
_
,
err
:=
NewNetwork
(
ctx
,
bad
,
id
,
ps
,
metrics
.
NewBandwidthCounter
());
err
==
nil
{
t
.
Fatal
(
"should have failed to create swarm"
)
t
.
Fatal
(
"should have failed to create swarm"
)
}
}
if
_
,
err
:=
NewNetwork
(
ctx
,
goodAndBad
,
id
,
ps
,
nil
,
metrics
.
NewBandwidthCounter
());
err
!=
nil
{
if
_
,
err
:=
NewNetwork
(
ctx
,
goodAndBad
,
id
,
ps
,
metrics
.
NewBandwidthCounter
());
err
!=
nil
{
t
.
Fatal
(
"should have succeeded in creating swarm"
,
err
)
t
.
Fatal
(
"should have succeeded in creating swarm"
,
err
)
}
}
}
}
...
...
swarm_net.go
View file @
b2d941fc
...
@@ -18,8 +18,14 @@ import (
...
@@ -18,8 +18,14 @@ import (
// to implement inet.Network.
// to implement inet.Network.
type
Network
Swarm
type
Network
Swarm
// NewNetwork constructs a new network and starts listening on given addresses.
func
NewNetwork
(
ctx
context
.
Context
,
listen
[]
ma
.
Multiaddr
,
local
peer
.
ID
,
func
NewNetwork
(
ctx
context
.
Context
,
listen
[]
ma
.
Multiaddr
,
local
peer
.
ID
,
peers
pstore
.
Peerstore
,
bwc
metrics
.
Reporter
)
(
*
Network
,
error
)
{
return
NewNetworkWithProtector
(
ctx
,
listen
,
local
,
peers
,
nil
,
bwc
)
}
// NewNetwork constructs a new network and starts listening on given addresses.
func
NewNetworkWithProtector
(
ctx
context
.
Context
,
listen
[]
ma
.
Multiaddr
,
local
peer
.
ID
,
peers
pstore
.
Peerstore
,
protec
ipnet
.
Protector
,
bwc
metrics
.
Reporter
)
(
*
Network
,
error
)
{
peers
pstore
.
Peerstore
,
protec
ipnet
.
Protector
,
bwc
metrics
.
Reporter
)
(
*
Network
,
error
)
{
s
,
err
:=
NewSwarmWithProtector
(
ctx
,
listen
,
local
,
peers
,
protec
,
bwc
)
s
,
err
:=
NewSwarmWithProtector
(
ctx
,
listen
,
local
,
peers
,
protec
,
bwc
)
...
...
swarm_net_test.go
View file @
b2d941fc
...
@@ -17,7 +17,7 @@ func GenSwarmNetwork(t *testing.T, ctx context.Context) *Network {
...
@@ -17,7 +17,7 @@ func GenSwarmNetwork(t *testing.T, ctx context.Context) *Network {
ps
:=
pstore
.
NewPeerstore
()
ps
:=
pstore
.
NewPeerstore
()
ps
.
AddPubKey
(
p
.
ID
,
p
.
PubKey
)
ps
.
AddPubKey
(
p
.
ID
,
p
.
PubKey
)
ps
.
AddPrivKey
(
p
.
ID
,
p
.
PrivKey
)
ps
.
AddPrivKey
(
p
.
ID
,
p
.
PrivKey
)
n
,
err
:=
NewNetwork
(
ctx
,
[]
ma
.
Multiaddr
{
p
.
Addr
},
p
.
ID
,
ps
,
nil
,
nil
)
n
,
err
:=
NewNetwork
(
ctx
,
[]
ma
.
Multiaddr
{
p
.
Addr
},
p
.
ID
,
ps
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
...
...
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