@@ -14,12 +14,13 @@ import (
14
14
"github.com/jbenet/goprocess"
15
15
"github.com/jbenet/goprocess/context"
16
16
"github.com/jbenet/goprocess/periodic"
17
- "github.com/libp2p/go-libp2p-host"
17
+
18
+ "github.com/libp2p/go-libp2p-core/host"
19
+ "github.com/libp2p/go-libp2p-core/network"
20
+ "github.com/libp2p/go-libp2p-core/peer"
21
+ "github.com/libp2p/go-libp2p-core/peerstore"
22
+ "github.com/libp2p/go-libp2p-core/routing"
18
23
"github.com/libp2p/go-libp2p-loggables"
19
- "github.com/libp2p/go-libp2p-net"
20
- "github.com/libp2p/go-libp2p-peer"
21
- "github.com/libp2p/go-libp2p-peerstore"
22
- "github.com/libp2p/go-libp2p-routing"
23
24
)
24
25
25
26
var log = logging .Logger ("bootstrap" )
@@ -51,7 +52,7 @@ type BootstrapConfig struct {
51
52
// BootstrapPeers is a function that returns a set of bootstrap peers
52
53
// for the bootstrap process to use. This makes it possible for clients
53
54
// to control the peers the process uses at any moment.
54
- BootstrapPeers func () []peerstore. PeerInfo
55
+ BootstrapPeers func () []peer. AddrInfo
55
56
}
56
57
57
58
// DefaultBootstrapConfig specifies default sane parameters for bootstrapping.
@@ -61,9 +62,9 @@ var DefaultBootstrapConfig = BootstrapConfig{
61
62
ConnectionTimeout : (30 * time .Second ) / 3 , // Perod / 3
62
63
}
63
64
64
- func BootstrapConfigWithPeers (pis []peerstore. PeerInfo ) BootstrapConfig {
65
+ func BootstrapConfigWithPeers (pis []peer. AddrInfo ) BootstrapConfig {
65
66
cfg := DefaultBootstrapConfig
66
- cfg .BootstrapPeers = func () []peerstore. PeerInfo {
67
+ cfg .BootstrapPeers = func () []peer. AddrInfo {
67
68
return pis
68
69
}
69
70
return cfg
@@ -73,7 +74,7 @@ func BootstrapConfigWithPeers(pis []peerstore.PeerInfo) BootstrapConfig {
73
74
// check the number of open connections and -- if there are too few -- initiate
74
75
// connections to well-known bootstrap peers. It also kicks off subsystem
75
76
// bootstrapping (i.e. routing).
76
- func Bootstrap (id peer.ID , host host.Host , rt routing.IpfsRouting , cfg BootstrapConfig ) (io.Closer , error ) {
77
+ func Bootstrap (id peer.ID , host host.Host , rt routing.Routing , cfg BootstrapConfig ) (io.Closer , error ) {
77
78
78
79
// make a signal to wait for one bootstrap round to complete.
79
80
doneWithRound := make (chan struct {})
@@ -135,9 +136,9 @@ func bootstrapRound(ctx context.Context, host host.Host, cfg BootstrapConfig) er
135
136
numToDial := cfg .MinPeerThreshold - len (connected )
136
137
137
138
// filter out bootstrap nodes we are already connected to
138
- var notConnected []peerstore. PeerInfo
139
+ var notConnected []peer. AddrInfo
139
140
for _ , p := range peers {
140
- if host .Network ().Connectedness (p .ID ) != net .Connected {
141
+ if host .Network ().Connectedness (p .ID ) != network .Connected {
141
142
notConnected = append (notConnected , p )
142
143
}
143
144
}
@@ -156,7 +157,7 @@ func bootstrapRound(ctx context.Context, host host.Host, cfg BootstrapConfig) er
156
157
return bootstrapConnect (ctx , host , randSubset )
157
158
}
158
159
159
- func bootstrapConnect (ctx context.Context , ph host.Host , peers []peerstore. PeerInfo ) error {
160
+ func bootstrapConnect (ctx context.Context , ph host.Host , peers []peer. AddrInfo ) error {
160
161
if len (peers ) < 1 {
161
162
return ErrNotEnoughBootstrapPeers
162
163
}
@@ -171,7 +172,7 @@ func bootstrapConnect(ctx context.Context, ph host.Host, peers []peerstore.PeerI
171
172
// Also, performed asynchronously for dial speed.
172
173
173
174
wg .Add (1 )
174
- go func (p peerstore. PeerInfo ) {
175
+ go func (p peer. AddrInfo ) {
175
176
defer wg .Done ()
176
177
defer log .EventBegin (ctx , "bootstrapDial" , ph .ID (), p .ID ).Done ()
177
178
log .Debugf ("%s bootstrapping to %s" , ph .ID (), p .ID )
@@ -205,12 +206,12 @@ func bootstrapConnect(ctx context.Context, ph host.Host, peers []peerstore.PeerI
205
206
return nil
206
207
}
207
208
208
- func randomSubsetOfPeers (in []peerstore. PeerInfo , max int ) []peerstore. PeerInfo {
209
+ func randomSubsetOfPeers (in []peer. AddrInfo , max int ) []peer. AddrInfo {
209
210
if max > len (in ) {
210
211
max = len (in )
211
212
}
212
213
213
- out := make ([]peerstore. PeerInfo , max )
214
+ out := make ([]peer. AddrInfo , max )
214
215
for i , val := range rand .Perm (len (in ))[:max ] {
215
216
out [i ] = in [val ]
216
217
}
@@ -219,20 +220,20 @@ func randomSubsetOfPeers(in []peerstore.PeerInfo, max int) []peerstore.PeerInfo
219
220
220
221
type Peers []config.BootstrapPeer
221
222
222
- func (bpeers Peers ) ToPeerInfos () []peerstore. PeerInfo {
223
- pinfos := make (map [peer.ID ]* peerstore. PeerInfo )
223
+ func (bpeers Peers ) ToPeerInfos () []peer. AddrInfo {
224
+ pinfos := make (map [peer.ID ]* peer. AddrInfo )
224
225
for _ , bootstrap := range bpeers {
225
226
pinfo , ok := pinfos [bootstrap .ID ()]
226
227
if ! ok {
227
- pinfo = new (peerstore. PeerInfo )
228
+ pinfo = new (peer. AddrInfo )
228
229
pinfos [bootstrap .ID ()] = pinfo
229
230
pinfo .ID = bootstrap .ID ()
230
231
}
231
232
232
233
pinfo .Addrs = append (pinfo .Addrs , bootstrap .Transport ())
233
234
}
234
235
235
- var peers []peerstore. PeerInfo
236
+ var peers []peer. AddrInfo
236
237
for _ , pinfo := range pinfos {
237
238
peers = append (peers , * pinfo )
238
239
}
0 commit comments