2019-07-03 16:59:49 +00:00
|
|
|
package config
|
|
|
|
|
2019-10-30 16:38:39 +00:00
|
|
|
import (
|
|
|
|
"encoding"
|
|
|
|
"time"
|
2020-04-03 04:54:07 +00:00
|
|
|
|
2020-06-18 20:15:18 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
|
|
|
|
2020-04-03 04:54:07 +00:00
|
|
|
sectorstorage "github.com/filecoin-project/sector-storage"
|
2019-10-30 16:38:39 +00:00
|
|
|
)
|
2019-07-03 16:59:49 +00:00
|
|
|
|
2019-10-30 16:38:39 +00:00
|
|
|
// Common is common config between full node and miner
|
|
|
|
type Common struct {
|
2019-07-04 12:04:39 +00:00
|
|
|
API API
|
|
|
|
Libp2p Libp2p
|
2020-05-04 15:30:54 +00:00
|
|
|
Pubsub Pubsub
|
2019-10-30 16:38:39 +00:00
|
|
|
}
|
2019-10-11 02:45:45 +00:00
|
|
|
|
2019-10-30 16:38:39 +00:00
|
|
|
// FullNode is a full node config
|
|
|
|
type FullNode struct {
|
|
|
|
Common
|
2020-04-29 23:51:55 +00:00
|
|
|
Client Client
|
2019-10-11 02:45:45 +00:00
|
|
|
Metrics Metrics
|
2019-07-03 16:59:49 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 17:59:38 +00:00
|
|
|
// // Common
|
|
|
|
|
2020-07-11 08:55:13 +00:00
|
|
|
// StorageMiner is a miner config
|
2019-10-30 16:38:39 +00:00
|
|
|
type StorageMiner struct {
|
|
|
|
Common
|
2019-11-12 17:59:38 +00:00
|
|
|
|
2020-07-06 18:39:26 +00:00
|
|
|
Dealmaking DealmakingConfig
|
|
|
|
Storage sectorstorage.SealerConfig
|
|
|
|
SealingDelay Duration
|
2020-06-11 18:29:59 +00:00
|
|
|
}
|
|
|
|
|
2020-06-11 19:15:28 +00:00
|
|
|
type DealmakingConfig struct {
|
2020-06-26 19:27:41 +00:00
|
|
|
ConsiderOnlineStorageDeals bool
|
|
|
|
ConsiderOfflineStorageDeals bool
|
|
|
|
ConsiderOnlineRetrievalDeals bool
|
|
|
|
ConsiderOfflineRetrievalDeals bool
|
|
|
|
PieceCidBlocklist []cid.Cid
|
2019-10-30 16:38:39 +00:00
|
|
|
}
|
|
|
|
|
2019-07-03 16:59:49 +00:00
|
|
|
// API contains configs for API endpoint
|
|
|
|
type API struct {
|
2020-04-03 04:54:07 +00:00
|
|
|
ListenAddress string
|
|
|
|
RemoteListenAddress string
|
|
|
|
Timeout Duration
|
2019-07-03 16:59:49 +00:00
|
|
|
}
|
|
|
|
|
2019-07-04 12:04:39 +00:00
|
|
|
// Libp2p contains configs for libp2p
|
|
|
|
type Libp2p struct {
|
2020-06-09 00:03:11 +00:00
|
|
|
ListenAddresses []string
|
|
|
|
AnnounceAddresses []string
|
|
|
|
NoAnnounceAddresses []string
|
|
|
|
BootstrapPeers []string
|
|
|
|
ProtectedPeers []string
|
2019-12-17 16:09:43 +00:00
|
|
|
|
|
|
|
ConnMgrLow uint
|
|
|
|
ConnMgrHigh uint
|
|
|
|
ConnMgrGrace Duration
|
2019-07-04 12:04:39 +00:00
|
|
|
}
|
|
|
|
|
2020-05-04 15:30:54 +00:00
|
|
|
type Pubsub struct {
|
|
|
|
Bootstrapper bool
|
|
|
|
DirectPeers []string
|
|
|
|
RemoteTracer string
|
|
|
|
}
|
|
|
|
|
2019-11-12 17:59:38 +00:00
|
|
|
// // Full Node
|
|
|
|
|
2019-10-11 02:45:45 +00:00
|
|
|
type Metrics struct {
|
2020-05-04 15:30:54 +00:00
|
|
|
Nickname string
|
|
|
|
HeadNotifs bool
|
2019-10-11 02:45:45 +00:00
|
|
|
}
|
|
|
|
|
2020-04-29 23:51:55 +00:00
|
|
|
type Client struct {
|
2020-05-26 12:50:35 +00:00
|
|
|
UseIpfs bool
|
|
|
|
IpfsMAddr string
|
|
|
|
IpfsUseForRetrieval bool
|
2020-04-29 23:51:55 +00:00
|
|
|
}
|
|
|
|
|
2019-10-30 16:38:39 +00:00
|
|
|
func defCommon() Common {
|
|
|
|
return Common{
|
2019-07-03 16:59:49 +00:00
|
|
|
API: API{
|
2020-04-03 23:56:52 +00:00
|
|
|
ListenAddress: "/ip4/127.0.0.1/tcp/1234/http",
|
|
|
|
Timeout: Duration(30 * time.Second),
|
2019-07-03 16:59:49 +00:00
|
|
|
},
|
2019-07-04 12:04:39 +00:00
|
|
|
Libp2p: Libp2p{
|
|
|
|
ListenAddresses: []string{
|
2019-07-09 13:46:55 +00:00
|
|
|
"/ip4/0.0.0.0/tcp/0",
|
|
|
|
"/ip6/::/tcp/0",
|
2019-07-04 12:04:39 +00:00
|
|
|
},
|
2020-06-09 00:03:11 +00:00
|
|
|
AnnounceAddresses: []string{},
|
|
|
|
NoAnnounceAddresses: []string{},
|
2019-12-17 16:09:43 +00:00
|
|
|
|
2019-12-18 15:38:58 +00:00
|
|
|
ConnMgrLow: 150,
|
|
|
|
ConnMgrHigh: 180,
|
2019-12-17 16:09:43 +00:00
|
|
|
ConnMgrGrace: Duration(20 * time.Second),
|
2019-07-04 12:04:39 +00:00
|
|
|
},
|
2020-05-04 15:30:54 +00:00
|
|
|
Pubsub: Pubsub{
|
|
|
|
Bootstrapper: false,
|
|
|
|
DirectPeers: nil,
|
|
|
|
RemoteTracer: "/ip4/147.75.67.199/tcp/4001/p2p/QmTd6UvR47vUidRNZ1ZKXHrAFhqTJAD27rKL9XYghEKgKX",
|
|
|
|
},
|
2019-07-03 16:59:49 +00:00
|
|
|
}
|
2019-10-30 16:38:39 +00:00
|
|
|
|
2019-07-03 16:59:49 +00:00
|
|
|
}
|
|
|
|
|
2020-04-03 23:56:52 +00:00
|
|
|
// DefaultFullNode returns the default config
|
2019-10-30 16:38:39 +00:00
|
|
|
func DefaultFullNode() *FullNode {
|
|
|
|
return &FullNode{
|
|
|
|
Common: defCommon(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func DefaultStorageMiner() *StorageMiner {
|
2019-11-12 18:31:17 +00:00
|
|
|
cfg := &StorageMiner{
|
2019-10-30 16:38:39 +00:00
|
|
|
Common: defCommon(),
|
2019-11-12 17:59:38 +00:00
|
|
|
|
2020-03-27 20:08:06 +00:00
|
|
|
Storage: sectorstorage.SealerConfig{
|
2020-03-24 19:38:00 +00:00
|
|
|
AllowPreCommit1: true,
|
|
|
|
AllowPreCommit2: true,
|
|
|
|
AllowCommit: true,
|
2020-05-26 08:20:32 +00:00
|
|
|
AllowUnseal: true,
|
2020-03-24 19:38:00 +00:00
|
|
|
},
|
2020-06-11 19:15:28 +00:00
|
|
|
|
|
|
|
Dealmaking: DealmakingConfig{
|
2020-06-26 19:27:41 +00:00
|
|
|
ConsiderOnlineStorageDeals: true,
|
|
|
|
ConsiderOfflineStorageDeals: true,
|
|
|
|
ConsiderOnlineRetrievalDeals: true,
|
|
|
|
ConsiderOfflineRetrievalDeals: true,
|
|
|
|
PieceCidBlocklist: []cid.Cid{},
|
2020-06-11 19:15:28 +00:00
|
|
|
},
|
2020-07-06 18:39:26 +00:00
|
|
|
|
|
|
|
SealingDelay: Duration(time.Hour),
|
2019-10-30 16:38:39 +00:00
|
|
|
}
|
2019-11-12 21:42:26 +00:00
|
|
|
cfg.Common.API.ListenAddress = "/ip4/127.0.0.1/tcp/2345/http"
|
2020-04-03 23:56:52 +00:00
|
|
|
cfg.Common.API.RemoteListenAddress = "127.0.0.1:2345"
|
2019-11-12 18:31:17 +00:00
|
|
|
return cfg
|
2019-10-30 16:38:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ encoding.TextMarshaler = (*Duration)(nil)
|
|
|
|
var _ encoding.TextUnmarshaler = (*Duration)(nil)
|
|
|
|
|
|
|
|
// Duration is a wrapper type for time.Duration
|
|
|
|
// for decoding and encoding from/to TOML
|
2019-07-03 16:59:49 +00:00
|
|
|
type Duration time.Duration
|
|
|
|
|
|
|
|
// UnmarshalText implements interface for TOML decoding
|
|
|
|
func (dur *Duration) UnmarshalText(text []byte) error {
|
|
|
|
d, err := time.ParseDuration(string(text))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
*dur = Duration(d)
|
|
|
|
return err
|
|
|
|
}
|
2019-10-30 16:38:39 +00:00
|
|
|
|
|
|
|
func (dur Duration) MarshalText() ([]byte, error) {
|
|
|
|
d := time.Duration(dur)
|
|
|
|
return []byte(d.String()), nil
|
|
|
|
}
|