Skip to content
Snippets Groups Projects
Commit 3764ebf7 authored by Hans Moog's avatar Hans Moog
Browse files

Fix: fixed remaining event handlers

parent 54b87796
No related branches found
No related tags found
No related merge requests found
Showing
with 70 additions and 250 deletions
...@@ -64,6 +64,8 @@ func index(w http.ResponseWriter, r *http.Request) { ...@@ -64,6 +64,8 @@ func index(w http.ResponseWriter, r *http.Request) {
links: [] links: []
}; };
var existingLinks = {};
const elem = document.getElementById("3d-graph"); const elem = document.getElementById("3d-graph");
const Graph = ForceGraph3D()(elem) const Graph = ForceGraph3D()(elem)
...@@ -125,14 +127,19 @@ func index(w http.ResponseWriter, r *http.Request) { ...@@ -125,14 +127,19 @@ func index(w http.ResponseWriter, r *http.Request) {
} }
function connectNodes(sourceNodeId, targetNodeId) { function connectNodes(sourceNodeId, targetNodeId) {
if(existingLinks[sourceNodeId + targetNodeId] == undefined && existingLinks[targetNodeId + sourceNodeId] == undefined) {
data.links = [...data.links, { source: sourceNodeId, target: targetNodeId }]; data.links = [...data.links, { source: sourceNodeId, target: targetNodeId }];
updateGraph(); updateGraph();
} }
}
function disconnectNodes(sourceNodeId, targetNodeId) { 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)); 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];
updateGraph(); updateGraph();
} }
......
package protocol package protocol
import ( import (
"github.com/iotaledger/goshimmer/packages/events"
"github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/packages/node"
"net" "net"
) )
func createErrorHandler(plugin *node.Plugin) func(ip net.IP, err error) { func createErrorHandler(plugin *node.Plugin) *events.Closure {
return func(ip net.IP, err error) { return events.NewClosure(func(ip net.IP, err error) {
plugin.LogDebug("error when communicating with " + ip.String() + ": " + err.Error()) plugin.LogDebug("error when communicating with " + ip.String() + ": " + err.Error())
} })
} }
package protocol package protocol
import ( import (
"github.com/iotaledger/goshimmer/packages/events"
"github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/packages/node"
"github.com/iotaledger/goshimmer/plugins/autopeering/instances/acceptedneighbors" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/acceptedneighbors"
"github.com/iotaledger/goshimmer/plugins/autopeering/instances/chosenneighbors" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/chosenneighbors"
"github.com/iotaledger/goshimmer/plugins/autopeering/types/drop" "github.com/iotaledger/goshimmer/plugins/autopeering/types/drop"
) )
func createIncomingDropProcessor(plugin *node.Plugin) func(drop *drop.Drop) { func createIncomingDropProcessor(plugin *node.Plugin) *events.Closure {
return func(drop *drop.Drop) { return events.NewClosure(func(drop *drop.Drop) {
plugin.LogDebug("received drop message from " + drop.Issuer.String()) plugin.LogDebug("received drop message from " + drop.Issuer.String())
chosenneighbors.INSTANCE.Remove(drop.Issuer.Identity.StringIdentifier) chosenneighbors.INSTANCE.Remove(drop.Issuer.Identity.StringIdentifier)
acceptedneighbors.INSTANCE.Remove(drop.Issuer.Identity.StringIdentifier) acceptedneighbors.INSTANCE.Remove(drop.Issuer.Identity.StringIdentifier)
} })
} }
package protocol package protocol
import ( import (
"github.com/iotaledger/goshimmer/packages/events"
"github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/packages/node"
"github.com/iotaledger/goshimmer/plugins/autopeering/instances/knownpeers" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/knownpeers"
"github.com/iotaledger/goshimmer/plugins/autopeering/types/ping" "github.com/iotaledger/goshimmer/plugins/autopeering/types/ping"
) )
func createIncomingPingProcessor(plugin *node.Plugin) func(ping *ping.Ping) { func createIncomingPingProcessor(plugin *node.Plugin) *events.Closure {
return func(ping *ping.Ping) { return events.NewClosure(func(ping *ping.Ping) {
plugin.LogDebug("received ping from " + ping.Issuer.String()) plugin.LogDebug("received ping from " + ping.Issuer.String())
knownpeers.INSTANCE.AddOrUpdate(ping.Issuer) knownpeers.INSTANCE.AddOrUpdate(ping.Issuer)
for _, neighbor := range ping.Neighbors { for _, neighbor := range ping.Neighbors {
knownpeers.INSTANCE.AddOrUpdate(neighbor) knownpeers.INSTANCE.AddOrUpdate(neighbor)
} }
} })
} }
package protocol package protocol
import ( import (
"github.com/iotaledger/goshimmer/packages/events"
"github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/packages/node"
"github.com/iotaledger/goshimmer/plugins/autopeering/instances/acceptedneighbors" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/acceptedneighbors"
"github.com/iotaledger/goshimmer/plugins/autopeering/instances/knownpeers" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/knownpeers"
...@@ -12,10 +13,10 @@ import ( ...@@ -12,10 +13,10 @@ import (
"math/rand" "math/rand"
) )
func createIncomingRequestProcessor(plugin *node.Plugin) func(req *request.Request) { func createIncomingRequestProcessor(plugin *node.Plugin) *events.Closure {
return func(req *request.Request) { return events.NewClosure(func(req *request.Request) {
go processIncomingRequest(plugin, req) go processIncomingRequest(plugin, req)
} })
} }
func processIncomingRequest(plugin *node.Plugin, req *request.Request) { func processIncomingRequest(plugin *node.Plugin, req *request.Request) {
......
package protocol package protocol
import ( import (
"github.com/iotaledger/goshimmer/packages/events"
"github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/packages/node"
"github.com/iotaledger/goshimmer/plugins/autopeering/instances/chosenneighbors" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/chosenneighbors"
"github.com/iotaledger/goshimmer/plugins/autopeering/instances/knownpeers" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/knownpeers"
"github.com/iotaledger/goshimmer/plugins/autopeering/types/response" "github.com/iotaledger/goshimmer/plugins/autopeering/types/response"
) )
func createIncomingResponseProcessor(plugin *node.Plugin) func(peeringResponse *response.Response) { func createIncomingResponseProcessor(plugin *node.Plugin) *events.Closure {
return func(peeringResponse *response.Response) { return events.NewClosure(func(peeringResponse *response.Response) {
go processIncomingResponse(plugin, peeringResponse) go processIncomingResponse(plugin, peeringResponse)
} })
} }
func processIncomingResponse(plugin *node.Plugin, peeringResponse *response.Response) { func processIncomingResponse(plugin *node.Plugin, peeringResponse *response.Response) {
......
package tcp package tcp
import ( import (
"github.com/iotaledger/goshimmer/packages/events"
"github.com/iotaledger/goshimmer/plugins/autopeering/types/ping" "github.com/iotaledger/goshimmer/plugins/autopeering/types/ping"
"github.com/iotaledger/goshimmer/plugins/autopeering/types/request" "github.com/iotaledger/goshimmer/plugins/autopeering/types/request"
"github.com/iotaledger/goshimmer/plugins/autopeering/types/response" "github.com/iotaledger/goshimmer/plugins/autopeering/types/response"
"net" "net"
"reflect"
) )
var Events = &pluginEvents{ var Events = struct {
ReceivePing: &pingEvent{make(map[uintptr]PingConsumer)}, ReceivePing *events.Event
ReceiveRequest: &requestEvent{make(map[uintptr]RequestConsumer)}, ReceiveRequest *events.Event
ReceiveResponse: &responseEvent{make(map[uintptr]ResponseConsumer)}, ReceiveResponse *events.Event
Error: &ipErrorEvent{make(map[uintptr]IPErrorConsumer)}, Error *events.Event
} }{
events.NewEvent(pingCaller),
type pluginEvents struct { events.NewEvent(requestCaller),
ReceivePing *pingEvent events.NewEvent(responseCaller),
ReceiveRequest *requestEvent events.NewEvent(errorCaller),
ReceiveResponse *responseEvent }
Error *ipErrorEvent
} func pingCaller(handler interface{}, params ...interface{}) { handler.(func(*ping.Ping))(params[0].(*ping.Ping)) }
func requestCaller(handler interface{}, params ...interface{}) { handler.(func(*request.Request))(params[0].(*request.Request)) }
type pingEvent struct { func responseCaller(handler interface{}, params ...interface{}) { handler.(func(*response.Response))(params[0].(*response.Response)) }
callbacks map[uintptr]PingConsumer func errorCaller(handler interface{}, params ...interface{}) { handler.(func(net.IP, error))(params[0].(net.IP), params[1].(error)) }
}
func (this *pingEvent) Attach(callback PingConsumer) {
this.callbacks[reflect.ValueOf(callback).Pointer()] = callback
}
func (this *pingEvent) Detach(callback PingConsumer) {
delete(this.callbacks, reflect.ValueOf(callback).Pointer())
}
func (this *pingEvent) Trigger(ping *ping.Ping) {
for _, callback := range this.callbacks {
callback(ping)
}
}
type requestEvent struct {
callbacks map[uintptr]RequestConsumer
}
func (this *requestEvent) Attach(callback RequestConsumer) {
this.callbacks[reflect.ValueOf(callback).Pointer()] = callback
}
func (this *requestEvent) Detach(callback RequestConsumer) {
delete(this.callbacks, reflect.ValueOf(callback).Pointer())
}
func (this *requestEvent) Trigger(req *request.Request) {
for _, callback := range this.callbacks {
callback(req)
}
}
type responseEvent struct {
callbacks map[uintptr]ResponseConsumer
}
func (this *responseEvent) Attach(callback ResponseConsumer) {
this.callbacks[reflect.ValueOf(callback).Pointer()] = callback
}
func (this *responseEvent) Detach(callback ResponseConsumer) {
delete(this.callbacks, reflect.ValueOf(callback).Pointer())
}
func (this *responseEvent) Trigger(peeringResponse *response.Response) {
for _, callback := range this.callbacks {
callback(peeringResponse)
}
}
type ipErrorEvent struct {
callbacks map[uintptr]IPErrorConsumer
}
func (this *ipErrorEvent) Attach(callback IPErrorConsumer) {
this.callbacks[reflect.ValueOf(callback).Pointer()] = callback
}
func (this *ipErrorEvent) Detach(callback IPErrorConsumer) {
delete(this.callbacks, reflect.ValueOf(callback).Pointer())
}
func (this *ipErrorEvent) Trigger(ip net.IP, err error) {
for _, callback := range this.callbacks {
callback(ip, err)
}
}
...@@ -100,8 +100,8 @@ func ProcessIncomingPacket(connectionState *byte, receiveBuffer *[]byte, conn *n ...@@ -100,8 +100,8 @@ func ProcessIncomingPacket(connectionState *byte, receiveBuffer *[]byte, conn *n
} }
} }
func parsePackageHeader(data []byte) (ConnectionState, []byte, error) { func parsePackageHeader(data []byte) (byte, []byte, error) {
var connectionState ConnectionState var connectionState byte
var receiveBuffer []byte var receiveBuffer []byte
switch data[0] { switch data[0] {
......
package tcp
import (
"github.com/iotaledger/goshimmer/plugins/autopeering/types/ping"
"github.com/iotaledger/goshimmer/plugins/autopeering/types/request"
"github.com/iotaledger/goshimmer/plugins/autopeering/types/response"
"net"
)
type PingConsumer = func(p *ping.Ping)
type RequestConsumer = func(req *request.Request)
type ResponseConsumer = func(peeringResponse *response.Response)
type IPErrorConsumer = func(ip net.IP, err error)
type ConnectionState = byte
package udp package udp
import ( import (
"github.com/iotaledger/goshimmer/packages/events"
"github.com/iotaledger/goshimmer/plugins/autopeering/types/drop" "github.com/iotaledger/goshimmer/plugins/autopeering/types/drop"
"github.com/iotaledger/goshimmer/plugins/autopeering/types/ping" "github.com/iotaledger/goshimmer/plugins/autopeering/types/ping"
"github.com/iotaledger/goshimmer/plugins/autopeering/types/request" "github.com/iotaledger/goshimmer/plugins/autopeering/types/request"
"github.com/iotaledger/goshimmer/plugins/autopeering/types/response" "github.com/iotaledger/goshimmer/plugins/autopeering/types/response"
"net" "net"
"reflect"
) )
var Events = &pluginEvents{ var Events = struct {
ReceiveDrop: &dropEvent{make(map[uintptr]DropConsumer)}, ReceiveDrop *events.Event
ReceivePing: &pingEvent{make(map[uintptr]PingConsumer)}, ReceivePing *events.Event
ReceiveRequest: &requestEvent{make(map[uintptr]ConnectionPeeringRequestConsumer)}, ReceiveRequest *events.Event
ReceiveResponse: &responseEvent{make(map[uintptr]ConnectionPeeringResponseConsumer)}, ReceiveResponse *events.Event
Error: &ipErrorEvent{make(map[uintptr]IPErrorConsumer)}, Error *events.Event
} }{
events.NewEvent(dropCaller),
type pluginEvents struct { events.NewEvent(pingCaller),
ReceiveDrop *dropEvent events.NewEvent(requestCaller),
ReceivePing *pingEvent events.NewEvent(responseCaller),
ReceiveRequest *requestEvent events.NewEvent(errorCaller),
ReceiveResponse *responseEvent }
Error *ipErrorEvent
} func dropCaller(handler interface{}, params ...interface{}) { handler.(func(*drop.Drop))(params[0].(*drop.Drop)) }
func pingCaller(handler interface{}, params ...interface{}) { handler.(func(*ping.Ping))(params[0].(*ping.Ping)) }
type dropEvent struct { func requestCaller(handler interface{}, params ...interface{}) { handler.(func(*request.Request))(params[0].(*request.Request)) }
callbacks map[uintptr]DropConsumer func responseCaller(handler interface{}, params ...interface{}) { handler.(func(*response.Response))(params[0].(*response.Response)) }
} func errorCaller(handler interface{}, params ...interface{}) { handler.(func(net.IP, error))(params[0].(net.IP), params[1].(error)) }
func (this *dropEvent) Attach(callback DropConsumer) {
this.callbacks[reflect.ValueOf(callback).Pointer()] = callback
}
func (this *dropEvent) Detach(callback DropConsumer) {
delete(this.callbacks, reflect.ValueOf(callback).Pointer())
}
func (this *dropEvent) Trigger(drop *drop.Drop) {
for _, callback := range this.callbacks {
callback(drop)
}
}
type pingEvent struct {
callbacks map[uintptr]PingConsumer
}
func (this *pingEvent) Attach(callback PingConsumer) {
this.callbacks[reflect.ValueOf(callback).Pointer()] = callback
}
func (this *pingEvent) Detach(callback PingConsumer) {
delete(this.callbacks, reflect.ValueOf(callback).Pointer())
}
func (this *pingEvent) Trigger(ping *ping.Ping) {
for _, callback := range this.callbacks {
callback(ping)
}
}
type requestEvent struct {
callbacks map[uintptr]ConnectionPeeringRequestConsumer
}
func (this *requestEvent) Attach(callback ConnectionPeeringRequestConsumer) {
this.callbacks[reflect.ValueOf(callback).Pointer()] = callback
}
func (this *requestEvent) Detach(callback ConnectionPeeringRequestConsumer) {
delete(this.callbacks, reflect.ValueOf(callback).Pointer())
}
func (this *requestEvent) Trigger(request *request.Request) {
for _, callback := range this.callbacks {
callback(request)
}
}
type responseEvent struct {
callbacks map[uintptr]ConnectionPeeringResponseConsumer
}
func (this *responseEvent) Attach(callback ConnectionPeeringResponseConsumer) {
this.callbacks[reflect.ValueOf(callback).Pointer()] = callback
}
func (this *responseEvent) Detach(callback ConnectionPeeringResponseConsumer) {
delete(this.callbacks, reflect.ValueOf(callback).Pointer())
}
func (this *responseEvent) Trigger(peeringResponse *response.Response) {
for _, callback := range this.callbacks {
callback(peeringResponse)
}
}
type ipErrorEvent struct {
callbacks map[uintptr]IPErrorConsumer
}
func (this *ipErrorEvent) Attach(callback IPErrorConsumer) {
this.callbacks[reflect.ValueOf(callback).Pointer()] = callback
}
func (this *ipErrorEvent) Detach(callback IPErrorConsumer) {
delete(this.callbacks, reflect.ValueOf(callback).Pointer())
}
func (this *ipErrorEvent) Trigger(ip net.IP, err error) {
for _, callback := range this.callbacks {
callback(ip, err)
}
}
...@@ -19,9 +19,9 @@ import ( ...@@ -19,9 +19,9 @@ import (
var udpServer = udp.NewServer(int(math.Max(float64(request.MARSHALLED_TOTAL_SIZE), float64(response.MARSHALLED_TOTAL_SIZE)))) var udpServer = udp.NewServer(int(math.Max(float64(request.MARSHALLED_TOTAL_SIZE), float64(response.MARSHALLED_TOTAL_SIZE))))
func ConfigureServer(plugin *node.Plugin) { func ConfigureServer(plugin *node.Plugin) {
Events.Error.Attach(func(ip net.IP, err error) { Events.Error.Attach(events.NewClosure(func(ip net.IP, err error) {
plugin.LogFailure(err.Error()) plugin.LogFailure(err.Error())
}) }))
udpServer.Events.ReceiveData.Attach(events.NewClosure(processReceivedData)) udpServer.Events.ReceiveData.Attach(events.NewClosure(processReceivedData))
udpServer.Events.Error.Attach(events.NewClosure(func(err error) { udpServer.Events.Error.Attach(events.NewClosure(func(err error) {
......
package udp
import (
"github.com/iotaledger/goshimmer/plugins/autopeering/types/drop"
"github.com/iotaledger/goshimmer/plugins/autopeering/types/ping"
"github.com/iotaledger/goshimmer/plugins/autopeering/types/request"
"github.com/iotaledger/goshimmer/plugins/autopeering/types/response"
"net"
)
type DropConsumer = func(d *drop.Drop)
type PingConsumer = func(p *ping.Ping)
type ConnectionPeeringRequestConsumer = func(request *request.Request)
type ConnectionPeeringResponseConsumer = func(peeringResponse *response.Response)
type IPErrorConsumer = func(ip net.IP, err error)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment