diff --git a/main.go b/main.go index ea8dfe65d0e46998c3baff7a23b3b72af1a30cfb..c58b8fc2e81a9caeb32febffd5d34af1a301a380 100644 --- a/main.go +++ b/main.go @@ -13,8 +13,8 @@ func main() { node.Run( cli.PLUGIN, autopeering.PLUGIN, + analysis.PLUGIN, statusscreen.PLUGIN, gracefulshutdown.PLUGIN, - analysis.PLUGIN, ) } diff --git a/plugins/analysis/server/plugin.go b/plugins/analysis/server/plugin.go index 7fb373b9149d1099b2a2d1fbe54706dd4484cd44..58eb2555039b208b9d6a63cdc3a8bc8fc5c49adf 100644 --- a/plugins/analysis/server/plugin.go +++ b/plugins/analysis/server/plugin.go @@ -63,6 +63,7 @@ func HandleConnection(conn *network.ManagedConnection) { } onDisconnect = func() { Events.NodeOffline.Trigger(connectedNodeId) + Events.RemoveNode.Trigger(connectedNodeId) conn.Events.ReceiveData.Detach(onReceiveData) conn.Events.Close.Detach(onDisconnect) diff --git a/plugins/analysis/webinterface/httpserver/data_stream.go b/plugins/analysis/webinterface/httpserver/data_stream.go index a7e4bf7bac4a44b110710c80727156a0c797a4c8..f628eca4a54b249d363fc5eb31a8f38226fcc97f 100644 --- a/plugins/analysis/webinterface/httpserver/data_stream.go +++ b/plugins/analysis/webinterface/httpserver/data_stream.go @@ -8,10 +8,25 @@ import ( "golang.org/x/net/websocket" ) +var nodes = make(map[string]bool) +var links = make(map[string]map[string]bool) + func dataStream(ws *websocket.Conn) { eventHandlers := &types.EventHandlers{ - AddNode: func(nodeId string) { fmt.Fprint(ws, "A"+nodeId) }, - RemoveNode: func(nodeId string) { fmt.Fprint(ws, "a"+nodeId) }, + AddNode: func(nodeId string) { + if _, exists := nodes[nodeId]; !exists { + nodes[nodeId] = true + + fmt.Fprint(ws, "A"+nodeId) + } + }, + RemoveNode: func(nodeId string) { + if _, exists := nodes[nodeId]; exists { + delete(nodes, nodeId) + + fmt.Fprint(ws, "a"+nodeId) + } + }, ConnectNodes: func(sourceId string, targetId string) { fmt.Fprint(ws, "C"+sourceId+targetId) }, DisconnectNodes: func(sourceId string, targetId string) { fmt.Fprint(ws, "c"+sourceId+targetId) }, NodeOnline: func(nodeId string) { fmt.Fprint(ws, "O"+nodeId) }, diff --git a/plugins/analysis/webinterface/httpserver/index.go b/plugins/analysis/webinterface/httpserver/index.go index ea92cd23c138a46a935201db09c6a00b647c6f83..023ca380b2bc09fd44fdc0cab271d8bada9bd206 100644 --- a/plugins/analysis/webinterface/httpserver/index.go +++ b/plugins/analysis/webinterface/httpserver/index.go @@ -34,7 +34,7 @@ func index(w http.ResponseWriter, r *http.Request) { break; case "A": - addNode(e.data.substr(1)); + //addNode(e.data.substr(1)); break; case "a": @@ -42,6 +42,8 @@ func index(w http.ResponseWriter, r *http.Request) { break; case "C": + addNode(e.data.substr(1, 40)); + addNode(e.data.substr(41, 40)); connectNodes(e.data.substr(1, 40), e.data.substr(41, 40)); break; @@ -72,13 +74,27 @@ func index(w http.ResponseWriter, r *http.Request) { .enableNodeDrag(false) .onNodeHover(node => elem.style.cursor = node ? 'pointer' : null) .onNodeClick(removeNodeX) - .linkDirectionalParticles(3) - .linkDirectionalParticleWidth(0.8) - .linkDirectionalParticleSpeed(0.01) + //.linkDirectionalParticles(3) + //.linkDirectionalParticleWidth(0.8) + //.linkDirectionalParticleSpeed(0.01) .nodeColor(node => node.online ? 'rgba(0,255,0,1)' : 'rgba(255,255,255,1)') .graphData(data); - function addNode(nodeId) { + var updateRequired = true; + + setInterval(function() { + if (updateRequired) { + Graph.graphData(data); + + updateRequired = false; + } + }, 500) + + updateGraph = function() { + updateRequired = true; + }; + + function addNode(nodeId, displayImmediately) { node = {id : nodeId, online: false}; if (!(node.id in nodesById)) { @@ -86,7 +102,7 @@ func index(w http.ResponseWriter, r *http.Request) { nodesById[node.id] = node; - Graph.graphData(data); + updateGraph(); } } @@ -96,31 +112,35 @@ func index(w http.ResponseWriter, r *http.Request) { delete nodesById[nodeId]; - Graph.graphData(data); + updateGraph(); } function setNodeOnline(nodeId) { - nodesById[nodeId].online = true; + if (nodeId in nodesById) { + nodesById[nodeId].online = true; + } - Graph.graphData(data); + updateGraph(); } function setNodeOffline(nodeId) { - nodesById[nodeId].online = false; + if (nodeId in nodesById) { + nodesById[nodeId].online = false; - Graph.graphData(data); + updateGraph(); + } } function connectNodes(sourceNodeId, targetNodeId) { data.links = [...data.links, { source: sourceNodeId, target: targetNodeId }]; - Graph.graphData(data); + updateGraph(); } 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)); - Graph.graphData(data); + updateGraph(); } function removeNodeX(node) { diff --git a/plugins/analysis/webinterface/recordedevents/recorded_events.go b/plugins/analysis/webinterface/recordedevents/recorded_events.go index 2f63d9d3287f7631d878b3114150c004c0ba5c28..b465f4eab2bdbf7acd43b43724a92eae69f48c3a 100644 --- a/plugins/analysis/webinterface/recordedevents/recorded_events.go +++ b/plugins/analysis/webinterface/recordedevents/recorded_events.go @@ -9,33 +9,90 @@ import ( var recordedEvents = make([]types.EventHandlersConsumer, 0) +var nodes = make(map[string]bool) +var links = make(map[string]map[string]bool) + func Configure(plugin *node.Plugin) { server.Events.AddNode.Attach(func(nodeId string) { + nodes[nodeId] = false + /* + recordedEvents = append(recordedEvents, func(handlers *types.EventHandlers) { + handlers.AddNode(nodeId) + }) + */ + }) + + server.Events.RemoveNode.Attach(func(nodeId string) { + delete(nodes, nodeId) + /* recordedEvents = append(recordedEvents, func(handlers *types.EventHandlers) { handlers.AddNode(nodeId) }) + */ }) server.Events.NodeOnline.Attach(func(nodeId string) { + nodes[nodeId] = true + /* recordedEvents = append(recordedEvents, func(handlers *types.EventHandlers) { handlers.NodeOnline(nodeId) }) + */ }) server.Events.NodeOffline.Attach(func(nodeId string) { + nodes[nodeId] = false + /* recordedEvents = append(recordedEvents, func(handlers *types.EventHandlers) { handlers.NodeOffline(nodeId) }) + */ }) server.Events.ConnectNodes.Attach(func(sourceId string, targetId string) { + connectionMap, connectionMapExists := links[sourceId] + if !connectionMapExists { + connectionMap = make(map[string]bool) + + links[sourceId] = connectionMap + } + connectionMap[targetId] = true + /* + recordedEvents = append(recordedEvents, func(handlers *types.EventHandlers) { + handlers.ConnectNodes(sourceId, targetId) + }) + */ + }) + + server.Events.DisconnectNodes.Attach(func(sourceId string, targetId string) { + connectionMap, connectionMapExists := links[sourceId] + if connectionMapExists { + delete(connectionMap, targetId) + } + /* recordedEvents = append(recordedEvents, func(handlers *types.EventHandlers) { handlers.ConnectNodes(sourceId, targetId) }) + */ }) } func Replay(handlers *types.EventHandlers, delay time.Duration) { + for nodeId, online := range nodes { + handlers.AddNode(nodeId) + if online { + handlers.NodeOnline(nodeId) + } else { + handlers.NodeOffline(nodeId) + } + } + + for sourceId, targetMap := range links { + for targetId, _ := range targetMap { + handlers.ConnectNodes(sourceId, targetId) + } + } + /* for _, recordedEvent := range recordedEvents { recordedEvent(handlers) @@ -43,4 +100,5 @@ func Replay(handlers *types.EventHandlers, delay time.Duration) { time.Sleep(delay) } } + */ } diff --git a/plugins/autopeering/instances/chosenneighborcandidates/instance.go b/plugins/autopeering/instances/chosenneighborcandidates/instance.go index e5c1af0b884150af8fc9b2e600d35e2b1b310153..d57b684c72f7ff54434eecac6a54b567c6beb358 100644 --- a/plugins/autopeering/instances/chosenneighborcandidates/instance.go +++ b/plugins/autopeering/instances/chosenneighborcandidates/instance.go @@ -1,6 +1,7 @@ package chosenneighborcandidates import ( + "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/neighborhood" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/outgoingrequest" "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" @@ -16,7 +17,7 @@ var DISTANCE = func(anchor *peer.Peer) func(p *peer.Peer) uint64 { } } -func init() { +func Configure(plugin *node.Plugin) { updateNeighborCandidates() neighborhood.Events.Update.Attach(updateNeighborCandidates) diff --git a/plugins/autopeering/instances/entrynodes/instance.go b/plugins/autopeering/instances/entrynodes/instance.go index 0c557ed3a3a74761b6cb21888578100ad8be1168..51d1e220c78f66813148e818745f16347341fb03 100644 --- a/plugins/autopeering/instances/entrynodes/instance.go +++ b/plugins/autopeering/instances/entrynodes/instance.go @@ -3,6 +3,7 @@ package entrynodes import ( "encoding/hex" "github.com/iotaledger/goshimmer/packages/identity" + "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/autopeering/parameters" "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" "github.com/iotaledger/goshimmer/plugins/autopeering/types/peerlist" @@ -11,7 +12,11 @@ import ( "strings" ) -var INSTANCE = parseEntryNodes() +var INSTANCE peerlist.PeerList + +func Configure(node *node.Plugin) { + INSTANCE = parseEntryNodes() +} func parseEntryNodes() peerlist.PeerList { result := make(peerlist.PeerList, 0) diff --git a/plugins/autopeering/instances/knownpeers/instance.go b/plugins/autopeering/instances/knownpeers/instance.go index 3b5af569574180ecb053700765c9fea9009ec70c..baf11fef41d43bd5de6fc00911dd170860ca0928 100644 --- a/plugins/autopeering/instances/knownpeers/instance.go +++ b/plugins/autopeering/instances/knownpeers/instance.go @@ -1,12 +1,17 @@ package knownpeers import ( + "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/entrynodes" "github.com/iotaledger/goshimmer/plugins/autopeering/types/peerregister" ) var INSTANCE = initKnownPeers() +func Configure(plugin *node.Plugin) { + INSTANCE = initKnownPeers() +} + func initKnownPeers() peerregister.PeerRegister { knownPeers := make(peerregister.PeerRegister) for _, entryNode := range entrynodes.INSTANCE { diff --git a/plugins/autopeering/instances/neighborhood/instance.go b/plugins/autopeering/instances/neighborhood/instance.go index 7ce955001f5a924278c53eedbd30f57cafa50bdb..ea3da9334ef1c3a0720a16596ea3cb0ac872ef0b 100644 --- a/plugins/autopeering/instances/neighborhood/instance.go +++ b/plugins/autopeering/instances/neighborhood/instance.go @@ -1,6 +1,7 @@ package neighborhood import ( + "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/packages/timeutil" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/knownpeers" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/outgoingrequest" @@ -27,7 +28,7 @@ var NEIGHBORHOOD_SELECTOR = func(this peerregister.PeerRegister, req *request.Re var lastUpdate = time.Now() -func init() { +func Configure(plugin *node.Plugin) { updateNeighborHood() go timeutil.Ticker(updateNeighborHood, 1 * time.Second) diff --git a/plugins/autopeering/instances/outgoingrequest/instance.go b/plugins/autopeering/instances/outgoingrequest/instance.go index e4310e727c860072253ed541304da73a461da63a..c91a9dbc04d4afaef65a40c36298d23e9b73e34d 100644 --- a/plugins/autopeering/instances/outgoingrequest/instance.go +++ b/plugins/autopeering/instances/outgoingrequest/instance.go @@ -1,6 +1,7 @@ package outgoingrequest import ( + "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/ownpeer" "github.com/iotaledger/goshimmer/plugins/autopeering/types/request" "github.com/iotaledger/goshimmer/plugins/autopeering/types/salt" @@ -9,7 +10,7 @@ import ( var INSTANCE *request.Request -func init() { +func Configure(plugin *node.Plugin) { INSTANCE = &request.Request{ Issuer: ownpeer.INSTANCE, } diff --git a/plugins/autopeering/instances/ownpeer/instance.go b/plugins/autopeering/instances/ownpeer/instance.go index 7daff310f300a20549dfc7bcc99f1e64085f16ad..c813077edaf5f2951f4a923044d4f1d4cce1e634 100644 --- a/plugins/autopeering/instances/ownpeer/instance.go +++ b/plugins/autopeering/instances/ownpeer/instance.go @@ -2,16 +2,21 @@ package ownpeer import ( "github.com/iotaledger/goshimmer/packages/accountability" + "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/autopeering/parameters" "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" "github.com/iotaledger/goshimmer/plugins/autopeering/saltmanager" "net" ) -var INSTANCE = &peer.Peer{ - Identity: accountability.OWN_ID, - PeeringPort: uint16(*parameters.PORT.Value), - GossipPort: uint16(*parameters.PORT.Value), - Address: net.IPv4(0, 0, 0, 0), - Salt: saltmanager.PUBLIC_SALT, +var INSTANCE *peer.Peer + +func Configure(plugin *node.Plugin) { + INSTANCE = &peer.Peer{ + Identity: accountability.OWN_ID, + PeeringPort: uint16(*parameters.PORT.Value), + GossipPort: uint16(*parameters.PORT.Value), + Address: net.IPv4(0, 0, 0, 0), + Salt: saltmanager.PUBLIC_SALT, + } } diff --git a/plugins/autopeering/instances/plugin.go b/plugins/autopeering/instances/plugin.go new file mode 100644 index 0000000000000000000000000000000000000000..7b3d1d1b46f2fbedc948b55ac6de09cdaecf2b96 --- /dev/null +++ b/plugins/autopeering/instances/plugin.go @@ -0,0 +1,20 @@ +package instances + +import ( + "github.com/iotaledger/goshimmer/packages/node" + "github.com/iotaledger/goshimmer/plugins/autopeering/instances/chosenneighborcandidates" + "github.com/iotaledger/goshimmer/plugins/autopeering/instances/entrynodes" + "github.com/iotaledger/goshimmer/plugins/autopeering/instances/knownpeers" + "github.com/iotaledger/goshimmer/plugins/autopeering/instances/neighborhood" + "github.com/iotaledger/goshimmer/plugins/autopeering/instances/outgoingrequest" + "github.com/iotaledger/goshimmer/plugins/autopeering/instances/ownpeer" +) + +func Configure(plugin *node.Plugin) { + ownpeer.Configure(plugin) + entrynodes.Configure(plugin) + knownpeers.Configure(plugin) + neighborhood.Configure(plugin) + outgoingrequest.Configure(plugin) + chosenneighborcandidates.Configure(plugin) +} diff --git a/plugins/autopeering/plugin.go b/plugins/autopeering/plugin.go index 19e4e5ae8c2ab01e07d61a46552542258bbae4ff..a4f5f6aef025e1e72c7d712646b3ad1083de67c3 100644 --- a/plugins/autopeering/plugin.go +++ b/plugins/autopeering/plugin.go @@ -3,6 +3,7 @@ package autopeering import ( "github.com/iotaledger/goshimmer/packages/daemon" "github.com/iotaledger/goshimmer/packages/node" + "github.com/iotaledger/goshimmer/plugins/autopeering/instances" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/knownpeers" "github.com/iotaledger/goshimmer/plugins/autopeering/protocol" "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" @@ -13,6 +14,7 @@ import ( ) func configure(plugin *node.Plugin) { + instances.Configure(plugin) server.Configure(plugin) protocol.Configure(plugin) diff --git a/plugins/autopeering/protocol/constants/constants.go b/plugins/autopeering/protocol/constants/constants.go index e181bf150c4deb04eba98dae6d197cafdd836d9c..ca9bdc23d8311b7deb81e06c2caa3f68f9c0e729 100644 --- a/plugins/autopeering/protocol/constants/constants.go +++ b/plugins/autopeering/protocol/constants/constants.go @@ -3,9 +3,9 @@ package constants import "time" const ( - NEIGHBOR_COUNT = 8 + NEIGHBOR_COUNT = 4 - FIND_NEIGHBOR_INTERVAL = 5 * time.Second + FIND_NEIGHBOR_INTERVAL = 60 * time.Second // How often does the outgoing ping processor check if new pings should be sent. PING_PROCESS_INTERVAL = 1 * time.Second diff --git a/plugins/autopeering/protocol/outgoing_ping_processor.go b/plugins/autopeering/protocol/outgoing_ping_processor.go index 12ddb628b4d61ca93a058e383266b896b11a603a..580791ac6a84ebf30ccec47253b73f95b653532f 100644 --- a/plugins/autopeering/protocol/outgoing_ping_processor.go +++ b/plugins/autopeering/protocol/outgoing_ping_processor.go @@ -5,7 +5,7 @@ import ( "github.com/iotaledger/goshimmer/packages/daemon" "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/neighborhood" - "github.com/iotaledger/goshimmer/plugins/autopeering/parameters" + "github.com/iotaledger/goshimmer/plugins/autopeering/instances/ownpeer" "github.com/iotaledger/goshimmer/plugins/autopeering/protocol/constants" "github.com/iotaledger/goshimmer/plugins/autopeering/protocol/types" "github.com/iotaledger/goshimmer/plugins/autopeering/saltmanager" @@ -13,7 +13,6 @@ import ( "github.com/iotaledger/goshimmer/plugins/autopeering/types/ping" "github.com/iotaledger/goshimmer/plugins/autopeering/types/salt" "math/rand" - "net" "time" ) @@ -27,13 +26,7 @@ func createOutgoingPingProcessor(plugin *node.Plugin) func() { lastPing = time.Now().Add(-constants.PING_CYCLE_LENGTH) outgoingPing := &ping.Ping{ - Issuer: &peer.Peer{ - Identity: accountability.OWN_ID, - Address: net.IPv4(0, 0, 0, 0), - PeeringPort: uint16(*parameters.PORT.Value), - GossipPort: uint16(*parameters.PORT.Value), - Salt: saltmanager.PUBLIC_SALT, - }, + Issuer: ownpeer.INSTANCE, } outgoingPing.Sign() diff --git a/plugins/autopeering/types/request/request.go b/plugins/autopeering/types/request/request.go index 79de558b9d2e8af37d81d1568c914b5a5d174a8e..b82c69ab49f2868aa193a9248a312b960d80618d 100644 --- a/plugins/autopeering/types/request/request.go +++ b/plugins/autopeering/types/request/request.go @@ -65,6 +65,17 @@ func (this *Request) Accept(peers []*peer.Peer) error { } func (this *Request) Reject(peers []*peer.Peer) error { + peeringResponse := &response.Response{ + Type: response.TYPE_REJECT, + Issuer: ownpeer.INSTANCE, + Peers: peers, + } + peeringResponse.Sign() + + if _, err := this.Issuer.Send(peeringResponse.Marshal(), types.PROTOCOL_TYPE_TCP, false); err != nil { + return err + } + return nil } diff --git a/plugins/autopeering/types/response/response.go b/plugins/autopeering/types/response/response.go index d4ece51ad714e063b7226a4ee6d53086ed11dc00..4151bb3da64f1d1322110c38687961e77b6978fe 100644 --- a/plugins/autopeering/types/response/response.go +++ b/plugins/autopeering/types/response/response.go @@ -3,6 +3,7 @@ package response import ( "bytes" "github.com/iotaledger/goshimmer/packages/identity" + "github.com/iotaledger/goshimmer/plugins/autopeering/protocol/constants" "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" "github.com/pkg/errors" ) @@ -76,11 +77,13 @@ func (this *Response) Marshal() []byte { copy(result[MARSHALLED_ISSUER_START:MARSHALLED_ISSUER_END], this.Issuer.Marshal()) for i, peer := range this.Peers { - PEERING_RESPONSE_MARSHALLED_PEER_START := MARSHALLED_PEERS_START + (i * MARSHALLED_PEER_SIZE) - PEERING_RESPONSE_MARSHALLED_PEER_END := PEERING_RESPONSE_MARSHALLED_PEER_START + MARSHALLED_PEER_SIZE + if i < constants.NEIGHBOR_COUNT { + PEERING_RESPONSE_MARSHALLED_PEER_START := MARSHALLED_PEERS_START + (i * MARSHALLED_PEER_SIZE) + PEERING_RESPONSE_MARSHALLED_PEER_END := PEERING_RESPONSE_MARSHALLED_PEER_START + MARSHALLED_PEER_SIZE - result[PEERING_RESPONSE_MARSHALLED_PEER_START] = 1 - copy(result[PEERING_RESPONSE_MARSHALLED_PEER_START+1:PEERING_RESPONSE_MARSHALLED_PEER_END], peer.Marshal()[:MARSHALLED_PEER_SIZE-1]) + result[PEERING_RESPONSE_MARSHALLED_PEER_START] = 1 + copy(result[PEERING_RESPONSE_MARSHALLED_PEER_START+1:PEERING_RESPONSE_MARSHALLED_PEER_END], peer.Marshal()[:MARSHALLED_PEER_SIZE-1]) + } } copy(result[MARSHALLED_SIGNATURE_START:MARSHALLED_SIGNATURE_END], this.Signature[:MARSHALLED_SIGNATURE_SIZE]) diff --git a/plugins/cli/plugin.go b/plugins/cli/plugin.go index fd3121b753196342d6ec3b4fa0a7d954bc31ff56..3eacb9b140bbf72a214a8d0eda6cf06007e37236 100644 --- a/plugins/cli/plugin.go +++ b/plugins/cli/plugin.go @@ -2,8 +2,8 @@ package cli import ( "flag" - "github.com/iotaledger/goshimmer/packages/parameter" "github.com/iotaledger/goshimmer/packages/node" + "github.com/iotaledger/goshimmer/packages/parameter" "strings" )