feat: add IndexerProvider AnnounceAddress config
This commit is contained in:
@@ -182,6 +182,7 @@ func DefaultStorageMiner() *StorageMiner {
|
||||
"/ip4/0.0.0.0/tcp/0",
|
||||
"/ip6/::/tcp/0",
|
||||
},
|
||||
AnnounceAddresses: []string{},
|
||||
|
||||
MaxSimultaneousTransfers: DefaultSimultaneousTransfers,
|
||||
},
|
||||
|
||||
@@ -346,6 +346,14 @@ see https://docs.filecoin.io/mine/lotus/miner-configuration/#using-filters-for-f
|
||||
|
||||
Comment: `Binding address for the libp2p host - 0 means random port.
|
||||
Format: multiaddress; see https://multiformats.io/multiaddr/`,
|
||||
},
|
||||
{
|
||||
Name: "AnnounceAddresses",
|
||||
Type: "[]string",
|
||||
|
||||
Comment: `Addresses to explicitly announce to other peers. If not specified,
|
||||
all interface addresses are announced
|
||||
Format: multiaddress`,
|
||||
},
|
||||
{
|
||||
Name: "MaxSimultaneousTransfers",
|
||||
|
||||
@@ -156,6 +156,11 @@ type IndexerProviderConfig struct {
|
||||
// Format: multiaddress; see https://multiformats.io/multiaddr/
|
||||
ListenAddresses []string
|
||||
|
||||
// Addresses to explicitly announce to other peers. If not specified,
|
||||
// all interface addresses are announced
|
||||
// Format: multiaddress
|
||||
AnnounceAddresses []string
|
||||
|
||||
// The maximum number of simultaneous data transfers between the indexers
|
||||
// and the indexer provider
|
||||
MaxSimultaneousTransfers uint64
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
mamask "github.com/whyrusleeping/multiaddr-filter"
|
||||
)
|
||||
|
||||
func makeAddrsFactory(announce []string, noAnnounce []string) (p2pbhost.AddrsFactory, error) {
|
||||
func MakeAddrsFactory(announce []string, noAnnounce []string) (p2pbhost.AddrsFactory, error) {
|
||||
var annAddrs []ma.Multiaddr
|
||||
for _, addr := range announce {
|
||||
maddr, err := ma.NewMultiaddr(addr)
|
||||
@@ -59,7 +59,7 @@ func makeAddrsFactory(announce []string, noAnnounce []string) (p2pbhost.AddrsFac
|
||||
|
||||
func AddrsFactory(announce []string, noAnnounce []string) func() (opts Libp2pOpts, err error) {
|
||||
return func() (opts Libp2pOpts, err error) {
|
||||
addrsFactory, err := makeAddrsFactory(announce, noAnnounce)
|
||||
addrsFactory, err := MakeAddrsFactory(announce, noAnnounce)
|
||||
if err != nil {
|
||||
return opts, err
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import (
|
||||
"github.com/filecoin-project/lotus/node/config"
|
||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||
"github.com/filecoin-project/lotus/node/modules/helpers"
|
||||
"github.com/filecoin-project/lotus/node/modules/lp2p"
|
||||
"github.com/filecoin-project/lotus/node/repo"
|
||||
)
|
||||
|
||||
@@ -57,7 +58,7 @@ func IndexerProvider(cfg config.IndexerProviderConfig) func(params IdxProv) (pro
|
||||
return nil, fmt.Errorf("missing private key for node ID: %s", args.PeerID.Pretty())
|
||||
}
|
||||
|
||||
h, err := createIndexerProviderHost(args.MetricsCtx, args.Lifecycle, pkey, args.Peerstore, cfg.ListenAddresses)
|
||||
h, err := createIndexerProviderHost(args.MetricsCtx, args.Lifecycle, pkey, args.Peerstore, cfg.ListenAddresses, cfg.AnnounceAddresses)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("creating indexer provider host: %w", err)
|
||||
}
|
||||
@@ -94,13 +95,18 @@ func IndexerProvider(cfg config.IndexerProviderConfig) func(params IdxProv) (pro
|
||||
}
|
||||
}
|
||||
|
||||
func createIndexerProviderHost(mctx helpers.MetricsCtx, lc fx.Lifecycle, pkey ci.PrivKey, pstore peerstore.Peerstore, listenAddrs []string) (host.Host, error) {
|
||||
func createIndexerProviderHost(mctx helpers.MetricsCtx, lc fx.Lifecycle, pkey ci.PrivKey, pstore peerstore.Peerstore, listenAddrs []string, announceAddrs []string) (host.Host, error) {
|
||||
ctx := helpers.LifecycleCtx(mctx, lc)
|
||||
addrsFactory, err := lp2p.MakeAddrsFactory(announceAddrs, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
opts := []libp2p.Option{
|
||||
libp2p.Identity(pkey),
|
||||
libp2p.Peerstore(pstore),
|
||||
libp2p.ListenAddrStrings(listenAddrs...),
|
||||
libp2p.AddrsFactory(addrsFactory),
|
||||
libp2p.Ping(true),
|
||||
libp2p.UserAgent("lotus-indexer-provider-" + build.UserVersion()),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user