2019-07-03 16:59:49 +00:00
|
|
|
package config
|
|
|
|
|
2019-10-30 16:38:39 +00:00
|
|
|
import (
|
|
|
|
"encoding"
|
|
|
|
"time"
|
|
|
|
)
|
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
|
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
|
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
|
|
|
|
|
2019-10-30 16:38:39 +00:00
|
|
|
// StorageMiner is a storage miner config
|
|
|
|
type StorageMiner struct {
|
|
|
|
Common
|
2019-11-12 17:59:38 +00:00
|
|
|
|
|
|
|
SectorBuilder SectorBuilder
|
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 {
|
|
|
|
ListenAddress string
|
|
|
|
Timeout Duration
|
|
|
|
}
|
|
|
|
|
2019-07-04 12:04:39 +00:00
|
|
|
// Libp2p contains configs for libp2p
|
|
|
|
type Libp2p struct {
|
|
|
|
ListenAddresses []string
|
2019-10-11 03:16:12 +00:00
|
|
|
BootstrapPeers []string
|
2019-07-04 12:04:39 +00:00
|
|
|
}
|
|
|
|
|
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 15:08:50 +00:00
|
|
|
HeadNotifs bool
|
2019-11-20 20:31:00 +00:00
|
|
|
PubsubTracing bool
|
2019-10-11 02:45:45 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 17:59:38 +00:00
|
|
|
// // Storage Miner
|
|
|
|
|
|
|
|
type SectorBuilder struct {
|
|
|
|
Path string
|
|
|
|
WorkerCount uint
|
2019-12-06 00:27:32 +00:00
|
|
|
|
|
|
|
DisableLocalPreCommit bool
|
|
|
|
DisableLocalCommit bool
|
2019-11-12 17:59:38 +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{
|
2019-11-12 21:42:26 +00:00
|
|
|
ListenAddress: "/ip4/127.0.0.1/tcp/1234/http",
|
2019-07-03 16:59:49 +00:00
|
|
|
Timeout: Duration(30 * time.Second),
|
|
|
|
},
|
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
|
|
|
},
|
|
|
|
},
|
2019-07-03 16:59:49 +00:00
|
|
|
}
|
2019-10-30 16:38:39 +00:00
|
|
|
|
2019-07-03 16:59:49 +00:00
|
|
|
}
|
|
|
|
|
2019-10-30 16:38:39 +00:00
|
|
|
// Default returns the default config
|
|
|
|
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
|
|
|
|
|
|
|
SectorBuilder: SectorBuilder{
|
|
|
|
WorkerCount: 5,
|
|
|
|
},
|
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"
|
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
|
|
|
|
}
|