Newer
Older
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package node
import (
"fmt"
"github.com/iotaledger/goshimmer/packages/daemon"
"sync"
)
type Node struct {
wg *sync.WaitGroup
loggers []*Logger
loadedPlugins []*Plugin
logLevel int
}
func Load(plugins ...*Plugin) *Node {
fmt.Println(" _____ _ _ ________ ______ ___ ___________ ")
fmt.Println(" / ___| | | |_ _| \\/ || \\/ || ___| ___ \\")
fmt.Println(" \\ `--.| |_| | | | | . . || . . || |__ | |_/ /")
fmt.Println(" `--. \\ _ | | | | |\\/| || |\\/| || __|| / ")
fmt.Println(" /\\__/ / | | |_| |_| | | || | | || |___| |\\ \\ ")
fmt.Println(" \\____/\\_| |_/\\___/\\_| |_/\\_| |_/\\____/\\_| \\_| fullnode 1.0")
fmt.Println()
node := &Node{
logLevel: LOG_LEVEL_INFO,
loggers: make([]*Logger, 0),
wg: &sync.WaitGroup{},
loadedPlugins: make([]*Plugin, 0),
}
node.AddLogger(DEFAULT_LOGGER)
node.Load(plugins...)
return node
}
func Run(plugins ...*Plugin) *Node {
node := Load(plugins...)
node.Run()
return node
}
func (node *Node) AddLogger(logger *Logger) {
node.loggers = append(node.loggers, logger)
}
func (node *Node) LogSuccess(pluginName string, message string) {
if node.logLevel >= LOG_LEVEL_SUCCESS {
for _, logger := range node.loggers {
if logger.Enabled {
logger.LogSuccess(pluginName, message)
}
}
}
}
func (node *Node) LogInfo(pluginName string, message string) {
if node.logLevel >= LOG_LEVEL_INFO {
for _, logger := range node.loggers {
if logger.Enabled {
logger.LogInfo(pluginName, message)
}
}
}
}
func (node *Node) LogWarning(pluginName string, message string) {
if node.logLevel >= LOG_LEVEL_WARNING {
for _, logger := range node.loggers {
if logger.Enabled {
logger.LogWarning(pluginName, message)
}
}
}
}
func (node *Node) LogFailure(pluginName string, message string) {
if node.logLevel >= LOG_LEVEL_FAILURE {
for _, logger := range node.loggers {
if logger.Enabled {
logger.LogFailure(pluginName, message)
}
}
}
}
func (node *Node) Load(plugins ...*Plugin) {
node.LogInfo("Node", "Loading plugins ...")
if len(plugins) >= 1 {
for _, plugin := range plugins {
plugin.wg = node.wg
plugin.Node = node
plugin.Events.Configure.Trigger(plugin)
node.LogInfo("Node", "Loading Plugin: "+plugin.Name+" ... done")
}
}
node.loadedPlugins = append(node.loadedPlugins, plugins...)
}
func (node *Node) Run() {
node.LogInfo("Node", "Executing plugins ...")
if len(node.loadedPlugins) >= 1 {
for _, plugin := range node.loadedPlugins {
plugin.Events.Run.Trigger(plugin)
node.LogSuccess("Node", "Starting Plugin: "+plugin.Name+" ... done")
}
}
node.LogSuccess("Node", "Starting background workers ...")
daemon.Run()
node.LogSuccess("Node", "Shutdown complete!")
}