@cryptotaxi247 / kubo / commits / 9adf5bc2b

go-ipfs-config: bootstrap: use ipfsaddr for boostrap peers :warning:

:warning: 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" ] ```

Juan Batiz-Benet committed Jan 20, 2015 at 16:05 UTC 9adf5bc2bfb69820ef42fb4f824678aa84af0e35
3 files changed +40 -54
config/bootstrap_peers.go
+31 -45
@@ -1,12 +1,9 @@
1 package config
2
3 import (
4 - "strings"
5 -
6 - ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
7 - mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
8 -
4 errors "github.com/jbenet/go-ipfs/util/debugerror"
5 +
6 + iaddr "github.com/jbenet/go-ipfs/util/ipfsaddr"
7 )
8
9 // DefaultBootstrapAddresses are the hardcoded bootstrap addresses
@@ -16,21 +13,25 @@ import (
13 // Note: this is here -- and not inside cmd/ipfs/init.go -- because of an
14 // import dependency issue. TODO: move this into a config/default/ package.
15 var DefaultBootstrapAddresses = []string{
19 - "/ip4/104.131.131.82/tcp/4001/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ", // mars.i.ipfs.io
20 - "/ip4/104.236.176.52/tcp/4001/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z", // neptune (to be neptune.i.ipfs.io)
21 - "/ip4/104.236.179.241/tcp/4001/QmSoLpPVmHKQ4XTPdz8tjDFgdeRFkpV8JgYq8JVJ69RrZm", // pluto (to be pluto.i.ipfs.io)
22 - "/ip4/162.243.248.213/tcp/4001/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm", // uranus (to be uranus.i.ipfs.io)
23 - "/ip4/128.199.219.111/tcp/4001/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu", // saturn (to be saturn.i.ipfs.io)
24 - "/ip4/104.236.76.40/tcp/4001/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64", // venus (to be venus.i.ipfs.io)
25 - "/ip4/178.62.158.247/tcp/4001/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd", // earth (to be earth.i.ipfs.io)
26 - "/ip4/178.62.61.185/tcp/4001/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3", // mercury (to be mercury.i.ipfs.io)
27 - "/ip4/104.236.151.122/tcp/4001/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx", // jupiter (to be jupiter.i.ipfs.io)
16 + "/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ", // mars.i.ipfs.io
17 + "/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z", // neptune (to be neptune.i.ipfs.io)
18 + "/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLpPVmHKQ4XTPdz8tjDFgdeRFkpV8JgYq8JVJ69RrZm", // pluto (to be pluto.i.ipfs.io)
19 + "/ip4/162.243.248.213/tcp/4001/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm", // uranus (to be uranus.i.ipfs.io)
20 + "/ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu", // saturn (to be saturn.i.ipfs.io)
21 + "/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64", // venus (to be venus.i.ipfs.io)
22 + "/ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd", // earth (to be earth.i.ipfs.io)
23 + "/ip4/178.62.61.185/tcp/4001/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3", // mercury (to be mercury.i.ipfs.io)
24 + "/ip4/104.236.151.122/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx", // jupiter (to be jupiter.i.ipfs.io)
25 }
26
27 // BootstrapPeer is a peer used to bootstrap the network.
31 -type BootstrapPeer struct {
32 - Address string
33 - PeerID string // until multiaddr supports ipfs, use another field.
28 +type BootstrapPeer iaddr.IPFSAddr
29 +
30 +// ErrInvalidPeerAddr signals an address is not a valid peer address.
31 +var ErrInvalidPeerAddr = errors.New("invalid peer address")
32 +
33 +func (c *Config) BootstrapPeers() ([]BootstrapPeer, error) {
34 + return ParseBootstrapPeers(c.Bootstrap)
35 }
36
37 // 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
46 return ps, nil
47 }
48
48 -func (bp *BootstrapPeer) String() string {
49 - return bp.Address + "/" + bp.PeerID
49 +func (c *Config) SetBootstrapPeers(bps []BootstrapPeer) {
50 + c.Bootstrap = BootstrapPeerStrings(bps)
51 }
52
53 func ParseBootstrapPeer(addr string) (BootstrapPeer, error) {
53 - // to be replaced with just multiaddr parsing, once ptp is a multiaddr protocol
54 - idx := strings.LastIndex(addr, "/")
55 - if idx == -1 {
56 - return BootstrapPeer{}, errors.New("invalid address")
57 - }
58 - addrS := addr[:idx]
59 - peeridS := addr[idx+1:]
60 -
61 - // make sure addrS parses as a multiaddr.
62 - if len(addrS) > 0 {
63 - maddr, err := ma.NewMultiaddr(addrS)
64 - if err != nil {
65 - return BootstrapPeer{}, err
66 - }
67 -
68 - addrS = maddr.String()
69 - }
70 -
71 - // make sure idS parses as a peer.ID
72 - _, err := mh.FromB58String(peeridS)
54 + ia, err := iaddr.ParseString(addr)
55 if err != nil {
74 - return BootstrapPeer{}, err
56 + return nil, err
57 }
76 -
77 - return BootstrapPeer{
78 - Address: addrS,
79 - PeerID: peeridS,
80 - }, nil
58 + return BootstrapPeer(ia), err
59 }
60
61 func ParseBootstrapPeers(addrs []string) ([]BootstrapPeer, error) {
@@ -91,3 +69,11 @@ func ParseBootstrapPeers(addrs []string) ([]BootstrapPeer, error) {
69 }
70 return peers, nil
71 }
72 +
73 +func BootstrapPeerStrings(bps []BootstrapPeer) []string {
74 + bpss := make([]string, len(bps))
75 + for i, p := range bps {
76 + bpss[i] = p.String()
77 + }
78 + return bpss
79 +}
config/config.go
+8 -8
@@ -16,14 +16,14 @@ var log = u.Logger("config")
16
17 // Config is used to load IPFS config files.
18 type Config struct {
19 - Identity Identity // local node's peer identity
20 - Datastore Datastore // local node's storage
21 - Addresses Addresses // local node's addresses
22 - Mounts Mounts // local node's mount points
23 - Version Version // local node's version management
24 - Bootstrap []BootstrapPeer // local nodes's bootstrap peers
25 - Tour Tour // local node's tour position
26 - Gateway Gateway // local node's gateway server options
19 + Identity Identity // local node's peer identity
20 + Datastore Datastore // local node's storage
21 + Addresses Addresses // local node's addresses
22 + Mounts Mounts // local node's mount points
23 + Version Version // local node's version management
24 + Bootstrap []string // local nodes's bootstrap peer addresses
25 + Tour Tour // local node's tour position
26 + Gateway Gateway // local node's gateway server options
27 }
28
29 const (
config/init.go
+1 -1
@@ -38,7 +38,7 @@ func Init(out io.Writer, nBitsForKeypair int) (*Config, error) {
38 API: "/ip4/127.0.0.1/tcp/5001",
39 },
40
41 - Bootstrap: bootstrapPeers,
41 + Bootstrap: BootstrapPeerStrings(bootstrapPeers),
42 Datastore: *ds,
43 Identity: identity,
44