Skip to content

Commit

Permalink
Merge pull request #39 from TRON-US/ipfs-0.5.1
Browse files Browse the repository at this point in the history
Upgrade to upstream ipfs 0.5.1
  • Loading branch information
Eric Chen authored May 13, 2020
2 parents e7cd0dd + 872ea3d commit 6ffd94c
Show file tree
Hide file tree
Showing 19 changed files with 435 additions and 162 deletions.
30 changes: 0 additions & 30 deletions .travis.yml

This file was deleted.

21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
go-btfs-config
==================

> go-btfs configuration datastructure.
Documentation lives in the go-btfs repo: [docs/config.md](https://github.com/TRON-US/go-btfs/blob/master/docs/config.md).

## Table of Contents

- [Contribute](#contribute)
- [License](#license)

## Contribute

PRs are welcome!

Small note: If editing the Readme, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.

## License

MIT © TRON-US
81 changes: 81 additions & 0 deletions 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 Duration `json:",omitempty"`
}
54 changes: 25 additions & 29 deletions bootstrap_peers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import (

peer "github.com/libp2p/go-libp2p-core/peer"
ma "github.com/multiformats/go-multiaddr"

// Needs to be imported so that users can import this package directly
// and still parse the bootstrap addresses.
_ "github.com/multiformats/go-multiaddr-dns"
)

// DefaultBootstrapAddresses are the hardcoded bootstrap addresses
Expand All @@ -19,33 +15,33 @@ import (
// NOTE: This is here -- and not inside cmd/btfs/init.go -- because of an
// import dependency issue. TODO: move this into a config/default/ package.
var DefaultBootstrapAddresses = []string{
"/ip4/18.237.54.123/tcp/4001/btfs/QmWJWGxKKaqZUW4xga2BCzT5FBtYDL8Cc5Q5jywd6xPt1g",
"/ip4/54.213.128.120/tcp/4001/btfs/QmWm3vBCRuZcJMUT9jDZysoYBb66aokmSReX26UaMk8qq5",
"/ip4/34.213.5.20/tcp/4001/btfs/QmQVQBsM7uoJy8hATjTm51uSAkx2y3iGLhSwA6LWLa7iQJ",
"/ip4/18.237.202.91/tcp/4001/btfs/QmbVFdiNkvxtc7Nni7yBWAgtHg8MuyhaZ5mDaYR2ZrhhvN",
"/ip4/13.229.45.41/tcp/4001/btfs/QmX7RZXh27AX8iv2BKLGMgPBiuUpEy8p4LFXgtXAfaZDn9",
"/ip4/54.254.227.188/tcp/4001/btfs/QmYqCq3PasrzLr3PxtLo5D6spEAJ836W9Re9Eo4zUou45U",
"/ip4/52.77.240.134/tcp/4001/btfs/QmURPwdLYesWUDB66EGXvDvwcyV44rVRqV2iGNqKN24eVu",
"/ip4/3.126.224.22/tcp/4001/btfs/QmWTTmvchTodUaVvuKZMo67xk7ZgkxJf4nBo7SZry3vGU5",
"/ip4/18.194.71.27/tcp/4001/btfs/QmYHkY5CrWcvgaDo4PfvzTQgaZtfaqRGDjwW1MrHUj8cLK",
"/ip4/54.93.47.134/tcp/4001/btfs/QmeHaHe7WvjeY37z5MYC3qYQcQcuvDwUhwTXtP3KhKLXXK",
"/ip4/18.237.54.123/tcp/4001/p2p/QmWJWGxKKaqZUW4xga2BCzT5FBtYDL8Cc5Q5jywd6xPt1g",
"/ip4/54.213.128.120/tcp/4001/p2p/QmWm3vBCRuZcJMUT9jDZysoYBb66aokmSReX26UaMk8qq5",
"/ip4/34.213.5.20/tcp/4001/p2p/QmQVQBsM7uoJy8hATjTm51uSAkx2y3iGLhSwA6LWLa7iQJ",
"/ip4/18.237.202.91/tcp/4001/p2p/QmbVFdiNkvxtc7Nni7yBWAgtHg8MuyhaZ5mDaYR2ZrhhvN",
"/ip4/13.229.45.41/tcp/4001/p2p/QmX7RZXh27AX8iv2BKLGMgPBiuUpEy8p4LFXgtXAfaZDn9",
"/ip4/54.254.227.188/tcp/4001/p2p/QmYqCq3PasrzLr3PxtLo5D6spEAJ836W9Re9Eo4zUou45U",
"/ip4/52.77.240.134/tcp/4001/p2p/QmURPwdLYesWUDB66EGXvDvwcyV44rVRqV2iGNqKN24eVu",
"/ip4/3.126.224.22/tcp/4001/p2p/QmWTTmvchTodUaVvuKZMo67xk7ZgkxJf4nBo7SZry3vGU5",
"/ip4/18.194.71.27/tcp/4001/p2p/QmYHkY5CrWcvgaDo4PfvzTQgaZtfaqRGDjwW1MrHUj8cLK",
"/ip4/54.93.47.134/tcp/4001/p2p/QmeHaHe7WvjeY37z5MYC3qYQcQcuvDwUhwTXtP3KhKLXXK",
}
var DefaultTestnetBootstrapAddresses = []string{
"/ip4/13.59.69.165/tcp/45301/btfs/16Uiu2HAmFFwNdgSoLhfgJUPEfPEVodppRxaeZBVpAvrH5s3qSkWo",
"/ip4/13.59.69.165/tcp/34237/btfs/16Uiu2HAmDigS3SDx6g9Sp6MUfdFHvDwS8Zw8E14V6bLhCAHA3jjB",
"/ip4/13.59.69.165/tcp/43097/btfs/16Uiu2HAm7HQoEbQe1fYt4LtnG6z5TqwTrrqUv5xsnt4nukskWmAi",
"/ip4/13.59.69.165/tcp/38955/btfs/16Uiu2HAm5WrYvkJwaRP7ZAroWCfjaUxKkNssqcSmEmKJ8vXVYp1o",
"/ip4/13.229.73.63/tcp/36707/btfs/16Uiu2HAmDis3wAorW46YyNmXNk963VAAHwZ1phjHXj5yduyawAUy",
"/ip4/13.229.73.63/tcp/42741/btfs/16Uiu2HAmSfqLCyqH5qQQF8zpzPMQvWiQunhWpYtSxwGw5QR2jhgU",
"/ip4/13.229.73.63/tcp/37403/btfs/16Uiu2HAmBHwyRUETsGqjYpgPRpnMC9y39tcVYH6vKxZidCBcBeFG",
"/ip4/13.229.73.63/tcp/37739/btfs/16Uiu2HAm2oKy37KvYmiv1nnRWZwUoLPZumNKFxPzhM1t8F3KxADu",
"/ip4/3.126.51.74/tcp/40155/btfs/16Uiu2HAmTMEqndByECXuxk1Rg8szxMqwS3tUFFWhAUduFzwfwmfK",
"/ip4/3.126.51.74/tcp/44569/btfs/16Uiu2HAmL4QNi68nSNbedUWp1A1cRR3z3NuJqQYmAYoj19ht6iNv",
"/ip4/3.126.51.74/tcp/39703/btfs/16Uiu2HAkzF6JMx4EL2C4cLoCLyQH8t1sgyttQxPfQtNt5FZhvpxs",
"/ip4/3.126.51.74/tcp/46713/btfs/16Uiu2HAm85HXJA7xmgNxxTVdFRuRCGstvrY8nW6KqfTtkuZrZg64",
"/ip4/18.163.235.175/tcp/36335/btfs/16Uiu2HAm8wVUsVsqksBfxy6yzHpVv5gELQnpU7Q2uhDyXFwr9bfV",
"/ip4/18.163.235.175/tcp/44029/btfs/16Uiu2HAmBvnQU5FWgEcfY1jaAK2Q9iQBy6FwQdDUtyT7mo8HU1Yu",
"/ip4/18.163.235.175/tcp/40191/btfs/16Uiu2HAkurshicwtTrqbrL3yv9xR7hogPvreUHJP3W8n9W5XMibz",
"/ip4/13.59.69.165/tcp/45301/p2p/16Uiu2HAmFFwNdgSoLhfgJUPEfPEVodppRxaeZBVpAvrH5s3qSkWo",
"/ip4/13.59.69.165/tcp/34237/p2p/16Uiu2HAmDigS3SDx6g9Sp6MUfdFHvDwS8Zw8E14V6bLhCAHA3jjB",
"/ip4/13.59.69.165/tcp/43097/p2p/16Uiu2HAm7HQoEbQe1fYt4LtnG6z5TqwTrrqUv5xsnt4nukskWmAi",
"/ip4/13.59.69.165/tcp/38955/p2p/16Uiu2HAm5WrYvkJwaRP7ZAroWCfjaUxKkNssqcSmEmKJ8vXVYp1o",
"/ip4/13.229.73.63/tcp/36707/p2p/16Uiu2HAmDis3wAorW46YyNmXNk963VAAHwZ1phjHXj5yduyawAUy",
"/ip4/13.229.73.63/tcp/42741/p2p/16Uiu2HAmSfqLCyqH5qQQF8zpzPMQvWiQunhWpYtSxwGw5QR2jhgU",
"/ip4/13.229.73.63/tcp/37403/p2p/16Uiu2HAmBHwyRUETsGqjYpgPRpnMC9y39tcVYH6vKxZidCBcBeFG",
"/ip4/13.229.73.63/tcp/37739/p2p/16Uiu2HAm2oKy37KvYmiv1nnRWZwUoLPZumNKFxPzhM1t8F3KxADu",
"/ip4/3.126.51.74/tcp/40155/p2p/16Uiu2HAmTMEqndByECXuxk1Rg8szxMqwS3tUFFWhAUduFzwfwmfK",
"/ip4/3.126.51.74/tcp/44569/p2p/16Uiu2HAmL4QNi68nSNbedUWp1A1cRR3z3NuJqQYmAYoj19ht6iNv",
"/ip4/3.126.51.74/tcp/39703/p2p/16Uiu2HAkzF6JMx4EL2C4cLoCLyQH8t1sgyttQxPfQtNt5FZhvpxs",
"/ip4/3.126.51.74/tcp/46713/p2p/16Uiu2HAm85HXJA7xmgNxxTVdFRuRCGstvrY8nW6KqfTtkuZrZg64",
"/ip4/18.163.235.175/tcp/36335/p2p/16Uiu2HAm8wVUsVsqksBfxy6yzHpVv5gELQnpU7Q2uhDyXFwr9bfV",
"/ip4/18.163.235.175/tcp/44029/p2p/16Uiu2HAmBvnQU5FWgEcfY1jaAK2Q9iQBy6FwQdDUtyT7mo8HU1Yu",
"/ip4/18.163.235.175/tcp/40191/p2p/16Uiu2HAkurshicwtTrqbrL3yv9xR7hogPvreUHJP3W8n9W5XMibz",
}

// ErrInvalidPeerAddr signals an address is not a valid peer address.
Expand Down
18 changes: 18 additions & 0 deletions bootstrap_peers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,21 @@ func TestBoostrapPeerStrings(t *testing.T) {
}
}
}

func TestTestnetBoostrapPeerStrings(t *testing.T) {
parsed, err := ParseBootstrapPeers(DefaultTestnetBootstrapAddresses)
if err != nil {
t.Fatal(err)
}

formatted := BootstrapPeerStrings(parsed)
sort.Strings(formatted)
expected := append([]string{}, DefaultTestnetBootstrapAddresses...)
sort.Strings(expected)

for i, s := range formatted {
if expected[i] != s {
t.Fatalf("expected %s, %s", expected[i], s)
}
}
}
2 changes: 2 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Config struct {
Gateway Gateway // local node's gateway server options
API API // local node's API settings
Swarm SwarmConfig
AutoNAT AutoNATConfig
Pubsub PubsubConfig

Services Services // External service domains and info
Expand All @@ -33,6 +34,7 @@ type Config struct {
Reprovider Reprovider
Experimental Experiments
UI UI
Plugins Plugins
}

const (
Expand Down
2 changes: 1 addition & 1 deletion experiments.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ type Experiments struct {
FilestoreEnabled bool
UrlstoreEnabled bool
ShardingEnabled bool
GraphsyncEnabled bool
Libp2pStreamMounting bool
P2pHttpProxy bool
QUIC bool
PreferTLS bool
StrategicProviding bool
StorageHostEnabled bool
StorageClientEnabled bool
Expand Down
68 changes: 64 additions & 4 deletions gateway.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,71 @@
package config

type GatewaySpec struct {
// Paths is explicit list of path prefixes that should be handled by
// this gateway. Example: `["/ipfs", "/ipns", "/api"]`
Paths []string

// UseSubdomains indicates whether or not this gateway uses subdomains
// for IPFS resources instead of paths. That is: http://CID.ipfs.GATEWAY/...
//
// If this flag is set, any /ipns/$id and/or /ipfs/$id paths in PathPrefixes
// will be permanently redirected to http://$id.[ipns|ipfs].$gateway/.
//
// We do not support using both paths and subdomains for a single domain
// for security reasons (Origin isolation).
UseSubdomains bool

// NoDNSLink configures this gateway to _not_ resolve DNSLink for the FQDN
// provided in `Host` HTTP header.
NoDNSLink bool
}

// Gateway contains options for the HTTP gateway server.
type Gateway struct {
HTTPHeaders map[string][]string // HTTP headers to return with the gateway

// HTTPHeaders configures the headers that should be returned by this
// gateway.
HTTPHeaders map[string][]string // HTTP headers to return with the gateway

// RootRedirect is the path to which requests to `/` on this gateway
// should be redirected.
RootRedirect string
Writable bool

// Writable enables PUT/POST request handling by this gateway. Usually,
// writing is done through the API, not the gateway.
Writable bool

// PathPrefixes is an array of acceptable url paths that a client can
// specify in X-Ipfs-Path-Prefix header.
//
// The X-Ipfs-Path-Prefix header is used to specify a base path to prepend
// to links in directory listings and for trailing-slash redirects. It is
// intended to be set by a frontend http proxy like nginx.
//
// Example: To mount blog.ipfs.io (a DNSLink site) at ipfs.io/blog
// set PathPrefixes to ["/blog"] and nginx config to translate paths
// and pass Host header (for DNSLink):
// location /blog/ {
// rewrite "^/blog(/.*)$" $1 break;
// proxy_set_header Host blog.ipfs.io;
// proxy_set_header X-Ipfs-Gateway-Prefix /blog;
// proxy_pass http://127.0.0.1:8080;
// }
PathPrefixes []string
APICommands []string
NoFetch bool

// FIXME: Not yet implemented
APICommands []string

// NoFetch configures the gateway to _not_ fetch blocks in response to
// requests.
NoFetch bool

// NoDNSLink configures the gateway to _not_ perform DNS TXT record
// lookups in response to requests with values in `Host` HTTP header.
// This flag can be overriden per FQDN in PublicGateways.
NoDNSLink bool

// PublicGateways configures behavior of known public gateways.
// Each key is a fully qualified domain name (FQDN).
PublicGateways map[string]*GatewaySpec
}
6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ module github.com/TRON-US/go-btfs-config

require (
github.com/facebookgo/atomicfile v0.0.0-20151019160806-2de1f203e7d5
github.com/ipfs/go-ipfs-util v0.0.1
github.com/libp2p/go-libp2p-core v0.0.6
github.com/libp2p/go-libp2p-core v0.5.0
github.com/mitchellh/go-homedir v1.1.0
github.com/multiformats/go-multiaddr v0.0.4
github.com/multiformats/go-multiaddr-dns v0.0.2
github.com/multiformats/go-multiaddr v0.2.1
github.com/tron-us/go-btfs-common v0.2.11
)

Expand Down
Loading

0 comments on commit 6ffd94c

Please sign in to comment.