Skip to content

Commit

Permalink
Merge pull request #8756 from laurentsenta/feat/add-back-ipfs-config
Browse files Browse the repository at this point in the history
Move go-ipfs-config back into go-ipfs,
close ipfs/go-ipfs-config#151
  • Loading branch information
lidel authored Mar 9, 2022
2 parents d5ad847 + 6379013 commit 83b3ec4
Show file tree
Hide file tree
Showing 83 changed files with 2,433 additions and 55 deletions.
7 changes: 7 additions & 0 deletions .circleci/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,18 @@ jobs:
# make sure the examples run against the current version of go-ipfs
go mod edit -replace github.com/ipfs/go-ipfs=./../../..
go mod tidy
# use the internal config package when we test the current version of go-ipfs
sed -i.bak 's;"github.com/ipfs/go-ipfs-config";"github.com/ipfs/go-ipfs/config";' ./main.go
go test -v ./...
# restore the go.mod and go.sum files to their original state
mv go.mod.bak go.mod
mv go.sum.bak go.sum
# restore the main.go to its original state
mv main.go.bak main.go
working_directory: ~/ipfs/go-ipfs/docs/examples/go-ipfs-as-a-library

- run:
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@ Listing of the main packages used in the IPFS ecosystem. There are also three sp
| **Namesys** |
| [`go-ipns`](//github.com/ipfs/go-ipns) | [![Travis CI](https://flat.badgen.net/travis/ipfs/go-ipns/master)](https://travis-ci.com/ipfs/go-ipns) | [![codecov](https://codecov.io/gh/ipfs/go-ipns/branch/master/graph/badge.svg?style=flat-square)](https://codecov.io/gh/ipfs/go-ipns) | IPNS datastructures and validation logic |
| **Repo** |
| [`go-ipfs-config`](//github.com/ipfs/go-ipfs-config) | [![Travis CI](https://flat.badgen.net/travis/ipfs/go-ipfs-config/master)](https://travis-ci.com/ipfs/go-ipfs-config) | [![codecov](https://codecov.io/gh/ipfs/go-ipfs-config/branch/master/graph/badge.svg?style=flat-square)](https://codecov.io/gh/ipfs/go-ipfs-config) | go-ipfs config file definitions |
| [`go-fs-lock`](//github.com/ipfs/go-fs-lock) | [![Travis CI](https://flat.badgen.net/travis/ipfs/go-fs-lock/master)](https://travis-ci.com/ipfs/go-fs-lock) | [![codecov](https://codecov.io/gh/ipfs/go-fs-lock/branch/master/graph/badge.svg?style=flat-square)](https://codecov.io/gh/ipfs/go-fs-lock) | lockfile management functions |
| [`fs-repo-migrations`](//github.com/ipfs/fs-repo-migrations) | [![Travis CI](https://flat.badgen.net/travis/ipfs/fs-repo-migrations/master)](https://travis-ci.com/ipfs/fs-repo-migrations) | [![codecov](https://codecov.io/gh/ipfs/fs-repo-migrations/branch/master/graph/badge.svg?style=flat-square)](https://codecov.io/gh/ipfs/fs-repo-migrations) | repo migrations |
| **IPLD** |
Expand Down
4 changes: 2 additions & 2 deletions cmd/ipfs/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import (
multierror "github.com/hashicorp/go-multierror"

version "github.com/ipfs/go-ipfs"
config "github.com/ipfs/go-ipfs-config"
cserial "github.com/ipfs/go-ipfs-config/serialize"
utilmain "github.com/ipfs/go-ipfs/cmd/ipfs/util"
oldcmds "github.com/ipfs/go-ipfs/commands"
config "github.com/ipfs/go-ipfs/config"
cserial "github.com/ipfs/go-ipfs/config/serialize"
"github.com/ipfs/go-ipfs/core"
commands "github.com/ipfs/go-ipfs/core/commands"
"github.com/ipfs/go-ipfs/core/coreapi"
Expand Down
2 changes: 1 addition & 1 deletion cmd/ipfs/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
unixfs "github.com/ipfs/go-unixfs"

cmds "github.com/ipfs/go-ipfs-cmds"
config "github.com/ipfs/go-ipfs-config"
files "github.com/ipfs/go-ipfs-files"
config "github.com/ipfs/go-ipfs/config"
options "github.com/ipfs/interface-go-ipfs-core/options"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/ipfs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
cmds "github.com/ipfs/go-ipfs-cmds"
"github.com/ipfs/go-ipfs-cmds/cli"
cmdhttp "github.com/ipfs/go-ipfs-cmds/http"
config "github.com/ipfs/go-ipfs-config"
u "github.com/ipfs/go-ipfs-util"
config "github.com/ipfs/go-ipfs/config"
logging "github.com/ipfs/go-log"
loggables "github.com/libp2p/go-libp2p-loggables"
ma "github.com/multiformats/go-multiaddr"
Expand Down
2 changes: 1 addition & 1 deletion cmd/ipfs/pinmfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
logging "github.com/ipfs/go-log"
pinclient "github.com/ipfs/go-pinning-service-http-client"

config "github.com/ipfs/go-ipfs-config"
config "github.com/ipfs/go-ipfs/config"
"github.com/ipfs/go-ipfs/core"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/ipfs/pinmfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"
"time"

config "github.com/ipfs/go-ipfs-config"
config "github.com/ipfs/go-ipfs/config"
ipld "github.com/ipfs/go-ipld-format"
merkledag "github.com/ipfs/go-merkledag"
"github.com/libp2p/go-libp2p-core/host"
Expand Down
3 changes: 2 additions & 1 deletion cmd/ipfswatch/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !plan9
// +build !plan9

package main
Expand All @@ -18,8 +19,8 @@ import (
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"

fsnotify "github.com/fsnotify/fsnotify"
config "github.com/ipfs/go-ipfs-config"
files "github.com/ipfs/go-ipfs-files"
config "github.com/ipfs/go-ipfs/config"
process "github.com/jbenet/goprocess"
homedir "github.com/mitchellh/go-homedir"
)
Expand Down
2 changes: 1 addition & 1 deletion commands/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
loader "github.com/ipfs/go-ipfs/plugin/loader"

cmds "github.com/ipfs/go-ipfs-cmds"
config "github.com/ipfs/go-ipfs-config"
config "github.com/ipfs/go-ipfs/config"
logging "github.com/ipfs/go-log"
coreiface "github.com/ipfs/interface-go-ipfs-core"
options "github.com/ipfs/interface-go-ipfs-core/options"
Expand Down
11 changes: 11 additions & 0 deletions config/addresses.go
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
}
5 changes: 5 additions & 0 deletions config/api.go
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.
}
81 changes: 81 additions & 0 deletions config/autonat.go
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"`
}
77 changes: 77 additions & 0 deletions config/bootstrap_peers.go
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
}
24 changes: 24 additions & 0 deletions config/bootstrap_peers_test.go
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)
}
}
}
Loading

0 comments on commit 83b3ec4

Please sign in to comment.