Skip to content
Snippets Groups Projects
Unverified Commit 26e99d88 authored by Wolfgang Welz's avatar Wolfgang Welz Committed by GitHub
Browse files

Merge pull request #85 from iotaledger/use-viper

Removes parameter/events packages in favor of hive.go's
parents c2d1b2f9 ca5519b1
No related branches found
No related tags found
No related merge requests found
Showing
with 207 additions and 144 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,4 +15,4 @@ services:
- "14666:14666/tcp"
- "14626:14626/udp"
- "14626:14626/tcp"
command: "-node-disable-plugins statusscreen"
command: "--node.disablePlugins statusscreen"
......@@ -10,20 +10,22 @@ require (
github.com/gdamore/tcell v1.2.0
github.com/go-zeromq/zmq4 v0.5.0
github.com/golang/protobuf v1.3.2 // indirect
github.com/google/open-location-code/go v0.0.0-20190723034300-2c7115db77a3
github.com/google/open-location-code/go v0.0.0-20190903173953-119bc96a3a51
github.com/gorilla/websocket v1.4.1
github.com/iotaledger/iota.go v1.0.0-beta.7
github.com/kr/pretty v0.1.0 // indirect
github.com/iotaledger/hive.go v0.0.0-20191113184748-b545de9170d9
github.com/iotaledger/iota.go v1.0.0-beta.9
github.com/labstack/echo v3.3.10+incompatible
github.com/labstack/gommon v0.3.0 // indirect
github.com/magiconair/properties v1.8.1
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
github.com/pkg/errors v0.8.1
github.com/rivo/tview v0.0.0-20190829161255-f8bc69b90341
github.com/rivo/uniseg v0.1.0 // indirect
github.com/sasha-s/go-deadlock v0.2.0 // indirect
github.com/spf13/pflag v1.0.5
golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd // indirect
golang.org/x/text v0.3.2 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/zeromq/goczmq.v4 v4.1.0 // indirect
)
This diff is collapsed.
package daemon
import (
"github.com/iotaledger/goshimmer/packages/events"
"github.com/iotaledger/hive.go/events"
)
var Events = struct {
......
......@@ -6,6 +6,7 @@ import (
"github.com/dgraph-io/badger"
"github.com/dgraph-io/badger/options"
"github.com/iotaledger/hive.go/parameter"
"github.com/pkg/errors"
)
......@@ -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)) }
package network
import (
"github.com/iotaledger/goshimmer/packages/events"
"github.com/iotaledger/hive.go/events"
)
type BufferedConnectionEvents struct {
......
......@@ -6,7 +6,7 @@ import (
"sync"
"time"
"github.com/iotaledger/goshimmer/packages/events"
"github.com/iotaledger/hive.go/events"
)
type ManagedConnection struct {
......
......@@ -5,8 +5,8 @@ import (
"strconv"
"sync"
"github.com/iotaledger/goshimmer/packages/events"
"github.com/iotaledger/goshimmer/packages/network"
"github.com/iotaledger/hive.go/events"
)
type Server struct {
......
package tcp
import (
"github.com/iotaledger/goshimmer/packages/events"
"github.com/iotaledger/goshimmer/packages/network"
"github.com/iotaledger/hive.go/events"
)
type serverEvents struct {
......
......@@ -3,7 +3,7 @@ package udp
import (
"net"
"github.com/iotaledger/goshimmer/packages/events"
"github.com/iotaledger/hive.go/events"
)
type serverEvents struct {
......
......@@ -5,7 +5,7 @@ import (
"strconv"
"sync"
"github.com/iotaledger/goshimmer/packages/events"
"github.com/iotaledger/hive.go/events"
)
type Server struct {
......
package node
import (
"github.com/iotaledger/goshimmer/packages/events"
"github.com/iotaledger/hive.go/events"
)
type pluginEvents 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")
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment