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