-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8756 from laurentsenta/feat/add-back-ipfs-config
Move go-ipfs-config back into go-ipfs, close ipfs/go-ipfs-config#151
- Loading branch information
Showing
83 changed files
with
2,433 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package config | ||
|
||
// Addresses stores the (string) multiaddr addresses for the node. | ||
type Addresses struct { | ||
Swarm []string // addresses for the swarm to listen on | ||
Announce []string // swarm addresses to announce to the network, if len > 0 replaces auto detected addresses | ||
AppendAnnounce []string // similar to Announce but doesn't overwride auto detected addresses, they are just appended | ||
NoAnnounce []string // swarm addresses not to announce to the network | ||
API Strings // address for the local API (RPC) | ||
Gateway Strings // address to listen on for IPFS HTTP object gateway | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package config | ||
|
||
type API struct { | ||
HTTPHeaders map[string][]string // HTTP headers to return with the API. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// AutoNATServiceMode configures the ipfs node's AutoNAT service. | ||
type AutoNATServiceMode int | ||
|
||
const ( | ||
// AutoNATServiceUnset indicates that the user has not set the | ||
// AutoNATService mode. | ||
// | ||
// When unset, nodes configured to be public DHT nodes will _also_ | ||
// perform limited AutoNAT dialbacks. | ||
AutoNATServiceUnset AutoNATServiceMode = iota | ||
// AutoNATServiceEnabled indicates that the user has enabled the | ||
// AutoNATService. | ||
AutoNATServiceEnabled | ||
// AutoNATServiceDisabled indicates that the user has disabled the | ||
// AutoNATService. | ||
AutoNATServiceDisabled | ||
) | ||
|
||
func (m *AutoNATServiceMode) UnmarshalText(text []byte) error { | ||
switch string(text) { | ||
case "": | ||
*m = AutoNATServiceUnset | ||
case "enabled": | ||
*m = AutoNATServiceEnabled | ||
case "disabled": | ||
*m = AutoNATServiceDisabled | ||
default: | ||
return fmt.Errorf("unknown autonat mode: %s", string(text)) | ||
} | ||
return nil | ||
} | ||
|
||
func (m AutoNATServiceMode) MarshalText() ([]byte, error) { | ||
switch m { | ||
case AutoNATServiceUnset: | ||
return nil, nil | ||
case AutoNATServiceEnabled: | ||
return []byte("enabled"), nil | ||
case AutoNATServiceDisabled: | ||
return []byte("disabled"), nil | ||
default: | ||
return nil, fmt.Errorf("unknown autonat mode: %d", m) | ||
} | ||
} | ||
|
||
// AutoNATConfig configures the node's AutoNAT subsystem. | ||
type AutoNATConfig struct { | ||
// ServiceMode configures the node's AutoNAT service mode. | ||
ServiceMode AutoNATServiceMode `json:",omitempty"` | ||
|
||
// Throttle configures AutoNAT dialback throttling. | ||
// | ||
// If unset, the conservative libp2p defaults will be unset. To help the | ||
// network, please consider setting this and increasing the limits. | ||
// | ||
// By default, the limits will be a total of 30 dialbacks, with a | ||
// per-peer max of 3 peer, resetting every minute. | ||
Throttle *AutoNATThrottleConfig `json:",omitempty"` | ||
} | ||
|
||
// AutoNATThrottleConfig configures the throttle limites | ||
type AutoNATThrottleConfig struct { | ||
// GlobalLimit and PeerLimit sets the global and per-peer dialback | ||
// limits. The AutoNAT service will only perform the specified number of | ||
// dialbacks per interval. | ||
// | ||
// Setting either to 0 will disable the appropriate limit. | ||
GlobalLimit, PeerLimit int | ||
|
||
// Interval specifies how frequently this node should reset the | ||
// global/peer dialback limits. | ||
// | ||
// When unset, this defaults to 1 minute. | ||
Interval OptionalDuration `json:",omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package config | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
peer "github.com/libp2p/go-libp2p-core/peer" | ||
ma "github.com/multiformats/go-multiaddr" | ||
) | ||
|
||
// DefaultBootstrapAddresses are the hardcoded bootstrap addresses | ||
// for IPFS. they are nodes run by the IPFS team. docs on these later. | ||
// As with all p2p networks, bootstrap is an important security concern. | ||
// | ||
// 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{ | ||
"/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN", | ||
"/dnsaddr/bootstrap.libp2p.io/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa", | ||
"/dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb", | ||
"/dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt", | ||
"/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ", // mars.i.ipfs.io | ||
"/ip4/104.131.131.82/udp/4001/quic/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ", // mars.i.ipfs.io | ||
} | ||
|
||
// ErrInvalidPeerAddr signals an address is not a valid peer address. | ||
var ErrInvalidPeerAddr = errors.New("invalid peer address") | ||
|
||
func (c *Config) BootstrapPeers() ([]peer.AddrInfo, error) { | ||
return ParseBootstrapPeers(c.Bootstrap) | ||
} | ||
|
||
// DefaultBootstrapPeers returns the (parsed) set of default bootstrap peers. | ||
// if it fails, it returns a meaningful error for the user. | ||
// This is here (and not inside cmd/ipfs/init) because of module dependency problems. | ||
func DefaultBootstrapPeers() ([]peer.AddrInfo, error) { | ||
ps, err := ParseBootstrapPeers(DefaultBootstrapAddresses) | ||
if err != nil { | ||
return nil, fmt.Errorf(`failed to parse hardcoded bootstrap peers: %s | ||
This is a problem with the ipfs codebase. Please report it to the dev team`, err) | ||
} | ||
return ps, nil | ||
} | ||
|
||
func (c *Config) SetBootstrapPeers(bps []peer.AddrInfo) { | ||
c.Bootstrap = BootstrapPeerStrings(bps) | ||
} | ||
|
||
// ParseBootstrapPeer parses a bootstrap list into a list of AddrInfos. | ||
func ParseBootstrapPeers(addrs []string) ([]peer.AddrInfo, error) { | ||
maddrs := make([]ma.Multiaddr, len(addrs)) | ||
for i, addr := range addrs { | ||
var err error | ||
maddrs[i], err = ma.NewMultiaddr(addr) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
return peer.AddrInfosFromP2pAddrs(maddrs...) | ||
} | ||
|
||
// BootstrapPeerStrings formats a list of AddrInfos as a bootstrap peer list | ||
// suitable for serialization. | ||
func BootstrapPeerStrings(bps []peer.AddrInfo) []string { | ||
bpss := make([]string, 0, len(bps)) | ||
for _, pi := range bps { | ||
addrs, err := peer.AddrInfoToP2pAddrs(&pi) | ||
if err != nil { | ||
// programmer error. | ||
panic(err) | ||
} | ||
for _, addr := range addrs { | ||
bpss = append(bpss, addr.String()) | ||
} | ||
} | ||
return bpss | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package config | ||
|
||
import ( | ||
"sort" | ||
"testing" | ||
) | ||
|
||
func TestBoostrapPeerStrings(t *testing.T) { | ||
parsed, err := ParseBootstrapPeers(DefaultBootstrapAddresses) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
formatted := BootstrapPeerStrings(parsed) | ||
sort.Strings(formatted) | ||
expected := append([]string{}, DefaultBootstrapAddresses...) | ||
sort.Strings(expected) | ||
|
||
for i, s := range formatted { | ||
if expected[i] != s { | ||
t.Fatalf("expected %s, %s", expected[i], s) | ||
} | ||
} | ||
} |
Oops, something went wrong.