-
Notifications
You must be signed in to change notification settings - Fork 14
/
config.go
86 lines (69 loc) · 2.98 KB
/
config.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
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
Refactored: 1
*/
package mir
import (
"github.com/pkg/errors"
"github.com/filecoin-project/mir/pkg/logging"
)
// The NodeConfig struct represents configuration parameters of the node
// that are independent of the protocol the Node is executing.
// NodeConfig only contains protocol-independent parameters. Protocol-specific parameters
// should be specified when instantiating the protocol implementation as one of the Node's modules.
type NodeConfig struct {
// Logger provides the logging functions.
Logger logging.Logger
// MaxEventBatchSize is the maximum number of events that can be dispatched to a module in a single batch.
MaxEventBatchSize int
// PauseInputThreshold is the number of events in the node's internal event buffer that triggers the disabling
// of further external input (i.e. events emitted by active modules). Events emitted by passive modules are
// not affected. The processing of external events is resumed when the number of events in the buffer drops
// below the ResumeInputThreshold.
PauseInputThreshold int
// ResumeInputThreshold is the number of events in the node's internal event buffer that triggers the enabling
// of external input (i.e. events emitted by active modules). Events emitted by passive modules are not affected.
// When the external input is disabled and the number of events in the buffer drops below ResumeInputThreshold,
// external input events can be added to the event buffer again.
ResumeInputThreshold int
// Stats configures event processing statistics generation.
// Enable by setting Stats.Period to a positive value.
Stats StatsConfig
}
// DefaultNodeConfig returns the default node configuration.
// It can be used as a base for creating more specific configurations when instantiating a Node.
func DefaultNodeConfig() *NodeConfig {
return &NodeConfig{
Logger: logging.ConsoleInfoLogger,
MaxEventBatchSize: 512,
PauseInputThreshold: 8192,
ResumeInputThreshold: 6144,
Stats: StatsConfig{
Logger: logging.ConsoleDebugLogger,
LogLevel: logging.LevelDebug,
Period: 0, // Stats logging disabled by default.
},
}
}
func (c *NodeConfig) Validate() error {
if c.MaxEventBatchSize <= 0 {
return errors.Errorf("MaxEventBatchSize must be greater than 0, got %d", c.MaxEventBatchSize)
}
if c.PauseInputThreshold <= 0 {
return errors.Errorf("PauseInputThreshold must be greater than 0, got %d", c.PauseInputThreshold)
}
if c.ResumeInputThreshold < 0 {
return errors.Errorf("ResumeInputThreshold must be greater than or equal to 0, got %d", c.ResumeInputThreshold)
}
if c.PauseInputThreshold < c.ResumeInputThreshold {
return errors.Errorf("PauseInputThreshold (%d) must be greater than or equal to ResumeInputThreshold (%d)",
c.PauseInputThreshold, c.ResumeInputThreshold)
}
return nil
}
func (c *NodeConfig) WithLogger(logger logging.Logger) *NodeConfig {
newConfig := *c
newConfig.Logger = logger
return &newConfig
}