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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
|
using System;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.PeerResolvers;
using System.ServiceModel.Description;
namespace System.ServiceModel.PeerResolvers
{
internal class Consts
{
public const string Namespace = "http://schemas.microsoft.com/net/2006/05/peer";
}
[ServiceContract (Namespace = Consts.Namespace, SessionMode = SessionMode.Allowed)]
internal interface IPeerConnectorContract
{
[OperationContract (Action = Consts.Namespace + "/Connect", IsOneWay = true)]
void Connect (ConnectInfo connect);
[OperationContract (Action = Consts.Namespace + "/Welcome", IsOneWay = true)]
void Welcome (WelcomeInfo welcome);
[OperationContract (Action = Consts.Namespace + "/Refuse", IsOneWay = true)]
void Refuse (RefuseInfo refuse);
[OperationContract (Action = Consts.Namespace + "/Disconnect", IsOneWay = true)]
void Disconnect (DisconnectInfo disconnect);
[OperationContract (Action = Consts.Namespace + "/LinkUtility", IsOneWay = true)]
void LinkUtility (LinkUtilityInfo linkUtility);
[OperationContract (Action = Consts.Namespace + "/Ping", IsOneWay = true)]
void Ping ();
[OperationContract (IsOneWay = true)]
void SendMessage (Message msg);
}
[ServiceContract (Namespace = Consts.Namespace, SessionMode = SessionMode.Allowed, CallbackContract = typeof (IPeerConnectorContract))]
internal interface IPeerReceiverContract
{
[OperationContract (Action = Consts.Namespace + "/Connect", IsOneWay = true)]
void Connect (ConnectInfo connect);
[OperationContract (IsOneWay = true)]
void SendMessage (Message msg);
}
// Common datatype
[DataContract (Name = "Referral", Namespace = Consts.Namespace)]
internal class Referral
{
[DataMember]
public ulong Id { get; set; }
[DataMember]
public PeerNodeAddress PeerNodeAddress { get; set; }
}
internal enum RefuseReason
{
DuplicateNeighbor,
DuplicateNodeId,
NodeBusy,
}
internal enum DisconnectReason
{
LeavingMesh,
NotUsefulNeighbor,
DuplicateNeighbor,
DuplicateNodeId,
}
// Connect
[DataContract (Name = "Connect", Namespace = Consts.Namespace)]
internal class ConnectInfoDC
{
[DataMember]
public PeerNodeAddress PeerNodeAddress { get; set; }
[DataMember]
public ulong NodeId { get; set; }
}
[MessageContract (IsWrapped = false)]
internal class ConnectInfo
{
public ConnectInfo ()
{
dc = new ConnectInfoDC ();
}
[MessageBodyMember (Name = "Connect", Namespace = Consts.Namespace)]
ConnectInfoDC dc;
public PeerNodeAddress PeerNodeAddress {
get { return dc.PeerNodeAddress; }
set { dc.PeerNodeAddress = value; }
}
public ulong NodeId {
get { return dc.NodeId; }
set { dc.NodeId = value; }
}
}
// Welcome
[DataContract (Name = "Welcome", Namespace = Consts.Namespace)]
internal class WelcomeInfoDC
{
[DataMember]
public ulong NodeId { get; set; }
[DataMember]
public Referral [] Referrals { get; set; }
}
[MessageContract (IsWrapped = false)]
internal class WelcomeInfo
{
public WelcomeInfo ()
{
dc = new WelcomeInfoDC ();
}
[MessageBodyMember (Name = "Welcome", Namespace = Consts.Namespace)]
WelcomeInfoDC dc;
public ulong NodeId {
get { return dc.NodeId; }
set { dc.NodeId = value; }
}
public Referral [] Referrals {
get { return dc.Referrals; }
set { dc.Referrals = value; }
}
}
// Refuse
[DataContract (Name = "Refuse", Namespace = Consts.Namespace)]
internal class RefuseInfoDC
{
[DataMember]
public Referral [] Referrals { get; set; }
[DataMember]
public RefuseReason Reason { get; set; }
}
[MessageContract (IsWrapped = false)]
internal class RefuseInfo
{
public RefuseInfo ()
{
dc = new RefuseInfoDC ();
}
[MessageBodyMember (Name = "Refuse", Namespace = Consts.Namespace)]
RefuseInfoDC dc;
public Referral [] Referrals {
get { return dc.Referrals; }
set { dc.Referrals = value; }
}
public RefuseReason Reason {
get { return dc.Reason; }
set { dc.Reason = value; }
}
}
// Disconnect
[DataContract (Name = "Disconnect", Namespace = Consts.Namespace)]
internal class DisconnectInfoDC
{
[DataMember]
public Referral [] Referrals { get; set; }
[DataMember]
public DisconnectReason Reason { get; set; }
}
[MessageContract (IsWrapped = false)]
internal class DisconnectInfo
{
public DisconnectInfo ()
{
dc = new DisconnectInfoDC ();
}
[MessageBodyMember (Name = "Disconnect", Namespace = Consts.Namespace)]
DisconnectInfoDC dc;
public Referral [] Referrals {
get { return dc.Referrals; }
set { dc.Referrals = value; }
}
public DisconnectReason Reason {
get { return dc.Reason; }
set { dc.Reason = value; }
}
}
// LinkUtilityInfo
[DataContract (Name = "LinkUtilityInfo", Namespace = Consts.Namespace)]
internal class LinkUtilityInfoDC
{
[DataMember]
public uint Total { get; set; }
[DataMember]
public uint Useful { get; set; }
}
[MessageContract (IsWrapped = false)]
internal class LinkUtilityInfo
{
public LinkUtilityInfo ()
{
dc = new LinkUtilityInfoDC ();
}
[MessageBodyMember (Name = "LinkUtilityInfo", Namespace = Consts.Namespace)]
LinkUtilityInfoDC dc;
public uint Total {
get { return dc.Total; }
set { dc.Total = value; }
}
public uint Useful {
get { return dc.Useful; }
set { dc.Useful = value; }
}
}
}
|