mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 10:27:46 +08:00
* plumb through go-datastore context changes * update go-libp2p to v0.16.0 * use LIBP2P_TCP_REUSEPORT instead of IPFS_REUSEPORT * use relay config * making deprecation notice match the go-ipfs-config key * docs(config): circuit relay v2 * docs(config): fix links and headers * feat(config): Internal.Libp2pForceReachability This switches to config that supports setting and reading Internal.Libp2pForceReachability OptionalString flag * use configuration option for static relays * chore: go-ipfs-config v0.18.0 https://github.com/ipfs/go-ipfs-config/releases/tag/v0.18.0 * feat: circuit v1 migration prompt when Swarm.EnableRelayHop is set (#8559) * exit when Swarm.EnableRelayHop is set * docs: Experimental.ShardingEnabled migration This ensures existing users of global sharding experiment get notified that the flag no longer works + that autosharding happens automatically. For people who NEED to keep the old behavior (eg. have no time to migrate today) there is a note about restoring it with `UnixFSShardingSizeThreshold`. * chore: add dag-jose code to the cid command output * add support for setting automatic unixfs sharding threshold from the config * test: have tests use low cutoff for sharding to mimic old behavior * test: change error message to match the current error * test: Add automatic sharding/unsharding tests (#8547) * test: refactored naming in the sharding sharness tests to make more sense * ci: set interop test executor to convenience image for Go1.16 + Node * ci: use interop master Co-authored-by: Marcin Rataj <lidel@lidel.org> Co-authored-by: Marten Seemann <martenseemann@gmail.com> Co-authored-by: Marcin Rataj <lidel@lidel.org> Co-authored-by: Gus Eggert <gus@gus.dev> Co-authored-by: Lucas Molas <schomatis@gmail.com>
91 lines
2.0 KiB
Go
91 lines
2.0 KiB
Go
package libp2p
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/libp2p/go-libp2p"
|
|
"github.com/libp2p/go-libp2p-core/host"
|
|
"github.com/libp2p/go-libp2p-core/peer"
|
|
"github.com/libp2p/go-libp2p-core/peerstore"
|
|
"github.com/libp2p/go-libp2p-core/routing"
|
|
record "github.com/libp2p/go-libp2p-record"
|
|
routedhost "github.com/libp2p/go-libp2p/p2p/host/routed"
|
|
|
|
"github.com/ipfs/go-ipfs/core/node/helpers"
|
|
"github.com/ipfs/go-ipfs/repo"
|
|
|
|
"go.uber.org/fx"
|
|
)
|
|
|
|
type P2PHostIn struct {
|
|
fx.In
|
|
|
|
Repo repo.Repo
|
|
Validator record.Validator
|
|
HostOption HostOption
|
|
RoutingOption RoutingOption
|
|
ID peer.ID
|
|
Peerstore peerstore.Peerstore
|
|
|
|
Opts [][]libp2p.Option `group:"libp2p"`
|
|
}
|
|
|
|
type P2PHostOut struct {
|
|
fx.Out
|
|
|
|
Host host.Host
|
|
Routing routing.Routing `name:"initialrouting"`
|
|
}
|
|
|
|
func Host(mctx helpers.MetricsCtx, lc fx.Lifecycle, params P2PHostIn) (out P2PHostOut, err error) {
|
|
opts := []libp2p.Option{libp2p.NoListenAddrs}
|
|
for _, o := range params.Opts {
|
|
opts = append(opts, o...)
|
|
}
|
|
|
|
ctx := helpers.LifecycleCtx(mctx, lc)
|
|
cfg, err := params.Repo.Config()
|
|
if err != nil {
|
|
return out, err
|
|
}
|
|
bootstrappers, err := cfg.BootstrapPeers()
|
|
if err != nil {
|
|
return out, err
|
|
}
|
|
|
|
opts = append(opts, libp2p.Routing(func(h host.Host) (routing.PeerRouting, error) {
|
|
r, err := params.RoutingOption(
|
|
ctx, h,
|
|
params.Repo.Datastore(),
|
|
params.Validator,
|
|
bootstrappers...,
|
|
)
|
|
out.Routing = r
|
|
return r, err
|
|
}))
|
|
|
|
out.Host, err = params.HostOption(params.ID, params.Peerstore, opts...)
|
|
if err != nil {
|
|
return P2PHostOut{}, err
|
|
}
|
|
|
|
// this code is necessary just for tests: mock network constructions
|
|
// ignore the libp2p constructor options that actually construct the routing!
|
|
if out.Routing == nil {
|
|
r, err := params.RoutingOption(ctx, out.Host, params.Repo.Datastore(), params.Validator, bootstrappers...)
|
|
if err != nil {
|
|
return P2PHostOut{}, err
|
|
}
|
|
out.Routing = r
|
|
out.Host = routedhost.Wrap(out.Host, out.Routing)
|
|
}
|
|
|
|
lc.Append(fx.Hook{
|
|
OnStop: func(ctx context.Context) error {
|
|
return out.Host.Close()
|
|
},
|
|
})
|
|
|
|
return out, err
|
|
}
|