Skip to content
Snippets Groups Projects
Select Git revision
  • 37061e640696e153e0fa9b8928ffab3df8b46c66
  • develop default protected
  • congestioncontrol
  • merge-v-data-collection-spammer-0.8.2
  • WIP-merge-v-data-collection-spammer-0.8.2
  • merge-v-data-collection-spammer-0.7.7
  • tmp
  • test-masterpow-fixing
  • test-masterpow
  • test-echo
  • v-data-collection
  • v-data-collection-spammer
  • tmp-dump-spam-info
  • dump-msg-info-0.3.1
  • test-dump-message-info
  • spammer-exprandom
  • extra/tutorial
  • without_tipselection
  • hacking-docker-network
  • hacking-docker-network-0.2.3
  • master
  • v0.2.3
22 results

runSimulation.bat

Blame
  • events.go 2.39 KiB
    package protocol
    
    import (
        "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer"
        "github.com/iotaledger/goshimmer/plugins/autopeering/types/request"
        "github.com/iotaledger/goshimmer/plugins/autopeering/types/response"
        "reflect"
    )
    
    var Events = protocolEvents{
        DiscoverPeer:            &peerEvent{make(map[uintptr]PeerConsumer)},
        IncomingRequestAccepted: &requestEvent{make(map[uintptr]RequestConsumer)},
        IncomingRequestRejected: &requestEvent{make(map[uintptr]RequestConsumer)},
        OutgoingRequestAccepted: &responseEvent{make(map[uintptr]ResponseConsumer)},
        OutgoingRequestRejected: &responseEvent{make(map[uintptr]ResponseConsumer)},
    }
    
    type protocolEvents struct {
        DiscoverPeer            *peerEvent
        IncomingRequestAccepted *requestEvent
        IncomingRequestRejected *requestEvent
        OutgoingRequestAccepted *responseEvent
        OutgoingRequestRejected *responseEvent
    }
    
    type peerEvent struct {
        callbacks map[uintptr]PeerConsumer
    }
    
    func (this *peerEvent) Attach(callback PeerConsumer) {
        this.callbacks[reflect.ValueOf(callback).Pointer()] = callback
    }
    
    func (this *peerEvent) Detach(callback PeerConsumer) {
        delete(this.callbacks, reflect.ValueOf(callback).Pointer())
    }
    
    func (this *peerEvent) Trigger(p *peer.Peer) {
        for _, callback := range this.callbacks {
            callback(p)
        }
    }
    
    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(res *response.Response) {
        for _, callback := range this.callbacks {
            callback(res)
        }
    }
    
    type PeerConsumer = func(p *peer.Peer)
    
    type RequestConsumer = func(req *request.Request)
    
    type ResponseConsumer = func(res *response.Response)