/
vine.vdl.go
376 lines (332 loc) · 11.7 KB
/
vine.vdl.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
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// This file was auto-generated by the vanadium vdl tool.
// Package: vine
package vine
import (
"v.io/v23"
"v.io/v23/context"
"v.io/v23/i18n"
"v.io/v23/rpc"
"v.io/v23/vdl"
"v.io/v23/verror"
)
var _ = __VDLInit() // Must be first; see __VDLInit comments for details.
//////////////////////////////////////////////////
// Type definitions
// PeerKey is a key that represents a connection from a Dialer tag to an Acceptor tag.
type PeerKey struct {
Dialer string
Acceptor string
}
func (PeerKey) VDLReflect(struct {
Name string `vdl:"v.io/x/ref/runtime/protocols/vine.PeerKey"`
}) {
}
func (x PeerKey) VDLIsZero() bool {
return x == PeerKey{}
}
func (x PeerKey) VDLWrite(enc vdl.Encoder) error {
if err := enc.StartValue(__VDLType_struct_1); err != nil {
return err
}
if x.Dialer != "" {
if err := enc.NextFieldValueString(0, vdl.StringType, x.Dialer); err != nil {
return err
}
}
if x.Acceptor != "" {
if err := enc.NextFieldValueString(1, vdl.StringType, x.Acceptor); err != nil {
return err
}
}
if err := enc.NextField(-1); err != nil {
return err
}
return enc.FinishValue()
}
func (x *PeerKey) VDLRead(dec vdl.Decoder) error {
*x = PeerKey{}
if err := dec.StartValue(__VDLType_struct_1); err != nil {
return err
}
decType := dec.Type()
for {
index, err := dec.NextField()
switch {
case err != nil:
return err
case index == -1:
return dec.FinishValue()
}
if decType != __VDLType_struct_1 {
index = __VDLType_struct_1.FieldIndexByName(decType.Field(index).Name)
if index == -1 {
if err := dec.SkipValue(); err != nil {
return err
}
continue
}
}
switch index {
case 0:
switch value, err := dec.ReadValueString(); {
case err != nil:
return err
default:
x.Dialer = value
}
case 1:
switch value, err := dec.ReadValueString(); {
case err != nil:
return err
default:
x.Acceptor = value
}
}
}
}
// PeerBehavior specifies characteristics of a connection.
type PeerBehavior struct {
// Reachable specifies whether the outgoing or incoming connection can be
// dialed or accepted.
// TODO(suharshs): Make this a user defined error which vine will return instead of a bool.
Reachable bool
// Discoverable specifies whether the Dialer can advertise a discovery packet
// to the Acceptor. This is useful for emulating neighborhoods.
// TODO(suharshs): Discoverable should always be bidirectional. It is unrealistic for
// A to discover B, but not vice versa.
Discoverable bool
}
func (PeerBehavior) VDLReflect(struct {
Name string `vdl:"v.io/x/ref/runtime/protocols/vine.PeerBehavior"`
}) {
}
func (x PeerBehavior) VDLIsZero() bool {
return x == PeerBehavior{}
}
func (x PeerBehavior) VDLWrite(enc vdl.Encoder) error {
if err := enc.StartValue(__VDLType_struct_2); err != nil {
return err
}
if x.Reachable {
if err := enc.NextFieldValueBool(0, vdl.BoolType, x.Reachable); err != nil {
return err
}
}
if x.Discoverable {
if err := enc.NextFieldValueBool(1, vdl.BoolType, x.Discoverable); err != nil {
return err
}
}
if err := enc.NextField(-1); err != nil {
return err
}
return enc.FinishValue()
}
func (x *PeerBehavior) VDLRead(dec vdl.Decoder) error {
*x = PeerBehavior{}
if err := dec.StartValue(__VDLType_struct_2); err != nil {
return err
}
decType := dec.Type()
for {
index, err := dec.NextField()
switch {
case err != nil:
return err
case index == -1:
return dec.FinishValue()
}
if decType != __VDLType_struct_2 {
index = __VDLType_struct_2.FieldIndexByName(decType.Field(index).Name)
if index == -1 {
if err := dec.SkipValue(); err != nil {
return err
}
continue
}
}
switch index {
case 0:
switch value, err := dec.ReadValueBool(); {
case err != nil:
return err
default:
x.Reachable = value
}
case 1:
switch value, err := dec.ReadValueBool(); {
case err != nil:
return err
default:
x.Discoverable = value
}
}
}
}
//////////////////////////////////////////////////
// Error definitions
var (
ErrInvalidAddress = verror.Register("v.io/x/ref/runtime/protocols/vine.InvalidAddress", verror.NoRetry, "{1:}{2:} invalid vine address {3}, address must be of the form 'network/address/tag'")
ErrAddressNotReachable = verror.Register("v.io/x/ref/runtime/protocols/vine.AddressNotReachable", verror.NoRetry, "{1:}{2:} address {3} not reachable")
ErrNoRegisteredProtocol = verror.Register("v.io/x/ref/runtime/protocols/vine.NoRegisteredProtocol", verror.NoRetry, "{1:}{2:} no registered protocol {3}")
ErrCantAcceptFromTag = verror.Register("v.io/x/ref/runtime/protocols/vine.CantAcceptFromTag", verror.NoRetry, "{1:}{2:} can't accept connection from tag {3}")
)
// NewErrInvalidAddress returns an error with the ErrInvalidAddress ID.
func NewErrInvalidAddress(ctx *context.T, address string) error {
return verror.New(ErrInvalidAddress, ctx, address)
}
// NewErrAddressNotReachable returns an error with the ErrAddressNotReachable ID.
func NewErrAddressNotReachable(ctx *context.T, address string) error {
return verror.New(ErrAddressNotReachable, ctx, address)
}
// NewErrNoRegisteredProtocol returns an error with the ErrNoRegisteredProtocol ID.
func NewErrNoRegisteredProtocol(ctx *context.T, protocol string) error {
return verror.New(ErrNoRegisteredProtocol, ctx, protocol)
}
// NewErrCantAcceptFromTag returns an error with the ErrCantAcceptFromTag ID.
func NewErrCantAcceptFromTag(ctx *context.T, tag string) error {
return verror.New(ErrCantAcceptFromTag, ctx, tag)
}
//////////////////////////////////////////////////
// Interface definitions
// VineClientMethods is the client interface
// containing Vine methods.
//
// Vine is the interface to a vine service that can dynamically change the network
// behavior of connection's on the vine service's process.
type VineClientMethods interface {
// SetBehaviors sets the policy that the accepting vine service's process
// will use on connections.
// behaviors is a map from server tag to the desired connection behavior.
// For example,
// client.SetBehaviors(map[PeerKey]PeerBehavior{PeerKey{"foo", "bar"}, PeerBehavior{Reachable: false}})
// will cause all vine protocol dial calls from "foo" to "bar" to fail.
SetBehaviors(_ *context.T, behaviors map[PeerKey]PeerBehavior, _ ...rpc.CallOpt) error
}
// VineClientStub adds universal methods to VineClientMethods.
type VineClientStub interface {
VineClientMethods
rpc.UniversalServiceMethods
}
// VineClient returns a client stub for Vine.
func VineClient(name string) VineClientStub {
return implVineClientStub{name}
}
type implVineClientStub struct {
name string
}
func (c implVineClientStub) SetBehaviors(ctx *context.T, i0 map[PeerKey]PeerBehavior, opts ...rpc.CallOpt) (err error) {
err = v23.GetClient(ctx).Call(ctx, c.name, "SetBehaviors", []interface{}{i0}, nil, opts...)
return
}
// VineServerMethods is the interface a server writer
// implements for Vine.
//
// Vine is the interface to a vine service that can dynamically change the network
// behavior of connection's on the vine service's process.
type VineServerMethods interface {
// SetBehaviors sets the policy that the accepting vine service's process
// will use on connections.
// behaviors is a map from server tag to the desired connection behavior.
// For example,
// client.SetBehaviors(map[PeerKey]PeerBehavior{PeerKey{"foo", "bar"}, PeerBehavior{Reachable: false}})
// will cause all vine protocol dial calls from "foo" to "bar" to fail.
SetBehaviors(_ *context.T, _ rpc.ServerCall, behaviors map[PeerKey]PeerBehavior) error
}
// VineServerStubMethods is the server interface containing
// Vine methods, as expected by rpc.Server.
// There is no difference between this interface and VineServerMethods
// since there are no streaming methods.
type VineServerStubMethods VineServerMethods
// VineServerStub adds universal methods to VineServerStubMethods.
type VineServerStub interface {
VineServerStubMethods
// Describe the Vine interfaces.
Describe__() []rpc.InterfaceDesc
}
// VineServer returns a server stub for Vine.
// It converts an implementation of VineServerMethods into
// an object that may be used by rpc.Server.
func VineServer(impl VineServerMethods) VineServerStub {
stub := implVineServerStub{
impl: impl,
}
// Initialize GlobState; always check the stub itself first, to handle the
// case where the user has the Glob method defined in their VDL source.
if gs := rpc.NewGlobState(stub); gs != nil {
stub.gs = gs
} else if gs := rpc.NewGlobState(impl); gs != nil {
stub.gs = gs
}
return stub
}
type implVineServerStub struct {
impl VineServerMethods
gs *rpc.GlobState
}
func (s implVineServerStub) SetBehaviors(ctx *context.T, call rpc.ServerCall, i0 map[PeerKey]PeerBehavior) error {
return s.impl.SetBehaviors(ctx, call, i0)
}
func (s implVineServerStub) Globber() *rpc.GlobState {
return s.gs
}
func (s implVineServerStub) Describe__() []rpc.InterfaceDesc {
return []rpc.InterfaceDesc{VineDesc}
}
// VineDesc describes the Vine interface.
var VineDesc rpc.InterfaceDesc = descVine
// descVine hides the desc to keep godoc clean.
var descVine = rpc.InterfaceDesc{
Name: "Vine",
PkgPath: "v.io/x/ref/runtime/protocols/vine",
Doc: "// Vine is the interface to a vine service that can dynamically change the network\n// behavior of connection's on the vine service's process.",
Methods: []rpc.MethodDesc{
{
Name: "SetBehaviors",
Doc: "// SetBehaviors sets the policy that the accepting vine service's process\n// will use on connections.\n// behaviors is a map from server tag to the desired connection behavior.\n// For example,\n// client.SetBehaviors(map[PeerKey]PeerBehavior{PeerKey{\"foo\", \"bar\"}, PeerBehavior{Reachable: false}})\n// will cause all vine protocol dial calls from \"foo\" to \"bar\" to fail.",
InArgs: []rpc.ArgDesc{
{"behaviors", ``}, // map[PeerKey]PeerBehavior
},
},
},
}
// Hold type definitions in package-level variables, for better performance.
var (
__VDLType_struct_1 *vdl.Type
__VDLType_struct_2 *vdl.Type
)
var __VDLInitCalled bool
// __VDLInit performs vdl initialization. It is safe to call multiple times.
// If you have an init ordering issue, just insert the following line verbatim
// into your source files in this package, right after the "package foo" clause:
//
// var _ = __VDLInit()
//
// The purpose of this function is to ensure that vdl initialization occurs in
// the right order, and very early in the init sequence. In particular, vdl
// registration and package variable initialization needs to occur before
// functions like vdl.TypeOf will work properly.
//
// This function returns a dummy value, so that it can be used to initialize the
// first var in the file, to take advantage of Go's defined init order.
func __VDLInit() struct{} {
if __VDLInitCalled {
return struct{}{}
}
__VDLInitCalled = true
// Register types.
vdl.Register((*PeerKey)(nil))
vdl.Register((*PeerBehavior)(nil))
// Initialize type definitions.
__VDLType_struct_1 = vdl.TypeOf((*PeerKey)(nil)).Elem()
__VDLType_struct_2 = vdl.TypeOf((*PeerBehavior)(nil)).Elem()
// Set error format strings.
i18n.Cat().SetWithBase(i18n.LangID("en"), i18n.MsgID(ErrInvalidAddress.ID), "{1:}{2:} invalid vine address {3}, address must be of the form 'network/address/tag'")
i18n.Cat().SetWithBase(i18n.LangID("en"), i18n.MsgID(ErrAddressNotReachable.ID), "{1:}{2:} address {3} not reachable")
i18n.Cat().SetWithBase(i18n.LangID("en"), i18n.MsgID(ErrNoRegisteredProtocol.ID), "{1:}{2:} no registered protocol {3}")
i18n.Cat().SetWithBase(i18n.LangID("en"), i18n.MsgID(ErrCantAcceptFromTag.ID), "{1:}{2:} can't accept connection from tag {3}")
return struct{}{}
}