From 289f3bd3c3a1a38438688e2e9e203113f617e944 Mon Sep 17 00:00:00 2001 From: capossele <angelocapossele@gmail.com> Date: Mon, 2 Dec 2019 18:20:15 +0000 Subject: [PATCH] :construction: WIP --- go.mod | 8 ++-- go.sum | 40 ++++--------------- plugins/analysis/client/plugin.go | 7 ++-- plugins/autopeering/autopeering.go | 64 +++++++++++++++++++----------- plugins/autopeering/entrynodes.go | 6 ++- plugins/autopeering/parameters.go | 14 +++---- plugins/autopeering/plugin.go | 27 +++++++++---- plugins/cli/cli.go | 5 +-- plugins/dashboard/plugin.go | 2 +- plugins/dashboard/tps.go | 17 +++++++- plugins/ui/logger.go | 3 +- plugins/ui/nodeInfo.go | 20 +++++++--- plugins/ui/ui.go | 2 +- 13 files changed, 120 insertions(+), 95 deletions(-) diff --git a/go.mod b/go.mod index 67b5c1f9..a27fc5a9 100644 --- a/go.mod +++ b/go.mod @@ -9,8 +9,8 @@ require ( github.com/go-zeromq/zmq4 v0.6.2 github.com/google/open-location-code/go v0.0.0-20190903173953-119bc96a3a51 github.com/gorilla/websocket v1.4.1 - github.com/iotaledger/autopeering-sim v0.0.0-20191127100001-7ff75c77f051 - github.com/iotaledger/hive.go v0.0.0-20191125115115-f88d4ecab6dd + github.com/iotaledger/autopeering-sim v0.0.0-20191202124431-1705dc628175 + github.com/iotaledger/hive.go v0.0.0-20191202111738-357cee7a1c37 github.com/iotaledger/iota.go v1.0.0-beta.10 github.com/labstack/echo v3.3.10+incompatible github.com/lucasb-eyer/go-colorful v1.0.3 // indirect @@ -30,8 +30,8 @@ require ( golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f // indirect golang.org/x/net v0.0.0-20191126235420-ef20fe5d7933 golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect - golang.org/x/sys v0.0.0-20191127021746-63cb32ae39b2 // indirect - golang.org/x/tools v0.0.0-20191127064951-724660f1afeb // indirect + golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9 // indirect + golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d // indirect golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 // indirect gopkg.in/yaml.v2 v2.2.7 // indirect ) diff --git a/go.sum b/go.sum index cb24f7c5..dce6a55c 100644 --- a/go.sum +++ b/go.sum @@ -93,27 +93,13 @@ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= -github.com/iotaledger/autopeering-sim v0.0.0-20191125082010-418faee91e5a h1:4/GYRv+ClV261Dq53B4toHbWq/mdzLEAPaZ9g9Ytio8= -github.com/iotaledger/autopeering-sim v0.0.0-20191125082010-418faee91e5a/go.mod h1:JiaqaxLkQVnd8e/sya9y/LlRW56WlRKRl2TQXQCVssI= -github.com/iotaledger/autopeering-sim v0.0.0-20191125182425-ba5a8313e083 h1:CZ0fRxEPIgzR3oUC0tNw0aNr2x0CPXSexZN0wCMRaDs= -github.com/iotaledger/autopeering-sim v0.0.0-20191125182425-ba5a8313e083/go.mod h1:JiaqaxLkQVnd8e/sya9y/LlRW56WlRKRl2TQXQCVssI= -github.com/iotaledger/autopeering-sim v0.0.0-20191125185303-6b5ef6b0dc7c h1:uHWtkHBSnkyuC7WzZaXTgwGs3pT3rM7nzKHCsmVS7pw= -github.com/iotaledger/autopeering-sim v0.0.0-20191125185303-6b5ef6b0dc7c/go.mod h1:JiaqaxLkQVnd8e/sya9y/LlRW56WlRKRl2TQXQCVssI= -github.com/iotaledger/autopeering-sim v0.0.0-20191125190556-b29181ff31e4 h1:4Uuow46qBpOd3JAivhNT26yifcKZYcOuD+AWGJzzu18= -github.com/iotaledger/autopeering-sim v0.0.0-20191125190556-b29181ff31e4/go.mod h1:JiaqaxLkQVnd8e/sya9y/LlRW56WlRKRl2TQXQCVssI= -github.com/iotaledger/autopeering-sim v0.0.0-20191126105507-9db87680fea0 h1:H/tSIRwKBpyEZwBCWJmashK0IlmoBSw7J3Kuk9bmiXw= -github.com/iotaledger/autopeering-sim v0.0.0-20191126105507-9db87680fea0/go.mod h1:JiaqaxLkQVnd8e/sya9y/LlRW56WlRKRl2TQXQCVssI= -github.com/iotaledger/autopeering-sim v0.0.0-20191126113046-8576d83d22f3 h1:85JvTkyY4n66Um+ZdjeMdMREup2tZo6uG1W5Qx9j8VQ= -github.com/iotaledger/autopeering-sim v0.0.0-20191126113046-8576d83d22f3/go.mod h1:JiaqaxLkQVnd8e/sya9y/LlRW56WlRKRl2TQXQCVssI= -github.com/iotaledger/autopeering-sim v0.0.0-20191126125252-956917114dee h1:LslhNxj2Jll9eVhbwIqM2ecfUmp1bNR106KlaxLUeFg= -github.com/iotaledger/autopeering-sim v0.0.0-20191126125252-956917114dee/go.mod h1:JiaqaxLkQVnd8e/sya9y/LlRW56WlRKRl2TQXQCVssI= -github.com/iotaledger/autopeering-sim v0.0.0-20191127100001-7ff75c77f051 h1:6JWvB/U6C2b92A5Bupnjj6J9KiO0i0AQHQ8RVmMagQo= -github.com/iotaledger/autopeering-sim v0.0.0-20191127100001-7ff75c77f051/go.mod h1:JiaqaxLkQVnd8e/sya9y/LlRW56WlRKRl2TQXQCVssI= +github.com/iotaledger/autopeering-sim v0.0.0-20191202124431-1705dc628175 h1:/RAxj+VEPTykp9cWRKTtydkfuBDaFemI7/bdNYCD7Nw= +github.com/iotaledger/autopeering-sim v0.0.0-20191202124431-1705dc628175/go.mod h1:JiaqaxLkQVnd8e/sya9y/LlRW56WlRKRl2TQXQCVssI= github.com/iotaledger/goshimmer v0.0.0-20191113134331-c2d1b2f9d533/go.mod h1:7vYiofXphp9+PkgVAEM0pvw3aoi4ksrZ7lrEgX50XHs= github.com/iotaledger/hive.go v0.0.0-20191118130432-89eebe8fe8eb h1:nuS/LETRJ8obUyBIZeyxeei0ZPlyOMj8YPziOgSM4Og= github.com/iotaledger/hive.go v0.0.0-20191118130432-89eebe8fe8eb/go.mod h1:1Thhlil4lHzuy53EVvmEbEvWBFY0Tasp4kCBfxBCPIk= -github.com/iotaledger/hive.go v0.0.0-20191125115115-f88d4ecab6dd h1:3tfMtDaByXXwx6jyPG1Qz8PtlN3YXc+3zLO2QRC7C9E= -github.com/iotaledger/hive.go v0.0.0-20191125115115-f88d4ecab6dd/go.mod h1:1Thhlil4lHzuy53EVvmEbEvWBFY0Tasp4kCBfxBCPIk= +github.com/iotaledger/hive.go v0.0.0-20191202111738-357cee7a1c37 h1:Vex6W5Oae7xXvVmnCrl7J4o+PCx0FW3paMzXxQDr8H4= +github.com/iotaledger/hive.go v0.0.0-20191202111738-357cee7a1c37/go.mod h1:1Thhlil4lHzuy53EVvmEbEvWBFY0Tasp4kCBfxBCPIk= github.com/iotaledger/iota.go v1.0.0-beta.7/go.mod h1:dMps6iMVU1pf5NDYNKIw4tRsPeC8W3ZWjOvYHOO1PMg= github.com/iotaledger/iota.go v1.0.0-beta.9 h1:c654s9pkdhMBkABUvWg+6k91MEBbdtmZXP1xDfQpajg= github.com/iotaledger/iota.go v1.0.0-beta.9/go.mod h1:F6WBmYd98mVjAmmPVYhnxg8NNIWCjjH8VWT9qvv3Rc8= @@ -287,8 +273,6 @@ golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 h1:k7pJ2yAPLPgbskkFdhRCsA77k golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191119073136-fc4aabc6c914 h1:MlY3mEfbnWGmUi4rtHOtNnnnN4UJRGSyLPx+DXA5Sq4= golang.org/x/net v0.0.0-20191119073136-fc4aabc6c914/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20191125084936-ffdde1057850 h1:Vq85/r8R9IdcUHmZ0/nQlUg1v15rzvQ2sHdnZAj/x7s= -golang.org/x/net v0.0.0-20191125084936-ffdde1057850/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191126235420-ef20fe5d7933 h1:e6HwijUxhDe+hPNjZQQn9bA5PW3vNmnN64U2ZW759Lk= golang.org/x/net v0.0.0-20191126235420-ef20fe5d7933/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -320,8 +304,8 @@ golang.org/x/sys v0.0.0-20191018095205-727590c5006e h1:ZtoklVMHQy6BFRHkbG6JzK+S6 golang.org/x/sys v0.0.0-20191018095205-727590c5006e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e h1:N7DeIrjYszNmSW409R3frPPwglRwMkXSBzwVbkOjLLA= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191127021746-63cb32ae39b2 h1:/J2nHFg1MTqaRLFO7M+J78ASNsJoz3r0cvHBPQ77fsE= -golang.org/x/sys v0.0.0-20191127021746-63cb32ae39b2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9 h1:ZBzSG/7F4eNKz2L3GE9o300RX0Az1Bw5HF7PDraD+qU= +golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= @@ -335,17 +319,9 @@ golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191121040551-947d4aa89328 h1:t3X42h9e6xdbrCD/gPyWqAXr2BEpdJqRd1brThaaxII= golang.org/x/tools v0.0.0-20191121040551-947d4aa89328/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191125011157-cc15fab314e3 h1:aHkNOJLg6a84bdLJN1yjqMSTadeAuaudhEPNSkLAWoA= -golang.org/x/tools v0.0.0-20191125011157-cc15fab314e3/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191125180314-a99e43fcffb7 h1:+R9+VCIcEYiZ7t1BAjuRV+y0mBc7kH/pLO8D3NdKXJY= -golang.org/x/tools v0.0.0-20191125180314-a99e43fcffb7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191125182823-acc15743c3f6 h1:Gf5uAD3vrwHdZZsPCuRG2v1g2pX8ClixhrwqxTJ9QQ0= -golang.org/x/tools v0.0.0-20191125182823-acc15743c3f6/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191126055441-b0650ceb63d9 h1:m9xhlkk2j+sO9WjAgNfTtl505MN7ZkuW69nOcBlp9qY= -golang.org/x/tools v0.0.0-20191126055441-b0650ceb63d9/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191127064951-724660f1afeb h1:K4JMHRJSgd1q/yXZNrKKyneQJcLm1rn7JsokEs/xE9I= -golang.org/x/tools v0.0.0-20191127064951-724660f1afeb/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d h1:/iIZNFGxc/a7C3yWjGcnboV+Tkc7mxr+p6fDztwoxuM= +golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA= diff --git a/plugins/analysis/client/plugin.go b/plugins/analysis/client/plugin.go index 3d000846..32bc5cea 100644 --- a/plugins/analysis/client/plugin.go +++ b/plugins/analysis/client/plugin.go @@ -5,10 +5,6 @@ import ( "net" "time" - "github.com/iotaledger/hive.go/daemon" - "github.com/iotaledger/hive.go/logger" - "github.com/iotaledger/hive.go/parameter" - "github.com/iotaledger/autopeering-sim/discover" "github.com/iotaledger/autopeering-sim/selection" "github.com/iotaledger/goshimmer/packages/network" @@ -20,8 +16,11 @@ import ( "github.com/iotaledger/goshimmer/plugins/analysis/types/removenode" "github.com/iotaledger/goshimmer/plugins/autopeering" "github.com/iotaledger/goshimmer/plugins/autopeering/local" + "github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/logger" "github.com/iotaledger/hive.go/node" + "github.com/iotaledger/hive.go/parameter" ) var log = logger.NewLogger("Analysis-Client") diff --git a/plugins/autopeering/autopeering.go b/plugins/autopeering/autopeering.go index 46b38a70..526b9295 100644 --- a/plugins/autopeering/autopeering.go +++ b/plugins/autopeering/autopeering.go @@ -12,6 +12,7 @@ import ( "github.com/iotaledger/autopeering-sim/discover" "github.com/iotaledger/autopeering-sim/logger" "github.com/iotaledger/autopeering-sim/peer" + "github.com/iotaledger/autopeering-sim/peer/service" "github.com/iotaledger/autopeering-sim/selection" "github.com/iotaledger/autopeering-sim/server" "github.com/iotaledger/autopeering-sim/transport" @@ -56,27 +57,22 @@ func start() { ) host := parameter.NodeConfig.GetString(CFG_ADDRESS) - localhost := host + //localhost := host apPort := strconv.Itoa(parameter.NodeConfig.GetInt(CFG_PORT)) gossipPort := strconv.Itoa(parameter.NodeConfig.GetInt(gossip.GOSSIP_PORT)) - var externalAddr *string if host == "0.0.0.0" { host = getMyIP() - hostPort := host + ":" + apPort - externalAddr = &hostPort } + listenAddr := host + ":" + apPort gossipAddr := host + ":" + gossipPort - outboundSelectionDisabled := !parameter.NodeConfig.GetBool(CFG_SEND_REQUESTS) - inboundSelectionDisabled := !parameter.NodeConfig.GetBool(CFG_ACCEPT_REQUESTS) - logger := logger.NewLogger(defaultZLC, debugLevel) defer func() { _ = logger.Sync() }() // ignore the returned error - addr, err := net.ResolveUDPAddr("udp", localhost+":"+apPort) + addr, err := net.ResolveUDPAddr("udp", host+":"+apPort) if err != nil { log.Fatalf("ResolveUDPAddr: %v", err) } @@ -101,30 +97,30 @@ func start() { // create a new local node db := peer.NewPersistentDB(logger.Named("db")) defer db.Close() - local.INSTANCE, err = peer.NewLocal(db) + local.INSTANCE, err = peer.NewLocal("udp", listenAddr, db) if err != nil { log.Fatalf("ListenUDP: %v", err) } - // add a service for the peering - local.INSTANCE.Services()["peering"] = peer.NetworkAddress{Network: "udp", Address: listenAddr} + // add a service for the gossip - local.INSTANCE.Services()["gossip"] = peer.NetworkAddress{Network: "tcp", Address: gossipAddr} + local.INSTANCE.UpdateService(service.GossipKey, &networkAddress{"tcp", gossipAddr}) + log.Debug("Local Services:", local.INSTANCE.Services().CreateRecord().String()) Discovery = discover.New(local.INSTANCE, discover.Config{ Log: logger.Named("disc"), MasterPeers: masterPeers, }) + //if parameter.NodeConfig.GetBool(CFG_SELECTION) { Selection = selection.New(local.INSTANCE, Discovery, selection.Config{ Log: logger.Named("sel"), Param: &selection.Parameters{ - OutboundSelectionDisabled: outboundSelectionDisabled, - InboundSelectionDisabled: inboundSelectionDisabled, - RequiredService: []string{"gossip"}, + SaltLifetime: selection.DefaultSaltLifetime, + // RequiredService: []string{"gossip"}, }, }) // start a server doing discovery and peering - srv = server.Listen(local.INSTANCE, trans, externalAddr, logger.Named("srv"), Discovery, Selection) + srv = server.Listen(local.INSTANCE, trans, logger.Named("srv"), Discovery, Selection) defer srv.Close() // start the discovery on that connection @@ -132,12 +128,13 @@ func start() { defer Discovery.Close() // start the peering on that connection - Selection.Start(srv) - defer Selection.Close() + if parameter.NodeConfig.GetBool(CFG_SELECTION) { + Selection.Start(srv) + defer Selection.Close() + } id := base64.StdEncoding.EncodeToString(local.INSTANCE.PublicKey()) - a, b, _ := net.SplitHostPort(srv.LocalAddr()) - logger.Info("Discovery protocol started: ID="+id+", address="+srv.LocalAddr(), a, b) + logger.Info("Discovery protocol started: ID=" + id + ", address=" + srv.LocalAddr()) go func() { for t := range time.NewTicker(2 * time.Second).C { @@ -169,9 +166,28 @@ func printReport(log *zap.SugaredLogger) { return } knownPeers := Discovery.GetVerifiedPeers() - incoming := Selection.GetIncomingNeighbors() - outgoing := Selection.GetOutgoingNeighbors() + incoming := []*peer.Peer{} + outgoing := []*peer.Peer{} + if Selection != nil { + incoming = Selection.GetIncomingNeighbors() + outgoing = Selection.GetOutgoingNeighbors() + } log.Info("Known peers:", len(knownPeers)) - log.Info("Chosen:", len(outgoing), outgoing) - log.Info("Accepted:", len(incoming), incoming) + log.Info("Chosen:", len(outgoing)) + log.Info("Accepted:", len(incoming)) +} + +type networkAddress struct { + network string + address string +} + +// Network returns the service's network name. +func (a *networkAddress) Network() string { + return a.network +} + +// String returns the service's address in string form. +func (a *networkAddress) String() string { + return a.address } diff --git a/plugins/autopeering/entrynodes.go b/plugins/autopeering/entrynodes.go index 836903f2..0dc48627 100644 --- a/plugins/autopeering/entrynodes.go +++ b/plugins/autopeering/entrynodes.go @@ -5,6 +5,7 @@ import ( "strings" "github.com/iotaledger/autopeering-sim/peer" + "github.com/iotaledger/autopeering-sim/peer/service" "github.com/iotaledger/goshimmer/packages/errors" "github.com/iotaledger/hive.go/parameter" ) @@ -24,7 +25,10 @@ func parseEntryNodes() (result []*peer.Peer, err error) { return nil, errors.Wrap(err, "parseMaster") } - result = append(result, peer.NewPeer(pubKey, parts[1])) + services := service.New() + services.Update(service.PeeringKey, "udp", parts[1]) + + result = append(result, peer.NewPeer(pubKey, services)) } return result, nil diff --git a/plugins/autopeering/parameters.go b/plugins/autopeering/parameters.go index 63da5d3e..fdbe32a0 100644 --- a/plugins/autopeering/parameters.go +++ b/plugins/autopeering/parameters.go @@ -5,17 +5,15 @@ import ( ) const ( - CFG_ADDRESS = "autopeering.address" - CFG_ENTRY_NODES = "autopeering.entryNodes" - CFG_PORT = "autopeering.port" - CFG_ACCEPT_REQUESTS = "autopeering.acceptRequests" - CFG_SEND_REQUESTS = "autopeering.sendRequests" + CFG_ADDRESS = "autopeering.address" + CFG_ENTRY_NODES = "autopeering.entryNodes" + CFG_PORT = "autopeering.port" + CFG_SELECTION = "autopeering.selection" ) func init() { flag.String(CFG_ADDRESS, "0.0.0.0", "address to bind for incoming peering requests") - flag.String(CFG_ENTRY_NODES, "7f7a876a4236091257e650da8dcf195fbe3cb625@159.69.158.51:14626", "list of trusted entry nodes for auto peering") + flag.String(CFG_ENTRY_NODES, "pub_Key@127.0.0.1:14626", "list of trusted entry nodes for auto peering") flag.Int(CFG_PORT, 14626, "udp port for incoming peering requests") - flag.Bool(CFG_ACCEPT_REQUESTS, true, "accept incoming autopeering requests") - flag.Bool(CFG_SEND_REQUESTS, true, "send autopeering requests") + flag.Bool(CFG_SELECTION, true, "enable peer selection") } diff --git a/plugins/autopeering/plugin.go b/plugins/autopeering/plugin.go index 3ebd4a00..04f54e7f 100644 --- a/plugins/autopeering/plugin.go +++ b/plugins/autopeering/plugin.go @@ -4,6 +4,7 @@ import ( "net" "github.com/iotaledger/autopeering-sim/discover" + "github.com/iotaledger/autopeering-sim/peer/service" "github.com/iotaledger/autopeering-sim/selection" "github.com/iotaledger/goshimmer/plugins/gossip" "github.com/iotaledger/hive.go/daemon" @@ -29,24 +30,34 @@ func run(plugin *node.Plugin) { func configureLogging(plugin *node.Plugin) { gossip.Events.RemoveNeighbor.Attach(events.NewClosure(func(peer *gossip.Neighbor) { - Selection.DropPeer(peer.Peer) + if Selection != nil { + Selection.DropPeer(peer.Peer) + } })) selection.Events.Dropped.Attach(events.NewClosure(func(ev *selection.DroppedEvent) { - log.Debug("neighbor removed: " + ev.DroppedID.String()) + log.Info("neighbor removed: " + ev.DroppedID.String()) gossip.RemoveNeighbor(ev.DroppedID.String()) })) selection.Events.IncomingPeering.Attach(events.NewClosure(func(ev *selection.PeeringEvent) { - log.Debug("accepted neighbor added: " + ev.Peer.Address() + " / " + ev.Peer.String()) - address, port, _ := net.SplitHostPort(ev.Services["gossip"].Address) - gossip.AddNeighbor(gossip.NewNeighbor(ev.Peer, address, port)) + log.Info("accepted neighbor added: " + ev.Peer.Address() + " / " + ev.Peer.String()) + log.Info("services: " + ev.Peer.Services().CreateRecord().String()) + gossipService := ev.Peer.Services().Get(service.GossipKey) + if gossipService != nil { + address, port, _ := net.SplitHostPort(ev.Peer.Services().Get(service.GossipKey).String()) + gossip.AddNeighbor(gossip.NewNeighbor(ev.Peer, address, port)) + } })) selection.Events.OutgoingPeering.Attach(events.NewClosure(func(ev *selection.PeeringEvent) { - log.Debug("chosen neighbor added: " + ev.Peer.Address() + " / " + ev.Peer.String()) - address, port, _ := net.SplitHostPort(ev.Services["gossip"].Address) - gossip.AddNeighbor(gossip.NewNeighbor(ev.Peer, address, port)) + log.Info("chosen neighbor added: " + ev.Peer.Address() + " / " + ev.Peer.String()) + log.Info("services: " + ev.Peer.Services().CreateRecord().String()) + gossipService := ev.Peer.Services().Get(service.GossipKey) + if gossipService != nil { + address, port, _ := net.SplitHostPort(ev.Peer.Services().Get(service.GossipKey).String()) + gossip.AddNeighbor(gossip.NewNeighbor(ev.Peer, address, port)) + } })) discover.Events.PeerDiscovered.Attach(events.NewClosure(func(ev *discover.DiscoveredEvent) { diff --git a/plugins/cli/cli.go b/plugins/cli/cli.go index 104d1d44..39ea901f 100644 --- a/plugins/cli/cli.go +++ b/plugins/cli/cli.go @@ -7,9 +7,8 @@ import ( "sort" "strings" - flag "github.com/spf13/pflag" - "github.com/iotaledger/hive.go/node" + flag "github.com/spf13/pflag" ) var enabledPlugins []string @@ -44,5 +43,5 @@ func printUsage() { fmt.Fprintf(os.Stderr, "\nThe following plugins are enabled by default and can be disabled with -%s:\n %s\n", node.CFG_DISABLE_PLUGINS, getList(enabledPlugins)) fmt.Fprintf(os.Stderr, "The following plugins are disabled by default and can be enabled with -%s:\n %s\n", node.CFG_ENABLE_PLUGINS, getList(disabledPlugins)) - fmt.Fprintf(os.Stderr, "The enabled/disabled plugins can be overriden by altering %s/%s inside config.json\n\n", node.CFG_ENABLE_PLUGINS, node.CFG_DISABLE_PLUGINS) + fmt.Fprintf(os.Stderr, "The enabled/disabled plugins can be overridden by altering %s/%s inside config.json\n\n", node.CFG_ENABLE_PLUGINS, node.CFG_DISABLE_PLUGINS) } diff --git a/plugins/dashboard/plugin.go b/plugins/dashboard/plugin.go index a5815826..64f6e69c 100644 --- a/plugins/dashboard/plugin.go +++ b/plugins/dashboard/plugin.go @@ -1,7 +1,6 @@ package dashboard import ( - "github.com/iotaledger/hive.go/logger" "net/http" "time" @@ -10,6 +9,7 @@ import ( "github.com/iotaledger/goshimmer/plugins/metrics" "github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/logger" "github.com/iotaledger/hive.go/node" ) diff --git a/plugins/dashboard/tps.go b/plugins/dashboard/tps.go index 3a20bbb3..6f6710bd 100644 --- a/plugins/dashboard/tps.go +++ b/plugins/dashboard/tps.go @@ -69,10 +69,23 @@ func GetStatus() *Status { } uptime += fmt.Sprintf("%02ds ", int(duration.Seconds())%60) + outgoing := "0" + incoming := "0" + neighbors := "0" + if autopeering.Selection != nil { + outgoing = strconv.Itoa(len(autopeering.Selection.GetOutgoingNeighbors())) + incoming = strconv.Itoa(len(autopeering.Selection.GetIncomingNeighbors())) + neighbors = strconv.Itoa(len(autopeering.Selection.GetNeighbors())) + } + knownPeers := "0" + if autopeering.Discovery != nil { + knownPeers = strconv.Itoa(len(autopeering.Discovery.GetVerifiedPeers())) + } + return &Status{ Id: local.INSTANCE.ID().String(), - Neighbor: "Neighbors: " + strconv.Itoa(len(autopeering.Selection.GetOutgoingNeighbors())) + " chosen / " + strconv.Itoa(len(autopeering.Selection.GetIncomingNeighbors())) + " accepted / " + strconv.Itoa(len(autopeering.Selection.GetNeighbors())) + " total", - KnownPeer: "Known Peers: " + strconv.Itoa(len(autopeering.Discovery.GetVerifiedPeers())) + " total", + Neighbor: "Neighbors: " + outgoing + " chosen / " + incoming + " accepted / " + neighbors + " total", + KnownPeer: "Known Peers: " + knownPeers + " total", Uptime: uptime, } } diff --git a/plugins/ui/logger.go b/plugins/ui/logger.go index b34519ce..a4653aac 100644 --- a/plugins/ui/logger.go +++ b/plugins/ui/logger.go @@ -1,9 +1,10 @@ package ui import ( - "github.com/iotaledger/hive.go/logger" "sync" "time" + + "github.com/iotaledger/hive.go/logger" ) var logMutex = sync.Mutex{} diff --git a/plugins/ui/nodeInfo.go b/plugins/ui/nodeInfo.go index 70f25317..c23b2544 100644 --- a/plugins/ui/nodeInfo.go +++ b/plugins/ui/nodeInfo.go @@ -39,11 +39,19 @@ func gatherInfo() nodeInfo { // update neighbors chosenNeighbors := []string{} acceptedNeighbors := []string{} - for _, peer := range autopeering.Selection.GetOutgoingNeighbors() { - chosenNeighbors = append(chosenNeighbors, peer.String()) + neighbors := 0 + knownPeers := 0 + if autopeering.Selection != nil { + for _, peer := range autopeering.Selection.GetOutgoingNeighbors() { + chosenNeighbors = append(chosenNeighbors, peer.String()) + } + for _, peer := range autopeering.Selection.GetIncomingNeighbors() { + acceptedNeighbors = append(acceptedNeighbors, peer.String()) + } + neighbors = len(chosenNeighbors) + len(acceptedNeighbors) } - for _, peer := range autopeering.Selection.GetIncomingNeighbors() { - acceptedNeighbors = append(acceptedNeighbors, peer.String()) + if autopeering.Discovery != nil { + knownPeers = len(autopeering.Discovery.GetVerifiedPeers()) } receivedTps, solidTps := updateTpsCounters() @@ -52,8 +60,8 @@ func gatherInfo() nodeInfo { ID: local.INSTANCE.ID().String(), ChosenNeighbors: chosenNeighbors, AcceptedNeighbors: acceptedNeighbors, - KnownPeersSize: len(autopeering.Discovery.GetVerifiedPeers()), //knownpeers.INSTANCE.Peers.Len(), - NeighborhoodSize: len(autopeering.Selection.GetNeighbors()), //neighborhood.INSTANCE.Peers.Len(), + KnownPeersSize: knownPeers, + NeighborhoodSize: neighbors, Uptime: uint64(duration), ReceivedTps: receivedTps, SolidTps: solidTps, diff --git a/plugins/ui/ui.go b/plugins/ui/ui.go index f4e5afad..2bc5d365 100644 --- a/plugins/ui/ui.go +++ b/plugins/ui/ui.go @@ -1,7 +1,6 @@ package ui import ( - "github.com/iotaledger/hive.go/logger" "net/http" "strings" "sync/atomic" @@ -14,6 +13,7 @@ import ( "github.com/iotaledger/goshimmer/plugins/webapi" "github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/logger" "github.com/iotaledger/hive.go/node" "github.com/labstack/echo" -- GitLab