Skip to content

Commit 83b3ec4

Browse files
authored
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
2 parents d5ad847 + 6379013 commit 83b3ec4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+2433
-55
lines changed

.circleci/main.yml

+7
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,18 @@ jobs:
120120
# make sure the examples run against the current version of go-ipfs
121121
go mod edit -replace github.com/ipfs/go-ipfs=./../../..
122122
go mod tidy
123+
124+
# use the internal config package when we test the current version of go-ipfs
125+
sed -i.bak 's;"github.com/ipfs/go-ipfs-config";"github.com/ipfs/go-ipfs/config";' ./main.go
126+
123127
go test -v ./...
124128
125129
# restore the go.mod and go.sum files to their original state
126130
mv go.mod.bak go.mod
127131
mv go.sum.bak go.sum
132+
133+
# restore the main.go to its original state
134+
mv main.go.bak main.go
128135
working_directory: ~/ipfs/go-ipfs/docs/examples/go-ipfs-as-a-library
129136

130137
- run:

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,6 @@ Listing of the main packages used in the IPFS ecosystem. There are also three sp
412412
| **Namesys** |
413413
| [`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 |
414414
| **Repo** |
415-
| [`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 |
416415
| [`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 |
417416
| [`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 |
418417
| **IPLD** |

cmd/ipfs/daemon.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ import (
1717
multierror "github.com/hashicorp/go-multierror"
1818

1919
version "github.com/ipfs/go-ipfs"
20-
config "github.com/ipfs/go-ipfs-config"
21-
cserial "github.com/ipfs/go-ipfs-config/serialize"
2220
utilmain "github.com/ipfs/go-ipfs/cmd/ipfs/util"
2321
oldcmds "github.com/ipfs/go-ipfs/commands"
22+
config "github.com/ipfs/go-ipfs/config"
23+
cserial "github.com/ipfs/go-ipfs/config/serialize"
2424
"github.com/ipfs/go-ipfs/core"
2525
commands "github.com/ipfs/go-ipfs/core/commands"
2626
"github.com/ipfs/go-ipfs/core/coreapi"

cmd/ipfs/init.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import (
1919
unixfs "github.com/ipfs/go-unixfs"
2020

2121
cmds "github.com/ipfs/go-ipfs-cmds"
22-
config "github.com/ipfs/go-ipfs-config"
2322
files "github.com/ipfs/go-ipfs-files"
23+
config "github.com/ipfs/go-ipfs/config"
2424
options "github.com/ipfs/interface-go-ipfs-core/options"
2525
)
2626

cmd/ipfs/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import (
2424
cmds "github.com/ipfs/go-ipfs-cmds"
2525
"github.com/ipfs/go-ipfs-cmds/cli"
2626
cmdhttp "github.com/ipfs/go-ipfs-cmds/http"
27-
config "github.com/ipfs/go-ipfs-config"
2827
u "github.com/ipfs/go-ipfs-util"
28+
config "github.com/ipfs/go-ipfs/config"
2929
logging "github.com/ipfs/go-log"
3030
loggables "github.com/libp2p/go-libp2p-loggables"
3131
ma "github.com/multiformats/go-multiaddr"

cmd/ipfs/pinmfs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
logging "github.com/ipfs/go-log"
1414
pinclient "github.com/ipfs/go-pinning-service-http-client"
1515

16-
config "github.com/ipfs/go-ipfs-config"
16+
config "github.com/ipfs/go-ipfs/config"
1717
"github.com/ipfs/go-ipfs/core"
1818
)
1919

cmd/ipfs/pinmfs_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"testing"
88
"time"
99

10-
config "github.com/ipfs/go-ipfs-config"
10+
config "github.com/ipfs/go-ipfs/config"
1111
ipld "github.com/ipfs/go-ipld-format"
1212
merkledag "github.com/ipfs/go-merkledag"
1313
"github.com/libp2p/go-libp2p-core/host"

cmd/ipfswatch/main.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !plan9
12
// +build !plan9
23

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

2021
fsnotify "github.com/fsnotify/fsnotify"
21-
config "github.com/ipfs/go-ipfs-config"
2222
files "github.com/ipfs/go-ipfs-files"
23+
config "github.com/ipfs/go-ipfs/config"
2324
process "github.com/jbenet/goprocess"
2425
homedir "github.com/mitchellh/go-homedir"
2526
)

commands/context.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
loader "github.com/ipfs/go-ipfs/plugin/loader"
1212

1313
cmds "github.com/ipfs/go-ipfs-cmds"
14-
config "github.com/ipfs/go-ipfs-config"
14+
config "github.com/ipfs/go-ipfs/config"
1515
logging "github.com/ipfs/go-log"
1616
coreiface "github.com/ipfs/interface-go-ipfs-core"
1717
options "github.com/ipfs/interface-go-ipfs-core/options"

config/addresses.go

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package config
2+
3+
// Addresses stores the (string) multiaddr addresses for the node.
4+
type Addresses struct {
5+
Swarm []string // addresses for the swarm to listen on
6+
Announce []string // swarm addresses to announce to the network, if len > 0 replaces auto detected addresses
7+
AppendAnnounce []string // similar to Announce but doesn't overwride auto detected addresses, they are just appended
8+
NoAnnounce []string // swarm addresses not to announce to the network
9+
API Strings // address for the local API (RPC)
10+
Gateway Strings // address to listen on for IPFS HTTP object gateway
11+
}

config/api.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package config
2+
3+
type API struct {
4+
HTTPHeaders map[string][]string // HTTP headers to return with the API.
5+
}

config/autonat.go

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package config
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
// AutoNATServiceMode configures the ipfs node's AutoNAT service.
8+
type AutoNATServiceMode int
9+
10+
const (
11+
// AutoNATServiceUnset indicates that the user has not set the
12+
// AutoNATService mode.
13+
//
14+
// When unset, nodes configured to be public DHT nodes will _also_
15+
// perform limited AutoNAT dialbacks.
16+
AutoNATServiceUnset AutoNATServiceMode = iota
17+
// AutoNATServiceEnabled indicates that the user has enabled the
18+
// AutoNATService.
19+
AutoNATServiceEnabled
20+
// AutoNATServiceDisabled indicates that the user has disabled the
21+
// AutoNATService.
22+
AutoNATServiceDisabled
23+
)
24+
25+
func (m *AutoNATServiceMode) UnmarshalText(text []byte) error {
26+
switch string(text) {
27+
case "":
28+
*m = AutoNATServiceUnset
29+
case "enabled":
30+
*m = AutoNATServiceEnabled
31+
case "disabled":
32+
*m = AutoNATServiceDisabled
33+
default:
34+
return fmt.Errorf("unknown autonat mode: %s", string(text))
35+
}
36+
return nil
37+
}
38+
39+
func (m AutoNATServiceMode) MarshalText() ([]byte, error) {
40+
switch m {
41+
case AutoNATServiceUnset:
42+
return nil, nil
43+
case AutoNATServiceEnabled:
44+
return []byte("enabled"), nil
45+
case AutoNATServiceDisabled:
46+
return []byte("disabled"), nil
47+
default:
48+
return nil, fmt.Errorf("unknown autonat mode: %d", m)
49+
}
50+
}
51+
52+
// AutoNATConfig configures the node's AutoNAT subsystem.
53+
type AutoNATConfig struct {
54+
// ServiceMode configures the node's AutoNAT service mode.
55+
ServiceMode AutoNATServiceMode `json:",omitempty"`
56+
57+
// Throttle configures AutoNAT dialback throttling.
58+
//
59+
// If unset, the conservative libp2p defaults will be unset. To help the
60+
// network, please consider setting this and increasing the limits.
61+
//
62+
// By default, the limits will be a total of 30 dialbacks, with a
63+
// per-peer max of 3 peer, resetting every minute.
64+
Throttle *AutoNATThrottleConfig `json:",omitempty"`
65+
}
66+
67+
// AutoNATThrottleConfig configures the throttle limites
68+
type AutoNATThrottleConfig struct {
69+
// GlobalLimit and PeerLimit sets the global and per-peer dialback
70+
// limits. The AutoNAT service will only perform the specified number of
71+
// dialbacks per interval.
72+
//
73+
// Setting either to 0 will disable the appropriate limit.
74+
GlobalLimit, PeerLimit int
75+
76+
// Interval specifies how frequently this node should reset the
77+
// global/peer dialback limits.
78+
//
79+
// When unset, this defaults to 1 minute.
80+
Interval OptionalDuration `json:",omitempty"`
81+
}

config/bootstrap_peers.go

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package config
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
7+
peer "github.com/libp2p/go-libp2p-core/peer"
8+
ma "github.com/multiformats/go-multiaddr"
9+
)
10+
11+
// DefaultBootstrapAddresses are the hardcoded bootstrap addresses
12+
// for IPFS. they are nodes run by the IPFS team. docs on these later.
13+
// As with all p2p networks, bootstrap is an important security concern.
14+
//
15+
// NOTE: This is here -- and not inside cmd/ipfs/init.go -- because of an
16+
// import dependency issue. TODO: move this into a config/default/ package.
17+
var DefaultBootstrapAddresses = []string{
18+
"/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN",
19+
"/dnsaddr/bootstrap.libp2p.io/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa",
20+
"/dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb",
21+
"/dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt",
22+
"/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ", // mars.i.ipfs.io
23+
"/ip4/104.131.131.82/udp/4001/quic/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ", // mars.i.ipfs.io
24+
}
25+
26+
// ErrInvalidPeerAddr signals an address is not a valid peer address.
27+
var ErrInvalidPeerAddr = errors.New("invalid peer address")
28+
29+
func (c *Config) BootstrapPeers() ([]peer.AddrInfo, error) {
30+
return ParseBootstrapPeers(c.Bootstrap)
31+
}
32+
33+
// DefaultBootstrapPeers returns the (parsed) set of default bootstrap peers.
34+
// if it fails, it returns a meaningful error for the user.
35+
// This is here (and not inside cmd/ipfs/init) because of module dependency problems.
36+
func DefaultBootstrapPeers() ([]peer.AddrInfo, error) {
37+
ps, err := ParseBootstrapPeers(DefaultBootstrapAddresses)
38+
if err != nil {
39+
return nil, fmt.Errorf(`failed to parse hardcoded bootstrap peers: %s
40+
This is a problem with the ipfs codebase. Please report it to the dev team`, err)
41+
}
42+
return ps, nil
43+
}
44+
45+
func (c *Config) SetBootstrapPeers(bps []peer.AddrInfo) {
46+
c.Bootstrap = BootstrapPeerStrings(bps)
47+
}
48+
49+
// ParseBootstrapPeer parses a bootstrap list into a list of AddrInfos.
50+
func ParseBootstrapPeers(addrs []string) ([]peer.AddrInfo, error) {
51+
maddrs := make([]ma.Multiaddr, len(addrs))
52+
for i, addr := range addrs {
53+
var err error
54+
maddrs[i], err = ma.NewMultiaddr(addr)
55+
if err != nil {
56+
return nil, err
57+
}
58+
}
59+
return peer.AddrInfosFromP2pAddrs(maddrs...)
60+
}
61+
62+
// BootstrapPeerStrings formats a list of AddrInfos as a bootstrap peer list
63+
// suitable for serialization.
64+
func BootstrapPeerStrings(bps []peer.AddrInfo) []string {
65+
bpss := make([]string, 0, len(bps))
66+
for _, pi := range bps {
67+
addrs, err := peer.AddrInfoToP2pAddrs(&pi)
68+
if err != nil {
69+
// programmer error.
70+
panic(err)
71+
}
72+
for _, addr := range addrs {
73+
bpss = append(bpss, addr.String())
74+
}
75+
}
76+
return bpss
77+
}

config/bootstrap_peers_test.go

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package config
2+
3+
import (
4+
"sort"
5+
"testing"
6+
)
7+
8+
func TestBoostrapPeerStrings(t *testing.T) {
9+
parsed, err := ParseBootstrapPeers(DefaultBootstrapAddresses)
10+
if err != nil {
11+
t.Fatal(err)
12+
}
13+
14+
formatted := BootstrapPeerStrings(parsed)
15+
sort.Strings(formatted)
16+
expected := append([]string{}, DefaultBootstrapAddresses...)
17+
sort.Strings(expected)
18+
19+
for i, s := range formatted {
20+
if expected[i] != s {
21+
t.Fatalf("expected %s, %s", expected[i], s)
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)