Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions core/coreapi/test/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"testing"

"github.com/ipfs/go-filestore"
"github.com/ipfs/go-ipfs-keystore"
keystore "github.com/ipfs/go-ipfs-keystore"
"github.com/ipfs/go-ipfs/core"
"github.com/ipfs/go-ipfs/core/bootstrap"
"github.com/ipfs/go-ipfs/core/coreapi"
Expand All @@ -19,20 +19,20 @@ import (

"github.com/ipfs/go-datastore"
syncds "github.com/ipfs/go-datastore/sync"
"github.com/ipfs/go-ipfs-config"
config "github.com/ipfs/go-ipfs-config"
coreiface "github.com/ipfs/interface-go-ipfs-core"
"github.com/ipfs/interface-go-ipfs-core/tests"
"github.com/libp2p/go-libp2p-core/crypto"
peer "github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p/p2p/net/mock"
"github.com/libp2p/go-libp2p-core/peer"
mocknet "github.com/libp2p/go-libp2p/p2p/net/mock"
)

const testPeerID = "QmTFauExutTsy4XP6JbMFcw2Wa9645HJt2bTqL6qYDCKfe"

type NodeProvider struct{}

func (NodeProvider) MakeAPISwarm(ctx context.Context, fullIdentity bool, n int) ([]coreiface.CoreAPI, error) {
mn := mocknet.New(ctx)
mn := mocknet.New()

nodes := make([]*core.IpfsNode, n)
apis := make([]coreiface.CoreAPI, n)
Expand Down
6 changes: 2 additions & 4 deletions core/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ import (

// NewMockNode constructs an IpfsNode for use in tests.
func NewMockNode() (*core.IpfsNode, error) {
ctx := context.Background()

// effectively offline, only peer in its network
return core.NewNode(ctx, &core.BuildCfg{
return core.NewNode(context.Background(), &core.BuildCfg{
Online: true,
Host: MockHostOption(mocknet.New(ctx)),
Host: MockHostOption(mocknet.New()),
})
}

Expand Down
9 changes: 5 additions & 4 deletions core/node/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config) fx.Option {
}

// If `cfg.Swarm.DisableRelay` is set and `Network.RelayTransport` isn't, use the former.
enableRelayTransport := cfg.Swarm.Transports.Network.Relay.WithDefault(!cfg.Swarm.DisableRelay) //nolint
enableRelayTransport := cfg.Swarm.Transports.Network.Relay.WithDefault(!cfg.Swarm.DisableRelay) // nolint

// Warn about a deprecated option.
//nolint
// nolint
if cfg.Swarm.DisableRelay {
logger.Error("The 'Swarm.DisableRelay' config field is deprecated.")
if enableRelayTransport {
Expand All @@ -124,7 +124,7 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config) fx.Option {
logger.Error("Use the 'Swarm.Transports.Network.Relay' config field instead")
}
}
//nolint
// nolint
if cfg.Swarm.EnableAutoRelay {
logger.Error("The 'Swarm.EnableAutoRelay' config field is deprecated.")
if cfg.Swarm.RelayClient.Enabled == config.Default {
Expand All @@ -133,7 +133,7 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config) fx.Option {
logger.Error("'Swarm.EnableAutoRelay' has been overridden by 'Swarm.AutoRelay.Enabled'")
}
}
//nolint
// nolint
if cfg.Swarm.EnableRelayHop {
logger.Fatal("The `Swarm.EnableRelayHop` config field is ignored.\n" +
"Use `Swarm.RelayService` to configure the circuit v2 relay.\n" +
Expand All @@ -144,6 +144,7 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config) fx.Option {
opts := fx.Options(
BaseLibP2P,

fx.Provide(libp2p.ResourceManager()),
fx.Provide(libp2p.AddrFilters(cfg.Swarm.AddrFilters)),
fx.Provide(libp2p.AddrsFactory(cfg.Addresses.Announce, cfg.Addresses.AppendAnnounce, cfg.Addresses.NoAnnounce)),
fx.Provide(libp2p.SmuxTransport(cfg.Swarm.Transports)),
Expand Down
7 changes: 5 additions & 2 deletions core/node/libp2p/libp2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (

logging "github.com/ipfs/go-log"
"github.com/libp2p/go-libp2p"
connmgr "github.com/libp2p/go-libp2p-connmgr"
"github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/peerstore"
"github.com/libp2p/go-libp2p/p2p/net/connmgr"
"go.uber.org/fx"
)

Expand All @@ -30,7 +30,10 @@ var UserAgent = simpleOpt(libp2p.UserAgent(version.GetUserAgentVersion()))

func ConnectionManager(low, high int, grace time.Duration) func() (opts Libp2pOpts, err error) {
return func() (opts Libp2pOpts, err error) {
cm := connmgr.NewConnManager(low, high, grace)
cm, err := connmgr.NewConnManager(low, high, connmgr.WithGracePeriod(grace))
if err != nil {
return opts, err
}
opts.Opts = append(opts.Opts, libp2p.ConnectionManager(cm))
return
}
Expand Down
40 changes: 40 additions & 0 deletions core/node/libp2p/rcmgr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package libp2p

import (
"errors"
"fmt"
"os"

"github.com/libp2p/go-libp2p"
rcmgr "github.com/libp2p/go-libp2p-resource-manager"
)

func ResourceManager() func() (Libp2pOpts, error) {
return func() (opts Libp2pOpts, err error) {
var limiter *rcmgr.BasicLimiter

limitsIn, err := os.Open("./limits.json")
switch {
case err == nil:
defer limitsIn.Close()
limiter, err = rcmgr.NewDefaultLimiterFromJSON(limitsIn)
if err != nil {
return opts, fmt.Errorf("error parsing limit file: %w", err)
}
case errors.Is(err, os.ErrNotExist):
limiter = rcmgr.NewDefaultLimiter()
default:
return opts, err
}

libp2p.SetDefaultServiceLimits(limiter)

// TODO: close the resource manager when the node is shut down
rcmgr, err := rcmgr.NewResourceManager(limiter)
if err != nil {
return opts, fmt.Errorf("error creating resource manager: %w", err)
}
opts.Opts = append(opts.Opts, libp2p.ResourceManager(rcmgr))
return opts, nil
}
}
4 changes: 2 additions & 2 deletions core/node/libp2p/smux.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (

config "github.com/ipfs/go-ipfs-config"
"github.com/libp2p/go-libp2p"
smux "github.com/libp2p/go-libp2p-core/mux"
"github.com/libp2p/go-libp2p-core/network"
mplex "github.com/libp2p/go-libp2p-mplex"
yamux "github.com/libp2p/go-libp2p-yamux"
)

func yamuxTransport() smux.Multiplexer {
func yamuxTransport() network.Multiplexer {
tpt := *yamux.DefaultTransport
tpt.AcceptBacklog = 512
if os.Getenv("YAMUX_DEBUG") != "" {
Expand Down
14 changes: 10 additions & 4 deletions core/node/libp2p/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"fmt"

config "github.com/ipfs/go-ipfs-config"
libp2p "github.com/libp2p/go-libp2p"
metrics "github.com/libp2p/go-libp2p-core/metrics"
"github.com/libp2p/go-libp2p"
certbot "github.com/libp2p/go-libp2p-certbot"
"github.com/libp2p/go-libp2p-core/metrics"
libp2pquic "github.com/libp2p/go-libp2p-quic-transport"
tcp "github.com/libp2p/go-tcp-transport"
"github.com/libp2p/go-tcp-transport"
websocket "github.com/libp2p/go-ws-transport"

"go.uber.org/fx"
Expand All @@ -25,7 +26,12 @@ func Transports(tptConfig config.Transports) interface{} {
}

if tptConfig.Network.Websocket.WithDefault(true) {
opts.Opts = append(opts.Opts, libp2p.Transport(websocket.New))
certManager, err := certbot.New()
if err != nil {
return opts, err
}
opts.Opts = append(opts.Opts, libp2p.CertificateManager(certManager))
opts.Opts = append(opts.Opts, libp2p.Transport(websocket.New, websocket.WithTLSConfig(certManager.GetTLSConfig())))
}

if tptConfig.Network.QUIC.WithDefault(!privateNetworkEnabled) {
Expand Down
30 changes: 16 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/ipfs/go-datastore v0.5.1
github.com/ipfs/go-detect-race v0.0.1
github.com/ipfs/go-ds-badger v0.3.0
github.com/ipfs/go-ds-flatfs v0.5.1
github.com/ipfs/go-ds-flatfs v0.5.0
github.com/ipfs/go-ds-leveldb v0.5.0
github.com/ipfs/go-ds-measure v0.2.0
github.com/ipfs/go-fetcher v1.6.1
Expand Down Expand Up @@ -61,37 +61,39 @@ require (
github.com/ipfs/tar-utils v0.0.2
github.com/ipld/go-car v0.3.2
github.com/ipld/go-codec-dagpb v1.3.0
github.com/ipld/go-ipld-prime v0.14.2
github.com/ipld/go-ipld-prime v0.14.1
github.com/jbenet/go-random v0.0.0-20190219211222-123a90aedc0c
github.com/jbenet/go-temp-err-catcher v0.1.0
github.com/jbenet/goprocess v0.1.4
github.com/libp2p/go-doh-resolver v0.3.1
github.com/libp2p/go-libp2p v0.16.0
github.com/libp2p/go-libp2p-connmgr v0.2.4
github.com/libp2p/go-libp2p-core v0.11.0
github.com/libp2p/go-libp2p v0.18.0-rc4.0.20220221074742-9c686ae9d01c
github.com/libp2p/go-libp2p-certbot v0.0.0-20220221073041-da11cb40dd1f
github.com/libp2p/go-libp2p-connmgr v0.3.2-0.20220115145817-a7820a5879c7 // indirect
github.com/libp2p/go-libp2p-core v0.14.0
github.com/libp2p/go-libp2p-discovery v0.6.0
github.com/libp2p/go-libp2p-http v0.2.1
github.com/libp2p/go-libp2p-kad-dht v0.15.0
github.com/libp2p/go-libp2p-kbucket v0.4.7
github.com/libp2p/go-libp2p-loggables v0.1.0
github.com/libp2p/go-libp2p-mplex v0.4.1
github.com/libp2p/go-libp2p-mplex v0.5.0
github.com/libp2p/go-libp2p-noise v0.3.0
github.com/libp2p/go-libp2p-peerstore v0.4.0
github.com/libp2p/go-libp2p-peerstore v0.6.0
github.com/libp2p/go-libp2p-pubsub v0.6.0
github.com/libp2p/go-libp2p-pubsub-router v0.5.0
github.com/libp2p/go-libp2p-quic-transport v0.15.0
github.com/libp2p/go-libp2p-quic-transport v0.16.1
github.com/libp2p/go-libp2p-record v0.1.3
github.com/libp2p/go-libp2p-resource-manager v0.1.3
github.com/libp2p/go-libp2p-routing-helpers v0.2.3
github.com/libp2p/go-libp2p-swarm v0.8.0
github.com/libp2p/go-libp2p-testing v0.5.0
github.com/libp2p/go-libp2p-swarm v0.10.1
github.com/libp2p/go-libp2p-testing v0.7.0
github.com/libp2p/go-libp2p-tls v0.3.1
github.com/libp2p/go-libp2p-yamux v0.6.0
github.com/libp2p/go-libp2p-yamux v0.8.2
github.com/libp2p/go-socket-activation v0.1.0
github.com/libp2p/go-tcp-transport v0.4.0
github.com/libp2p/go-ws-transport v0.5.0
github.com/libp2p/go-tcp-transport v0.5.0
github.com/libp2p/go-ws-transport v0.6.1-0.20220221074654-eeaddb3c061d
github.com/miekg/dns v1.1.43
github.com/mitchellh/go-homedir v1.1.0
github.com/multiformats/go-multiaddr v0.4.1
github.com/multiformats/go-multiaddr v0.5.0
github.com/multiformats/go-multiaddr-dns v0.3.1
github.com/multiformats/go-multibase v0.0.3
github.com/multiformats/go-multicodec v0.3.0
Expand Down
Loading