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
e272315e
Commit
e272315e
authored
Nov 15, 2016
by
Jeromy Johnson
Committed by
GitHub
Nov 15, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #8 from libp2p/feat/pnet
Introduce changes required for Private Netowrk support
parents
4e991e68
b2d941fc
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
7 deletions
+24
-7
package.json
package.json
+2
-2
swarm.go
swarm.go
+12
-2
swarm_listen.go
swarm_listen.go
+1
-1
swarm_net.go
swarm_net.go
+9
-2
No files found.
package.json
View file @
e272315e
...
...
@@ -81,9 +81,9 @@
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"Qm
U1YMnktAuCPBC7TqhbZRkpZ7KCiekv7SZtaLU5zpTgq
b"
,
"hash"
:
"Qm
V7iorvAUv766HnS5gZrsYAkFqKdTTF73kGvUDu5XFzC
b"
,
"name"
:
"go-libp2p-conn"
,
"version"
:
"1.
4
.0"
"version"
:
"1.
5
.0"
},
{
"author"
:
"whyrusleeping"
,
...
...
swarm.go
View file @
e272315e
...
...
@@ -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,18 @@ type Swarm struct {
bwc
metrics
.
Reporter
limiter
*
dialLimiter
protec
ipnet
.
Protector
}
func
NewSwarm
(
ctx
context
.
Context
,
listenAddrs
[]
ma
.
Multiaddr
,
local
peer
.
ID
,
peers
pstore
.
Peerstore
,
bwc
metrics
.
Reporter
)
(
*
Swarm
,
error
)
{
return
NewSwarmWithProtector
(
ctx
,
listenAddrs
,
local
,
peers
,
nil
,
bwc
)
}
// 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
WithProtector
(
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
{
...
...
@@ -131,7 +139,9 @@ func NewSwarm(ctx context.Context, listenAddrs []ma.Multiaddr,
fdRateLimit
:
make
(
chan
struct
{},
concurrentFdDials
),
Filters
:
filter
.
NewFilters
(),
dialer
:
conn
.
NewDialer
(
local
,
peers
.
PrivKey
(
local
),
wrap
),
protec
:
protec
,
}
s
.
dialer
.
Protector
=
protec
s
.
dsync
=
NewDialSync
(
s
.
doDial
)
s
.
limiter
=
newDialLimiter
(
s
.
dialAddr
)
...
...
swarm_listen.go
View file @
e272315e
...
...
@@ -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
WithProtector
(
s
.
Context
(),
tptlist
,
s
.
local
,
sk
,
s
.
protec
)
if
err
!=
nil
{
return
err
}
...
...
swarm_net.go
View file @
e272315e
...
...
@@ -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"
...
...
@@ -17,11 +18,17 @@ import (
// to implement inet.Network.
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
)
{
s
,
err
:=
NewSwarm
(
ctx
,
listen
,
local
,
peers
,
bwc
)
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
)
{
s
,
err
:=
NewSwarmWithProtector
(
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