instead of guessing the address, just use a config value

This commit is contained in:
lanzafame 2020-04-03 14:54:07 +10:00
parent 5b6bbfe903
commit 3ba2b0e365
2 changed files with 9 additions and 10 deletions

View File

@ -16,7 +16,6 @@ import (
pubsub "github.com/libp2p/go-libp2p-pubsub" pubsub "github.com/libp2p/go-libp2p-pubsub"
record "github.com/libp2p/go-libp2p-record" record "github.com/libp2p/go-libp2p-record"
"github.com/multiformats/go-multiaddr" "github.com/multiformats/go-multiaddr"
manet "github.com/multiformats/go-multiaddr-net"
"go.uber.org/fx" "go.uber.org/fx"
"golang.org/x/xerrors" "golang.org/x/xerrors"
@ -338,10 +337,7 @@ func ConfigCommon(cfg *config.Common) Option {
return lr.SetAPIEndpoint(e) return lr.SetAPIEndpoint(e)
}), }),
Override(new(sectorstorage.URLs), func(e dtypes.APIEndpoint) (sectorstorage.URLs, error) { Override(new(sectorstorage.URLs), func(e dtypes.APIEndpoint) (sectorstorage.URLs, error) {
_, ip, err := manet.DialArgs(e) ip := cfg.API.RemoteListenAddress
if err != nil {
return nil, xerrors.Errorf("getting api endpoint dial args: %w", err)
}
var urls sectorstorage.URLs var urls sectorstorage.URLs
urls = append(urls, "http://"+ip+"/remote") // TODO: This makes assumptions, and probably bad ones too urls = append(urls, "http://"+ip+"/remote") // TODO: This makes assumptions, and probably bad ones too

View File

@ -2,8 +2,9 @@ package config
import ( import (
"encoding" "encoding"
"github.com/filecoin-project/sector-storage"
"time" "time"
sectorstorage "github.com/filecoin-project/sector-storage"
) )
// Common is common config between full node and miner // Common is common config between full node and miner
@ -29,8 +30,9 @@ type StorageMiner struct {
// API contains configs for API endpoint // API contains configs for API endpoint
type API struct { type API struct {
ListenAddress string ListenAddress string
Timeout Duration RemoteListenAddress string
Timeout Duration
} }
// Libp2p contains configs for libp2p // Libp2p contains configs for libp2p
@ -55,8 +57,9 @@ type Metrics struct {
func defCommon() Common { func defCommon() Common {
return Common{ return Common{
API: API{ API: API{
ListenAddress: "/ip4/127.0.0.1/tcp/1234/http", ListenAddress: "/ip4/127.0.0.1/tcp/1234/http",
Timeout: Duration(30 * time.Second), RemoteListenAddress: "127.0.0.1:1234",
Timeout: Duration(30 * time.Second),
}, },
Libp2p: Libp2p{ Libp2p: Libp2p{
ListenAddresses: []string{ ListenAddresses: []string{