github.com/keltia/go-ipfs@v0.3.8-0.20150909044612-210793031c63/repo/config/bootstrap_peers.go (about)

     1  package config
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  
     7  	iaddr "github.com/ipfs/go-ipfs/util/ipfsaddr"
     8  )
     9  
    10  // DefaultBootstrapAddresses are the hardcoded bootstrap addresses
    11  // for ipfs. they are nodes run by the ipfs team. docs on these later.
    12  // As with all p2p networks, bootstrap is an important security concern.
    13  //
    14  // Note: this is here -- and not inside cmd/ipfs/init.go -- because of an
    15  // import dependency issue. TODO: move this into a config/default/ package.
    16  var DefaultBootstrapAddresses = []string{
    17  	"/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",  // mars.i.ipfs.io
    18  	"/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z",  // neptune (to be neptune.i.ipfs.io)
    19  	"/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLpPVmHKQ4XTPdz8tjDFgdeRFkpV8JgYq8JVJ69RrZm", // pluto (to be pluto.i.ipfs.io)
    20  	"/ip4/162.243.248.213/tcp/4001/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm", // uranus (to be uranus.i.ipfs.io)
    21  	"/ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu", // saturn (to be saturn.i.ipfs.io)
    22  	"/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64",   // venus (to be venus.i.ipfs.io)
    23  	"/ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd",  // earth (to be earth.i.ipfs.io)
    24  	"/ip4/178.62.61.185/tcp/4001/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3",   // mercury (to be mercury.i.ipfs.io)
    25  	"/ip4/104.236.151.122/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx", // jupiter (to be jupiter.i.ipfs.io)
    26  }
    27  
    28  // BootstrapPeer is a peer used to bootstrap the network.
    29  type BootstrapPeer iaddr.IPFSAddr
    30  
    31  // ErrInvalidPeerAddr signals an address is not a valid peer address.
    32  var ErrInvalidPeerAddr = errors.New("invalid peer address")
    33  
    34  func (c *Config) BootstrapPeers() ([]BootstrapPeer, error) {
    35  	return ParseBootstrapPeers(c.Bootstrap)
    36  }
    37  
    38  // DefaultBootstrapPeers returns the (parsed) set of default bootstrap peers.
    39  // if it fails, it returns a meaningful error for the user.
    40  // This is here (and not inside cmd/ipfs/init) because of module dependency problems.
    41  func DefaultBootstrapPeers() ([]BootstrapPeer, error) {
    42  	ps, err := ParseBootstrapPeers(DefaultBootstrapAddresses)
    43  	if err != nil {
    44  		return nil, fmt.Errorf(`failed to parse hardcoded bootstrap peers: %s
    45  This is a problem with the ipfs codebase. Please report it to the dev team.`, err)
    46  	}
    47  	return ps, nil
    48  }
    49  
    50  func (c *Config) SetBootstrapPeers(bps []BootstrapPeer) {
    51  	c.Bootstrap = BootstrapPeerStrings(bps)
    52  }
    53  
    54  func ParseBootstrapPeer(addr string) (BootstrapPeer, error) {
    55  	ia, err := iaddr.ParseString(addr)
    56  	if err != nil {
    57  		return nil, err
    58  	}
    59  	return BootstrapPeer(ia), err
    60  }
    61  
    62  func ParseBootstrapPeers(addrs []string) ([]BootstrapPeer, error) {
    63  	peers := make([]BootstrapPeer, len(addrs))
    64  	var err error
    65  	for i, addr := range addrs {
    66  		peers[i], err = ParseBootstrapPeer(addr)
    67  		if err != nil {
    68  			return nil, err
    69  		}
    70  	}
    71  	return peers, nil
    72  }
    73  
    74  func BootstrapPeerStrings(bps []BootstrapPeer) []string {
    75  	bpss := make([]string, len(bps))
    76  	for i, p := range bps {
    77  		bpss[i] = p.String()
    78  	}
    79  	return bpss
    80  }