diff --git a/.gitignore b/.gitignore index a18828787a58e5c0fc77d0e557d946f67e720faa..217c41d974ce6dbd54b2cab04fdef4b7570615a0 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ # Logs logs/* +testNodes/* # Project files .idea diff --git a/go.mod b/go.mod index d7079bdf9d3904bccd4f85ec3508960b1dc6d91e..e73cf08c67aa249e619dcb5730e4eaaca8f94d8f 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ 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-20191121125328-c607091f6bc8 + github.com/iotaledger/autopeering-sim v0.0.0-20191125082010-418faee91e5a github.com/iotaledger/hive.go v0.0.0-20191118130432-89eebe8fe8eb github.com/iotaledger/iota.go v1.0.0-beta.10 github.com/labstack/echo v3.3.10+incompatible @@ -19,10 +19,12 @@ require ( 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-20191018125527-685bf6da76c2 + github.com/rivo/tview v0.0.0-20191121195645-2d957c4be01d github.com/valyala/fasttemplate v1.1.0 // indirect + go.uber.org/zap v1.13.0 golang.org/x/crypto v0.0.0-20191119213627-4f8c1d86b1ba - golang.org/x/net v0.0.0-20191119073136-fc4aabc6c914 + 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 ) diff --git a/go.sum b/go.sum index bbfbf8db7374a86caf894ef0032f43d4d28a3834..be5fc55b1d4939d3a55d4cf1de236013d38743fb 100644 --- a/go.sum +++ b/go.sum @@ -94,6 +94,18 @@ github.com/iotaledger/autopeering-sim v0.0.0-20191121112351-05d62de2edf2 h1:CGGJ github.com/iotaledger/autopeering-sim v0.0.0-20191121112351-05d62de2edf2/go.mod h1:JiaqaxLkQVnd8e/sya9y/LlRW56WlRKRl2TQXQCVssI= github.com/iotaledger/autopeering-sim v0.0.0-20191121125328-c607091f6bc8 h1:4G8MSFJhykckV4n5nQ48lx/qg3sf4MqHP6X4yoii2sc= github.com/iotaledger/autopeering-sim v0.0.0-20191121125328-c607091f6bc8/go.mod h1:JiaqaxLkQVnd8e/sya9y/LlRW56WlRKRl2TQXQCVssI= +github.com/iotaledger/autopeering-sim v0.0.0-20191121203423-98315403e684 h1:+zVGrC8o9/UrCZvmwgi5sUIgN7UeBWufowRX/ATGS3Q= +github.com/iotaledger/autopeering-sim v0.0.0-20191121203423-98315403e684/go.mod h1:JiaqaxLkQVnd8e/sya9y/LlRW56WlRKRl2TQXQCVssI= +github.com/iotaledger/autopeering-sim v0.0.0-20191122094050-3251b06f764a h1:GayngK7kqD+Xw1+jVTVn0MCkwsdeURcNvXTqPfA07Cg= +github.com/iotaledger/autopeering-sim v0.0.0-20191122094050-3251b06f764a/go.mod h1:JiaqaxLkQVnd8e/sya9y/LlRW56WlRKRl2TQXQCVssI= +github.com/iotaledger/autopeering-sim v0.0.0-20191122165813-905dac7a7390 h1:mBRYX/C8/BR9dTw4Jkgw7HyvYUB50jLYW1LaAG7kXg0= +github.com/iotaledger/autopeering-sim v0.0.0-20191122165813-905dac7a7390/go.mod h1:JiaqaxLkQVnd8e/sya9y/LlRW56WlRKRl2TQXQCVssI= +github.com/iotaledger/autopeering-sim v0.0.0-20191122182429-a6129bebaa09 h1:97V2yiOqnz5u8+8g2yPuoet5BFt1gOXnXWTRPb7I2Cg= +github.com/iotaledger/autopeering-sim v0.0.0-20191122182429-a6129bebaa09/go.mod h1:JiaqaxLkQVnd8e/sya9y/LlRW56WlRKRl2TQXQCVssI= +github.com/iotaledger/autopeering-sim v0.0.0-20191122190327-b1fcfa1bf02b h1:ri8xe7feJk9GzT4c4HCy2SqBTb6fWoGzZ2aRMU3LjSk= +github.com/iotaledger/autopeering-sim v0.0.0-20191122190327-b1fcfa1bf02b/go.mod h1:JiaqaxLkQVnd8e/sya9y/LlRW56WlRKRl2TQXQCVssI= +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/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= @@ -159,6 +171,8 @@ github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40T github.com/rivo/tview v0.0.0-20190829161255-f8bc69b90341/go.mod h1:+rKjP5+h9HMwWRpAfhIkkQ9KE3m3Nz5rwn7YtUpwgqk= github.com/rivo/tview v0.0.0-20191018125527-685bf6da76c2 h1:GVXSfgXOMAeLvFH7IrpY3yYM8H3YekZEFcZ14q9gQXM= github.com/rivo/tview v0.0.0-20191018125527-685bf6da76c2/go.mod h1:/rBeY22VG2QprWnEqG57IBC8biVu3i0DOIjRLc9I8H0= +github.com/rivo/tview v0.0.0-20191121195645-2d957c4be01d h1:dPWYyMzc2VB5XX7eA/Pe5TXBGzhlVZZr54GhRJLTbts= +github.com/rivo/tview v0.0.0-20191121195645-2d957c4be01d/go.mod h1:/rBeY22VG2QprWnEqG57IBC8biVu3i0DOIjRLc9I8H0= github.com/rivo/uniseg v0.0.0-20190513083848-b9f5b9457d44/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= @@ -237,6 +251,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL 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-20191124235446-72fef5d5e266 h1:QuOiA7GCO0OSDzlNlFyOWOywDsjuzW8M2yvBfCqw+cY= +golang.org/x/net v0.0.0-20191124235446-72fef5d5e266/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -277,6 +293,14 @@ 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-20191122080028-f774e2e2e5be h1:6d2MOtryvuMarrCTOqjhCZCVONST5uq4zNzBWKxzOls= +golang.org/x/tools v0.0.0-20191122080028-f774e2e2e5be/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191122161556-0ae87fff1b85 h1:T0S3IX2zGoozKqzqe8CQZRrJooHPr2aV/HmirRBwnRM= +golang.org/x/tools v0.0.0-20191122161556-0ae87fff1b85/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191122182703-035a8167be0b h1:CeeSPSpqT/6nJ9vHD7VQV5SkrnGMNnpYtwYajVX+29I= +golang.org/x/tools v0.0.0-20191122182703-035a8167be0b/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/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/packages/accountability/accountability.go b/packages/accountability/accountability.go deleted file mode 100644 index 6eff4ddd1e69e85654f87b127cb596ae7a77e3a1..0000000000000000000000000000000000000000 --- a/packages/accountability/accountability.go +++ /dev/null @@ -1,59 +0,0 @@ -package accountability - -import ( - "sync" - - "github.com/dgraph-io/badger" - "github.com/iotaledger/goshimmer/packages/identity" - "github.com/iotaledger/goshimmer/packages/settings" -) - -// Name of the key under which the node identity is stored. -const identityKey = "IDENTITY" - -var ownId *identity.Identity -var lazyInit sync.Once - -func OwnId() *identity.Identity { - lazyInit.Do(initOwnId) - - return ownId -} - -func initOwnId() { - ownId = getIdentity() -} - -func generateNewIdentity() *identity.Identity { - - newIdentity := identity.GeneratePrivateIdentity() - - key := []byte(identityKey) - value := newIdentity.Marshal() - - if err := settings.Set(key, value); err != nil { - panic(err) - } - - return newIdentity -} - -func getIdentity() *identity.Identity { - key := []byte(identityKey) - - value, err := settings.Get(key) - if err != nil { - if err == badger.ErrKeyNotFound { - return generateNewIdentity() - } else { - panic(err) - } - } - - result, err := identity.Unmarshal(value) - if err != nil { - panic(err) - } - - return result -} diff --git a/plugins/analysis/client/plugin.go b/plugins/analysis/client/plugin.go index fa7099e65250f83acc62b113f98ba9d41b739b8d..43e277e01af2f5c67b2b555ee4689f8cd0ab26e5 100644 --- a/plugins/analysis/client/plugin.go +++ b/plugins/analysis/client/plugin.go @@ -1,12 +1,12 @@ package client import ( + "encoding/hex" "net" "time" "github.com/iotaledger/autopeering-sim/discover" "github.com/iotaledger/autopeering-sim/selection" - "github.com/iotaledger/goshimmer/packages/accountability" "github.com/iotaledger/goshimmer/packages/daemon" "github.com/iotaledger/goshimmer/packages/network" "github.com/iotaledger/goshimmer/packages/node" @@ -15,10 +15,16 @@ import ( "github.com/iotaledger/goshimmer/plugins/analysis/types/connectnodes" "github.com/iotaledger/goshimmer/plugins/analysis/types/disconnectnodes" "github.com/iotaledger/goshimmer/plugins/analysis/types/ping" + "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/events" ) +var debug *node.Plugin + func Run(plugin *node.Plugin) { + debug = plugin daemon.BackgroundWorker("Analysis Client", func() { shuttingDown := false @@ -37,7 +43,7 @@ func Run(plugin *node.Plugin) { eventDispatchers := getEventDispatchers(managedConn) reportCurrentStatus(eventDispatchers) - setupHooks(managedConn, eventDispatchers) + setupHooks(plugin, managedConn, eventDispatchers) shuttingDown = keepConnectionAlive(managedConn) } @@ -49,46 +55,72 @@ func Run(plugin *node.Plugin) { func getEventDispatchers(conn *network.ManagedConnection) *EventDispatchers { return &EventDispatchers{ AddNode: func(nodeId []byte) { - conn.Write((&addnode.Packet{NodeId: nodeId}).Marshal()) + _, err := conn.Write((&addnode.Packet{NodeId: nodeId}).Marshal()) + if err != nil { + debug.LogFailure(err.Error()) + } + }, + RemoveNode: func(nodeId []byte) { + _, err := conn.Write((&removenode.Packet{NodeId: nodeId}).Marshal()) + if err != nil { + debug.LogFailure(err.Error()) + } }, ConnectNodes: func(sourceId []byte, targetId []byte) { - conn.Write((&connectnodes.Packet{SourceId: sourceId, TargetId: targetId}).Marshal()) + _, err := conn.Write((&connectnodes.Packet{SourceId: sourceId, TargetId: targetId}).Marshal()) + if err != nil { + debug.LogFailure(err.Error()) + } }, DisconnectNodes: func(sourceId []byte, targetId []byte) { - conn.Write((&disconnectnodes.Packet{SourceId: sourceId, TargetId: targetId}).Marshal()) + _, err := conn.Write((&disconnectnodes.Packet{SourceId: sourceId, TargetId: targetId}).Marshal()) + if err != nil { + debug.LogFailure(err.Error()) + } }, } } func reportCurrentStatus(eventDispatchers *EventDispatchers) { - eventDispatchers.AddNode(accountability.OwnId().Identifier.Bytes()) + if local.INSTANCE != nil { + eventDispatchers.AddNode(local.INSTANCE.ID().Bytes()) + } reportChosenNeighbors(eventDispatchers) } -func setupHooks(conn *network.ManagedConnection, eventDispatchers *EventDispatchers) { +func setupHooks(plugin *node.Plugin, conn *network.ManagedConnection, eventDispatchers *EventDispatchers) { // define hooks //////////////////////////////////////////////////////////////////////////////////////////////////// onDiscoverPeer := events.NewClosure(func(ev *discover.DiscoveredEvent) { - go eventDispatchers.AddNode(ev.Peer.ID().Bytes()) + plugin.LogInfo("onDiscoverPeer: " + hex.EncodeToString(ev.Peer.ID().Bytes())) + eventDispatchers.AddNode(ev.Peer.ID().Bytes()) + }) + + onDeletePeer := events.NewClosure(func(ev *discover.DeletedEvent) { + plugin.LogInfo("onDeletePeer: " + hex.EncodeToString(ev.Peer.ID().Bytes())) + eventDispatchers.RemoveNode(ev.Peer.ID().Bytes()) }) onAddAcceptedNeighbor := events.NewClosure(func(ev *selection.PeeringEvent) { - eventDispatchers.ConnectNodes(ev.Peer.ID().Bytes(), accountability.OwnId().Identifier.Bytes()) + plugin.LogInfo("onAddAcceptedNeighbor: " + hex.EncodeToString(ev.Peer.ID().Bytes()) + " - " + hex.EncodeToString(local.INSTANCE.ID().Bytes())) + eventDispatchers.ConnectNodes(ev.Peer.ID().Bytes(), local.INSTANCE.ID().Bytes()) }) onRemoveNeighbor := events.NewClosure(func(ev *selection.DroppedEvent) { - eventDispatchers.DisconnectNodes(ev.DroppedID.Bytes(), accountability.OwnId().Identifier.Bytes()) - eventDispatchers.DisconnectNodes(accountability.OwnId().Identifier.Bytes(), ev.DroppedID.Bytes()) + plugin.LogInfo("onRemoveNeighbor: " + hex.EncodeToString(ev.DroppedID.Bytes()) + " - " + hex.EncodeToString(local.INSTANCE.ID().Bytes())) + eventDispatchers.DisconnectNodes(ev.DroppedID.Bytes(), local.INSTANCE.ID().Bytes()) }) onAddChosenNeighbor := events.NewClosure(func(ev *selection.PeeringEvent) { - eventDispatchers.ConnectNodes(accountability.OwnId().Identifier.Bytes(), ev.Peer.ID().Bytes()) + plugin.LogInfo("onAddChosenNeighbor: " + hex.EncodeToString(local.INSTANCE.ID().Bytes()) + " - " + hex.EncodeToString(ev.Peer.ID().Bytes())) + eventDispatchers.ConnectNodes(local.INSTANCE.ID().Bytes(), ev.Peer.ID().Bytes()) }) // setup hooks ///////////////////////////////////////////////////////////////////////////////////////////////////// discover.Events.PeerDiscovered.Attach(onDiscoverPeer) + discover.Events.PeerDeleted.Attach(onDeletePeer) selection.Events.IncomingPeering.Attach(onAddAcceptedNeighbor) selection.Events.OutgoingPeering.Attach(onAddChosenNeighbor) selection.Events.Dropped.Attach(onRemoveNeighbor) @@ -108,12 +140,12 @@ func setupHooks(conn *network.ManagedConnection, eventDispatchers *EventDispatch } func reportChosenNeighbors(dispatchers *EventDispatchers) { - // for _, chosenNeighbor := range chosenneighbors.INSTANCE.Peers.GetMap() { - // dispatchers.AddNode(chosenNeighbor.GetIdentity().Identifier) - // } - // for _, chosenNeighbor := range chosenneighbors.INSTANCE.Peers.GetMap() { - // dispatchers.ConnectNodes(accountability.OwnId().Identifier, chosenNeighbor.GetIdentity().Identifier) - // } + if autopeering.Selection != nil { + for _, chosenNeighbor := range autopeering.Selection.GetOutgoingNeighbors() { + dispatchers.AddNode(chosenNeighbor.ID().Bytes()) + dispatchers.ConnectNodes(local.INSTANCE.ID().Bytes(), chosenNeighbor.ID().Bytes()) + } + } } func keepConnectionAlive(conn *network.ManagedConnection) bool { diff --git a/plugins/analysis/client/types.go b/plugins/analysis/client/types.go index 1af7c8f102f699a3268ae78cc1c810918a7b8958..dabbb160013a8823d2bcb0b2c8d87dfe97834d15 100644 --- a/plugins/analysis/client/types.go +++ b/plugins/analysis/client/types.go @@ -2,6 +2,7 @@ package client type EventDispatchers struct { AddNode func(nodeId []byte) + RemoveNode func(nodeId []byte) ConnectNodes func(sourceId []byte, targetId []byte) DisconnectNodes func(sourceId []byte, targetId []byte) } diff --git a/plugins/analysis/server/plugin.go b/plugins/analysis/server/plugin.go index 36b8670843301df53fe39bc011c7e6a276d7a4a3..b34f5a29bc66586c03663fe3ac5182c5e2ec27fb 100644 --- a/plugins/analysis/server/plugin.go +++ b/plugins/analysis/server/plugin.go @@ -6,7 +6,6 @@ import ( "strconv" "github.com/iotaledger/goshimmer/packages/daemon" - "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/packages/network" "github.com/iotaledger/goshimmer/packages/network/tcp" "github.com/iotaledger/goshimmer/packages/node" @@ -15,12 +14,16 @@ import ( "github.com/iotaledger/goshimmer/plugins/analysis/types/disconnectnodes" "github.com/iotaledger/goshimmer/plugins/analysis/types/ping" "github.com/iotaledger/goshimmer/plugins/analysis/types/removenode" + "github.com/iotaledger/hive.go/events" "github.com/pkg/errors" ) var server *tcp.Server +var debug *node.Plugin + func Configure(plugin *node.Plugin) { + debug = plugin server = tcp.NewServer() server.Events.Connect.Attach(events.NewClosure(HandleConnection)) @@ -153,7 +156,7 @@ func processIncomingPacket(connectionState *byte, receiveBuffer *[]byte, conn *n processIncomingDisconnectNodesPacket(connectionState, receiveBuffer, conn, data, offset, connectedNodeId) case STATE_REMOVE_NODE: - processIncomingAddNodePacket(connectionState, receiveBuffer, conn, data, offset, connectedNodeId) + processIncomingRemoveNodePacket(connectionState, receiveBuffer, conn, data, offset, connectedNodeId) } } @@ -309,3 +312,32 @@ func processIncomingDisconnectNodesPacket(connectionState *byte, receiveBuffer * } } } + +func processIncomingRemoveNodePacket(connectionState *byte, receiveBuffer *[]byte, conn *network.ManagedConnection, data []byte, offset *int, connectedNodeId *string) { + remainingCapacity := int(math.Min(float64(removenode.MARSHALED_TOTAL_SIZE-*offset), float64(len(data)))) + + copy((*receiveBuffer)[*offset:], data[:remainingCapacity]) + + if *offset+len(data) < removenode.MARSHALED_TOTAL_SIZE { + *offset += len(data) + } else { + if removeNodePacket, err := removenode.Unmarshal(*receiveBuffer); err != nil { + Events.Error.Trigger(err) + + conn.Close() + + return + } else { + nodeId := hex.EncodeToString(removeNodePacket.NodeId) + + Events.RemoveNode.Trigger(nodeId) + + } + + *connectionState = STATE_CONSECUTIVE + + if *offset+len(data) > addnode.MARSHALED_TOTAL_SIZE { + processIncomingPacket(connectionState, receiveBuffer, conn, data[remainingCapacity:], offset, connectedNodeId) + } + } +} diff --git a/plugins/analysis/types/addnode/constants.go b/plugins/analysis/types/addnode/constants.go index 6534ce8da6a998cb4356343f4a886c00d145b0d3..a112e89aa7550521b7dd59e85e6862e8e9facf3c 100644 --- a/plugins/analysis/types/addnode/constants.go +++ b/plugins/analysis/types/addnode/constants.go @@ -1,5 +1,7 @@ package addnode +import "crypto/sha256" + const ( MARSHALED_PACKET_HEADER = 0x01 @@ -8,7 +10,7 @@ const ( MARSHALED_PACKET_HEADER_END = MARSHALED_PACKET_HEADER_START + MARSHALED_PACKET_HEADER_SIZE MARSHALED_ID_START = MARSHALED_PACKET_HEADER_END - MARSHALED_ID_SIZE = 20 + MARSHALED_ID_SIZE = sha256.Size MARSHALED_ID_END = MARSHALED_ID_START + MARSHALED_ID_SIZE MARSHALED_TOTAL_SIZE = MARSHALED_ID_END diff --git a/plugins/analysis/types/connectnodes/constants.go b/plugins/analysis/types/connectnodes/constants.go index d40065208b1a3f07ab3c57758932598aa8c3c2c1..09889329a44e0c98c8207eb1cc8d6a0175c7ef0b 100644 --- a/plugins/analysis/types/connectnodes/constants.go +++ b/plugins/analysis/types/connectnodes/constants.go @@ -1,5 +1,7 @@ package connectnodes +import "crypto/sha256" + const ( MARSHALED_PACKET_HEADER = 0x03 @@ -8,11 +10,11 @@ const ( MARSHALED_PACKET_HEADER_END = MARSHALED_PACKET_HEADER_START + MARSHALED_PACKET_HEADER_SIZE MARSHALED_SOURCE_ID_START = MARSHALED_PACKET_HEADER_END - MARSHALED_SOURCE_ID_SIZE = 20 + MARSHALED_SOURCE_ID_SIZE = sha256.Size MARSHALED_SOURCE_ID_END = MARSHALED_SOURCE_ID_START + MARSHALED_SOURCE_ID_SIZE MARSHALED_TARGET_ID_START = MARSHALED_SOURCE_ID_END - MARSHALED_TARGET_ID_SIZE = 20 + MARSHALED_TARGET_ID_SIZE = sha256.Size MARSHALED_TARGET_ID_END = MARSHALED_TARGET_ID_START + MARSHALED_TARGET_ID_SIZE MARSHALED_TOTAL_SIZE = MARSHALED_TARGET_ID_END diff --git a/plugins/analysis/types/disconnectnodes/constants.go b/plugins/analysis/types/disconnectnodes/constants.go index 928a723f9e3639c351116e4b6e8746e70ceca4b2..adf347455bccef6bebdac55f671930bd86289ad3 100644 --- a/plugins/analysis/types/disconnectnodes/constants.go +++ b/plugins/analysis/types/disconnectnodes/constants.go @@ -1,5 +1,7 @@ package disconnectnodes +import "crypto/sha256" + const ( MARSHALED_PACKET_HEADER = 0x04 @@ -8,11 +10,11 @@ const ( MARSHALED_PACKET_HEADER_END = MARSHALED_PACKET_HEADER_START + MARSHALED_PACKET_HEADER_SIZE MARSHALED_SOURCE_ID_START = MARSHALED_PACKET_HEADER_END - MARSHALED_SOURCE_ID_SIZE = 20 + MARSHALED_SOURCE_ID_SIZE = sha256.Size MARSHALED_SOURCE_ID_END = MARSHALED_SOURCE_ID_START + MARSHALED_SOURCE_ID_SIZE MARSHALED_TARGET_ID_START = MARSHALED_SOURCE_ID_END - MARSHALED_TARGET_ID_SIZE = 20 + MARSHALED_TARGET_ID_SIZE = sha256.Size MARSHALED_TARGET_ID_END = MARSHALED_TARGET_ID_START + MARSHALED_TARGET_ID_SIZE MARSHALED_TOTAL_SIZE = MARSHALED_TARGET_ID_END diff --git a/plugins/analysis/types/removenode/constants.go b/plugins/analysis/types/removenode/constants.go index 52d9bcc5c0a02d3a8cd734ff7c4395a5cd7687b2..b8edb5d1795c5199e38b3b95ea7b08ef1f206999 100644 --- a/plugins/analysis/types/removenode/constants.go +++ b/plugins/analysis/types/removenode/constants.go @@ -1,5 +1,7 @@ package removenode +import "crypto/sha256" + const ( MARSHALED_PACKET_HEADER = 0x02 @@ -8,7 +10,7 @@ const ( MARSHALED_PACKET_HEADER_END = MARSHALED_PACKET_HEADER_START + MARSHALED_PACKET_HEADER_SIZE MARSHALED_ID_START = MARSHALED_PACKET_HEADER_END - MARSHALED_ID_SIZE = 20 + MARSHALED_ID_SIZE = sha256.Size MARSHALED_ID_END = MARSHALED_ID_START + MARSHALED_ID_SIZE MARSHALED_TOTAL_SIZE = MARSHALED_ID_END diff --git a/plugins/analysis/webinterface/httpserver/data_stream.go b/plugins/analysis/webinterface/httpserver/data_stream.go index 2548064908015efa85319a6bbb0e7c96340d8276..a2d54db771cab43a5c012516942070bf1db3d29e 100644 --- a/plugins/analysis/webinterface/httpserver/data_stream.go +++ b/plugins/analysis/webinterface/httpserver/data_stream.go @@ -3,10 +3,10 @@ package httpserver import ( "fmt" - "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/plugins/analysis/server" "github.com/iotaledger/goshimmer/plugins/analysis/webinterface/recordedevents" "github.com/iotaledger/goshimmer/plugins/analysis/webinterface/types" + "github.com/iotaledger/hive.go/events" "golang.org/x/net/websocket" ) diff --git a/plugins/analysis/webinterface/httpserver/index.go b/plugins/analysis/webinterface/httpserver/index.go index b0d791ebd5253e7684653214d744f8ae5fae7f95..9fce6f7698d45b702b850f76b770f5f4ef1e4e91 100644 --- a/plugins/analysis/webinterface/httpserver/index.go +++ b/plugins/analysis/webinterface/httpserver/index.go @@ -26,6 +26,7 @@ func index(w http.ResponseWriter, r *http.Request) { }; socket.onmessage = function (e) { + console.log("Len: ", data.nodes.length); switch (e.data[0]) { case "_": // do nothing - its just a ping @@ -33,26 +34,32 @@ func index(w http.ResponseWriter, r *http.Request) { case "A": addNode(e.data.substr(1)); + console.log("Add node:",e.data.substr(1)); break; case "a": removeNode(e.data.substr(1)); + console.log("Remove node:", e.data.substr(1)); break; case "C": - connectNodes(e.data.substr(1, 40), e.data.substr(41, 40)); + connectNodes(e.data.substr(1, 64), e.data.substr(65, 128)); + console.log("Connect nodes:",e.data.substr(1, 64), " - ", e.data.substr(65, 128)); break; case "c": - disconnectNodes(e.data.substr(1, 40), e.data.substr(41, 40)); + disconnectNodes(e.data.substr(1, 64), e.data.substr(65, 128)); + console.log("Disconnect nodes:",e.data.substr(1, 64), " - ", e.data.substr(65, 128)); break; case "O": setNodeOnline(e.data.substr(1)); + console.log("setNodeOnline:",e.data.substr(1)); break; case "o": setNodeOffline(e.data.substr(1)); + console.log("setNodeOffline:",e.data.substr(1)); break; } }; @@ -96,6 +103,7 @@ func index(w http.ResponseWriter, r *http.Request) { data.nodes = [...data.nodes, node]; nodesById[node.id] = node; + nodesById[nodeId].online = true; updateGraph(); } @@ -128,6 +136,14 @@ func index(w http.ResponseWriter, r *http.Request) { function connectNodes(sourceNodeId, targetNodeId) { if(existingLinks[sourceNodeId + targetNodeId] == undefined && existingLinks[targetNodeId + sourceNodeId] == undefined) { + if (!(sourceNodeId in nodesById)) { + addNode(sourceNodeId); + } + if (!(targetNodeId in nodesById)) { + addNode(targetNodeId); + } + nodesById[sourceNodeId].online = true; + nodesById[targetNodeId].online = true; data.links = [...data.links, { source: sourceNodeId, target: targetNodeId }]; updateGraph(); @@ -136,7 +152,6 @@ func index(w http.ResponseWriter, r *http.Request) { function disconnectNodes(sourceNodeId, targetNodeId) { data.links = data.links.filter(l => !(l.source.id == sourceNodeId && l.target.id == targetNodeId) && !(l.source.id == targetNodeId && l.target.id == sourceNodeId)); - delete existingLinks[sourceNodeId + targetNodeId]; delete existingLinks[targetNodeId + sourceNodeId]; @@ -144,6 +159,9 @@ func index(w http.ResponseWriter, r *http.Request) { } function removeNodeX(node) { + if (!(node.id in nodesById)) { + addNode(sourceNodeId); + } removeNode(node.id) } </script> diff --git a/plugins/analysis/webinterface/httpserver/plugin.go b/plugins/analysis/webinterface/httpserver/plugin.go index a7c8daf9ff6ca2cfa8eac097d3c84eaba821e511..a86fb7dffea3a4a3c139463c04123296f6bae981 100644 --- a/plugins/analysis/webinterface/httpserver/plugin.go +++ b/plugins/analysis/webinterface/httpserver/plugin.go @@ -5,8 +5,8 @@ import ( "time" "github.com/iotaledger/goshimmer/packages/daemon" - "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/packages/node" + "github.com/iotaledger/hive.go/events" "golang.org/x/net/context" "golang.org/x/net/websocket" ) diff --git a/plugins/analysis/webinterface/recordedevents/recorded_events.go b/plugins/analysis/webinterface/recordedevents/recorded_events.go index 882696997bd0d5223a6701bd094685cd166950dc..95934ad11fdef2b27297f6ef87cdd2e5fa1f38bd 100644 --- a/plugins/analysis/webinterface/recordedevents/recorded_events.go +++ b/plugins/analysis/webinterface/recordedevents/recorded_events.go @@ -1,12 +1,13 @@ package recordedevents import ( + "strconv" "sync" - "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/analysis/server" "github.com/iotaledger/goshimmer/plugins/analysis/webinterface/types" + "github.com/iotaledger/hive.go/events" ) var nodes = make(map[string]bool) @@ -16,6 +17,7 @@ var lock sync.Mutex func Configure(plugin *node.Plugin) { server.Events.AddNode.Attach(events.NewClosure(func(nodeId string) { + plugin.LogInfo("AddNode: " + nodeId + " sizeof " + strconv.Itoa(len(nodeId))) if _, exists := nodes[nodeId]; !exists { lock.Lock() defer lock.Unlock() @@ -27,6 +29,7 @@ func Configure(plugin *node.Plugin) { })) server.Events.RemoveNode.Attach(events.NewClosure(func(nodeId string) { + plugin.LogInfo("RemoveNode: " + nodeId) lock.Lock() defer lock.Unlock() @@ -34,6 +37,7 @@ func Configure(plugin *node.Plugin) { })) server.Events.NodeOnline.Attach(events.NewClosure(func(nodeId string) { + plugin.LogInfo("NodeOnline: " + nodeId) lock.Lock() defer lock.Unlock() @@ -41,6 +45,7 @@ func Configure(plugin *node.Plugin) { })) server.Events.NodeOffline.Attach(events.NewClosure(func(nodeId string) { + plugin.LogInfo("NodeOffline: " + nodeId) lock.Lock() defer lock.Unlock() @@ -48,6 +53,7 @@ func Configure(plugin *node.Plugin) { })) server.Events.ConnectNodes.Attach(events.NewClosure(func(sourceId string, targetId string) { + plugin.LogInfo("ConnectNodes: " + sourceId + " - " + targetId) lock.Lock() defer lock.Unlock() @@ -61,6 +67,7 @@ func Configure(plugin *node.Plugin) { })) server.Events.DisconnectNodes.Attach(events.NewClosure(func(sourceId string, targetId string) { + plugin.LogInfo("DisconnectNodes: " + sourceId + " - " + targetId) lock.Lock() defer lock.Unlock() diff --git a/plugins/autopeering/autopeering.go b/plugins/autopeering/autopeering.go index 2c98a22c93d0fc855b39799c6caa3690a5de72fc..8f1e599c21a53dc08edf3c893c7f92abdda7926b 100644 --- a/plugins/autopeering/autopeering.go +++ b/plugins/autopeering/autopeering.go @@ -8,6 +8,7 @@ import ( "net" "net/http" "strconv" + "time" "github.com/iotaledger/autopeering-sim/discover" "github.com/iotaledger/autopeering-sim/logger" @@ -16,13 +17,15 @@ import ( "github.com/iotaledger/autopeering-sim/server" "github.com/iotaledger/autopeering-sim/transport" "github.com/iotaledger/goshimmer/packages/node" + "github.com/iotaledger/goshimmer/plugins/autopeering/local" "github.com/iotaledger/goshimmer/plugins/autopeering/parameters" "github.com/iotaledger/goshimmer/plugins/gossip" + "go.uber.org/zap" ) var ( PLUGIN = node.NewPlugin("Auto Peering", node.Enabled, configure, run) - debugLevel = "debug" + debugLevel = "info" close = make(chan struct{}, 1) srv *server.Server Discovery *discover.Protocol @@ -32,7 +35,7 @@ var ( const defaultZLC = `{ "level": "info", "development": false, - "outputPaths": ["./logs/autopeering.log"], + "outputPaths": ["stdout"], "errorOutputPaths": ["stderr"], "encoding": "console", "encoderConfig": { @@ -94,26 +97,26 @@ func start() { // create a new local node db := peer.NewPersistentDB(logger.Named("db")) defer db.Close() - local, err := peer.NewLocal(db) + local.INSTANCE, err = peer.NewLocal(db) if err != nil { log.Fatalf("ListenUDP: %v", err) } // add a service for the peering - local.Services()["peering"] = peer.NetworkAddress{Network: "udp", Address: listenAddr} + local.INSTANCE.Services()["peering"] = peer.NetworkAddress{Network: "udp", Address: listenAddr} // add a service for the gossip - local.Services()["gossip"] = peer.NetworkAddress{Network: "tcp", Address: gossipAddr} + local.INSTANCE.Services()["gossip"] = peer.NetworkAddress{Network: "tcp", Address: gossipAddr} - Discovery = discover.New(local, discover.Config{ + Discovery = discover.New(local.INSTANCE, discover.Config{ Log: logger.Named("disc"), MasterPeers: masterPeers, }) - Selection = selection.New(local, Discovery, selection.Config{ + Selection = selection.New(local.INSTANCE, Discovery, selection.Config{ Log: logger.Named("sel"), SaltLifetime: selection.DefaultSaltLifetime, }) // start a server doing discovery and peering - srv = server.Listen(local, trans, 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 @@ -124,30 +127,20 @@ func start() { Selection.Start(srv) defer Selection.Close() - id := base64.StdEncoding.EncodeToString(local.PublicKey()) + 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) + go func() { + for t := range time.NewTicker(2 * time.Second).C { + _ = t + printReport(logger) + } + }() + <-close } -// func parseMaster(s string) (*peer.Peer, error) { -// if len(s) == 0 { -// return nil, nil -// } - -// parts := strings.Split(s, "@") -// if len(parts) != 2 { -// return nil, errors.New("parseMaster") -// } -// pubKey, err := base64.StdEncoding.DecodeString(parts[0]) -// if err != nil { -// return nil, errors.Wrap(err, "parseMaster") -// } - -// return peer.NewPeer(pubKey, parts[1]), nil -// } - func getMyIP() string { url := "https://api.ipify.org?format=text" resp, err := http.Get(url) @@ -161,3 +154,15 @@ func getMyIP() string { } return fmt.Sprintf("%s", ip) } + +func printReport(log *zap.SugaredLogger) { + if Discovery == nil || Selection == nil { + return + } + knownPeers := Discovery.GetVerifiedPeers() + incoming := Selection.GetIncomingNeighbors() + outgoing := Selection.GetOutgoingNeighbors() + log.Info("Known peers:", len(knownPeers)) + log.Info("Chosen:", len(outgoing), outgoing) + log.Info("Accepted:", len(incoming), incoming) +} diff --git a/plugins/autopeering/local/local.go b/plugins/autopeering/local/local.go new file mode 100644 index 0000000000000000000000000000000000000000..d384c80735859ecb415a1f15f5cd11552d1dcaa9 --- /dev/null +++ b/plugins/autopeering/local/local.go @@ -0,0 +1,5 @@ +package local + +import "github.com/iotaledger/autopeering-sim/peer" + +var INSTANCE *peer.Local diff --git a/plugins/dashboard/tps.go b/plugins/dashboard/tps.go index ac1f5ceb24ca83108f80ff4775925e6146836cf5..3a20bbb388f785322049ad715c126bb657ba69d7 100644 --- a/plugins/dashboard/tps.go +++ b/plugins/dashboard/tps.go @@ -11,8 +11,8 @@ import ( "time" "github.com/gorilla/websocket" - "github.com/iotaledger/goshimmer/packages/accountability" "github.com/iotaledger/goshimmer/plugins/autopeering" + "github.com/iotaledger/goshimmer/plugins/autopeering/local" "github.com/iotaledger/goshimmer/plugins/metrics" "github.com/iotaledger/hive.go/events" ) @@ -70,7 +70,7 @@ func GetStatus() *Status { uptime += fmt.Sprintf("%02ds ", int(duration.Seconds())%60) return &Status{ - Id: accountability.OwnId().StringIdentifier, + 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", Uptime: uptime, diff --git a/plugins/gossip/neighbors.go b/plugins/gossip/neighbors.go index f4374c517bf1fb7ce7d84160e39a7cb07113977d..6d1671dddc50f06594417158bbd4f2e541151853 100644 --- a/plugins/gossip/neighbors.go +++ b/plugins/gossip/neighbors.go @@ -8,18 +8,19 @@ import ( "time" "github.com/iotaledger/autopeering-sim/peer" - "github.com/iotaledger/goshimmer/packages/accountability" "github.com/iotaledger/goshimmer/packages/daemon" "github.com/iotaledger/goshimmer/packages/errors" "github.com/iotaledger/goshimmer/packages/identity" "github.com/iotaledger/goshimmer/packages/network" "github.com/iotaledger/goshimmer/packages/node" + "github.com/iotaledger/goshimmer/plugins/autopeering/local" "github.com/iotaledger/hive.go/events" ) func configureNeighbors(plugin *node.Plugin) { Events.AddNeighbor.Attach(events.NewClosure(func(neighbor *Neighbor) { plugin.LogSuccess("new neighbor added " + neighbor.GetIdentity().StringIdentifier + "@" + neighbor.GetAddress().String() + ":" + neighbor.GetPort()) + //plugin.LogSuccess("new neighbor added " + hex.EncodeToString(neighbor.Peer.ID().Bytes()) + "@" + neighbor.GetAddress().String() + ":" + neighbor.GetPort()) })) Events.UpdateNeighbor.Attach(events.NewClosure(func(neighbor *Neighbor) { @@ -221,7 +222,7 @@ func (neighbor *Neighbor) Connect() (*protocol, bool, errors.IdentifiableError) // drop the "secondary" connection upon successful handshake neighbor.GetInitiatedProtocol().Events.HandshakeCompleted.Attach(events.NewClosure(func() { - if accountability.OwnId().StringIdentifier <= neighbor.GetIdentity().StringIdentifier { + if local.INSTANCE.ID().String() <= neighbor.Peer.ID().String() { var acceptedProtocolConn *network.ManagedConnection if neighbor.GetAcceptedProtocol() != nil { acceptedProtocolConn = neighbor.GetAcceptedProtocol().Conn diff --git a/plugins/gossip/protocol.go b/plugins/gossip/protocol.go index 5cda6f99882248aafbb9af719911182a918097db..54c891714b80d4a7b8eb050bcfe6fb65c8c69438 100644 --- a/plugins/gossip/protocol.go +++ b/plugins/gossip/protocol.go @@ -5,8 +5,8 @@ import ( "sync" "github.com/iotaledger/goshimmer/packages/errors" - "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/packages/network" + "github.com/iotaledger/hive.go/events" ) // region constants and variables ////////////////////////////////////////////////////////////////////////////////////// diff --git a/plugins/gossip/protocol_v1.go b/plugins/gossip/protocol_v1.go index ee6681dc86870a3530ff4d77a9c17ed7959e8ae5..268ec8dc249f685f352143a78122d621cef0c0b6 100644 --- a/plugins/gossip/protocol_v1.go +++ b/plugins/gossip/protocol_v1.go @@ -3,19 +3,19 @@ package gossip import ( "strconv" - "github.com/iotaledger/goshimmer/packages/accountability" "github.com/iotaledger/goshimmer/packages/byteutils" "github.com/iotaledger/goshimmer/packages/errors" - "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/packages/identity" "github.com/iotaledger/goshimmer/packages/model/meta_transaction" + "github.com/iotaledger/goshimmer/plugins/autopeering/local" + "github.com/iotaledger/hive.go/events" "github.com/iotaledger/iota.go/consts" ) // region protocolV1 /////////////////////////////////////////////////////////////////////////////////////////////////// func protocolV1(protocol *protocol) errors.IdentifiableError { - if err := protocol.Send(accountability.OwnId()); err != nil { + if err := protocol.Send(local.INSTANCE.ID().Bytes()); err != nil { return err } diff --git a/plugins/gossip/send_queue.go b/plugins/gossip/send_queue.go index 02ba9415644dca046b8e9580a814ee54f9055502..7b92be4ab051ae72c427fc86615632824972f0ba 100644 --- a/plugins/gossip/send_queue.go +++ b/plugins/gossip/send_queue.go @@ -4,9 +4,9 @@ import ( "sync" "github.com/iotaledger/goshimmer/packages/daemon" - "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/packages/model/meta_transaction" "github.com/iotaledger/goshimmer/packages/node" + "github.com/iotaledger/hive.go/events" ) // region plugin module setup ////////////////////////////////////////////////////////////////////////////////////////// diff --git a/plugins/gossip/server.go b/plugins/gossip/server.go index cee62e7d5e0fa085a9be2996b4a1d6e5d2b5b2fe..32c80b756977f0d5f49e0f8fa3bfc5b4ef5e1de7 100644 --- a/plugins/gossip/server.go +++ b/plugins/gossip/server.go @@ -3,14 +3,14 @@ package gossip import ( "strconv" - "github.com/iotaledger/goshimmer/packages/accountability" "github.com/iotaledger/goshimmer/packages/daemon" "github.com/iotaledger/goshimmer/packages/errors" - "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/packages/identity" "github.com/iotaledger/goshimmer/packages/network" "github.com/iotaledger/goshimmer/packages/network/tcp" "github.com/iotaledger/goshimmer/packages/node" + "github.com/iotaledger/goshimmer/plugins/autopeering/local" + "github.com/iotaledger/hive.go/events" ) var TCPServer = tcp.NewServer() @@ -40,7 +40,7 @@ func configureServer(plugin *node.Plugin) { // drop the "secondary" connection upon successful handshake protocol.Events.HandshakeCompleted.Attach(events.NewClosure(func() { - if protocol.Neighbor.GetIdentity().StringIdentifier <= accountability.OwnId().StringIdentifier { + if protocol.Neighbor.Peer.ID().String() <= local.INSTANCE.ID().String() { var initiatedProtocolConn *network.ManagedConnection if protocol.Neighbor.GetInitiatedProtocol() != nil { initiatedProtocolConn = protocol.Neighbor.GetInitiatedProtocol().Conn diff --git a/plugins/statusscreen/ui_header_bar.go b/plugins/statusscreen/ui_header_bar.go index e1a1d17b88739c64aa8ea3bcfff7227666aec6c4..4cff25dd17781c9b7af171d00678e4d73087773a 100644 --- a/plugins/statusscreen/ui_header_bar.go +++ b/plugins/statusscreen/ui_header_bar.go @@ -9,8 +9,8 @@ import ( "time" "github.com/gdamore/tcell" - "github.com/iotaledger/goshimmer/packages/accountability" "github.com/iotaledger/goshimmer/plugins/autopeering" + "github.com/iotaledger/goshimmer/plugins/autopeering/local" "github.com/rivo/tview" ) @@ -81,6 +81,7 @@ func (headerBar *UIHeaderBar) Update() { incoming := "0" neighbors := "0" total := "0" + myID := "-" if autopeering.Selection != nil { outgoing = strconv.Itoa(len(autopeering.Selection.GetOutgoingNeighbors())) incoming = strconv.Itoa(len(autopeering.Selection.GetIncomingNeighbors())) @@ -89,8 +90,11 @@ func (headerBar *UIHeaderBar) Update() { if autopeering.Discovery != nil { total = strconv.Itoa(len(autopeering.Discovery.GetVerifiedPeers())) } + if local.INSTANCE != nil { + myID = local.INSTANCE.ID().String() + } - fmt.Fprintf(headerBar.InfoContainer, "[::b]Node ID: [::d]%40v ", accountability.OwnId().StringIdentifier) + fmt.Fprintf(headerBar.InfoContainer, "[::b]Node ID: [::d]%40v ", myID) fmt.Fprintln(headerBar.InfoContainer) fmt.Fprintf(headerBar.InfoContainer, "[::b]Neighbors: [::d]%40v ", outgoing+" chosen / "+incoming+" accepted / "+neighbors+" total") fmt.Fprintln(headerBar.InfoContainer) diff --git a/plugins/ui/files.go b/plugins/ui/files.go index 3d36119445ad9df550c1fe38cdee0bdf0d904491..a336e08738e3f3d437a22a6f167346987e02cab9 100644 --- a/plugins/ui/files.go +++ b/plugins/ui/files.go @@ -1,7 +1,7 @@ package ui var files = map[string]string{ - "css/styles.css":`/* mobile */ + "css/styles.css": `/* mobile */ html { font-size:12px; } @@ -206,7 +206,7 @@ body.fade { font-size: 0.8rem; } `, - "index.html":`<!DOCTYPE html> + "index.html": `<!DOCTYPE html> <html> <head> @@ -365,7 +365,7 @@ body.fade { </body> </html>`, - "js/forcegraph.js":` + "js/forcegraph.js": ` Vue.component('force-graph', { props:['neighbors', 'me'], data: function() { @@ -423,7 +423,7 @@ Vue.component('force-graph', { '</div>'+ '</div>' })`, - "js/icons.js":` + "js/icons.js": ` Vue.component('iota-icon', { props:['size'], template: '<svg :height="size" :width="size" style="margin-right:10px;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_1" x="0px" y="0px" viewBox="0 0 128 128" xml:space="preserve"><path d="M79.6 24.9c-.1-2.8 2.4-5.4 5.6-5.3 2.8.1 5.1 2.5 5.1 5.4 0 3-2.5 5.3-5.6 5.3-2.8 0-5.1-2.5-5.1-5.4z" fill="#FFF"/><path d="M91 95.4c3 0 5.3 2.3 5.3 5.3s-2.4 5.4-5.4 5.4c-2.9 0-5.3-2.4-5.3-5.4 0-3 2.4-5.3 5.4-5.3z" fill="#FFF"/><path d="M22.4 73.4c-3 0-5.3-2.4-5.3-5.5 0-2.9 2.4-5.2 5.4-5.2 3 0 5.3 2.4 5.3 5.5-.1 2.9-2.5 5.2-5.4 5.2z" fill="#FFF"/><path d="M81.9 39.2c0-2.6 2-4.6 4.6-4.6 2.5 0 4.6 2.1 4.6 4.6 0 2.5-2.1 4.6-4.6 4.6-2.6 0-4.6-2.1-4.6-4.6z" fill="#FFF"/><path d="M33.9 55.1c2.6 0 4.6 2 4.7 4.5 0 2.5-2.1 4.6-4.6 4.6-2.5 0-4.6-2.1-4.6-4.6-.1-2.5 2-4.5 4.5-4.5z" fill="#FFF"/><path d="M98.4 45.4c-2.5 0-4.6-2.1-4.6-4.6 0-2.6 2.1-4.6 4.6-4.6 2.5 0 4.6 2.1 4.6 4.6 0 2.6-2 4.6-4.6 4.6z" fill="#FFF"/><path d="M77.9 99.5c-2.5 0-4.6-2.1-4.6-4.6 0-2.5 2-4.5 4.6-4.6 2.5 0 4.6 2.1 4.6 4.6 0 2.5-2.1 4.6-4.6 4.6z" fill="#FFF"/><path d="M33.9 48.5c0 2.5-2.1 4.6-4.6 4.6-2.5 0-4.5-2.1-4.5-4.6 0-2.5 2.1-4.6 4.6-4.6 2.5-.1 4.6 2 4.5 4.6z" fill="#FFF"/><path d="M70.4 109c-2.5 0-4.5-2-4.5-4.6 0-2.5 2-4.5 4.6-4.6 2.5 0 4.6 2.1 4.6 4.6-.1 2.6-2.1 4.6-4.7 4.6z" fill="#FFF"/><path d="M56.9 97.1c0-2.2 1.7-3.9 3.9-3.9s3.9 1.8 3.9 4-1.8 3.9-3.9 3.9c-2.2 0-3.9-1.8-3.9-4z" fill="#FFF"/><path d="M100.9 52.9c0 2.2-1.8 3.9-3.9 3.9-2.1 0-3.9-1.8-3.9-3.9 0-2.2 1.8-4 3.9-3.9 2.1 0 3.9 1.7 3.9 3.9z" fill="#FFF"/><path d="M44.4 43.7c0 2.2-1.7 3.9-3.9 3.9s-3.9-1.7-3.9-4c0-2.2 1.7-3.9 3.9-3.9 2.3.1 4 1.8 3.9 4z" fill="#FFF"/><path d="M49 54.9c0 2.2-1.7 3.9-3.9 3.9s-3.9-1.7-3.9-3.9 1.7-4 3.9-3.9c2.2 0 3.9 1.7 3.9 3.9z" fill="#FFF"/><path d="M35 33.5c0-2.2 1.8-3.9 3.9-3.9 2.2 0 3.9 1.8 3.9 3.9 0 2.2-1.7 3.9-3.9 3.9S35 35.7 35 33.5z" fill="#FFF"/><path d="M81.1 51.3c0-2.2 1.7-3.9 3.9-3.9s4 1.8 3.9 4c0 2.2-1.8 3.9-3.9 3.9-2.2-.2-3.9-1.9-3.9-4z" fill="#FFF"/><path d="M68.2 83.7c2.1 0 3.9 1.8 3.9 3.9 0 2.2-1.8 3.9-4 3.9s-3.9-1.7-3.9-3.9c.1-2.2 1.9-3.9 4-3.9z" fill="#FFF"/><path d="M56.7 103.6c0 2.2-1.7 3.9-3.9 3.9s-3.9-1.7-3.9-3.9 1.8-4 3.9-3.9c2.2 0 3.9 1.7 3.9 3.9z" fill="#FFF"/><path d="M106.5 60.5c-2.1 0-3.8-1.8-3.9-3.9 0-2.2 1.8-3.9 4-3.9 2.1 0 3.9 1.8 3.9 3.9 0 2.2-1.8 3.9-4 3.9z" fill="#FFF"/><path d="M57.5 89.3c0 1.9-1.5 3.4-3.4 3.3-1.9 0-3.4-1.5-3.4-3.3 0-1.9 1.5-3.4 3.4-3.4s3.4 1.5 3.4 3.4z" fill="#FFF"/><path d="M50.7 38.5c1.9 0 3.3 1.5 3.3 3.3 0 1.8-1.5 3.4-3.3 3.4-1.8 0-3.4-1.5-3.4-3.4.1-1.8 1.6-3.3 3.4-3.3z" fill="#FFF"/><path d="M58.2 79.7c0-1.9 1.4-3.4 3.3-3.4s3.4 1.5 3.4 3.3c0 1.9-1.5 3.3-3.3 3.3-1.9.1-3.4-1.3-3.4-3.2z" fill="#FFF"/><path d="M46.2 99.1c-1.9 0-3.4-1.4-3.4-3.3s1.5-3.3 3.3-3.4c1.9 0 3.4 1.5 3.4 3.4 0 1.8-1.5 3.3-3.3 3.3z" fill="#FFF"/><path d="M84.7 61c0 1.8-1.4 3.3-3.3 3.3s-3.4-1.5-3.3-3.4c0-1.9 1.5-3.3 3.3-3.3 1.9 0 3.3 1.5 3.3 3.4z" fill="#FFF"/><path d="M49.1 35c-1.9 0-3.4-1.4-3.4-3.3s1.5-3.4 3.4-3.4c1.8 0 3.3 1.5 3.4 3.4 0 1.8-1.5 3.3-3.4 3.3z" fill="#FFF"/><path d="M93.4 66c-1.9 0-3.3-1.5-3.3-3.3 0-1.8 1.5-3.3 3.4-3.3s3.3 1.5 3.3 3.4c0 1.8-1.5 3.2-3.4 3.2z" fill="#FFF"/><path d="M55.2 56.4c-1.8 0-3.3-1.5-3.3-3.4 0-1.8 1.6-3.3 3.4-3.3 1.9 0 3.3 1.5 3.3 3.4s-1.5 3.3-3.4 3.3z" fill="#FFF"/><path d="M103 69.6c-1.9-.1-3.3-1.6-3.3-3.5.1-1.8 1.6-3.3 3.4-3.2 1.9.1 3.4 1.6 3.3 3.6-.1 1.8-1.6 3.2-3.4 3.1z" fill="#FFF"/><path d="M64 56.4c-1.6 0-2.9-1.3-2.9-2.9 0-1.6 1.3-2.8 2.9-2.8 1.6 0 2.9 1.3 2.8 2.9.1 1.6-1.1 2.8-2.8 2.8z" fill="#FFF"/><path d="M95.4 73.7c0-1.6 1.2-2.9 2.8-2.9 1.6 0 2.9 1.2 2.9 2.9 0 1.6-1.4 3-2.9 3-1.5-.1-2.8-1.4-2.8-3z" fill="#FFF"/><path d="M60.7 32.2c0 1.6-1.2 2.8-2.9 2.8-1.6 0-2.9-1.3-2.9-2.9 0-1.6 1.3-2.9 3-2.8 1.6 0 2.8 1.3 2.8 2.9z" fill="#FFF"/><path d="M60.4 71.9c0 1.6-1.2 2.8-2.8 2.9-1.7 0-2.9-1.3-2.9-2.9 0-1.6 1.3-2.9 2.9-2.9 1.6 0 2.8 1.3 2.8 2.9z" fill="#FFF"/><path d="M50.2 84.3c-1.6 0-2.9-1.2-2.9-2.8 0-1.6 1.3-2.9 2.9-2.9 1.5 0 2.8 1.3 2.8 2.8 0 1.6-1.2 2.9-2.8 2.9z" fill="#FFF"/><path d="M91.5 70c0 1.6-1.2 2.9-2.9 2.9-1.5 0-2.9-1.4-2.9-2.9 0-1.6 1.3-2.9 2.9-2.9 1.7 0 2.9 1.3 2.9 2.9z" fill="#FFF"/><path d="M76.7 65.5c1.7 0 2.8 1.2 2.9 2.8 0 1.6-1.2 2.9-2.9 2.9-1.6 0-2.9-1.3-2.9-2.9 0-1.6 1.2-2.8 2.9-2.8z" fill="#FFF"/><path d="M45 87.9c0 1.6-1.3 2.9-2.9 2.9-1.6 0-2.9-1.3-2.9-2.9 0-1.6 1.3-2.9 2.9-2.9 1.6 0 2.9 1.3 2.9 2.9z" fill="#FFF"/><path d="M59.5 45.2c-1.6 0-2.9-1.3-2.9-2.9 0-1.5 1.3-2.9 2.9-2.9 1.5 0 2.9 1.3 2.9 2.9 0 1.6-1.3 2.9-2.9 2.9z" fill="#FFF"/><path d="M85.8 75.1c0 1.4-1.1 2.5-2.5 2.5s-2.4-1.1-2.4-2.5 1.1-2.5 2.4-2.5c1.3.1 2.4 1.2 2.5 2.5z" fill="#FFF"/><path d="M58.2 64.6c0 1.4-1.1 2.5-2.4 2.5-1.3 0-2.5-1.2-2.5-2.5s1.2-2.5 2.5-2.5c1.3.1 2.4 1.2 2.4 2.5z" fill="#FFF"/><path d="M40.4 78.2c1.4 0 2.5 1.1 2.4 2.5 0 1.3-1.2 2.5-2.5 2.5-1.4 0-2.5-1.2-2.5-2.6.1-1.4 1.2-2.4 2.6-2.4z" fill="#FFF"/><path d="M71.2 58c-1.4 0-2.5-1-2.5-2.4s1-2.5 2.5-2.5c1.4 0 2.5 1.1 2.5 2.4 0 1.5-1.1 2.5-2.5 2.5z" fill="#FFF"/><path d="M66.7 41.9c1.4 0 2.4 1.1 2.4 2.5s-1.1 2.5-2.4 2.5c-1.4 0-2.5-1.1-2.5-2.5s1.1-2.5 2.5-2.5z" fill="#FFF"/><path d="M50.7 74.2c0 1.4-1.1 2.5-2.4 2.5-1.3 0-2.5-1.2-2.5-2.6 0-1.4 1.1-2.4 2.5-2.4s2.4 1.1 2.4 2.5z" fill="#FFF"/><path d="M71.3 71.1c1.4 0 2.4 1.1 2.4 2.5S72.6 76 71.3 76c-1.4 0-2.5-1.1-2.5-2.5.1-1.4 1.1-2.4 2.5-2.4z" fill="#FFF"/><path d="M95.3 78.8c0 1.4-1 2.5-2.5 2.5-1.4 0-2.4-1.1-2.4-2.5 0-1.3 1.1-2.5 2.4-2.5 1.4 0 2.5 1.1 2.5 2.5z" fill="#FFF"/><path d="M65.1 31.8c1.4 0 2.4 1 2.4 2.4s-1.1 2.5-2.4 2.5c-1.4 0-2.5-1.1-2.5-2.5s1.1-2.4 2.5-2.4z" fill="#FFF"/><path d="M72.7 37.3c0 1.2-1 2.1-2.2 2.1-1.2 0-2.1-1-2.1-2.1 0-1.2.9-2.1 2.1-2.1 1.3 0 2.2.9 2.2 2.1z" fill="#FFF"/><path d="M38.1 74.2c0-1.2.9-2 2.1-2 1.2 0 2.2 1 2.1 2.2 0 1.1-1 2.1-2.1 2.1-1.2 0-2.1-1-2.1-2.3z" fill="#FFF"/><path d="M89.6 82.1c0 1.2-.9 2.2-2.1 2.2-1.2 0-2.2-1-2.2-2.1 0-1.2 1-2.1 2.2-2.1 1.2-.1 2.1.8 2.1 2z" fill="#FFF"/><path d="M50.3 67.9c0 1.2-1 2.1-2.1 2.1-1.2 0-2.1-1-2.1-2.2 0-1.1 1-2.1 2.1-2.1 1.2 0 2.1 1 2.1 2.2z" fill="#FFF"/><path d="M72.2 49.5c-1.2 0-2.1-.9-2.1-2.1 0-1.2.9-2.1 2.1-2.1 1.2 0 2.1.9 2.1 2.1 0 1.3-.9 2.1-2.1 2.1z" fill="#FFF"/><path d="M77.9 76.3c1.2 0 2.1.9 2.1 2.1 0 1.2-1 2.2-2.2 2.2-1.1 0-2-1-2-2.1 0-1.3.9-2.2 2.1-2.2z" fill="#FFF"/><path d="M43.1 69.1c0 1-.8 1.8-1.8 1.8s-1.9-.9-1.9-1.9c0-1 .9-1.8 1.9-1.8 1.1.1 1.8.8 1.8 1.9z" fill="#FFF"/><path d="M84.2 83.8c0 1-.8 1.8-1.8 1.8s-1.8-.9-1.8-1.8c0-1 .8-1.8 1.9-1.8.9 0 1.7.8 1.7 1.8z" fill="#FFF"/><path d="M74.5 39.1c1.1 0 1.9.7 1.9 1.8 0 1-.8 1.8-1.8 1.8s-1.8-.7-1.8-1.8c0-1 .7-1.8 1.7-1.8z" fill="#FFF"/></svg>' @@ -443,7 +443,7 @@ Vue.component('stop-icon', { Vue.component('empty-icon', { template: '<svg></svg>' })`, - "js/initials.js":`var initialData = { + "js/initials.js": `var initialData = { loggedIn: false, connected: false, tabs: ['Logs', 'Spammer', 'Transactions', 'Neighbors'], @@ -458,7 +458,7 @@ Vue.component('empty-icon', { loginError:'', } `, - "js/main.js":`new Vue({ + "js/main.js": `new Vue({ el: '#app', created() { this.init() @@ -618,7 +618,7 @@ Vue.component('empty-icon', { } }, })`, - "js/tpschart.js":`Vue.component('tps-chart', { + "js/tpschart.js": `Vue.component('tps-chart', { props: ['tps'], watch:{ tps: function (val, oldVal) { @@ -900,7 +900,7 @@ var highchartsTheme = { contrastTextColor: '#F0F0F3', maskColor: 'rgba(255,255,255,0.3)' }`, - "js/utils.js":`function uptimeConverter(seconds) { + "js/utils.js": `function uptimeConverter(seconds) { var s = '' var hrs = Math.floor(seconds / 3600); if (hrs) s += hrs+'h ' @@ -992,5 +992,4 @@ function debounce(func, delay) { function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); }`, - } diff --git a/plugins/ui/nodeInfo.go b/plugins/ui/nodeInfo.go index a97ab5a19b33a98ff1af3e1bf4e1ee49a6d19035..70f2531791ec3ad8c7bb04995567e9c238800182 100644 --- a/plugins/ui/nodeInfo.go +++ b/plugins/ui/nodeInfo.go @@ -4,8 +4,8 @@ import ( "sync/atomic" "time" - "github.com/iotaledger/goshimmer/packages/accountability" "github.com/iotaledger/goshimmer/plugins/autopeering" + "github.com/iotaledger/goshimmer/plugins/autopeering/local" ) var start = time.Now() @@ -49,7 +49,7 @@ func gatherInfo() nodeInfo { receivedTps, solidTps := updateTpsCounters() duration := time.Since(start) / time.Second info := nodeInfo{ - ID: accountability.OwnId().StringIdentifier, + ID: local.INSTANCE.ID().String(), ChosenNeighbors: chosenNeighbors, AcceptedNeighbors: acceptedNeighbors, KnownPeersSize: len(autopeering.Discovery.GetVerifiedPeers()), //knownpeers.INSTANCE.Peers.Len(), diff --git a/runNetwork.sh b/runNetwork.sh new file mode 100755 index 0000000000000000000000000000000000000000..30dd6a3399fd428bef3a0a48b50f5150f9d5156f --- /dev/null +++ b/runNetwork.sh @@ -0,0 +1,32 @@ + +#!/bin/bash + +if [ -z "$1" ]; then + echo "Usage: `basename $0` number_of_nodes" + exit 0 +fi + +re='^[0-9]+$' +if ! [[ $1 =~ $re ]] ; then + echo "Error: Number of nodes given is not a number" >&2; exit 1 +fi + +PEERING_PORT=14630 +GOSSIP_PORT=15670 + +if [ -d testNodes ]; then + rm -r testNodes +fi +mkdir testNodes +cd testNodes + +for i in `seq 1 $1`; do + PEERING_PORT=$((PEERING_PORT+1)) + GOSSIP_PORT=$((GOSSIP_PORT+1)) + mkdir node_$i + mkdir node_$i/logs + cp ../shimmer node_$i/ + cd node_$i + ./shimmer -autopeering-port $PEERING_PORT -gossip-port $GOSSIP_PORT -autopeering-address 127.0.0.1 -autopeering-entry-nodes 6rtO4nW2nzbSqZ8nrf0VFOn+fuyluf6ltJTkKpUc3LM=@127.0.0.1:14626 -node-log-level 4 -node-disable-plugins statusscreen -analysis-server-address 127.0.0.1:188 & + cd .. +done \ No newline at end of file