MCPcopy
hub / github.com/ipfs/kubo / Bootstrap

Method Bootstrap

core/core.go:193–244  ·  view source on GitHub ↗

Bootstrap will set and call the IpfsNodes bootstrap function.

(cfg bootstrap.BootstrapConfig)

Source from the content-addressed store, hash-verified

191
192// Bootstrap will set and call the IpfsNodes bootstrap function.
193func (n *IpfsNode) Bootstrap(cfg bootstrap.BootstrapConfig) error {
194 // TODO what should return value be when in offlineMode?
195 if n.Routing == nil {
196 return nil
197 }
198
199 if n.Bootstrapper != nil {
200 n.Bootstrapper.Close() // stop previous bootstrap process.
201 }
202
203 // if the caller did not specify a bootstrap peer function, get the
204 // freshest bootstrap peers from config. this responds to live changes.
205 if cfg.BootstrapPeers == nil {
206 cfg.BootstrapPeers = func() []peer.AddrInfo {
207 ps, err := n.loadBootstrapPeers()
208 if err != nil {
209 log.Warn("failed to parse bootstrap peers from config")
210 return nil
211 }
212 return ps
213 }
214 }
215 if load, _ := cfg.BackupPeers(); load == nil {
216 save := func(ctx context.Context, peerList []peer.AddrInfo) {
217 err := n.saveTempBootstrapPeers(ctx, peerList)
218 if err != nil {
219 log.Warnf("saveTempBootstrapPeers failed: %s", err)
220 return
221 }
222 }
223 load = func(ctx context.Context) []peer.AddrInfo {
224 peerList, err := n.loadTempBootstrapPeers(ctx)
225 if err != nil {
226 log.Warnf("loadTempBootstrapPeers failed: %s", err)
227 return nil
228 }
229 return peerList
230 }
231 cfg.SetBackupPeers(load, save)
232 }
233
234 repoConf, err := n.Repo.Config()
235 if err != nil {
236 return err
237 }
238 if repoConf.Internal.BackupBootstrapInterval != nil {
239 cfg.BackupBootstrapInterval = repoConf.Internal.BackupBootstrapInterval.WithDefault(time.Hour)
240 }
241
242 n.Bootstrapper, err = bootstrap.Bootstrap(n.Identity, n.PeerHost, n.Routing, cfg)
243 return err
244}
245
246var TempBootstrapPeersKey = datastore.NewKey("/local/temp_bootstrap_peers")
247

Callers 5

NewNodeFunction · 0.95
MakeAPISwarmMethod · 0.45
RunThreeLeggedCatFunction · 0.45
DirectAddCatFunction · 0.45
benchCatFunction · 0.45

Calls 6

loadBootstrapPeersMethod · 0.95
CloseMethod · 0.65
ConfigMethod · 0.65
WithDefaultMethod · 0.45

Tested by 4

MakeAPISwarmMethod · 0.36
RunThreeLeggedCatFunction · 0.36
DirectAddCatFunction · 0.36
benchCatFunction · 0.36