mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-25 12:27:43 +08:00
bootstrap: use ipfsaddr for boostrap peers ⚠️
⚠️ this commit makes your current configs unusable, as the
default bootstrap peers. You may need to edit your config.
Go from:
```js
Bootstrap: [
{
"Address": "/ip4/104.131.131.82/tcp/4001",
"PeerID": "QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ"
}
]
```
To:
```js
Bootstrap: [
"/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ"
]
```
This commit is contained in:
parent
2e6be0b199
commit
29bf59dded
@ -220,32 +220,25 @@ func bootstrapConnect(ctx context.Context,
|
||||
return nil
|
||||
}
|
||||
|
||||
func toPeerInfos(bpeers []config.BootstrapPeer) ([]peer.PeerInfo, error) {
|
||||
func toPeerInfos(bpeers []config.BootstrapPeer) []peer.PeerInfo {
|
||||
var peers []peer.PeerInfo
|
||||
for _, bootstrap := range bpeers {
|
||||
p, err := toPeerInfo(bootstrap)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
peers = append(peers, p)
|
||||
peers = append(peers, toPeerInfo(bootstrap))
|
||||
}
|
||||
return peers, nil
|
||||
return peers
|
||||
}
|
||||
|
||||
func toPeerInfo(bootstrap config.BootstrapPeer) (p peer.PeerInfo, err error) {
|
||||
id, err := peer.IDB58Decode(bootstrap.PeerID)
|
||||
if err != nil {
|
||||
return
|
||||
func toPeerInfo(bp config.BootstrapPeer) peer.PeerInfo {
|
||||
// for now, we drop the "ipfs addr" part of the multiaddr. the rest
|
||||
// of the codebase currently uses addresses without the peerid part.
|
||||
m := bp.Multiaddr()
|
||||
s := ma.Split(m)
|
||||
m = ma.Join(s[:len(s)-1]...)
|
||||
|
||||
return peer.PeerInfo{
|
||||
ID: bp.ID(),
|
||||
Addrs: []ma.Multiaddr{m},
|
||||
}
|
||||
maddr, err := ma.NewMultiaddr(bootstrap.Address)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
p = peer.PeerInfo{
|
||||
ID: id,
|
||||
Addrs: []ma.Multiaddr{maddr},
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func randomSubsetOfPeers(in []peer.PeerInfo, max int) []peer.PeerInfo {
|
||||
|
||||
@ -3,6 +3,7 @@ package commands
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"sort"
|
||||
|
||||
cmds "github.com/jbenet/go-ipfs/commands"
|
||||
repo "github.com/jbenet/go-ipfs/repo"
|
||||
@ -197,8 +198,13 @@ var bootstrapListCmd = &cmds.Command{
|
||||
return
|
||||
}
|
||||
|
||||
peers := cfg.Bootstrap
|
||||
peers, err := cfg.BootstrapPeers()
|
||||
if err != nil {
|
||||
res.SetError(err, cmds.ErrNormal)
|
||||
return
|
||||
}
|
||||
res.SetOutput(&BootstrapOutput{peers})
|
||||
return
|
||||
},
|
||||
Type: BootstrapOutput{},
|
||||
Marshalers: cmds.MarshalerMap{
|
||||
@ -219,9 +225,10 @@ func bootstrapMarshaler(res cmds.Response) (io.Reader, error) {
|
||||
|
||||
func bootstrapWritePeers(w io.Writer, prefix string, peers []config.BootstrapPeer) error {
|
||||
|
||||
for _, peer := range peers {
|
||||
s := prefix + peer.Address + "/" + peer.PeerID + "\n"
|
||||
_, err := w.Write([]byte(s))
|
||||
pstrs := config.BootstrapPeerStrings(peers)
|
||||
sort.Stable(sort.StringSlice(pstrs))
|
||||
for _, peer := range pstrs {
|
||||
_, err := w.Write([]byte(peer + "\n"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -235,14 +242,14 @@ func bootstrapAdd(r repo.Repo, cfg *config.Config, peers []config.BootstrapPeer)
|
||||
for _, peer := range peers {
|
||||
duplicate := false
|
||||
for _, peer2 := range cfg.Bootstrap {
|
||||
if peer.Address == peer2.Address && peer.PeerID == peer2.PeerID {
|
||||
if peer.Equal(peer2) {
|
||||
duplicate = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !duplicate {
|
||||
cfg.Bootstrap = append(cfg.Bootstrap, peer)
|
||||
cfg.Bootstrap = append(cfg.Bootstrap, peer.String())
|
||||
added = append(added, peer)
|
||||
}
|
||||
}
|
||||
@ -258,10 +265,15 @@ func bootstrapRemove(r repo.Repo, cfg *config.Config, toRemove []config.Bootstra
|
||||
removed := make([]config.BootstrapPeer, 0, len(toRemove))
|
||||
keep := make([]config.BootstrapPeer, 0, len(cfg.Bootstrap))
|
||||
|
||||
for _, peer := range cfg.Bootstrap {
|
||||
peers, err := cfg.BootstrapPeers()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, peer := range peers {
|
||||
found := false
|
||||
for _, peer2 := range toRemove {
|
||||
if peer.Address == peer2.Address && peer.PeerID == peer2.PeerID {
|
||||
if peer.Equal(peer2) {
|
||||
found = true
|
||||
removed = append(removed, peer)
|
||||
break
|
||||
@ -272,7 +284,7 @@ func bootstrapRemove(r repo.Repo, cfg *config.Config, toRemove []config.Bootstra
|
||||
keep = append(keep, peer)
|
||||
}
|
||||
}
|
||||
cfg.Bootstrap = keep
|
||||
cfg.SetBootstrapPeers(keep)
|
||||
|
||||
if err := r.SetConfig(cfg); err != nil {
|
||||
return nil, err
|
||||
@ -282,8 +294,10 @@ func bootstrapRemove(r repo.Repo, cfg *config.Config, toRemove []config.Bootstra
|
||||
}
|
||||
|
||||
func bootstrapRemoveAll(r repo.Repo, cfg *config.Config) ([]config.BootstrapPeer, error) {
|
||||
removed := make([]config.BootstrapPeer, len(cfg.Bootstrap))
|
||||
copy(removed, cfg.Bootstrap)
|
||||
removed, err := cfg.BootstrapPeers()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cfg.Bootstrap = nil
|
||||
if err := r.SetConfig(cfg); err != nil {
|
||||
|
||||
13
core/core.go
13
core/core.go
@ -318,10 +318,9 @@ func (n *IpfsNode) Bootstrap(cfg BootstrapConfig) error {
|
||||
// freshest bootstrap peers from config. this responds to live changes.
|
||||
if cfg.BootstrapPeers == nil {
|
||||
cfg.BootstrapPeers = func() []peer.PeerInfo {
|
||||
bpeers := n.Repo.Config().Bootstrap
|
||||
ps, err := toPeerInfos(bpeers)
|
||||
ps, err := n.loadBootstrapPeers()
|
||||
if err != nil {
|
||||
log.Warningf("failed to parse bootstrap peers from config: %s", bpeers)
|
||||
log.Warningf("failed to parse bootstrap peers from config: %s", n.Repo.Config().Bootstrap)
|
||||
return nil
|
||||
}
|
||||
return ps
|
||||
@ -370,6 +369,14 @@ func (n *IpfsNode) loadPrivateKey() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *IpfsNode) loadBootstrapPeers() ([]peer.PeerInfo, error) {
|
||||
parsed, err := n.Repo.Config().BootstrapPeers()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return toPeerInfos(parsed), nil
|
||||
}
|
||||
|
||||
// SetupOfflineRouting loads the local nodes private key and
|
||||
// uses it to instantiate a routing system in offline mode.
|
||||
// This is primarily used for offline ipns modifications.
|
||||
|
||||
@ -1,12 +1,9 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
|
||||
mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
|
||||
|
||||
errors "github.com/jbenet/go-ipfs/util/debugerror"
|
||||
|
||||
iaddr "github.com/jbenet/go-ipfs/util/ipfsaddr"
|
||||
)
|
||||
|
||||
// DefaultBootstrapAddresses are the hardcoded bootstrap addresses
|
||||
@ -16,21 +13,25 @@ import (
|
||||
// Note: this is here -- and not inside cmd/ipfs/init.go -- because of an
|
||||
// import dependency issue. TODO: move this into a config/default/ package.
|
||||
var DefaultBootstrapAddresses = []string{
|
||||
"/ip4/104.131.131.82/tcp/4001/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ", // mars.i.ipfs.io
|
||||
"/ip4/104.236.176.52/tcp/4001/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z", // neptune (to be neptune.i.ipfs.io)
|
||||
"/ip4/104.236.179.241/tcp/4001/QmSoLpPVmHKQ4XTPdz8tjDFgdeRFkpV8JgYq8JVJ69RrZm", // pluto (to be pluto.i.ipfs.io)
|
||||
"/ip4/162.243.248.213/tcp/4001/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm", // uranus (to be uranus.i.ipfs.io)
|
||||
"/ip4/128.199.219.111/tcp/4001/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu", // saturn (to be saturn.i.ipfs.io)
|
||||
"/ip4/104.236.76.40/tcp/4001/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64", // venus (to be venus.i.ipfs.io)
|
||||
"/ip4/178.62.158.247/tcp/4001/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd", // earth (to be earth.i.ipfs.io)
|
||||
"/ip4/178.62.61.185/tcp/4001/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3", // mercury (to be mercury.i.ipfs.io)
|
||||
"/ip4/104.236.151.122/tcp/4001/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx", // jupiter (to be jupiter.i.ipfs.io)
|
||||
"/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ", // mars.i.ipfs.io
|
||||
"/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z", // neptune (to be neptune.i.ipfs.io)
|
||||
"/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLpPVmHKQ4XTPdz8tjDFgdeRFkpV8JgYq8JVJ69RrZm", // pluto (to be pluto.i.ipfs.io)
|
||||
"/ip4/162.243.248.213/tcp/4001/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm", // uranus (to be uranus.i.ipfs.io)
|
||||
"/ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu", // saturn (to be saturn.i.ipfs.io)
|
||||
"/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64", // venus (to be venus.i.ipfs.io)
|
||||
"/ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd", // earth (to be earth.i.ipfs.io)
|
||||
"/ip4/178.62.61.185/tcp/4001/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3", // mercury (to be mercury.i.ipfs.io)
|
||||
"/ip4/104.236.151.122/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx", // jupiter (to be jupiter.i.ipfs.io)
|
||||
}
|
||||
|
||||
// BootstrapPeer is a peer used to bootstrap the network.
|
||||
type BootstrapPeer struct {
|
||||
Address string
|
||||
PeerID string // until multiaddr supports ipfs, use another field.
|
||||
type BootstrapPeer iaddr.IPFSAddr
|
||||
|
||||
// ErrInvalidPeerAddr signals an address is not a valid peer address.
|
||||
var ErrInvalidPeerAddr = errors.New("invalid peer address")
|
||||
|
||||
func (c *Config) BootstrapPeers() ([]BootstrapPeer, error) {
|
||||
return ParseBootstrapPeers(c.Bootstrap)
|
||||
}
|
||||
|
||||
// DefaultBootstrapPeers returns the (parsed) set of default bootstrap peers.
|
||||
@ -45,39 +46,16 @@ This is a problem with the ipfs codebase. Please report it to the dev team.`, er
|
||||
return ps, nil
|
||||
}
|
||||
|
||||
func (bp *BootstrapPeer) String() string {
|
||||
return bp.Address + "/" + bp.PeerID
|
||||
func (c *Config) SetBootstrapPeers(bps []BootstrapPeer) {
|
||||
c.Bootstrap = BootstrapPeerStrings(bps)
|
||||
}
|
||||
|
||||
func ParseBootstrapPeer(addr string) (BootstrapPeer, error) {
|
||||
// to be replaced with just multiaddr parsing, once ptp is a multiaddr protocol
|
||||
idx := strings.LastIndex(addr, "/")
|
||||
if idx == -1 {
|
||||
return BootstrapPeer{}, errors.New("invalid address")
|
||||
}
|
||||
addrS := addr[:idx]
|
||||
peeridS := addr[idx+1:]
|
||||
|
||||
// make sure addrS parses as a multiaddr.
|
||||
if len(addrS) > 0 {
|
||||
maddr, err := ma.NewMultiaddr(addrS)
|
||||
if err != nil {
|
||||
return BootstrapPeer{}, err
|
||||
}
|
||||
|
||||
addrS = maddr.String()
|
||||
}
|
||||
|
||||
// make sure idS parses as a peer.ID
|
||||
_, err := mh.FromB58String(peeridS)
|
||||
ia, err := iaddr.ParseString(addr)
|
||||
if err != nil {
|
||||
return BootstrapPeer{}, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return BootstrapPeer{
|
||||
Address: addrS,
|
||||
PeerID: peeridS,
|
||||
}, nil
|
||||
return BootstrapPeer(ia), err
|
||||
}
|
||||
|
||||
func ParseBootstrapPeers(addrs []string) ([]BootstrapPeer, error) {
|
||||
@ -91,3 +69,11 @@ func ParseBootstrapPeers(addrs []string) ([]BootstrapPeer, error) {
|
||||
}
|
||||
return peers, nil
|
||||
}
|
||||
|
||||
func BootstrapPeerStrings(bps []BootstrapPeer) []string {
|
||||
bpss := make([]string, len(bps))
|
||||
for i, p := range bps {
|
||||
bpss[i] = p.String()
|
||||
}
|
||||
return bpss
|
||||
}
|
||||
|
||||
@ -16,14 +16,14 @@ var log = u.Logger("config")
|
||||
|
||||
// Config is used to load IPFS config files.
|
||||
type Config struct {
|
||||
Identity Identity // local node's peer identity
|
||||
Datastore Datastore // local node's storage
|
||||
Addresses Addresses // local node's addresses
|
||||
Mounts Mounts // local node's mount points
|
||||
Version Version // local node's version management
|
||||
Bootstrap []BootstrapPeer // local nodes's bootstrap peers
|
||||
Tour Tour // local node's tour position
|
||||
Gateway Gateway // local node's gateway server options
|
||||
Identity Identity // local node's peer identity
|
||||
Datastore Datastore // local node's storage
|
||||
Addresses Addresses // local node's addresses
|
||||
Mounts Mounts // local node's mount points
|
||||
Version Version // local node's version management
|
||||
Bootstrap []string // local nodes's bootstrap peer addresses
|
||||
Tour Tour // local node's tour position
|
||||
Gateway Gateway // local node's gateway server options
|
||||
}
|
||||
|
||||
const (
|
||||
|
||||
@ -38,7 +38,7 @@ func Init(out io.Writer, nBitsForKeypair int) (*Config, error) {
|
||||
API: "/ip4/127.0.0.1/tcp/5001",
|
||||
},
|
||||
|
||||
Bootstrap: bootstrapPeers,
|
||||
Bootstrap: BootstrapPeerStrings(bootstrapPeers),
|
||||
Datastore: *ds,
|
||||
Identity: identity,
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
ipfs bootstrap add /ip4/$BOOTSTRAP_PORT_4011_TCP_ADDR/tcp/$BOOTSTRAP_PORT_4011_TCP_PORT/QmNXuBh8HFsWq68Fid8dMbGNQTh7eG6hV9rr1fQyfmfomE
|
||||
ipfs bootstrap add /ip4/$BOOTSTRAP_PORT_4011_TCP_ADDR/tcp/$BOOTSTRAP_PORT_4011_TCP_PORT/ipfs/QmNXuBh8HFsWq68Fid8dMbGNQTh7eG6hV9rr1fQyfmfomE
|
||||
|
||||
|
||||
echo "3nodetest> starting client daemon"
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
# must be connected to bootstrap node
|
||||
ipfs bootstrap add /ip4/$BOOTSTRAP_PORT_4011_TCP_ADDR/tcp/$BOOTSTRAP_PORT_4011_TCP_PORT/QmNXuBh8HFsWq68Fid8dMbGNQTh7eG6hV9rr1fQyfmfomE
|
||||
ipfs bootstrap add /ip4/$BOOTSTRAP_PORT_4011_TCP_ADDR/tcp/$BOOTSTRAP_PORT_4011_TCP_PORT/ipfs/QmNXuBh8HFsWq68Fid8dMbGNQTh7eG6hV9rr1fQyfmfomE
|
||||
|
||||
# wait for daemon to start/bootstrap
|
||||
# alternatively use ipfs swarm connect
|
||||
echo "3nodetest> starting server daemon"
|
||||
ipfs daemon &
|
||||
sleep 3
|
||||
# TODO instead of bootrapping: ipfs swarm connect /ip4/$BOOTSTRAP_PORT_4011_TCP_ADDR/tcp/$BOOTSTRAP_PORT_4011_TCP_PORT/QmNXuBh8HFsWq68Fid8dMbGNQTh7eG6hV9rr1fQyfmfomE
|
||||
# TODO instead of bootrapping: ipfs swarm connect /ip4/$BOOTSTRAP_PORT_4011_TCP_ADDR/tcp/$BOOTSTRAP_PORT_4011_TCP_PORT/ipfs/QmNXuBh8HFsWq68Fid8dMbGNQTh7eG6hV9rr1fQyfmfomE
|
||||
|
||||
# must mount this volume from data container
|
||||
ipfs add -q /data/filetiny > tmptiny
|
||||
|
||||
@ -15,6 +15,8 @@ var ErrInvalidAddr = errors.New("invalid ipfs address")
|
||||
type IPFSAddr interface {
|
||||
ID() peer.ID
|
||||
Multiaddr() ma.Multiaddr
|
||||
String() string
|
||||
Equal(b interface{}) bool
|
||||
}
|
||||
|
||||
type ipfsAddr struct {
|
||||
@ -30,6 +32,20 @@ func (a ipfsAddr) Multiaddr() ma.Multiaddr {
|
||||
return a.ma
|
||||
}
|
||||
|
||||
func (a ipfsAddr) String() string {
|
||||
return a.ma.String()
|
||||
}
|
||||
|
||||
func (a ipfsAddr) Equal(b interface{}) bool {
|
||||
if ib, ok := b.(IPFSAddr); ok {
|
||||
return a.Multiaddr().Equal(ib.Multiaddr())
|
||||
}
|
||||
if mb, ok := b.(ma.Multiaddr); ok {
|
||||
return a.Multiaddr().Equal(mb)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// ParseString parses a string representation of an address into an IPFSAddr
|
||||
func ParseString(str string) (a IPFSAddr, err error) {
|
||||
if str == "" {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user