-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathmessages.go
184 lines (153 loc) · 5.42 KB
/
messages.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
package onet
import (
"github.com/google/uuid"
"go.dedis.ch/onet/v3/network"
)
// ProtocolMsgID is to be embedded in every message that is made for a
// ID of ProtocolMsg message as registered in network
var ProtocolMsgID = network.RegisterMessage(ProtocolMsg{})
// RequestTreeMsgID of RequestTree message as registered in network
var RequestTreeMsgID = network.RegisterMessage(RequestTree{})
// ResponseTreeMsgID of TreeMarshal message as registered in network
var ResponseTreeMsgID = network.RegisterMessage(ResponseTree{})
// SendTreeMsgID of TreeMarshal message as registered in network
// Deprecated: use ResponseTreeMsgID
var SendTreeMsgID = TreeMarshalTypeID
// RequestRosterMsgID of RequestRoster message as registered in network
// Deprecated: only the tree is sent, not anymore the roster
var RequestRosterMsgID = network.RegisterMessage(RequestRoster{})
// SendRosterMsgID of Roster message as registered in network
// Deprecated: only the tree is sent, not anymore the roster
var SendRosterMsgID = RosterTypeID
// ConfigMsgID of the generic config message
var ConfigMsgID = network.RegisterMessage(ConfigMsg{})
// ProtocolMsg is to be embedded in every message that is made for a
// ProtocolInstance
type ProtocolMsg struct {
// Token uniquely identify the protocol instance this msg is made for
From *Token
// The TreeNodeId Where the message goes to
To *Token
// NOTE: this is taken from network.NetworkMessage
ServerIdentity *network.ServerIdentity
// MsgType of the underlying data
MsgType network.MessageTypeID
// The interface to the actual Data
Msg network.Message
// The actual data as binary blob
MsgSlice []byte
// The size of the data
Size network.Size
// Config is the config passed to the protocol constructor.
Config *GenericConfig
}
// ConfigMsg is sent by the overlay containing a generic slice of bytes to
// give to service in the `NewProtocol` method.
type ConfigMsg struct {
Config GenericConfig
Dest TokenID
}
// RoundID uniquely identifies a round of a protocol run
type RoundID uuid.UUID
// String returns the canonical representation of the rounds ID (wrapper around // uuid.UUID.String())
func (rId RoundID) String() string {
return uuid.UUID(rId).String()
}
// Equal returns true if and only if rID2 equals this RoundID.
func (rId RoundID) Equal(rID2 RoundID) bool {
return rId == rID2
}
// IsNil returns true iff the RoundID is Nil
func (rId RoundID) IsNil() bool {
return rId.Equal(RoundID(uuid.Nil))
}
// TokenID uniquely identifies the start and end-point of a message by an ID
// (see Token struct)
type TokenID uuid.UUID
// String returns the canonical representation of the TokenID (wrapper around // uuid.UUID.String())
func (t TokenID) String() string {
return uuid.UUID(t).String()
}
// Equal returns true if and only if t2 equals this TokenID.
func (t TokenID) Equal(t2 TokenID) bool {
return t == t2
}
// IsNil returns true iff the TokenID is Nil
func (t TokenID) IsNil() bool {
return t.Equal(TokenID(uuid.Nil))
}
// A Token contains all identifiers needed to uniquely identify one protocol
// instance. It gets passed when a new protocol instance is created and get used
// by every protocol instance when they want to send a message. That way, the
// host knows how to create the ProtocolMsg message around the protocol's message
// with the right fields set.
type Token struct {
RosterID RosterID
TreeID TreeID
// TO BE REMOVED
ProtoID ProtocolID
ServiceID ServiceID
RoundID RoundID
// TreeNodeID is defined by the
TreeNodeID TreeNodeID
}
// ID returns the TokenID which can be used to identify by token in map
func (t *Token) ID() TokenID {
// TODO: This used to have a caching mechanism, but it caused data races.
// See issue #239. When tuning performance, if this shows up as a hot path,
// we need to add caching back in (safely, this time).
url := network.NamespaceURL + "token/" + t.RosterID.String() +
t.RoundID.String() + t.ServiceID.String() + t.ProtoID.String() + t.TreeID.String() +
t.TreeNodeID.String()
return TokenID(uuid.NewSHA1(uuid.NameSpaceURL, []byte(url)))
}
// Clone returns a new token out of this one
func (t *Token) Clone() *Token {
t2 := *t
return &t2
}
// ChangeTreeNodeID return a new Token containing a reference to the given
// TreeNode
func (t *Token) ChangeTreeNodeID(newid TreeNodeID) *Token {
tOther := *t
tOther.TreeNodeID = newid
return &tOther
}
// TreeNodeInfo holds the sender and the destination of the message.
type TreeNodeInfo struct {
To *Token
From *Token
}
// OverlayMsg contains all routing-information about the tree and the
// roster.
type OverlayMsg struct {
TreeNodeInfo *TreeNodeInfo
// Deprecated: roster is not sent/requested anymore, only the tree
RequestRoster *RequestRoster
// Deprecated: roster is not sent/requested anymore, only the tree
Roster *Roster
RequestTree *RequestTree
ResponseTree *ResponseTree
// Deprecated: use ResponseTree to send the tree and the roster
TreeMarshal *TreeMarshal
Config *GenericConfig
}
// RequestRoster is used to ask the parent for a given Roster
type RequestRoster struct {
RosterID RosterID
}
// RequestTree is used to ask the parent for a given Tree
type RequestTree struct {
// The treeID of the tree we want
TreeID TreeID
// Version of the request tree
Version uint32
}
// ResponseTree contains the information to build a tree
type ResponseTree struct {
TreeMarshal *TreeMarshal
Roster *Roster
}
// RosterUnknown is used in case the entity list is unknown
type RosterUnknown struct {
}