-
Notifications
You must be signed in to change notification settings - Fork 4
/
config_babble.go
86 lines (70 loc) · 2.95 KB
/
config_babble.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package configuration
import (
"fmt"
"time"
"github.com/mosaicnetworks/monetd/src/common"
)
var (
defaultNodeAddr = fmt.Sprintf("%s:%d", common.GetMyIP(), 1337)
defaultHeartbeat = 200 * time.Millisecond
defaultTCPTimeout = 1000 * time.Millisecond
defaultCacheSize = 50000
defaultSyncLimit = 1000
defaultBootstrap = true
defaultMaxPool = 2
defaultMaintenanceMode = false
defaultSuspendLimit = 300
)
// BabbleConfig contains the configuration for the Babble node used by monetd.
// It only presents a subset of the options Babble can accept, because monetd
// forces some configurations values. In particular, the --fast-sync and
// --store flags are disabled because monetd does not support the FastSync
// protocol, and it requires a persistant database.
type BabbleConfig struct {
// BindAddr is the local address:port where this node gossips with other
// nodes. By default, this is "0.0.0.0", meaning Babble will bind to all
// addresses on the local machine and will advertise the private IPv4
// address to the rest of the cluster. However, in some cases, there may be
// a routable address that cannot be bound. Use AdvertiseAddr to enable
// gossiping a different address to support this. If this address is not
// routable, the node will be in a constant flapping state as other nodes
// will treat the non-routability as a failure
BindAddr string `mapstructure:"listen"`
// AdvertiseAddr is used to change the address that we advertise to other
// nodes in the cluster
AdvertiseAddr string `mapstructure:"advertise"`
// Gossip heartbeat
Heartbeat time.Duration `mapstructure:"heartbeat"`
// TCP timeout
TCPTimeout time.Duration `mapstructure:"timeout"`
// Max number of items in caches
CacheSize int `mapstructure:"cache-size"`
// Max number of Event in SyncResponse
SyncLimit int `mapstructure:"sync-limit"`
// Max number of connections in net pool
MaxPool int `mapstructure:"max-pool"`
// Bootstrap from database
Bootstrap bool `mapstructure:"bootstrap"`
// MaintenanceMode when set to true causes Babble to initialise in a
// suspended state. I.e. it does not start gossipping
MaintenanceMode bool `mapstructure:"maintenance-mode"`
// SuspendLimit is the number of undetermined-events produced since the last
// run, that will cause the node to be automaitically suspended.
SuspendLimit int `mapstructure:"suspend-limit"`
// Moniker is a friendly name to indentify this peer
Moniker string `mapstructure:"moniker"`
}
// DefaultBabbleConfig returns the default configuration for a Babble node
func DefaultBabbleConfig() *BabbleConfig {
return &BabbleConfig{
BindAddr: defaultNodeAddr,
Heartbeat: defaultHeartbeat,
TCPTimeout: defaultTCPTimeout,
CacheSize: defaultCacheSize,
SyncLimit: defaultSyncLimit,
MaxPool: defaultMaxPool,
Bootstrap: defaultBootstrap,
MaintenanceMode: defaultMaintenanceMode,
SuspendLimit: defaultSuspendLimit,
}
}