Skip to content

Commit

Permalink
feat: upgrade libp2p to 0.23.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Shawn-Huang-Tron committed Feb 22, 2023
1 parent 886d5df commit 4ceb318
Show file tree
Hide file tree
Showing 18 changed files with 1,023 additions and 133 deletions.
2 changes: 1 addition & 1 deletion autonat.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,5 @@ type AutoNATThrottleConfig struct {
// global/peer dialback limits.
//
// When unset, this defaults to 1 minute.
Interval Duration `json:",omitempty"`
Interval OptionalDuration `json:",omitempty"`
}
2 changes: 1 addition & 1 deletion bootstrap_peers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"fmt"

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

Expand Down
6 changes: 4 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ type Config struct {
AutoNAT AutoNATConfig
Pubsub PubsubConfig
Peering Peering

Services Services // External service domains and info
DNS DNS
Services Services // External service domains and info

Provider Provider
Reprovider Reprovider
Experimental Experiments
UI UI
Plugins Plugins

Internal Internal // experimental/unstable options
}

const (
Expand Down
17 changes: 17 additions & 0 deletions dns.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package config

// DNS specifies DNS resolution rules using custom resolvers
type DNS struct {
// Resolvers is a map of FQDNs to URLs for custom DNS resolution.
// URLs starting with `https://` indicate DoH endpoints.
// Support for other resolver types can be added in the future.
// https://en.wikipedia.org/wiki/Fully_qualified_domain_name
// https://en.wikipedia.org/wiki/DNS_over_HTTPS
//
// Example:
// - Custom resolver for ENS: `eth.` → `https://dns.eth.limo/dns-query`
// - Override the default OS resolver: `.` → `https://doh.applied-privacy.net/query`
Resolvers map[string]string
// MaxCacheTTL is the maximum duration DNS entries are valid in the cache.
MaxCacheTTL *OptionalDuration `json:",omitempty"`
}
1 change: 1 addition & 0 deletions experiments.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ type Experiments struct {
HostChallengeEnabled bool
ReportOnline bool
ReportStatusContract bool
AcceleratedDHTClient bool
}
42 changes: 39 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,46 @@ module github.com/TRON-US/go-btfs-config

require (
github.com/facebookgo/atomicfile v0.0.0-20151019160806-2de1f203e7d5
github.com/libp2p/go-libp2p-core v0.5.6
github.com/libp2p/go-libp2p v0.23.4
github.com/mitchellh/go-homedir v1.1.0
github.com/multiformats/go-multiaddr v0.2.2
github.com/multiformats/go-multiaddr v0.7.0
github.com/tron-us/go-btfs-common v0.2.11
)

go 1.14
require (
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/ipfs/go-cid v0.3.2 // indirect
github.com/ipfs/go-log/v2 v2.5.1 // indirect
github.com/klauspost/cpuid/v2 v2.1.1 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/libp2p/go-openssl v0.1.0 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-pointer v0.0.1 // indirect
github.com/minio/sha256-simd v1.0.0 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/multiformats/go-base32 v0.1.0 // indirect
github.com/multiformats/go-base36 v0.1.0 // indirect
github.com/multiformats/go-multibase v0.1.1 // indirect
github.com/multiformats/go-multicodec v0.6.0 // indirect
github.com/multiformats/go-multihash v0.2.1 // indirect
github.com/multiformats/go-varint v0.0.6 // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/tron-us/protobuf v1.3.4 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.23.0 // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
golang.org/x/net v0.0.0-20220920183852-bf014ff85ad5 // indirect
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 // indirect
google.golang.org/grpc v1.25.1 // indirect
google.golang.org/protobuf v1.28.1 // indirect
lukechampine.com/blake3 v1.1.7 // indirect
)

go 1.18
161 changes: 118 additions & 43 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package config
import (
"encoding/base64"

ic "github.com/libp2p/go-libp2p-core/crypto"
ic "github.com/libp2p/go-libp2p/core/crypto"
)

const IdentityTag = "Identity"
Expand Down
29 changes: 19 additions & 10 deletions init.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

hubpb "github.com/tron-us/go-btfs-common/protos/hub"

ci "github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/peer"
ci "github.com/libp2p/go-libp2p/core/crypto"
"github.com/libp2p/go-libp2p/core/peer"
)

func Init(out io.Writer, nBitsForKeypair int, keyType string, importKey string, mnemonic string, rmOnUnpin bool) (*Config, error) {
Expand Down Expand Up @@ -47,7 +47,7 @@ func Init(out io.Writer, nBitsForKeypair int, keyType string, importKey string,
},

Routing: Routing{
Type: "dht",
Type: NewOptionalString("dht"),
},

// setup the node mount points.
Expand All @@ -74,16 +74,16 @@ func Init(out io.Writer, nBitsForKeypair int, keyType string, importKey string,
},
Services: DefaultServicesConfig(),
Reprovider: Reprovider{
Interval: "12h",
Strategy: "all",
Interval: NewOptionalDuration(time.Hour * 12),
Strategy: NewOptionalString("all"),
},
Swarm: SwarmConfig{
SwarmKey: DefaultSwarmKey,
ConnMgr: ConnMgr{
LowWater: DefaultConnMgrLowWater,
HighWater: DefaultConnMgrHighWater,
GracePeriod: DefaultConnMgrGracePeriod.String(),
Type: "basic",
LowWater: &OptionalInteger{value: GetAddrOfConst(DefaultConnMgrLowWater)},
HighWater: &OptionalInteger{value: GetAddrOfConst(DefaultConnMgrHighWater)},
GracePeriod: NewOptionalDuration(DefaultConnMgrGracePeriod),
Type: NewOptionalString("basic"),
},
EnableAutoRelay: DefaultEnableAutoRelay,
},
Expand Down Expand Up @@ -125,6 +125,10 @@ const DefaultConnMgrLowWater = 600
// grace period
const DefaultConnMgrGracePeriod = time.Second * 20

// DefaultConnMgrType is the default value for the connection managers
// type.
const DefaultConnMgrType = "basic"

// DefaultSwarmKey is the default swarm key for mainnet BTFS
const DefaultSwarmKey = `/key/swarm/psk/1.0.0/
/base16/
Expand Down Expand Up @@ -311,7 +315,7 @@ func IdentityConfig(out io.Writer, nbits int, keyType string, importKey string,

// currently storing key unencrypted. in the future we need to encrypt it.
// TODO(security)
skbytes, err := sk.Bytes()
skbytes, err := ci.MarshalPrivateKey(sk)
if err != nil {
return ident, err
}
Expand All @@ -326,3 +330,8 @@ func IdentityConfig(out io.Writer, nbits int, keyType string, importKey string,
fmt.Fprintf(out, "peer identity: %s\n", ident.PeerID)
return ident, nil
}

func GetAddrOfConst(i int) *int64 {
var r = int64(i)
return &r
}
16 changes: 16 additions & 0 deletions internal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package config

type Internal struct {
// All marked as omitempty since we are expecting to make changes to all subcomponents of Internal
Bitswap *InternalBitswap `json:",omitempty"`
UnixFSShardingSizeThreshold *OptionalString `json:",omitempty"`
Libp2pForceReachability *OptionalString `json:",omitempty"`
}

type InternalBitswap struct {
TaskWorkerCount OptionalInteger
EngineBlockstoreWorkerCount OptionalInteger
EngineTaskWorkerCount OptionalInteger
MaxOutstandingBytesPerPeer OptionalInteger
ProviderSearchDelay OptionalDuration
}
2 changes: 1 addition & 1 deletion migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"reflect"
"strings"

"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p/core/peer"
)

func migrate_1_Services(cfg *Config) bool {
Expand Down
2 changes: 1 addition & 1 deletion peering.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package config

import "github.com/libp2p/go-libp2p-core/peer"
import "github.com/libp2p/go-libp2p/core/peer"

// Peering configures the peering service.
type Peering struct {
Expand Down
16 changes: 10 additions & 6 deletions profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,17 @@ functionality - performance of content discovery and data
fetching may be degraded.
`,
Transform: func(c *Config) error {
c.Routing.Type = "dhtclient"
c.Routing.Type = NewOptionalString("dhtclient") // TODO: https://github.com/ipfs/kubo/issues/9480
c.AutoNAT.ServiceMode = AutoNATServiceDisabled
c.Reprovider.Interval = "0"

c.Swarm.ConnMgr.LowWater = 20
c.Swarm.ConnMgr.HighWater = 40
c.Swarm.ConnMgr.GracePeriod = time.Minute.String()
c.Reprovider.Interval = NewOptionalDuration(0)

lowWater := int64(20)
highWater := int64(40)
gracePeriod := time.Minute
c.Swarm.ConnMgr.Type = NewOptionalString("basic")
c.Swarm.ConnMgr.LowWater = &OptionalInteger{value: &lowWater}
c.Swarm.ConnMgr.HighWater = &OptionalInteger{value: &highWater}
c.Swarm.ConnMgr.GracePeriod = &OptionalDuration{&gracePeriod}
return nil
},
},
Expand Down
9 changes: 7 additions & 2 deletions reprovider.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package config

import "time"

const DefaultReproviderInterval = time.Hour * 22 // https://github.com/ipfs/kubo/pull/9326
const DefaultReproviderStrategy = "all"

type Reprovider struct {
Interval string // Time period to reprovide locally stored objects to the network
Strategy string // Which keys to announce
Interval *OptionalDuration `json:",omitempty"` // Time period to reprovide locally stored objects to the network
Strategy *OptionalString `json:",omitempty"` // Which keys to announce
}
Loading

0 comments on commit 4ceb318

Please sign in to comment.