| // 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 ( |
| "fmt" |
| "v.io/v23" |
| "v.io/v23/context" |
| "v.io/v23/i18n" |
| "v.io/v23/rpc" |
| "v.io/v23/vdl" |
| "v.io/v23/verror" |
| ) |
| |
| // ConnBehavior specifies characteristics of a connection. |
| type ConnBehavior 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 |
| } |
| |
| func (ConnBehavior) __VDLReflect(struct { |
| Name string `vdl:"v.io/x/ref/runtime/protocols/vine.ConnBehavior"` |
| }) { |
| } |
| |
| func (m *ConnBehavior) FillVDLTarget(t vdl.Target, tt *vdl.Type) error { |
| if __VDLType_v_io_x_ref_runtime_protocols_vine_ConnBehavior == nil || __VDLType0 == nil { |
| panic("Initialization order error: types generated for FillVDLTarget not initialized. Consider moving caller to an init() block.") |
| } |
| fieldsTarget1, err := t.StartFields(tt) |
| if err != nil { |
| return err |
| } |
| |
| keyTarget2, fieldTarget3, err := fieldsTarget1.StartField("Reachable") |
| if err != vdl.ErrFieldNoExist && err != nil { |
| return err |
| } |
| if err != vdl.ErrFieldNoExist { |
| if err := fieldTarget3.FromBool(bool(m.Reachable), vdl.BoolType); err != nil { |
| return err |
| } |
| if err := fieldsTarget1.FinishField(keyTarget2, fieldTarget3); err != nil { |
| return err |
| } |
| } |
| if err := t.FinishFields(fieldsTarget1); err != nil { |
| return err |
| } |
| return nil |
| } |
| |
| func (m *ConnBehavior) MakeVDLTarget() vdl.Target { |
| return &ConnBehaviorTarget{Value: m} |
| } |
| |
| type ConnBehaviorTarget struct { |
| Value *ConnBehavior |
| reachableTarget vdl.BoolTarget |
| vdl.TargetBase |
| vdl.FieldsTargetBase |
| } |
| |
| func (t *ConnBehaviorTarget) StartFields(tt *vdl.Type) (vdl.FieldsTarget, error) { |
| |
| if !vdl.Compatible(tt, __VDLType_v_io_x_ref_runtime_protocols_vine_ConnBehavior) { |
| return nil, fmt.Errorf("type %v incompatible with %v", tt, __VDLType_v_io_x_ref_runtime_protocols_vine_ConnBehavior) |
| } |
| return t, nil |
| } |
| func (t *ConnBehaviorTarget) StartField(name string) (key, field vdl.Target, _ error) { |
| switch name { |
| case "Reachable": |
| t.reachableTarget.Value = &t.Value.Reachable |
| target, err := &t.reachableTarget, error(nil) |
| return nil, target, err |
| default: |
| return nil, nil, fmt.Errorf("field %s not in struct %v", name, __VDLType_v_io_x_ref_runtime_protocols_vine_ConnBehavior) |
| } |
| } |
| func (t *ConnBehaviorTarget) FinishField(_, _ vdl.Target) error { |
| return nil |
| } |
| func (t *ConnBehaviorTarget) FinishFields(_ vdl.FieldsTarget) error { |
| |
| return nil |
| } |
| |
| func init() { |
| vdl.Register((*ConnBehavior)(nil)) |
| } |
| |
| var __VDLType0 *vdl.Type = vdl.TypeOf((*ConnBehavior)(nil)) |
| var __VDLType_v_io_x_ref_runtime_protocols_vine_ConnBehavior *vdl.Type = vdl.TypeOf(ConnBehavior{}) |
| |
| func __VDLEnsureNativeBuilt() { |
| } |
| |
| 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}") |
| ) |
| |
| func init() { |
| 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}") |
| } |
| |
| // 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) |
| } |
| |
| // 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 { |
| // SetOutgoingBehaviors sets the policy that the accepting vine service's process |
| // will use on outgoing connections. |
| // outgoing is a map from server tag to the desired connection behavior. |
| // For example, |
| // client.SetOutgoingBehaviors(map[string]ConnBehavior{"foo", ConnBehavior{Reachable: false}}) |
| // will cause all vine protocol dial calls on the accepting vine service's |
| // process to fail when dialing out to tag "foo". |
| SetOutgoingBehaviors(_ *context.T, outgoing map[string]ConnBehavior, _ ...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) SetOutgoingBehaviors(ctx *context.T, i0 map[string]ConnBehavior, opts ...rpc.CallOpt) (err error) { |
| err = v23.GetClient(ctx).Call(ctx, c.name, "SetOutgoingBehaviors", []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 { |
| // SetOutgoingBehaviors sets the policy that the accepting vine service's process |
| // will use on outgoing connections. |
| // outgoing is a map from server tag to the desired connection behavior. |
| // For example, |
| // client.SetOutgoingBehaviors(map[string]ConnBehavior{"foo", ConnBehavior{Reachable: false}}) |
| // will cause all vine protocol dial calls on the accepting vine service's |
| // process to fail when dialing out to tag "foo". |
| SetOutgoingBehaviors(_ *context.T, _ rpc.ServerCall, outgoing map[string]ConnBehavior) 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) SetOutgoingBehaviors(ctx *context.T, call rpc.ServerCall, i0 map[string]ConnBehavior) error { |
| return s.impl.SetOutgoingBehaviors(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: "SetOutgoingBehaviors", |
| Doc: "// SetOutgoingBehaviors sets the policy that the accepting vine service's process\n// will use on outgoing connections.\n// outgoing is a map from server tag to the desired connection behavior.\n// For example,\n// client.SetOutgoingBehaviors(map[string]ConnBehavior{\"foo\", ConnBehavior{Reachable: false}})\n// will cause all vine protocol dial calls on the accepting vine service's\n// process to fail when dialing out to tag \"foo\".", |
| InArgs: []rpc.ArgDesc{ |
| {"outgoing", ``}, // map[string]ConnBehavior |
| }, |
| }, |
| }, |
| } |