Skip to content
Snippets Groups Projects
Unverified Commit 35a0c58c authored by Angelo Capossele's avatar Angelo Capossele Committed by GitHub
Browse files

Fix: Linter warnings (#351)

Fixes linter warnings.
parent e212795a
No related branches found
No related tags found
No related merge requests found
......@@ -26,7 +26,7 @@ var PLUGINS = node.Plugins(
portcheck.PLUGIN,
profiling.Plugin,
database.PLUGIN,
autopeering.PLUGIN,
autopeering.Plugin,
messagelayer.PLUGIN,
gossip.PLUGIN,
gracefulshutdown.PLUGIN,
......
......@@ -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
}
......
......@@ -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
......
......@@ -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")
}
......@@ -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")
}
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment