Skip to content
Snippets Groups Projects
Commit ecbd9372 authored by capossele's avatar capossele
Browse files

Merge remote-tracking branch 'origin/use-viper' into feat/new-autopeering

parents c7080aca 98ac2561
Branches
Tags
No related merge requests found
Showing
with 115 additions and 352 deletions
{
"node": {
"logLevel": 3,
"disablePlugins": [],
"enablePlugins": []
},
"database": {
"directory": "mainnetdb"
},
"analysis": {
"serverPort": 0,
"serverAddress": "159.69.158.51:188"
},
"gossip": {
"port": 14666
},
"zeromq": {
"port": 5556
},
"autopeering": {
"address": "0.0.0.0",
"port": 14626,
"entryNodes": [
"7f7a876a4236091257e650da8dcf195fbe3cb625@159.69.158.51:14626"
],
"acceptRequests": true,
"sendRequests": true
}
}
\ No newline at end of file
......@@ -15,16 +15,10 @@ require (
github.com/labstack/echo v3.3.10+incompatible
github.com/lucasb-eyer/go-colorful v1.0.3 // indirect
github.com/magiconair/properties v1.8.1
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-isatty v0.0.10 // indirect
github.com/mattn/go-runewidth v0.0.6 // indirect
github.com/pkg/errors v0.8.1
github.com/rivo/tview v0.0.0-20191121195645-2d957c4be01d
github.com/valyala/fasttemplate v1.1.0 // indirect
github.com/rivo/tview v0.0.0-20190829161255-f8bc69b90341
github.com/spf13/pflag v1.0.5
go.uber.org/zap v1.13.0
golang.org/x/crypto v0.0.0-20191119213627-4f8c1d86b1ba
golang.org/x/net v0.0.0-20191124235446-72fef5d5e266
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect
golang.org/x/tools v0.0.0-20191125011157-cc15fab314e3 // indirect
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 // indirect
golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472
golang.org/x/net v0.0.0-20191119073136-fc4aabc6c914
)
This diff is collapsed.
package database
import (
"github.com/iotaledger/hive.go/parameter"
"os"
"sync"
......@@ -37,7 +38,7 @@ func checkDir(dir string) error {
}
func createDB() (*badger.DB, error) {
directory := *DIRECTORY.Value
directory := parameter.NodeConfig.GetString(CFG_DIRECTORY)
if err := checkDir(directory); err != nil {
return nil, errors.Wrap(err, "Could not check directory")
}
......
package database
import (
"github.com/iotaledger/goshimmer/packages/parameter"
flag "github.com/spf13/pflag"
)
var DIRECTORY = parameter.AddString("DATABASE/DIRECTORY", "mainnetdb", "path to the database folder")
const (
CFG_DIRECTORY = "database.directory"
)
func init() {
flag.String(CFG_DIRECTORY, "mainnetdb", "path to the database folder")
}
package events
import "reflect"
type Closure struct {
Id uintptr
Fnc interface{}
}
func NewClosure(f interface{}) *Closure {
closure := &Closure{
Fnc: f,
}
closure.Id = reflect.ValueOf(closure).Pointer()
return closure
}
package events
import "sync"
type Event struct {
triggerFunc func(handler interface{}, params ...interface{})
callbacks map[uintptr]interface{}
mutex sync.RWMutex
}
func (this *Event) Attach(closure *Closure) {
this.mutex.Lock()
this.callbacks[closure.Id] = closure.Fnc
this.mutex.Unlock()
}
func (this *Event) Detach(closure *Closure) {
this.mutex.Lock()
delete(this.callbacks, closure.Id)
this.mutex.Unlock()
}
func (this *Event) Trigger(params ...interface{}) {
this.mutex.RLock()
for _, handler := range this.callbacks {
this.triggerFunc(handler, params...)
}
this.mutex.RUnlock()
}
func NewEvent(triggerFunc func(handler interface{}, params ...interface{})) *Event {
return &Event{
triggerFunc: triggerFunc,
callbacks: make(map[uintptr]interface{}),
}
}
package events
import (
"fmt"
"strconv"
"testing"
)
func BenchmarkEvent_Trigger(b *testing.B) {
event := NewEvent(intStringCaller)
event.Attach(NewClosure(func(param1 int, param2 string) {
// do nothing just get called
}))
b.ResetTimer()
for i := 0; i < b.N; i++ {
event.Trigger(4, "test")
}
}
// define how the event converts the generic parameters to the typed params - ugly but go has no generics :(
func intStringCaller(handler interface{}, params ...interface{}) {
handler.(func(int, string))(params[0].(int), params[1].(string))
}
func ExampleEvent() {
// create event object (usually exposed through a public struct that holds all the different event types)
event := NewEvent(intStringCaller)
// we have to wrap a function in a closure to make it identifiable
closure1 := NewClosure(func(param1 int, param2 string) {
fmt.Println("#1 " + param2 + ": " + strconv.Itoa(param1))
})
// multiple subscribers can attach to an event (closures can be inlined)
event.Attach(closure1)
event.Attach(NewClosure(func(param1 int, param2 string) {
fmt.Println("#2 " + param2 + ": " + strconv.Itoa(param1))
}))
// trigger the event
event.Trigger(1, "Hello World")
// unsubscribe the first closure and trigger again
event.Detach(closure1)
event.Trigger(1, "Hello World")
// Unordered output: #1 Hello World: 1
// #2 Hello World: 1
// #2 Hello World: 1
}
package events
func CallbackCaller(handler interface{}, params ...interface{}) { handler.(func())() }
func ErrorCaller(handler interface{}, params ...interface{}) { handler.(func(error))(params[0].(error)) }
......@@ -5,8 +5,8 @@ import (
"strconv"
"sync"
"github.com/iotaledger/hive.go/events"
"github.com/iotaledger/goshimmer/packages/network"
"github.com/iotaledger/hive.go/events"
)
type Server struct {
......
package tcp
import (
"github.com/iotaledger/hive.go/events"
"github.com/iotaledger/goshimmer/packages/network"
"github.com/iotaledger/hive.go/events"
)
type serverEvents struct {
......
......@@ -3,6 +3,8 @@ package node
import (
"sync"
"github.com/iotaledger/hive.go/parameter"
"github.com/iotaledger/goshimmer/packages/daemon"
)
......@@ -53,7 +55,7 @@ func (node *Node) AddLogger(logger *Logger) {
}
func (node *Node) LogSuccess(pluginName string, message string) {
if *LOG_LEVEL.Value >= LOG_LEVEL_SUCCESS {
if parameter.NodeConfig.GetInt(CFG_LOG_LEVEL) >= LOG_LEVEL_SUCCESS {
for _, logger := range node.loggers {
if logger.GetEnabled() {
logger.LogSuccess(pluginName, message)
......@@ -63,7 +65,7 @@ func (node *Node) LogSuccess(pluginName string, message string) {
}
func (node *Node) LogInfo(pluginName string, message string) {
if *LOG_LEVEL.Value >= LOG_LEVEL_INFO {
if parameter.NodeConfig.GetInt(CFG_LOG_LEVEL) >= LOG_LEVEL_INFO {
for _, logger := range node.loggers {
if logger.GetEnabled() {
logger.LogInfo(pluginName, message)
......@@ -73,7 +75,7 @@ func (node *Node) LogInfo(pluginName string, message string) {
}
func (node *Node) LogDebug(pluginName string, message string) {
if *LOG_LEVEL.Value >= LOG_LEVEL_DEBUG {
if parameter.NodeConfig.GetInt(CFG_LOG_LEVEL) >= LOG_LEVEL_DEBUG {
for _, logger := range node.loggers {
if logger.GetEnabled() {
logger.LogDebug(pluginName, message)
......@@ -83,7 +85,7 @@ func (node *Node) LogDebug(pluginName string, message string) {
}
func (node *Node) LogWarning(pluginName string, message string) {
if *LOG_LEVEL.Value >= LOG_LEVEL_WARNING {
if parameter.NodeConfig.GetInt(CFG_LOG_LEVEL) >= LOG_LEVEL_WARNING {
for _, logger := range node.loggers {
if logger.GetEnabled() {
logger.LogWarning(pluginName, message)
......@@ -93,7 +95,7 @@ func (node *Node) LogWarning(pluginName string, message string) {
}
func (node *Node) LogFailure(pluginName string, message string) {
if *LOG_LEVEL.Value >= LOG_LEVEL_FAILURE {
if parameter.NodeConfig.GetInt(CFG_LOG_LEVEL) >= LOG_LEVEL_FAILURE {
for _, logger := range node.loggers {
if logger.GetEnabled() {
logger.LogFailure(pluginName, message)
......
package node
import "github.com/iotaledger/goshimmer/packages/parameter"
var (
LOG_LEVEL = parameter.AddInt("NODE/LOG_LEVEL", LOG_LEVEL_INFO, "controls the log types that are shown")
import (
flag "github.com/spf13/pflag"
)
DISABLE_PLUGINS = parameter.AddString("NODE/DISABLE_PLUGINS", "", "a list of plugins that shall be disabled")
ENABLE_PLUGINS = parameter.AddString("NODE/ENABLE_PLUGINS", "", "a list of plugins that shall be enabled")
const (
CFG_LOG_LEVEL = "node.logLevel"
CFG_DISABLE_PLUGINS = "node.disablePlugins"
CFG_ENABLE_PLGUINS = "node.enablePlugins"
)
func init() {
flag.Int(CFG_LOG_LEVEL, LOG_LEVEL_INFO, "controls the log types that are shown")
flag.String(CFG_DISABLE_PLUGINS, "", "a list of plugins that shall be disabled")
flag.String(CFG_ENABLE_PLGUINS, "", "a list of plugins that shall be enabled")
}
......@@ -5,7 +5,7 @@ import (
"sync"
"github.com/iotaledger/hive.go/events"
"github.com/iotaledger/goshimmer/packages/parameter"
"github.com/iotaledger/hive.go/parameter"
)
const (
......
package parameter
import (
"github.com/iotaledger/hive.go/events"
)
var Events = struct {
AddBool *events.Event
AddInt *events.Event
AddString *events.Event
AddPlugin *events.Event
}{
AddBool: events.NewEvent(boolParameterCaller),
AddInt: events.NewEvent(intParameterCaller),
AddString: events.NewEvent(stringParameterCaller),
AddPlugin: events.NewEvent(pluginParameterCaller),
}
func boolParameterCaller(handler interface{}, params ...interface{}) {
handler.(func(*BoolParameter))(params[0].(*BoolParameter))
}
func intParameterCaller(handler interface{}, params ...interface{}) {
handler.(func(*IntParameter))(params[0].(*IntParameter))
}
func stringParameterCaller(handler interface{}, params ...interface{}) {
handler.(func(*StringParameter))(params[0].(*StringParameter))
}
func pluginParameterCaller(handler interface{}, params ...interface{}) {
handler.(func(string, int))(params[0].(string), params[1].(int))
}
package parameter
var boolParameters = make(map[string]*BoolParameter)
func AddBool(name string, defaultValue bool, description string) *BoolParameter {
if boolParameters[name] != nil {
panic("duplicate parameter - \"" + name + "\" was defined already")
}
newParameter := &BoolParameter{
Name: name,
DefaultValue: defaultValue,
Value: &defaultValue,
Description: description,
}
boolParameters[name] = newParameter
Events.AddBool.Trigger(newParameter)
return newParameter
}
func GetBool(name string) *BoolParameter {
return boolParameters[name]
}
func GetBools() map[string]*BoolParameter {
return boolParameters
}
var intParameters = make(map[string]*IntParameter)
func AddInt(name string, defaultValue int, description string) *IntParameter {
if _, exists := intParameters[name]; exists {
panic("duplicate parameter - \"" + name + "\" was defined already")
}
newParameter := &IntParameter{
Name: name,
DefaultValue: defaultValue,
Value: &defaultValue,
Description: description,
}
intParameters[name] = newParameter
Events.AddInt.Trigger(newParameter)
return newParameter
}
func GetInt(name string) *IntParameter {
return intParameters[name]
}
func GetInts() map[string]*IntParameter {
return intParameters
}
var stringParameters = make(map[string]*StringParameter)
func AddString(name string, defaultValue string, description string) *StringParameter {
if _, exists := stringParameters[name]; exists {
panic("duplicate parameter - \"" + name + "\" was defined already")
}
newParameter := &StringParameter{
Name: name,
DefaultValue: defaultValue,
Value: &defaultValue,
Description: description,
}
stringParameters[name] = newParameter
Events.AddString.Trigger(newParameter)
return stringParameters[name]
}
func GetString(name string) *StringParameter {
return stringParameters[name]
}
func GetStrings() map[string]*StringParameter {
return stringParameters
}
var plugins = make(map[string]int)
func AddPlugin(name string, status int) {
if _, exists := plugins[name]; exists {
panic("duplicate plugin - \"" + name + "\" was defined already")
}
plugins[name] = status
Events.AddPlugin.Trigger(name, status)
}
func GetPlugins() map[string]int {
return plugins
}
package parameter
type BoolParameter struct {
Name string
Value *bool
DefaultValue bool
Description string
}
type IntParameter struct {
Name string
Value *int
DefaultValue int
Description string
}
type StringParameter struct {
Name string
Value *string
DefaultValue string
Description string
}
type IntParameterConsumer = func(param *IntParameter)
type StringParameterConsumer = func(param *StringParameter)
package client
import "github.com/iotaledger/goshimmer/packages/parameter"
import (
flag "github.com/spf13/pflag"
)
var (
SERVER_ADDRESS = parameter.AddString("ANALYSIS/SERVER-ADDRESS", "159.69.158.51:188", "tcp server for collecting analysis information")
const (
CFG_SERVER_ADDRESS = "analysis.serverAddress"
)
func init() {
flag.String(CFG_SERVER_ADDRESS, "159.69.158.51:188", "tcp server for collecting analysis information")
}
......@@ -2,6 +2,7 @@ package client
import (
"encoding/hex"
"github.com/iotaledger/hive.go/parameter"
"net"
"time"
......@@ -34,7 +35,7 @@ func Run(plugin *node.Plugin) {
return
default:
if conn, err := net.Dial("tcp", *SERVER_ADDRESS.Value); err != nil {
if conn, err := net.Dial("tcp", parameter.NodeConfig.GetString(CFG_SERVER_ADDRESS)); err != nil {
plugin.LogDebug("Could not connect to reporting server: " + err.Error())
timeutil.Sleep(1 * time.Second)
......
......@@ -2,17 +2,18 @@ package analysis
import (
"github.com/iotaledger/goshimmer/packages/daemon"
"github.com/iotaledger/hive.go/events"
"github.com/iotaledger/goshimmer/packages/node"
"github.com/iotaledger/goshimmer/plugins/analysis/client"
"github.com/iotaledger/goshimmer/plugins/analysis/server"
"github.com/iotaledger/goshimmer/plugins/analysis/webinterface"
"github.com/iotaledger/hive.go/events"
"github.com/iotaledger/hive.go/parameter"
)
var PLUGIN = node.NewPlugin("Analysis", node.Enabled, configure, run)
func configure(plugin *node.Plugin) {
if *server.SERVER_PORT.Value != 0 {
if parameter.NodeConfig.GetInt(server.CFG_SERVER_PORT) != 0 {
webinterface.Configure(plugin)
server.Configure(plugin)
......@@ -23,14 +24,14 @@ func configure(plugin *node.Plugin) {
}
func run(plugin *node.Plugin) {
if *server.SERVER_PORT.Value != 0 {
if parameter.NodeConfig.GetInt(server.CFG_SERVER_PORT) != 0 {
webinterface.Run(plugin)
server.Run(plugin)
} else {
plugin.Node.LogSuccess("Node", "Starting Plugin: Analysis ... server is disabled (server-port is 0)")
}
if *client.SERVER_ADDRESS.Value != "" {
if parameter.NodeConfig.GetString(client.CFG_SERVER_ADDRESS) != "" {
client.Run(plugin)
} else {
plugin.Node.LogSuccess("Node", "Starting Plugin: Analysis ... client is disabled (server-address is empty)")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment