-
Notifications
You must be signed in to change notification settings - Fork 18
/
batch_channel.go
76 lines (62 loc) · 1.63 KB
/
batch_channel.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package cleisthenes
// Batch is result of ACS set of contributions of
// at least n-f number of nodes.
// BatchMessage is used between ACS component and Honeybadger component.
//
// After ACS done its own task for its epoch send BatchMessage to
// Honeybadger, then Honeybadger decrypt batch message.
type BatchMessage struct {
Epoch Epoch
Batch map[Member][]byte
}
type BatchSender interface {
Send(msg BatchMessage)
}
type BatchReceiver interface {
Receive() <-chan BatchMessage
}
type BatchChannel struct {
buffer chan BatchMessage
}
func NewBatchChannel(size int) *BatchChannel {
return &BatchChannel{
buffer: make(chan BatchMessage, size),
}
}
func (c *BatchChannel) Send(msg BatchMessage) {
c.buffer <- msg
}
func (c *BatchChannel) Receive() <-chan BatchMessage {
return c.buffer
}
// ResultMessage is result of Honeybadger. When Honeybadger receive
// BatchMessage from ACS, it decrypt BatchMessage and use it to
// ResultMessage.Batch field.
//
// Honeybadger knows what epoch of ACS done its task. and Honeybadger
// use that information of epoch and decrypted batch to create ResultMessage
// then send it back to application
type ResultMessage struct {
Epoch Epoch
Batch map[Member][]byte
}
type ResultSender interface {
Send(msg ResultMessage)
}
type ResultReceiver interface {
Receive() <-chan ResultMessage
}
type ResultChannel struct {
buffer chan ResultMessage
}
func NewResultChannel(size int) *ResultChannel {
return &ResultChannel{
buffer: make(chan ResultMessage, size),
}
}
func (c *ResultChannel) Send(msg ResultMessage) {
c.buffer <- msg
}
func (c *ResultChannel) Receive() <-chan ResultMessage {
return c.buffer
}