-
Notifications
You must be signed in to change notification settings - Fork 30
/
lib_nodes.go
44 lines (39 loc) · 975 Bytes
/
lib_nodes.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
package lib
import "time"
type Node interface {
ReceiveMessage(index int) []byte
ReceiveAnyMessage() (int, []byte)
ReceiveMessageIfAvailable(index int) []byte
ReceiveMessageWithTimeout(index int, timeout time.Duration) []byte
SendMessage(index int, message []byte)
GetInChannelsCount() int
GetOutChannelsCount() int
GetInNeighbors() []Node
GetOutNeighbors() []Node
GetIndex() int
GetState() []byte
SetState(state []byte)
GetSize() int
StartProcessing()
FinishProcessing(finish bool)
IgnoreFutureMessages()
Close() // only for use by Runner
}
type counterMessage struct {
finish bool
sentMessages int
receivedMessages int
}
type statsNode struct {
sentMessages int
receivedMessages int
inConfirm <-chan bool
outConfirm chan<- counterMessage
}
func getSynchronousChannels(n int) []chan []byte {
channels := make([]chan []byte, n)
for i := range channels {
channels[i] = make(chan []byte, 1)
}
return channels
}