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
5d1bbd52
Unverified
Commit
5d1bbd52
authored
Nov 09, 2016
by
Jakub Sztandera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Private Network protector to swarm
parent
4e991e68
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
7 deletions
+12
-7
swarm.go
swarm.go
+8
-4
swarm_listen.go
swarm_listen.go
+1
-1
swarm_net.go
swarm_net.go
+3
-2
No files found.
swarm.go
View file @
5d1bbd52
...
...
@@ -18,6 +18,7 @@ import (
addrutil
"github.com/libp2p/go-addr-util"
conn
"github.com/libp2p/go-libp2p-conn"
ci
"github.com/libp2p/go-libp2p-crypto"
ipnet
"github.com/libp2p/go-libp2p-interface-pnet"
metrics
"github.com/libp2p/go-libp2p-metrics"
mconn
"github.com/libp2p/go-libp2p-metrics/conn"
inet
"github.com/libp2p/go-libp2p-net"
...
...
@@ -98,11 +99,13 @@ type Swarm struct {
bwc
metrics
.
Reporter
limiter
*
dialLimiter
protec
ipnet
.
Protector
}
// NewSwarm constructs a Swarm, with a Chan.
func
NewSwarm
(
ctx
context
.
Context
,
listenAddrs
[]
ma
.
Multiaddr
,
local
peer
.
ID
,
peers
pstore
.
Peerstore
,
bwc
metrics
.
Reporter
)
(
*
Swarm
,
error
)
{
func
NewSwarm
(
ctx
context
.
Context
,
listenAddrs
[]
ma
.
Multiaddr
,
local
peer
.
ID
,
peers
pstore
.
Peerstore
,
protec
ipnet
.
Protector
,
bwc
metrics
.
Reporter
)
(
*
Swarm
,
error
)
{
listenAddrs
,
err
:=
filterAddrs
(
listenAddrs
)
if
err
!=
nil
{
...
...
@@ -130,7 +133,8 @@ func NewSwarm(ctx context.Context, listenAddrs []ma.Multiaddr,
bwc
:
bwc
,
fdRateLimit
:
make
(
chan
struct
{},
concurrentFdDials
),
Filters
:
filter
.
NewFilters
(),
dialer
:
conn
.
NewDialer
(
local
,
peers
.
PrivKey
(
local
),
wrap
),
dialer
:
conn
.
NewDialer
(
local
,
peers
.
PrivKey
(
local
),
protec
,
wrap
),
protec
:
protec
,
}
s
.
dsync
=
NewDialSync
(
s
.
doDial
)
...
...
@@ -158,7 +162,7 @@ func NewBlankSwarm(ctx context.Context, id peer.ID, privkey ci.PrivKey, pstpt ps
notifs
:
make
(
map
[
inet
.
Notifiee
]
ps
.
Notifiee
),
fdRateLimit
:
make
(
chan
struct
{},
concurrentFdDials
),
Filters
:
filter
.
NewFilters
(),
dialer
:
conn
.
NewDialer
(
id
,
privkey
,
nil
),
dialer
:
conn
.
NewDialer
(
id
,
privkey
,
nil
,
nil
),
}
// configure Swarm
...
...
swarm_listen.go
View file @
5d1bbd52
...
...
@@ -83,7 +83,7 @@ func (s *Swarm) addListener(tptlist transport.Listener) error {
log
.
Warning
(
"Listener not given PrivateKey, so WILL NOT SECURE conns."
)
}
list
,
err
:=
conn
.
WrapTransportListener
(
s
.
Context
(),
tptlist
,
s
.
local
,
sk
)
list
,
err
:=
conn
.
WrapTransportListener
(
s
.
Context
(),
tptlist
,
s
.
local
,
sk
,
s
.
protec
)
if
err
!=
nil
{
return
err
}
...
...
swarm_net.go
View file @
5d1bbd52
...
...
@@ -5,6 +5,7 @@ import (
"fmt"
"github.com/jbenet/goprocess"
ipnet
"github.com/libp2p/go-libp2p-interface-pnet"
metrics
"github.com/libp2p/go-libp2p-metrics"
inet
"github.com/libp2p/go-libp2p-net"
peer
"github.com/libp2p/go-libp2p-peer"
...
...
@@ -19,9 +20,9 @@ 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
,
peers
pstore
.
Peerstore
,
bwc
metrics
.
Reporter
)
(
*
Network
,
error
)
{
peers
pstore
.
Peerstore
,
protec
ipnet
.
Protector
,
bwc
metrics
.
Reporter
)
(
*
Network
,
error
)
{
s
,
err
:=
NewSwarm
(
ctx
,
listen
,
local
,
peers
,
bwc
)
s
,
err
:=
NewSwarm
(
ctx
,
listen
,
local
,
peers
,
protec
,
bwc
)
if
err
!=
nil
{
return
nil
,
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