Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package selection
import (
"github.com/iotaledger/goshimmer/packages/autopeering/peer"
"github.com/iotaledger/hive.go/events"
)
// Events contains all the events that are triggered during the neighbor selection.
var Events = struct {
// An OutgoingPeering event is triggered, when a valid response of PeeringRequest has been received.
OutgoingPeering *events.Event
// An IncomingPeering event is triggered, when a valid PeerRequest has been received.
IncomingPeering *events.Event
// A Dropped event is triggered, when a neigbhor is dropped or when a drop message is received.
Dropped *events.Event
}{
OutgoingPeering: events.NewEvent(peeringCaller),
IncomingPeering: events.NewEvent(peeringCaller),
Dropped: events.NewEvent(droppedCaller),
}
// PeeringEvent bundles the information sent in a peering event.
type PeeringEvent struct {
Self peer.ID // ID of the peer triggering the event.
Peer *peer.Peer // peering partner
Status bool // true, when the peering partner has accepted the request
}
// DroppedEvent bundles the information sent in Dropped events.
type DroppedEvent struct {
Self peer.ID // ID of the peer triggering the event.
DroppedID peer.ID // ID of the peer that gets dropped.
}
func peeringCaller(handler interface{}, params ...interface{}) {
handler.(func(*PeeringEvent))(params[0].(*PeeringEvent))
}
func droppedCaller(handler interface{}, params ...interface{}) {
handler.(func(*DroppedEvent))(params[0].(*DroppedEvent))
}