lotus/node/config/def.go

117 lines
2.1 KiB
Go
Raw Normal View History

package config
import (
"encoding"
2020-03-27 23:00:21 +00:00
"github.com/filecoin-project/sector-storage"
"time"
)
// Common is common config between full node and miner
type Common struct {
API API
Libp2p Libp2p
}
2019-10-11 02:45:45 +00:00
// FullNode is a full node config
type FullNode struct {
Common
2019-10-11 02:45:45 +00:00
Metrics Metrics
}
2019-11-12 17:59:38 +00:00
// // Common
// StorageMiner is a storage miner config
type StorageMiner struct {
Common
2019-11-12 17:59:38 +00:00
Storage sectorstorage.SealerConfig
}
// API contains configs for API endpoint
type API struct {
ListenAddress string
Timeout Duration
}
// Libp2p contains configs for libp2p
type Libp2p struct {
ListenAddresses []string
BootstrapPeers []string
ProtectedPeers []string
2019-12-17 16:09:43 +00:00
ConnMgrLow uint
ConnMgrHigh uint
ConnMgrGrace Duration
}
2019-11-12 17:59:38 +00:00
// // Full Node
2019-10-11 02:45:45 +00:00
type Metrics struct {
2019-11-20 20:31:00 +00:00
Nickname string
2019-12-11 23:31:59 +00:00
HeadNotifs bool
2019-11-20 20:31:00 +00:00
PubsubTracing bool
2019-10-11 02:45:45 +00:00
}
func defCommon() Common {
return Common{
API: API{
ListenAddress: "/ip4/127.0.0.1/tcp/1234/http",
Timeout: Duration(30 * time.Second),
},
Libp2p: Libp2p{
ListenAddresses: []string{
"/ip4/0.0.0.0/tcp/0",
"/ip6/::/tcp/0",
},
2019-12-17 16:09:43 +00:00
ConnMgrLow: 150,
ConnMgrHigh: 180,
2019-12-17 16:09:43 +00:00
ConnMgrGrace: Duration(20 * time.Second),
},
}
}
// Default returns the default config
func DefaultFullNode() *FullNode {
return &FullNode{
Common: defCommon(),
}
}
func DefaultStorageMiner() *StorageMiner {
cfg := &StorageMiner{
Common: defCommon(),
2019-11-12 17:59:38 +00:00
Storage: sectorstorage.SealerConfig{
AllowPreCommit1: true,
AllowPreCommit2: true,
AllowCommit: true,
},
}
cfg.Common.API.ListenAddress = "/ip4/127.0.0.1/tcp/2345/http"
return cfg
}
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
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
}
func (dur Duration) MarshalText() ([]byte, error) {
d := time.Duration(dur)
return []byte(d.String()), nil
}