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
52855747
Commit
52855747
authored
8 years ago
by
Jeromy Johnson
Browse files
Options
Download
Plain Diff
Merge pull request #60 from ipfs/deps/peerstore-split
split peerstore from peer package
parents
df1c7738
916bc557
master
2018-Q4-OKR
docs-improvements
feat/backoff-listing
feat/p2p-multiaddr
feat/pnet/working3
feat/protobuf
feat/relay-integrate
feat/udp
feat/update/go-reuseport
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
wip/js-interop
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
v4.1.0
v4.0.4
v4.0.3
v4.0.2
v4.0.1
v4.0.0
v3.6.0
v3.5.4
v3.5.3
v3.5.2
v3.5.1
v3.5.0
v3.4.3
v3.4.2
v3.4.1
v3.4.0
v3.3.7
v3.3.6
v3.3.4
v3.3.3
v3.3.2
v3.3.1
v3.3.0
No related merge requests found
Changes
20
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
p2p/discovery/mdns.go
+3
-2
p2p/discovery/mdns.go
p2p/host/basic/basic_host.go
+4
-3
p2p/host/basic/basic_host.go
p2p/host/host.go
+3
-2
p2p/host/host.go
p2p/host/routed/routed.go
+5
-4
p2p/host/routed/routed.go
p2p/net/interface.go
+2
-1
p2p/net/interface.go
p2p/net/mock/interface.go
+7
-5
p2p/net/mock/interface.go
p2p/net/mock/mock_net.go
+6
-5
p2p/net/mock/mock_net.go
p2p/net/mock/mock_peernet.go
+7
-5
p2p/net/mock/mock_peernet.go
p2p/net/swarm/dial_test.go
+10
-9
p2p/net/swarm/dial_test.go
p2p/net/swarm/peers_test.go
+2
-1
p2p/net/swarm/peers_test.go
p2p/net/swarm/simul_test.go
+3
-2
p2p/net/swarm/simul_test.go
p2p/net/swarm/swarm.go
+3
-2
p2p/net/swarm/swarm.go
p2p/net/swarm/swarm_addr_test.go
+3
-3
p2p/net/swarm/swarm_addr_test.go
p2p/net/swarm/swarm_net.go
+3
-2
p2p/net/swarm/swarm_net.go
p2p/net/swarm/swarm_test.go
+7
-6
p2p/net/swarm/swarm_test.go
p2p/protocol/identify/id.go
+3
-3
p2p/protocol/identify/id.go
p2p/protocol/identify/obsaddr.go
+3
-3
p2p/protocol/identify/obsaddr.go
p2p/protocol/ping/ping_test.go
+4
-2
p2p/protocol/ping/ping_test.go
p2p/test/util/util.go
+4
-4
p2p/test/util/util.go
package.json
+12
-6
package.json
with
94 additions
and
70 deletions
+94
-70
p2p/discovery/mdns.go
View file @
52855747
...
...
@@ -11,6 +11,7 @@ import (
"github.com/cryptix/mdns"
"github.com/ipfs/go-libp2p-peer"
pstore
"github.com/ipfs/go-libp2p-peerstore"
"github.com/ipfs/go-libp2p/p2p/host"
logging
"github.com/ipfs/go-log"
ma
"github.com/jbenet/go-multiaddr"
...
...
@@ -28,7 +29,7 @@ type Service interface {
}
type
Notifee
interface
{
HandlePeerFound
(
p
eer
.
PeerInfo
)
HandlePeerFound
(
p
store
.
PeerInfo
)
}
type
mdnsService
struct
{
...
...
@@ -154,7 +155,7 @@ func (m *mdnsService) handleEntry(e *mdns.ServiceEntry) {
return
}
pi
:=
p
eer
.
PeerInfo
{
pi
:=
p
store
.
PeerInfo
{
ID
:
mpeer
,
Addrs
:
[]
ma
.
Multiaddr
{
maddr
},
}
...
...
This diff is collapsed.
Click to expand it.
p2p/host/basic/basic_host.go
View file @
52855747
...
...
@@ -4,6 +4,7 @@ import (
"io"
peer
"github.com/ipfs/go-libp2p-peer"
pstore
"github.com/ipfs/go-libp2p-peerstore"
metrics
"github.com/ipfs/go-libp2p/p2p/metrics"
mstream
"github.com/ipfs/go-libp2p/p2p/metrics/stream"
inet
"github.com/ipfs/go-libp2p/p2p/net"
...
...
@@ -122,7 +123,7 @@ func (h *BasicHost) ID() peer.ID {
}
// Peerstore returns the Host's repository of Peer Addresses and Keys.
func
(
h
*
BasicHost
)
Peerstore
()
p
eer
.
Peerstore
{
func
(
h
*
BasicHost
)
Peerstore
()
p
store
.
Peerstore
{
return
h
.
Network
()
.
Peerstore
()
}
...
...
@@ -181,10 +182,10 @@ func (h *BasicHost) NewStream(ctx context.Context, pid protocol.ID, p peer.ID) (
// peerstore. If there is not an active connection, Connect will issue a
// h.Network.Dial, and block until a connection is open, or an error is
// returned. // TODO: Relay + NAT.
func
(
h
*
BasicHost
)
Connect
(
ctx
context
.
Context
,
pi
p
eer
.
PeerInfo
)
error
{
func
(
h
*
BasicHost
)
Connect
(
ctx
context
.
Context
,
pi
p
store
.
PeerInfo
)
error
{
// absorb addresses into peerstore
h
.
Peerstore
()
.
AddAddrs
(
pi
.
ID
,
pi
.
Addrs
,
p
eer
.
TempAddrTTL
)
h
.
Peerstore
()
.
AddAddrs
(
pi
.
ID
,
pi
.
Addrs
,
p
store
.
TempAddrTTL
)
cs
:=
h
.
Network
()
.
ConnsToPeer
(
pi
.
ID
)
if
len
(
cs
)
>
0
{
...
...
This diff is collapsed.
Click to expand it.
p2p/host/host.go
View file @
52855747
...
...
@@ -2,6 +2,7 @@ package host
import
(
peer
"github.com/ipfs/go-libp2p-peer"
pstore
"github.com/ipfs/go-libp2p-peerstore"
metrics
"github.com/ipfs/go-libp2p/p2p/metrics"
inet
"github.com/ipfs/go-libp2p/p2p/net"
protocol
"github.com/ipfs/go-libp2p/p2p/protocol"
...
...
@@ -23,7 +24,7 @@ type Host interface {
ID
()
peer
.
ID
// Peerstore returns the Host's repository of Peer Addresses and Keys.
Peerstore
()
p
eer
.
Peerstore
Peerstore
()
p
store
.
Peerstore
// Returns the listen addresses of the Host
Addrs
()
[]
ma
.
Multiaddr
...
...
@@ -39,7 +40,7 @@ type Host interface {
// peerstore. If there is not an active connection, Connect will issue a
// h.Network.Dial, and block until a connection is open, or an error is
// returned. // TODO: Relay + NAT.
Connect
(
ctx
context
.
Context
,
pi
p
eer
.
PeerInfo
)
error
Connect
(
ctx
context
.
Context
,
pi
p
store
.
PeerInfo
)
error
// SetStreamHandler sets the protocol handler on the Host's Mux.
// This is equivalent to:
...
...
This diff is collapsed.
Click to expand it.
p2p/host/routed/routed.go
View file @
52855747
...
...
@@ -6,6 +6,7 @@ import (
lgbl
"github.com/ipfs/go-libp2p-loggables"
peer
"github.com/ipfs/go-libp2p-peer"
pstore
"github.com/ipfs/go-libp2p-peerstore"
host
"github.com/ipfs/go-libp2p/p2p/host"
metrics
"github.com/ipfs/go-libp2p/p2p/metrics"
inet
"github.com/ipfs/go-libp2p/p2p/net"
...
...
@@ -32,7 +33,7 @@ type RoutedHost struct {
}
type
Routing
interface
{
FindPeer
(
context
.
Context
,
peer
.
ID
)
(
p
eer
.
PeerInfo
,
error
)
FindPeer
(
context
.
Context
,
peer
.
ID
)
(
p
store
.
PeerInfo
,
error
)
}
func
Wrap
(
h
host
.
Host
,
r
Routing
)
*
RoutedHost
{
...
...
@@ -44,7 +45,7 @@ func Wrap(h host.Host, r Routing) *RoutedHost {
//
// RoutedHost's Connect differs in that if the host has no addresses for a
// given peer, it will use its routing system to try to find some.
func
(
rh
*
RoutedHost
)
Connect
(
ctx
context
.
Context
,
pi
p
eer
.
PeerInfo
)
error
{
func
(
rh
*
RoutedHost
)
Connect
(
ctx
context
.
Context
,
pi
p
store
.
PeerInfo
)
error
{
// first, check if we're already connected.
if
len
(
rh
.
Network
()
.
ConnsToPeer
(
pi
.
ID
))
>
0
{
return
nil
...
...
@@ -52,7 +53,7 @@ func (rh *RoutedHost) Connect(ctx context.Context, pi peer.PeerInfo) error {
// if we were given some addresses, keep + use them.
if
len
(
pi
.
Addrs
)
>
0
{
rh
.
Peerstore
()
.
AddAddrs
(
pi
.
ID
,
pi
.
Addrs
,
p
eer
.
TempAddrTTL
)
rh
.
Peerstore
()
.
AddAddrs
(
pi
.
ID
,
pi
.
Addrs
,
p
store
.
TempAddrTTL
)
}
// Check if we have some addresses in our recent memory.
...
...
@@ -89,7 +90,7 @@ func (rh *RoutedHost) ID() peer.ID {
return
rh
.
host
.
ID
()
}
func
(
rh
*
RoutedHost
)
Peerstore
()
p
eer
.
Peerstore
{
func
(
rh
*
RoutedHost
)
Peerstore
()
p
store
.
Peerstore
{
return
rh
.
host
.
Peerstore
()
}
...
...
This diff is collapsed.
Click to expand it.
p2p/net/interface.go
View file @
52855747
...
...
@@ -4,6 +4,7 @@ import (
"io"
peer
"github.com/ipfs/go-libp2p-peer"
pstore
"github.com/ipfs/go-libp2p-peerstore"
conn
"github.com/ipfs/go-libp2p/p2p/net/conn"
ma
"github.com/jbenet/go-multiaddr"
"github.com/jbenet/goprocess"
...
...
@@ -91,7 +92,7 @@ type Dialer interface {
// Peerstore returns the internal peerstore
// This is useful to tell the dialer about a new address for a peer.
// Or use one of the public keys found out over the network.
Peerstore
()
p
eer
.
Peerstore
Peerstore
()
p
store
.
Peerstore
// LocalPeer returns the local peer associated with this network
LocalPeer
()
peer
.
ID
...
...
This diff is collapsed.
Click to expand it.
p2p/net/mock/interface.go
View file @
52855747
...
...
@@ -7,13 +7,15 @@
package
mocknet
import
(
ic
"github.com/ipfs/go-libp2p-crypto"
peer
"github.com/ipfs/go-libp2p-peer"
host
"github.com/ipfs/go-libp2p/p2p/host"
inet
"github.com/ipfs/go-libp2p/p2p/net"
"io"
"time"
host
"github.com/ipfs/go-libp2p/p2p/host"
inet
"github.com/ipfs/go-libp2p/p2p/net"
ic
"github.com/ipfs/go-libp2p-crypto"
peer
"github.com/ipfs/go-libp2p-peer"
pstore
"github.com/ipfs/go-libp2p-peerstore"
ma
"github.com/jbenet/go-multiaddr"
)
...
...
@@ -25,7 +27,7 @@ type Mocknet interface {
// AddPeer adds an existing peer. we need both a privkey and addr.
// ID is derived from PrivKey
AddPeer
(
ic
.
PrivKey
,
ma
.
Multiaddr
)
(
host
.
Host
,
error
)
AddPeerWithPeerstore
(
peer
.
ID
,
p
eer
.
Peerstore
)
(
host
.
Host
,
error
)
AddPeerWithPeerstore
(
peer
.
ID
,
p
store
.
Peerstore
)
(
host
.
Host
,
error
)
// retrieve things (with randomized iteration order)
Peers
()
[]
peer
.
ID
...
...
This diff is collapsed.
Click to expand it.
p2p/net/mock/mock_net.go
View file @
52855747
...
...
@@ -5,14 +5,15 @@ import (
"sort"
"sync"
ic
"github.com/ipfs/go-libp2p-crypto"
peer
"github.com/ipfs/go-libp2p-peer"
host
"github.com/ipfs/go-libp2p/p2p/host"
bhost
"github.com/ipfs/go-libp2p/p2p/host/basic"
inet
"github.com/ipfs/go-libp2p/p2p/net"
p2putil
"github.com/ipfs/go-libp2p/p2p/test/util"
testutil
"github.com/ipfs/go-libp2p/testutil"
ic
"github.com/ipfs/go-libp2p-crypto"
peer
"github.com/ipfs/go-libp2p-peer"
pstore
"github.com/ipfs/go-libp2p-peerstore"
ma
"github.com/jbenet/go-multiaddr"
"github.com/jbenet/goprocess"
goprocessctx
"github.com/jbenet/goprocess/context"
...
...
@@ -69,15 +70,15 @@ func (mn *mocknet) AddPeer(k ic.PrivKey, a ma.Multiaddr) (host.Host, error) {
return
nil
,
err
}
ps
:=
p
eer
.
NewPeerstore
()
ps
.
AddAddr
(
p
,
a
,
p
eer
.
PermanentAddrTTL
)
ps
:=
p
store
.
NewPeerstore
()
ps
.
AddAddr
(
p
,
a
,
p
store
.
PermanentAddrTTL
)
ps
.
AddPrivKey
(
p
,
k
)
ps
.
AddPubKey
(
p
,
k
.
GetPublic
())
return
mn
.
AddPeerWithPeerstore
(
p
,
ps
)
}
func
(
mn
*
mocknet
)
AddPeerWithPeerstore
(
p
peer
.
ID
,
ps
p
eer
.
Peerstore
)
(
host
.
Host
,
error
)
{
func
(
mn
*
mocknet
)
AddPeerWithPeerstore
(
p
peer
.
ID
,
ps
p
store
.
Peerstore
)
(
host
.
Host
,
error
)
{
n
,
err
:=
newPeernet
(
mn
.
ctx
,
mn
,
p
,
ps
)
if
err
!=
nil
{
return
nil
,
err
...
...
This diff is collapsed.
Click to expand it.
p2p/net/mock/mock_peernet.go
View file @
52855747
...
...
@@ -5,8 +5,10 @@ import (
"math/rand"
"sync"
peer
"github.com/ipfs/go-libp2p-peer"
inet
"github.com/ipfs/go-libp2p/p2p/net"
peer
"github.com/ipfs/go-libp2p-peer"
pstore
"github.com/ipfs/go-libp2p-peerstore"
ma
"github.com/jbenet/go-multiaddr"
"github.com/jbenet/goprocess"
goprocessctx
"github.com/jbenet/goprocess/context"
...
...
@@ -18,7 +20,7 @@ type peernet struct {
mocknet
*
mocknet
// parent
peer
peer
.
ID
ps
p
eer
.
Peerstore
ps
p
store
.
Peerstore
// conns are actual live connections between peers.
// many conns could run over each link.
...
...
@@ -38,7 +40,7 @@ type peernet struct {
}
// newPeernet constructs a new peernet
func
newPeernet
(
ctx
context
.
Context
,
m
*
mocknet
,
p
peer
.
ID
,
ps
p
eer
.
Peerstore
)
(
*
peernet
,
error
)
{
func
newPeernet
(
ctx
context
.
Context
,
m
*
mocknet
,
p
peer
.
ID
,
ps
p
store
.
Peerstore
)
(
*
peernet
,
error
)
{
n
:=
&
peernet
{
mocknet
:
m
,
...
...
@@ -82,7 +84,7 @@ func (pn *peernet) Close() error {
return
pn
.
proc
.
Close
()
}
func
(
pn
*
peernet
)
Peerstore
()
p
eer
.
Peerstore
{
func
(
pn
*
peernet
)
Peerstore
()
p
store
.
Peerstore
{
return
pn
.
ps
}
...
...
@@ -293,7 +295,7 @@ func (pn *peernet) BandwidthTotals() (in uint64, out uint64) {
// Listen tells the network to start listening on given multiaddrs.
func
(
pn
*
peernet
)
Listen
(
addrs
...
ma
.
Multiaddr
)
error
{
pn
.
Peerstore
()
.
AddAddrs
(
pn
.
LocalPeer
(),
addrs
,
p
eer
.
PermanentAddrTTL
)
pn
.
Peerstore
()
.
AddAddrs
(
pn
.
LocalPeer
(),
addrs
,
p
store
.
PermanentAddrTTL
)
return
nil
}
...
...
This diff is collapsed.
Click to expand it.
p2p/net/swarm/dial_test.go
View file @
52855747
...
...
@@ -7,11 +7,12 @@ import (
"testing"
"time"
peer
"github.com/ipfs/go-libp2p-peer"
addrutil
"github.com/ipfs/go-libp2p/p2p/net/swarm/addr"
testutil
"github.com/ipfs/go-libp2p/testutil"
ci
"github.com/ipfs/go-libp2p/testutil/ci"
peer
"github.com/ipfs/go-libp2p-peer"
pstore
"github.com/ipfs/go-libp2p-peerstore"
ma
"github.com/jbenet/go-multiaddr"
manet
"github.com/jbenet/go-multiaddr-net"
context
"golang.org/x/net/context"
...
...
@@ -32,7 +33,7 @@ func TestBasicDial(t *testing.T) {
s1
:=
swarms
[
0
]
s2
:=
swarms
[
1
]
s1
.
peers
.
AddAddrs
(
s2
.
local
,
s2
.
ListenAddresses
(),
p
eer
.
PermanentAddrTTL
)
s1
.
peers
.
AddAddrs
(
s2
.
local
,
s2
.
ListenAddresses
(),
p
store
.
PermanentAddrTTL
)
c
,
err
:=
s1
.
Dial
(
ctx
,
s2
.
local
)
if
err
!=
nil
{
...
...
@@ -57,7 +58,7 @@ func TestDialWithNoListeners(t *testing.T) {
defer
closeSwarms
(
swarms
)
s2
:=
swarms
[
0
]
s1
.
peers
.
AddAddrs
(
s2
.
local
,
s2
.
ListenAddresses
(),
p
eer
.
PermanentAddrTTL
)
s1
.
peers
.
AddAddrs
(
s2
.
local
,
s2
.
ListenAddresses
(),
p
store
.
PermanentAddrTTL
)
c
,
err
:=
s1
.
Dial
(
ctx
,
s2
.
local
)
if
err
!=
nil
{
...
...
@@ -101,7 +102,7 @@ func TestSimultDials(t *testing.T) {
connect
:=
func
(
s
*
Swarm
,
dst
peer
.
ID
,
addr
ma
.
Multiaddr
)
{
// copy for other peer
log
.
Debugf
(
"TestSimultOpen: connecting: %s --> %s (%s)"
,
s
.
local
,
dst
,
addr
)
s
.
peers
.
AddAddr
(
dst
,
addr
,
p
eer
.
TempAddrTTL
)
s
.
peers
.
AddAddr
(
dst
,
addr
,
p
store
.
TempAddrTTL
)
if
_
,
err
:=
s
.
Dial
(
ctx
,
dst
);
err
!=
nil
{
t
.
Fatal
(
"error swarm dialing to peer"
,
err
)
}
...
...
@@ -178,7 +179,7 @@ func TestDialWait(t *testing.T) {
s2p
,
s2addr
,
s2l
:=
newSilentPeer
(
t
)
go
acceptAndHang
(
s2l
)
defer
s2l
.
Close
()
s1
.
peers
.
AddAddr
(
s2p
,
s2addr
,
p
eer
.
PermanentAddrTTL
)
s1
.
peers
.
AddAddr
(
s2p
,
s2addr
,
p
store
.
PermanentAddrTTL
)
before
:=
time
.
Now
()
if
c
,
err
:=
s1
.
Dial
(
ctx
,
s2p
);
err
==
nil
{
...
...
@@ -224,13 +225,13 @@ func TestDialBackoff(t *testing.T) {
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
s1
.
peers
.
AddAddrs
(
s2
.
local
,
s2addrs
,
p
eer
.
PermanentAddrTTL
)
s1
.
peers
.
AddAddrs
(
s2
.
local
,
s2addrs
,
p
store
.
PermanentAddrTTL
)
// dial to a non-existent peer.
s3p
,
s3addr
,
s3l
:=
newSilentPeer
(
t
)
go
acceptAndHang
(
s3l
)
defer
s3l
.
Close
()
s1
.
peers
.
AddAddr
(
s3p
,
s3addr
,
p
eer
.
PermanentAddrTTL
)
s1
.
peers
.
AddAddr
(
s3p
,
s3addr
,
p
store
.
PermanentAddrTTL
)
// in this test we will:
// 1) dial 10x to each node.
...
...
@@ -442,7 +443,7 @@ func TestDialBackoffClears(t *testing.T) {
defer
s2l
.
Close
()
// phase 1 -- dial to non-operational addresses
s1
.
peers
.
AddAddr
(
s2
.
local
,
s2bad
,
p
eer
.
PermanentAddrTTL
)
s1
.
peers
.
AddAddr
(
s2
.
local
,
s2bad
,
p
store
.
PermanentAddrTTL
)
before
:=
time
.
Now
()
if
c
,
err
:=
s1
.
Dial
(
ctx
,
s2
.
local
);
err
==
nil
{
...
...
@@ -472,7 +473,7 @@ func TestDialBackoffClears(t *testing.T) {
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
s1
.
peers
.
AddAddrs
(
s2
.
local
,
ifaceAddrs1
,
p
eer
.
PermanentAddrTTL
)
s1
.
peers
.
AddAddrs
(
s2
.
local
,
ifaceAddrs1
,
p
store
.
PermanentAddrTTL
)
if
_
,
err
:=
s1
.
Dial
(
ctx
,
s2
.
local
);
err
==
nil
{
t
.
Fatal
(
"should have failed to dial backed off peer"
)
...
...
This diff is collapsed.
Click to expand it.
p2p/net/swarm/peers_test.go
View file @
52855747
...
...
@@ -4,6 +4,7 @@ import (
"testing"
peer
"github.com/ipfs/go-libp2p-peer"
pstore
"github.com/ipfs/go-libp2p-peerstore"
ma
"github.com/jbenet/go-multiaddr"
context
"golang.org/x/net/context"
)
...
...
@@ -17,7 +18,7 @@ func TestPeers(t *testing.T) {
connect
:=
func
(
s
*
Swarm
,
dst
peer
.
ID
,
addr
ma
.
Multiaddr
)
{
// TODO: make a DialAddr func.
s
.
peers
.
AddAddr
(
dst
,
addr
,
p
eer
.
PermanentAddrTTL
)
s
.
peers
.
AddAddr
(
dst
,
addr
,
p
store
.
PermanentAddrTTL
)
// t.Logf("connections from %s", s.LocalPeer())
// for _, c := range s.ConnectionsToPeer(dst) {
// t.Logf("connection from %s to %s: %v", s.LocalPeer(), dst, c)
...
...
This diff is collapsed.
Click to expand it.
p2p/net/swarm/simul_test.go
View file @
52855747
...
...
@@ -6,9 +6,10 @@ import (
"testing"
"time"
peer
"github.com/ipfs/go-libp2p-peer"
ci
"github.com/ipfs/go-libp2p/testutil/ci"
peer
"github.com/ipfs/go-libp2p-peer"
pstore
"github.com/ipfs/go-libp2p-peerstore"
ma
"github.com/jbenet/go-multiaddr"
context
"golang.org/x/net/context"
)
...
...
@@ -26,7 +27,7 @@ func TestSimultOpen(t *testing.T) {
connect
:=
func
(
s
*
Swarm
,
dst
peer
.
ID
,
addr
ma
.
Multiaddr
)
{
// copy for other peer
log
.
Debugf
(
"TestSimultOpen: connecting: %s --> %s (%s)"
,
s
.
local
,
dst
,
addr
)
s
.
peers
.
AddAddr
(
dst
,
addr
,
p
eer
.
PermanentAddrTTL
)
s
.
peers
.
AddAddr
(
dst
,
addr
,
p
store
.
PermanentAddrTTL
)
if
_
,
err
:=
s
.
Dial
(
ctx
,
dst
);
err
!=
nil
{
t
.
Fatal
(
"error swarm dialing to peer"
,
err
)
}
...
...
This diff is collapsed.
Click to expand it.
p2p/net/swarm/swarm.go
View file @
52855747
...
...
@@ -11,6 +11,7 @@ import (
"time"
peer
"github.com/ipfs/go-libp2p-peer"
pstore
"github.com/ipfs/go-libp2p-peerstore"
transport
"github.com/ipfs/go-libp2p-transport"
metrics
"github.com/ipfs/go-libp2p/p2p/metrics"
mconn
"github.com/ipfs/go-libp2p/p2p/metrics/conn"
...
...
@@ -67,7 +68,7 @@ func init() {
type
Swarm
struct
{
swarm
*
ps
.
Swarm
local
peer
.
ID
peers
p
eer
.
Peerstore
peers
p
store
.
Peerstore
connh
ConnHandler
dsync
dialsync
...
...
@@ -94,7 +95,7 @@ type Swarm struct {
// NewSwarm constructs a Swarm, with a Chan.
func
NewSwarm
(
ctx
context
.
Context
,
listenAddrs
[]
ma
.
Multiaddr
,
local
peer
.
ID
,
peers
p
eer
.
Peerstore
,
bwc
metrics
.
Reporter
)
(
*
Swarm
,
error
)
{
local
peer
.
ID
,
peers
p
store
.
Peerstore
,
bwc
metrics
.
Reporter
)
(
*
Swarm
,
error
)
{
listenAddrs
,
err
:=
filterAddrs
(
listenAddrs
)
if
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
p2p/net/swarm/swarm_addr_test.go
View file @
52855747
...
...
@@ -3,11 +3,11 @@ package swarm
import
(
"testing"
peer
"github.com/ipfs/go-libp2p-peer"
metrics
"github.com/ipfs/go-libp2p/p2p/metrics"
addrutil
"github.com/ipfs/go-libp2p/p2p/net/swarm/addr"
testutil
"github.com/ipfs/go-libp2p/testutil"
pstore
"github.com/ipfs/go-libp2p-peerstore"
ma
"github.com/jbenet/go-multiaddr"
context
"golang.org/x/net/context"
)
...
...
@@ -63,7 +63,7 @@ func TestFilterAddrs(t *testing.T) {
t
.
Fatal
(
err
)
}
ps
:=
p
eer
.
NewPeerstore
()
ps
:=
p
store
.
NewPeerstore
()
ctx
:=
context
.
Background
()
if
_
,
err
:=
NewNetwork
(
ctx
,
bad
,
id
,
ps
,
metrics
.
NewBandwidthCounter
());
err
==
nil
{
...
...
@@ -111,7 +111,7 @@ func TestDialBadAddrs(t *testing.T) {
test
:=
func
(
a
ma
.
Multiaddr
)
{
p
:=
testutil
.
RandPeerIDFatal
(
t
)
s
.
peers
.
AddAddr
(
p
,
a
,
p
eer
.
PermanentAddrTTL
)
s
.
peers
.
AddAddr
(
p
,
a
,
p
store
.
PermanentAddrTTL
)
if
_
,
err
:=
s
.
Dial
(
ctx
,
p
);
err
==
nil
{
t
.
Error
(
"swarm should not dial: %s"
,
m
)
}
...
...
This diff is collapsed.
Click to expand it.
p2p/net/swarm/swarm_net.go
View file @
52855747
...
...
@@ -4,6 +4,7 @@ import (
"fmt"
peer
"github.com/ipfs/go-libp2p-peer"
pstore
"github.com/ipfs/go-libp2p-peerstore"
metrics
"github.com/ipfs/go-libp2p/p2p/metrics"
inet
"github.com/ipfs/go-libp2p/p2p/net"
...
...
@@ -19,7 +20,7 @@ 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
p
eer
.
Peerstore
,
bwc
metrics
.
Reporter
)
(
*
Network
,
error
)
{
peers
p
store
.
Peerstore
,
bwc
metrics
.
Reporter
)
(
*
Network
,
error
)
{
s
,
err
:=
NewSwarm
(
ctx
,
listen
,
local
,
peers
,
bwc
)
if
err
!=
nil
{
...
...
@@ -63,7 +64,7 @@ func (n *Network) Peers() []peer.ID {
}
// Peers returns the Peerstore, which tracks known peers
func
(
n
*
Network
)
Peerstore
()
p
eer
.
Peerstore
{
func
(
n
*
Network
)
Peerstore
()
p
store
.
Peerstore
{
return
n
.
Swarm
()
.
peers
}
...
...
This diff is collapsed.
Click to expand it.
p2p/net/swarm/swarm_test.go
View file @
52855747
...
...
@@ -9,11 +9,12 @@ import (
"testing"
"time"
peer
"github.com/ipfs/go-libp2p-peer"
metrics
"github.com/ipfs/go-libp2p/p2p/metrics"
inet
"github.com/ipfs/go-libp2p/p2p/net"
testutil
"github.com/ipfs/go-libp2p/testutil"
peer
"github.com/ipfs/go-libp2p-peer"
pstore
"github.com/ipfs/go-libp2p-peerstore"
ma
"github.com/jbenet/go-multiaddr"
context
"golang.org/x/net/context"
)
...
...
@@ -52,7 +53,7 @@ func EchoStreamHandler(stream inet.Stream) {
func
makeDialOnlySwarm
(
ctx
context
.
Context
,
t
*
testing
.
T
)
*
Swarm
{
id
:=
testutil
.
RandIdentityOrFatal
(
t
)
peerstore
:=
p
eer
.
NewPeerstore
()
peerstore
:=
p
store
.
NewPeerstore
()
peerstore
.
AddPubKey
(
id
.
ID
(),
id
.
PublicKey
())
peerstore
.
AddPrivKey
(
id
.
ID
(),
id
.
PrivateKey
())
...
...
@@ -72,7 +73,7 @@ func makeSwarms(ctx context.Context, t *testing.T, num int) []*Swarm {
for
i
:=
0
;
i
<
num
;
i
++
{
localnp
:=
testutil
.
RandPeerNetParamsOrFatal
(
t
)
peerstore
:=
p
eer
.
NewPeerstore
()
peerstore
:=
p
store
.
NewPeerstore
()
peerstore
.
AddPubKey
(
localnp
.
ID
,
localnp
.
PubKey
)
peerstore
.
AddPrivKey
(
localnp
.
ID
,
localnp
.
PrivKey
)
...
...
@@ -94,7 +95,7 @@ func connectSwarms(t *testing.T, ctx context.Context, swarms []*Swarm) {
var
wg
sync
.
WaitGroup
connect
:=
func
(
s
*
Swarm
,
dst
peer
.
ID
,
addr
ma
.
Multiaddr
)
{
// TODO: make a DialAddr func.
s
.
peers
.
AddAddr
(
dst
,
addr
,
p
eer
.
PermanentAddrTTL
)
s
.
peers
.
AddAddr
(
dst
,
addr
,
p
store
.
PermanentAddrTTL
)
if
_
,
err
:=
s
.
Dial
(
ctx
,
dst
);
err
!=
nil
{
t
.
Fatal
(
"error swarm dialing to peer"
,
err
)
}
...
...
@@ -313,13 +314,13 @@ func TestAddrBlocking(t *testing.T) {
swarms
[
1
]
.
Filters
.
AddDialFilter
(
block
)
swarms
[
1
]
.
peers
.
AddAddr
(
swarms
[
0
]
.
LocalPeer
(),
swarms
[
0
]
.
ListenAddresses
()[
0
],
p
eer
.
PermanentAddrTTL
)
swarms
[
1
]
.
peers
.
AddAddr
(
swarms
[
0
]
.
LocalPeer
(),
swarms
[
0
]
.
ListenAddresses
()[
0
],
p
store
.
PermanentAddrTTL
)
_
,
err
=
swarms
[
1
]
.
Dial
(
ctx
,
swarms
[
0
]
.
LocalPeer
())
if
err
==
nil
{
t
.
Fatal
(
"dial should have failed"
)
}
swarms
[
0
]
.
peers
.
AddAddr
(
swarms
[
1
]
.
LocalPeer
(),
swarms
[
1
]
.
ListenAddresses
()[
0
],
p
eer
.
PermanentAddrTTL
)
swarms
[
0
]
.
peers
.
AddAddr
(
swarms
[
1
]
.
LocalPeer
(),
swarms
[
1
]
.
ListenAddresses
()[
0
],
p
store
.
PermanentAddrTTL
)
_
,
err
=
swarms
[
0
]
.
Dial
(
ctx
,
swarms
[
1
]
.
LocalPeer
())
if
err
==
nil
{
t
.
Fatal
(
"dial should have failed"
)
...
...
This diff is collapsed.
Click to expand it.
p2p/protocol/identify/id.go
View file @
52855747
...
...
@@ -6,7 +6,7 @@ import (
semver
"github.com/coreos/go-semver/semver"
ggio
"github.com/gogo/protobuf/io"
p
eer
"github.com/ipfs/go-libp2p-peer"
p
store
"github.com/ipfs/go-libp2p-peer
store
"
host
"github.com/ipfs/go-libp2p/p2p/host"
mstream
"github.com/ipfs/go-libp2p/p2p/metrics/stream"
inet
"github.com/ipfs/go-libp2p/p2p/net"
...
...
@@ -194,7 +194,7 @@ func (ids *IDService) consumeMessage(mes *pb.Identify, c inet.Conn) {
// update our peerstore with the addresses. here, we SET the addresses, clearing old ones.
// We are receiving from the peer itself. this is current address ground truth.
ids
.
Host
.
Peerstore
()
.
SetAddrs
(
p
,
lmaddrs
,
p
eer
.
ConnectedAddrTTL
)
ids
.
Host
.
Peerstore
()
.
SetAddrs
(
p
,
lmaddrs
,
p
store
.
ConnectedAddrTTL
)
log
.
Debugf
(
"%s received listen addrs for %s: %s"
,
c
.
LocalPeer
(),
c
.
RemotePeer
(),
lmaddrs
)
// get protocol versions
...
...
@@ -317,7 +317,7 @@ func (nn *netNotifiee) Disconnected(n inet.Network, v inet.Conn) {
ids
:=
nn
.
IDService
()
ps
:=
ids
.
Host
.
Peerstore
()
addrs
:=
ps
.
Addrs
(
v
.
RemotePeer
())
ps
.
SetAddrs
(
v
.
RemotePeer
(),
addrs
,
p
eer
.
RecentlyConnectedAddrTTL
)
ps
.
SetAddrs
(
v
.
RemotePeer
(),
addrs
,
p
store
.
RecentlyConnectedAddrTTL
)
}
func
(
nn
*
netNotifiee
)
OpenedStream
(
n
inet
.
Network
,
v
inet
.
Stream
)
{}
...
...
This diff is collapsed.
Click to expand it.
p2p/protocol/identify/obsaddr.go
View file @
52855747
...
...
@@ -4,7 +4,7 @@ import (
"sync"
"time"
p
eer
"github.com/ipfs/go-libp2p-peer"
p
store
"github.com/ipfs/go-libp2p-peer
store
"
ma
"github.com/jbenet/go-multiaddr"
)
...
...
@@ -69,7 +69,7 @@ func (oas *ObservedAddrSet) Add(addr ma.Multiaddr, observer ma.Multiaddr) {
// for zero-value.
if
oas
.
addrs
==
nil
{
oas
.
addrs
=
make
(
map
[
string
]
*
ObservedAddr
)
oas
.
ttl
=
p
eer
.
OwnObservedAddrTTL
oas
.
ttl
=
p
store
.
OwnObservedAddrTTL
}
s
:=
addr
.
String
()
...
...
@@ -114,7 +114,7 @@ func (oas *ObservedAddrSet) TTL() time.Duration {
defer
oas
.
Unlock
()
// for zero-value.
if
oas
.
addrs
==
nil
{
oas
.
ttl
=
p
eer
.
OwnObservedAddrTTL
oas
.
ttl
=
p
store
.
OwnObservedAddrTTL
}
return
oas
.
ttl
}
This diff is collapsed.
Click to expand it.
p2p/protocol/ping/ping_test.go
View file @
52855747
...
...
@@ -4,8 +4,10 @@ import (
"testing"
"time"
peer
"github.com/ipfs/go-libp2p-peer"
netutil
"github.com/ipfs/go-libp2p/p2p/test/util"
peer
"github.com/ipfs/go-libp2p-peer"
pstore
"github.com/ipfs/go-libp2p-peerstore"
context
"golang.org/x/net/context"
)
...
...
@@ -15,7 +17,7 @@ func TestPing(t *testing.T) {
h1
:=
netutil
.
GenHostSwarm
(
t
,
ctx
)
h2
:=
netutil
.
GenHostSwarm
(
t
,
ctx
)
err
:=
h1
.
Connect
(
ctx
,
p
eer
.
PeerInfo
{
err
:=
h1
.
Connect
(
ctx
,
p
store
.
PeerInfo
{
ID
:
h2
.
ID
(),
Addrs
:
h2
.
Addrs
(),
})
...
...
This diff is collapsed.
Click to expand it.
p2p/test/util/util.go
View file @
52855747
...
...
@@ -3,7 +3,7 @@ package testutil
import
(
"testing"
p
eer
"github.com/ipfs/go-libp2p-peer"
p
store
"github.com/ipfs/go-libp2p-peer
store
"
bhost
"github.com/ipfs/go-libp2p/p2p/host/basic"
metrics
"github.com/ipfs/go-libp2p/p2p/metrics"
inet
"github.com/ipfs/go-libp2p/p2p/net"
...
...
@@ -16,21 +16,21 @@ import (
func
GenSwarmNetwork
(
t
*
testing
.
T
,
ctx
context
.
Context
)
*
swarm
.
Network
{
p
:=
tu
.
RandPeerNetParamsOrFatal
(
t
)
ps
:=
p
eer
.
NewPeerstore
()
ps
:=
p
store
.
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
(),
p
eer
.
PermanentAddrTTL
)
ps
.
AddAddrs
(
p
.
ID
,
n
.
ListenAddresses
(),
p
store
.
PermanentAddrTTL
)
return
n
}
func
DivulgeAddresses
(
a
,
b
inet
.
Network
)
{
id
:=
a
.
LocalPeer
()
addrs
:=
a
.
Peerstore
()
.
Addrs
(
id
)
b
.
Peerstore
()
.
AddAddrs
(
id
,
addrs
,
p
eer
.
PermanentAddrTTL
)
b
.
Peerstore
()
.
AddAddrs
(
id
,
addrs
,
p
store
.
PermanentAddrTTL
)
}
func
GenHostSwarm
(
t
*
testing
.
T
,
ctx
context
.
Context
)
*
bhost
.
BasicHost
{
...
...
This diff is collapsed.
Click to expand it.
package.json
View file @
52855747
...
...
@@ -147,21 +147,21 @@
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"Qm
TfX8ffnQZ4twPpfC9ye7FcFeFKw4najRESmyeymsT6aa
"
,
"hash"
:
"Qm
UTWSWuaYmFdfb5UMmLxBdk9SrQUbyArrVvw6uRx2rLCU
"
,
"name"
:
"go-libp2p-loggables"
,
"version"
:
"1.0.
4
"
"version"
:
"1.0.
5
"
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"Qm
buSYB51KtX8izgab1fSyBgsyMH2hTuCfBtXm77PeXWca
"
,
"hash"
:
"Qm
UmvxT1NTXjk4v9ucPHgC5NHd7s2nHXrVvFbs68NrGuZC
"
,
"name"
:
"go-libp2p-secio"
,
"version"
:
"1.0.
4
"
"version"
:
"1.0.
6
"
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"Qm
boVACz6WES3byh3q8jdYPWL9TMz7CT89V34WPtruuRoS
"
,
"hash"
:
"Qm
Q6qQtDoFjfNoXoR74sxYWggGAFzeLxf4JCa2ATpbvvCp
"
,
"name"
:
"go-libp2p-transport"
,
"version"
:
"1.1.
3
"
"version"
:
"1.1.
4
"
},
{
"author"
:
"whyrusleeping"
,
...
...
@@ -180,6 +180,12 @@
"hash"
:
"QmWMKNLGkYJTZ4Tq3DQ8E9j86QaKvGjKgFzvLzGYXvW69Z"
,
"name"
:
"go-smux-spdystream"
,
"version"
:
"1.0.0"
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"QmZ62t46e9p7vMYqCmptwQC1RhRv5cpQ5cwoqYspedaXyq"
,
"name"
:
"go-libp2p-peerstore"
,
"version"
:
"1.0.0"
}
],
"gxVersion"
:
"0.4.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