-
Notifications
You must be signed in to change notification settings - Fork 1
/
signal.go
36 lines (29 loc) · 889 Bytes
/
signal.go
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
package noise
// header keep the context for triggered signal.
type header struct {
// Type of event published
peer *peer // Hold the involved peer
event Event // Hold the triggered event
}
// Peer return bundled peer
func (h *header) Peer() *peer { return h.peer }
// Type return Event type published.
func (m header) Type() Event { return m.event }
// [Signal] it is a message interface to transport network events.
// Each Signal keep a immutable state holding original header and body.
type Signal struct {
header header
body string
}
// Payload return an immutable payload.
func (s *Signal) Payload() string {
return s.body
}
// Type forward internal signal header event type.
func (s *Signal) Type() Event {
return s.header.Type()
}
// Reply send an answer to peer in context.
func (s *Signal) Reply(msg []byte) (uint32, error) {
return s.header.Peer().Send(msg)
}