feat: add IndexerProvider AnnounceAddress config

This commit is contained in:
Dirk McCormick 2021-12-13 18:15:28 +01:00
parent 6b7b9793ab
commit a51b08e386
6 changed files with 35 additions and 7 deletions

View File

@ -248,13 +248,13 @@
[IndexerProvider]
# env var: LOTUS_INDEXERPROVIDER_LINKCACHESIZE
#LinkCacheSize = 0
#LinkCacheSize = 1024
# env var: LOTUS_INDEXERPROVIDER_LINKEDCHUNKSIZE
#LinkedChunkSize = 0
#LinkedChunkSize = 100
# env var: LOTUS_INDEXERPROVIDER_PUBSUBTOPIC
#PubSubTopic = ""
#PubSubTopic = "indexer/ingest"
# env var: LOTUS_INDEXERPROVIDER_PURGELINKCACHE
#PurgeLinkCache = false
@ -266,6 +266,14 @@
# env var: LOTUS_INDEXERPROVIDER_LISTENADDRESSES
#ListenAddresses = ["/ip4/0.0.0.0/tcp/0", "/ip6/::/tcp/0"]
# Addresses to explicitly announce to other peers. If not specified,
# all interface addresses are announced
# Format: multiaddress
#
# type: []string
# env var: LOTUS_INDEXERPROVIDER_ANNOUNCEADDRESSES
#AnnounceAddresses = []
# The maximum number of simultaneous data transfers between the indexers
# and the indexer provider
#

View File

@ -182,6 +182,7 @@ func DefaultStorageMiner() *StorageMiner {
"/ip4/0.0.0.0/tcp/0",
"/ip6/::/tcp/0",
},
AnnounceAddresses: []string{},
MaxSimultaneousTransfers: DefaultSimultaneousTransfers,
},

View File

@ -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",

View File

@ -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

View File

@ -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
}

View File

@ -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()),
}