Bootstrap will set and call the IpfsNodes bootstrap function.
(cfg bootstrap.BootstrapConfig)
| 191 | |
| 192 | // Bootstrap will set and call the IpfsNodes bootstrap function. |
| 193 | func (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 | |
| 246 | var TempBootstrapPeersKey = datastore.NewKey("/local/temp_bootstrap_peers") |
| 247 |