diff --git a/pluginmgr/core/plugins.go b/pluginmgr/core/plugins.go index ecb28954d9f9f640290d2f61b2e91c7ea5fac840..401d430a1c4ed697bd54905d0a484924425742bc 100644 --- a/pluginmgr/core/plugins.go +++ b/pluginmgr/core/plugins.go @@ -26,7 +26,7 @@ var PLUGINS = node.Plugins( portcheck.PLUGIN, profiling.Plugin, database.PLUGIN, - autopeering.PLUGIN, + autopeering.Plugin, messagelayer.PLUGIN, gossip.PLUGIN, gracefulshutdown.PLUGIN, diff --git a/plugins/autopeering/autopeering.go b/plugins/autopeering/autopeering.go index dcbeefd3350162221a24217e0c593ec63811bf78..64754dd30687f3d907d9fbb414a5a7de05c2da06 100644 --- a/plugins/autopeering/autopeering.go +++ b/plugins/autopeering/autopeering.go @@ -9,6 +9,10 @@ import ( "strconv" "strings" + "github.com/iotaledger/goshimmer/plugins/autopeering/local" + "github.com/iotaledger/goshimmer/plugins/banner" + "github.com/iotaledger/goshimmer/plugins/config" + "github.com/iotaledger/goshimmer/plugins/gossip" "github.com/iotaledger/hive.go/autopeering/discover" "github.com/iotaledger/hive.go/autopeering/peer" "github.com/iotaledger/hive.go/autopeering/peer/service" @@ -18,11 +22,6 @@ import ( "github.com/iotaledger/hive.go/identity" "github.com/iotaledger/hive.go/logger" "github.com/iotaledger/hive.go/node" - - "github.com/iotaledger/goshimmer/plugins/autopeering/local" - "github.com/iotaledger/goshimmer/plugins/banner" - "github.com/iotaledger/goshimmer/plugins/config" - "github.com/iotaledger/goshimmer/plugins/gossip" ) // autopeering constants @@ -58,7 +57,7 @@ func hash32(b []byte) uint32 { // GetBindAddress returns the string form of the autopeering bind address. func GetBindAddress() string { peering := local.GetInstance().Services().Get(service.PeeringKey) - host := config.Node.GetString(local.CFG_BIND) + host := config.Node.GetString(local.CfgBind) port := strconv.Itoa(peering.Port()) return net.JoinHostPort(host, port) } @@ -107,7 +106,7 @@ func start(shutdownSignal <-chan struct{}) { // resolve the bind address localAddr, err := net.ResolveUDPAddr(peering.Network(), GetBindAddress()) if err != nil { - log.Fatalf("Error resolving %s: %v", local.CFG_BIND, err) + log.Fatalf("Error resolving %s: %v", local.CfgBind, err) } conn, err := net.ListenUDP(peering.Network(), localAddr) @@ -146,7 +145,7 @@ func start(shutdownSignal <-chan struct{}) { } func parseEntryNodes() (result []*peer.Peer, err error) { - for _, entryNodeDefinition := range config.Node.GetStringSlice(CFG_ENTRY_NODES) { + for _, entryNodeDefinition := range config.Node.GetStringSlice(CfgEntryNodes) { if entryNodeDefinition == "" { continue } diff --git a/plugins/autopeering/local/local.go b/plugins/autopeering/local/local.go index 4a7c7e84515491ea2a071200aad6f1eaccc235cd..c16f755ed5802a2bbbf352bd47aa0b39443c3f76 100644 --- a/plugins/autopeering/local/local.go +++ b/plugins/autopeering/local/local.go @@ -7,12 +7,11 @@ import ( "strings" "sync" + "github.com/iotaledger/goshimmer/packages/database" + "github.com/iotaledger/goshimmer/plugins/config" "github.com/iotaledger/hive.go/autopeering/peer" "github.com/iotaledger/hive.go/autopeering/peer/service" "github.com/iotaledger/hive.go/logger" - - "github.com/iotaledger/goshimmer/packages/database" - "github.com/iotaledger/goshimmer/plugins/config" ) var ( @@ -24,22 +23,22 @@ func configureLocal() *peer.Local { log := logger.NewLogger("Local") var peeringIP net.IP - if str := config.Node.GetString(CFG_EXTERNAL); strings.ToLower(str) == "auto" { + if str := config.Node.GetString(CfgExternal); strings.ToLower(str) == "auto" { // let the autopeering discover the IP peeringIP = net.IPv4zero } else { peeringIP = net.ParseIP(str) if peeringIP == nil { - log.Fatalf("Invalid IP address (%s): %s", CFG_EXTERNAL, str) + log.Fatalf("Invalid IP address (%s): %s", CfgExternal, str) } if !peeringIP.IsGlobalUnicast() { log.Warnf("IP is not a global unicast address: %s", peeringIP.String()) } } - peeringPort := config.Node.GetInt(CFG_PORT) + peeringPort := config.Node.GetInt(CfgPort) if 0 > peeringPort || peeringPort > 65535 { - log.Fatalf("Invalid port number (%s): %d", CFG_PORT, peeringPort) + log.Fatalf("Invalid port number (%s): %d", CfgPort, peeringPort) } // announce the peering service @@ -48,13 +47,13 @@ func configureLocal() *peer.Local { // set the private key from the seed provided in the config var seed [][]byte - if str := config.Node.GetString(CFG_SEED); str != "" { + if str := config.Node.GetString(CfgSeed); str != "" { bytes, err := base64.StdEncoding.DecodeString(str) if err != nil { - log.Fatalf("Invalid %s: %s", CFG_SEED, err) + log.Fatalf("Invalid %s: %s", CfgSeed, err) } if l := len(bytes); l != ed25519.SeedSize { - log.Fatalf("Invalid %s length: %d, need %d", CFG_SEED, l, ed25519.SeedSize) + log.Fatalf("Invalid %s length: %d, need %d", CfgSeed, l, ed25519.SeedSize) } seed = append(seed, bytes) } @@ -80,6 +79,7 @@ func configureLocal() *peer.Local { return local } +// GetInstance returns the instance of the local peer. func GetInstance() *peer.Local { once.Do(func() { instance = configureLocal() }) return instance diff --git a/plugins/autopeering/local/parameters.go b/plugins/autopeering/local/parameters.go index 9ffa15c81fe7fbc745b3c85723dda0af8a32a20a..b04ae156c9bf40e5a1de1d9db024b0655a166f22 100644 --- a/plugins/autopeering/local/parameters.go +++ b/plugins/autopeering/local/parameters.go @@ -5,15 +5,19 @@ import ( ) const ( - CFG_BIND = "network.bindAddress" - CFG_EXTERNAL = "network.externalAddress" - CFG_PORT = "autopeering.port" - CFG_SEED = "autopeering.seed" + // CfgBind defines the config flag of the network bind address. + CfgBind = "network.bindAddress" + // CfgExternal defines the config flag of the network external address. + CfgExternal = "network.externalAddress" + // CfgPort defines the config flag of the autopeering port. + CfgPort = "autopeering.port" + // CfgSeed defines the config flag of the autopeering private key seed. + CfgSeed = "autopeering.seed" ) func init() { - flag.String(CFG_BIND, "0.0.0.0", "bind address for global services such as autopeering and gossip") - flag.String(CFG_EXTERNAL, "auto", "external IP address under which the node is reachable; or 'auto' to determine it automatically") - flag.Int(CFG_PORT, 14626, "UDP port for incoming peering requests") - flag.BytesBase64(CFG_SEED, nil, "private key seed used to derive the node identity; optional Base64 encoded 256-bit string") + flag.String(CfgBind, "0.0.0.0", "bind address for global services such as autopeering and gossip") + flag.String(CfgExternal, "auto", "external IP address under which the node is reachable; or 'auto' to determine it automatically") + flag.Int(CfgPort, 14626, "UDP port for incoming peering requests") + flag.BytesBase64(CfgSeed, nil, "private key seed used to derive the node identity; optional Base64 encoded 256-bit string") } diff --git a/plugins/autopeering/parameters.go b/plugins/autopeering/parameters.go index 138b8d56e451c9024fd85c1b4296965337061c4d..01022ef352e2ae927b2841f399dd20c8a366607f 100644 --- a/plugins/autopeering/parameters.go +++ b/plugins/autopeering/parameters.go @@ -5,9 +5,10 @@ import ( ) const ( - CFG_ENTRY_NODES = "autopeering.entryNodes" + // CfgEntryNodes defines the config flag of the entry nodes. + CfgEntryNodes = "autopeering.entryNodes" ) func init() { - flag.StringSlice(CFG_ENTRY_NODES, []string{"V8LYtWWcPYYDTTXLeIEFjJEuWlsjDiI0+Pq/Cx9ai6g=@116.202.49.178:14626"}, "list of trusted entry nodes for auto peering") + flag.StringSlice(CfgEntryNodes, []string{"V8LYtWWcPYYDTTXLeIEFjJEuWlsjDiI0+Pq/Cx9ai6g=@116.202.49.178:14626"}, "list of trusted entry nodes for auto peering") } diff --git a/plugins/autopeering/plugin.go b/plugins/autopeering/plugin.go index e84cac5b7ed2b730bb65b25cad4bebe1b9ac9900..04e8d65a1b7e8a1e99ee56719db5738f8cef4702 100644 --- a/plugins/autopeering/plugin.go +++ b/plugins/autopeering/plugin.go @@ -16,7 +16,8 @@ import ( const name = "Autopeering" // name of the plugin -var PLUGIN = node.NewPlugin(name, node.Enabled, configure, run) +// Plugin defines the autopeering plugin. +var Plugin = node.NewPlugin(name, node.Enabled, configure, run) func configure(*node.Plugin) { log = logger.NewLogger(name) diff --git a/plugins/gossip/gossip.go b/plugins/gossip/gossip.go index 6255d8e33a7e1ffff6f2aa26eb296a8a590d03dc..be42070803563bd6d164cd4bf443ec41bf45c856 100644 --- a/plugins/gossip/gossip.go +++ b/plugins/gossip/gossip.go @@ -47,10 +47,10 @@ func start(shutdownSignal <-chan struct{}) { gossipEndpoint := lPeer.Services().Get(service.GossipKey) // resolve the bind address - address := net.JoinHostPort(config.Node.GetString(local.CFG_BIND), strconv.Itoa(gossipEndpoint.Port())) + address := net.JoinHostPort(config.Node.GetString(local.CfgBind), strconv.Itoa(gossipEndpoint.Port())) localAddr, err := net.ResolveTCPAddr(gossipEndpoint.Network(), address) if err != nil { - log.Fatalf("Error resolving %s: %v", local.CFG_BIND, err) + log.Fatalf("Error resolving %s: %v", local.CfgBind, err) } listener, err := net.ListenTCP(gossipEndpoint.Network(), localAddr) diff --git a/plugins/portcheck/plugin.go b/plugins/portcheck/plugin.go index 202c8bb4593cd3f72fad996d5ed50f2959ae6c77..260439a964d4907c78344c81911651151bc49632 100644 --- a/plugins/portcheck/plugin.go +++ b/plugins/portcheck/plugin.go @@ -39,7 +39,7 @@ func checkAutopeeringConnection() { // resolve the bind address localAddr, err := net.ResolveUDPAddr(peering.Network(), autopeering.GetBindAddress()) if err != nil { - log.Fatalf("Error resolving %s: %v", local.CFG_BIND, err) + log.Fatalf("Error resolving %s: %v", local.CfgBind, err) } // open a connection conn, err := net.ListenUDP(peering.Network(), localAddr)