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) {
links: []
};
var existingLinks = {};
const elem = document.getElementById("3d-graph");
const Graph = ForceGraph3D()(elem)
......@@ -125,14 +127,19 @@ func index(w http.ResponseWriter, r *http.Request) {
}
function connectNodes(sourceNodeId, targetNodeId) {
data.links = [...data.links, { source: sourceNodeId, target: targetNodeId }];
if(existingLinks[sourceNodeId + targetNodeId] == undefined && existingLinks[targetNodeId + sourceNodeId] == undefined) {
data.links = [...data.links, { source: sourceNodeId, target: targetNodeId }];
updateGraph();
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));
delete existingLinks[sourceNodeId + targetNodeId];
delete existingLinks[targetNodeId + sourceNodeId];
updateGraph();
}
......
package protocol
import (
"github.com/iotaledger/goshimmer/packages/events"
"github.com/iotaledger/goshimmer/packages/node"
"net"
)
func createErrorHandler(plugin *node.Plugin) func(ip net.IP, err error) {
return func(ip net.IP, err error) {
func createErrorHandler(plugin *node.Plugin) *events.Closure {
return events.NewClosure(func(ip net.IP, err error) {
plugin.LogDebug("error when communicating with " + ip.String() + ": " + err.Error())
}
})
}
package protocol
import (
"github.com/iotaledger/goshimmer/packages/events"
"github.com/iotaledger/goshimmer/packages/node"
"github.com/iotaledger/goshimmer/plugins/autopeering/instances/acceptedneighbors"
"github.com/iotaledger/goshimmer/plugins/autopeering/instances/chosenneighbors"
"github.com/iotaledger/goshimmer/plugins/autopeering/types/drop"
)
func createIncomingDropProcessor(plugin *node.Plugin) func(drop *drop.Drop) {
return func(drop *drop.Drop) {
func createIncomingDropProcessor(plugin *node.Plugin) *events.Closure {
return events.NewClosure(func(drop *drop.Drop) {
plugin.LogDebug("received drop message from " + drop.Issuer.String())
chosenneighbors.INSTANCE.Remove(drop.Issuer.Identity.StringIdentifier)
acceptedneighbors.INSTANCE.Remove(drop.Issuer.Identity.StringIdentifier)
}
})
}
package protocol
import (
"github.com/iotaledger/goshimmer/packages/events"
"github.com/iotaledger/goshimmer/packages/node"
"github.com/iotaledger/goshimmer/plugins/autopeering/instances/knownpeers"
"github.com/iotaledger/goshimmer/plugins/autopeering/types/ping"
)
func createIncomingPingProcessor(plugin *node.Plugin) func(ping *ping.Ping) {
return func(ping *ping.Ping) {
func createIncomingPingProcessor(plugin *node.Plugin) *events.Closure {
return events.NewClosure(func(ping *ping.Ping) {
plugin.LogDebug("received ping from " + ping.Issuer.String())
knownpeers.INSTANCE.AddOrUpdate(ping.Issuer)
for _, neighbor := range ping.Neighbors {
knownpeers.INSTANCE.AddOrUpdate(neighbor)
}
}
})
}
package protocol
import (
"github.com/iotaledger/goshimmer/packages/events"
"github.com/iotaledger/goshimmer/packages/node"
"github.com/iotaledger/goshimmer/plugins/autopeering/instances/acceptedneighbors"
"github.com/iotaledger/goshimmer/plugins/autopeering/instances/knownpeers"
......@@ -12,10 +13,10 @@ import (
"math/rand"
)
func createIncomingRequestProcessor(plugin *node.Plugin) func(req *request.Request) {
return func(req *request.Request) {
func createIncomingRequestProcessor(plugin *node.Plugin) *events.Closure {
return events.NewClosure(func(req *request.Request) {
go processIncomingRequest(plugin, req)
}
})
}
func processIncomingRequest(plugin *node.Plugin, req *request.Request) {
......
package protocol
import (
"github.com/iotaledger/goshimmer/packages/events"
"github.com/iotaledger/goshimmer/packages/node"
"github.com/iotaledger/goshimmer/plugins/autopeering/instances/chosenneighbors"
"github.com/iotaledger/goshimmer/plugins/autopeering/instances/knownpeers"
"github.com/iotaledger/goshimmer/plugins/autopeering/types/response"
)
func createIncomingResponseProcessor(plugin *node.Plugin) func(peeringResponse *response.Response) {
return func(peeringResponse *response.Response) {
func createIncomingResponseProcessor(plugin *node.Plugin) *events.Closure {
return events.NewClosure(func(peeringResponse *response.Response) {
go processIncomingResponse(plugin, peeringResponse)
}
})
}
func processIncomingResponse(plugin *node.Plugin, peeringResponse *response.Response) {
......
package tcp
import (
"github.com/iotaledger/goshimmer/packages/events"
"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"
"reflect"
)
var Events = &pluginEvents{
ReceivePing: &pingEvent{make(map[uintptr]PingConsumer)},
ReceiveRequest: &requestEvent{make(map[uintptr]RequestConsumer)},
ReceiveResponse: &responseEvent{make(map[uintptr]ResponseConsumer)},
Error: &ipErrorEvent{make(map[uintptr]IPErrorConsumer)},
}
type pluginEvents struct {
ReceivePing *pingEvent
ReceiveRequest *requestEvent
ReceiveResponse *responseEvent
Error *ipErrorEvent
}
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]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)
}
}
var Events = struct {
ReceivePing *events.Event
ReceiveRequest *events.Event
ReceiveResponse *events.Event
Error *events.Event
}{
events.NewEvent(pingCaller),
events.NewEvent(requestCaller),
events.NewEvent(responseCaller),
events.NewEvent(errorCaller),
}
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)) }
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)) }
......@@ -100,8 +100,8 @@ func ProcessIncomingPacket(connectionState *byte, receiveBuffer *[]byte, conn *n
}
}
func parsePackageHeader(data []byte) (ConnectionState, []byte, error) {
var connectionState ConnectionState
func parsePackageHeader(data []byte) (byte, []byte, error) {
var connectionState byte
var receiveBuffer []byte
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
import (
"github.com/iotaledger/goshimmer/packages/events"
"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"
"reflect"
)
var Events = &pluginEvents{
ReceiveDrop: &dropEvent{make(map[uintptr]DropConsumer)},
ReceivePing: &pingEvent{make(map[uintptr]PingConsumer)},
ReceiveRequest: &requestEvent{make(map[uintptr]ConnectionPeeringRequestConsumer)},
ReceiveResponse: &responseEvent{make(map[uintptr]ConnectionPeeringResponseConsumer)},
Error: &ipErrorEvent{make(map[uintptr]IPErrorConsumer)},
}
type pluginEvents struct {
ReceiveDrop *dropEvent
ReceivePing *pingEvent
ReceiveRequest *requestEvent
ReceiveResponse *responseEvent
Error *ipErrorEvent
}
type dropEvent struct {
callbacks map[uintptr]DropConsumer
}
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)
}
}
var Events = struct {
ReceiveDrop *events.Event
ReceivePing *events.Event
ReceiveRequest *events.Event
ReceiveResponse *events.Event
Error *events.Event
}{
events.NewEvent(dropCaller),
events.NewEvent(pingCaller),
events.NewEvent(requestCaller),
events.NewEvent(responseCaller),
events.NewEvent(errorCaller),
}
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)) }
func requestCaller(handler interface{}, params ...interface{}) { handler.(func(*request.Request))(params[0].(*request.Request)) }
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)) }
......@@ -19,9 +19,9 @@ import (
var udpServer = udp.NewServer(int(math.Max(float64(request.MARSHALLED_TOTAL_SIZE), float64(response.MARSHALLED_TOTAL_SIZE))))
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())
})
}))
udpServer.Events.ReceiveData.Attach(events.NewClosure(processReceivedData))
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