TUN-528: Move cloudflared into a separate repo

This commit is contained in:
Areg Harutyunyan
2018-05-01 18:45:06 -05:00
parent e8c621a648
commit d06fc520c7
4726 changed files with 1763680 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
{{if .Field.HasDiscriminant -}}
if s.Struct.Uint16({{.Node.DiscriminantOffset}}) != {{.Field.DiscriminantValue}} {
panic({{printf "Which() != %s" .Field.Name | printf "%q"}})
}
{{end -}}

View File

@@ -0,0 +1,9 @@
func (s {{.Node.Name}}) Has{{.Field.Name|title}}() bool {
{{if .Field.HasDiscriminant -}}
if s.Struct.Uint16({{.Node.DiscriminantOffset}}) != {{.Field.DiscriminantValue}} {
return false
}
{{end -}}
p, err := s.Struct.Ptr({{.Field.Slot.Offset}})
return p.IsValid() || err != nil
}

View File

@@ -0,0 +1,4 @@
InterfaceID: {{.Interface.Id|printf "%#x"}},
MethodID: {{.ID}},
InterfaceName: {{.Interface.DisplayName|printf "%q"}},
MethodName: {{.OriginalName|printf "%q"}},

View File

@@ -0,0 +1,3 @@
{{if .Field.HasDiscriminant -}}
s.Struct.SetUint16({{.Node.DiscriminantOffset}}, {{.Field.DiscriminantValue}})
{{end -}}

View File

@@ -0,0 +1,2 @@
// {{.Name}}_TypeID is the unique identifier for the type {{.Name}}.
const {{.Name}}_TypeID = {{.Id|printf "%#x"}}

View File

@@ -0,0 +1 @@
const {{.Node.Name}} = uint64({{.Node.Id|printf "%#x"}})

View File

@@ -0,0 +1,23 @@
{{ template "_typeid" .Node }}
func New{{.Node.Name}}(s *{{.G.Capnp}}.Segment) ({{.Node.Name}}, error) {
st, err := {{$.G.Capnp}}.NewStruct(s, {{.G.ObjectSize .Node}})
return {{.Node.Name}}{st}, err
}
func NewRoot{{.Node.Name}}(s *{{.G.Capnp}}.Segment) ({{.Node.Name}}, error) {
st, err := {{.G.Capnp}}.NewRootStruct(s, {{.G.ObjectSize .Node}})
return {{.Node.Name}}{st}, err
}
func ReadRoot{{.Node.Name}}(msg *{{.G.Capnp}}.Message) ({{.Node.Name}}, error) {
root, err := msg.RootPtr()
return {{.Node.Name}}{root.Struct()}, err
}
{{if .StringMethod}}
func (s {{.Node.Name}}) String() string {
str, _ := {{.G.Imports.Text}}.Marshal({{.Node.Id|printf "%#x"}}, s.Struct)
return str
}
{{end}}

View File

@@ -0,0 +1,14 @@
{{with .Consts -}}
// Constants defined in {{$.G.Basename}}.
const (
{{range .}} {{.Name}} = {{$.G.Value . .Const.Type .Const.Value}}
{{end}}
)
{{end}}
{{with .Vars -}}
// Constants defined in {{$.G.Basename}}.
var (
{{range .}} {{.Name}} = {{$.G.Value . .Const.Type .Const.Value}}
{{end}}
)
{{end}}

View File

@@ -0,0 +1,55 @@
{{with .Annotations.Doc -}}
// {{.}}
{{end -}}
type {{.Node.Name}} uint16
{{ template "_typeid" .Node }}
{{with .EnumValues -}}
// Values of {{$.Node.Name}}.
const (
{{range . -}}
{{.FullName}} {{$.Node.Name}} = {{.Val}}
{{end}}
)
// String returns the enum's constant name.
func (c {{$.Node.Name}}) String() string {
switch c {
{{range . -}}
{{if .Tag}}case {{.FullName}}: return {{printf "%q" .Tag}}
{{end}}
{{- end}}
default: return ""
}
}
// {{$.Node.Name}}FromString returns the enum value with a name,
// or the zero value if there's no such value.
func {{$.Node.Name}}FromString(c string) {{$.Node.Name}} {
switch c {
{{range . -}}
{{if .Tag}}case {{printf "%q" .Tag}}: return {{.FullName}}
{{end}}
{{- end}}
default: return 0
}
}
{{end}}
type {{.Node.Name}}_List struct { {{$.G.Capnp}}.List }
func New{{.Node.Name}}_List(s *{{$.G.Capnp}}.Segment, sz int32) ({{.Node.Name}}_List, error) {
l, err := {{.G.Capnp}}.NewUInt16List(s, sz)
return {{.Node.Name}}_List{l.List}, err
}
func (l {{.Node.Name}}_List) At(i int) {{.Node.Name}} {
ul := {{.G.Capnp}}.UInt16List{List: l.List}
return {{.Node.Name}}(ul.At(i))
}
func (l {{.Node.Name}}_List) Set(i int, v {{.Node.Name}}) {
ul := {{.G.Capnp}}.UInt16List{List: l.List}
ul.Set(i, uint16(v))
}

View File

@@ -0,0 +1,26 @@
{{with .Annotations.Doc -}}
// {{.}}
{{end -}}
type {{.Node.Name}} struct { Client {{.G.Capnp}}.Client }
{{ template "_typeid" .Node }}
{{range .Methods -}}
func (c {{$.Node.Name}}) {{.Name|title}}(ctx {{$.G.Imports.Context}}.Context, params func({{$.G.RemoteNodeName .Params $.Node}}) error, opts ...{{$.G.Capnp}}.CallOption) {{$.G.RemoteNodeName .Results $.Node}}_Promise {
if c.Client == nil {
return {{$.G.RemoteNodeName .Results $.Node}}_Promise{Pipeline: {{$.G.Capnp}}.NewPipeline({{$.G.Capnp}}.ErrorAnswer({{$.G.Capnp}}.ErrNullClient))}
}
call := &{{$.G.Capnp}}.Call{
Ctx: ctx,
Method: {{$.G.Capnp}}.Method{
{{template "_interfaceMethod" .}}
},
Options: {{$.G.Capnp}}.NewCallOptions(opts),
}
if params != nil {
call.ParamsSize = {{$.G.ObjectSize .Params}}
call.ParamsFunc = func(s {{$.G.Capnp}}.Struct) error { return params({{$.G.RemoteNodeName .Params $.Node}}{Struct: s}) }
}
return {{$.G.RemoteNodeName .Results $.Node}}_Promise{Pipeline: {{$.G.Capnp}}.NewPipeline(c.Client.Call(call))}
}
{{end}}

View File

@@ -0,0 +1,40 @@
type {{.Node.Name}}_Server interface {
{{range .Methods}}
{{.Name|title}}({{$.G.RemoteNodeName .Interface $.Node}}_{{.Name}}) error
{{end}}
}
func {{.Node.Name}}_ServerToClient(s {{.Node.Name}}_Server) {{.Node.Name}} {
c, _ := s.({{.G.Imports.Server}}.Closer)
return {{.Node.Name}}{Client: {{.G.Imports.Server}}.New({{.Node.Name}}_Methods(nil, s), c)}
}
func {{.Node.Name}}_Methods(methods []{{.G.Imports.Server}}.Method, s {{.Node.Name}}_Server) []{{.G.Imports.Server}}.Method {
if cap(methods) == 0 {
methods = make([]{{.G.Imports.Server}}.Method, 0, {{len .Methods}})
}
{{range .Methods}}
methods = append(methods, {{$.G.Imports.Server}}.Method{
Method: {{$.G.Capnp}}.Method{
{{template "_interfaceMethod" .}}
},
Impl: func(c {{$.G.Imports.Context}}.Context, opts {{$.G.Capnp}}.CallOptions, p, r {{$.G.Capnp}}.Struct) error {
call := {{$.G.RemoteNodeName .Interface $.Node}}_{{.Name}}{c, opts, {{$.G.RemoteNodeName .Params $.Node}}{Struct: p}, {{$.G.RemoteNodeName .Results $.Node}}{Struct: r} }
return s.{{.Name|title}}(call)
},
ResultsSize: {{$.G.ObjectSize .Results}},
})
{{end}}
return methods
}
{{range .Methods -}}
{{if eq .Interface.Id $.Node.Id}}
// {{$.Node.Name}}_{{.Name}} holds the arguments for a server call to {{$.Node.Name}}.{{.Name}}.
type {{$.Node.Name}}_{{.Name}} struct {
Ctx {{$.G.Imports.Context}}.Context
Options {{$.G.Capnp}}.CallOptions
Params {{$.G.RemoteNodeName .Params $.Node}}
Results {{$.G.RemoteNodeName .Results $.Node}}
}
{{end}}
{{- end}}

View File

@@ -0,0 +1,2 @@
{{.Typ}}{List: {{.G.Capnp}}.MustUnmarshalRootPtr({{.Value}}).List()}
{{- /* no EOL */ -}}

View File

@@ -0,0 +1,2 @@
{{.G.Capnp}}.MustUnmarshalRootPtr({{.Value}})
{{- /* no EOL */ -}}

View File

@@ -0,0 +1,8 @@
// {{.Node.Name}}_Promise is a wrapper for a {{.Node.Name}} promised by a client call.
type {{.Node.Name}}_Promise struct { *{{.G.Capnp}}.Pipeline }
func (p {{.Node.Name}}_Promise) Struct() ({{.Node.Name}}, error) {
s, err := p.Pipeline.Struct()
return {{.Node.Name}}{s}, err
}

View File

@@ -0,0 +1,4 @@
func (p {{.Node.Name}}_Promise) {{.Field.Name|title}}() *{{.G.Capnp}}.Pipeline {
return p.Pipeline.GetPipeline({{.Field.Slot.Offset}})
}

View File

@@ -0,0 +1,4 @@
func (p {{.Node.Name}}_Promise) {{.Field.Name|title}}() {{.G.RemoteNodeName .Interface .Node}} {
return {{.G.RemoteNodeName .Interface .Node}}{Client: p.Pipeline.GetPipeline({{.Field.Slot.Offset}}).Client()}
}

View File

@@ -0,0 +1,4 @@
func (p {{.Node.Name}}_Promise) {{.Field.Name|title}}() {{.G.RemoteNodeName .Struct .Node}}_Promise {
return {{.G.RemoteNodeName .Struct .Node}}_Promise{Pipeline: p.Pipeline.{{if .Default.IsValid}}GetPipelineDefault({{.Field.Slot.Offset}}, {{.Default}}){{else}}GetPipeline({{.Field.Slot.Offset}}){{end}} }
}

View File

@@ -0,0 +1 @@
func (p {{.Node.Name}}_Promise) {{.Field.Name|title}}() {{.Group.Name}}_Promise { return {{.Group.Name}}_Promise{p.Pipeline} }

View File

@@ -0,0 +1,8 @@
const schema_{{.FileID|printf "%x"}} = {{.SchemaLiteral}}
func init() {
{{.G.Imports.Schemas}}.Register(schema_{{.FileID|printf "%x"}},
{{- range .NodeIDs}}
{{.|printf "%#x"}},
{{- end}})
}

View File

@@ -0,0 +1,10 @@
func (s {{.Node.Name}}) {{.Field.Name|title}}() bool {
{{template "_checktag" . -}}
return {{if .Default}}!{{end}}s.Struct.Bit({{.Field.Slot.Offset}})
}
func (s {{.Node.Name}}) Set{{.Field.Name|title}}(v bool) {
{{template "_settag" . -}}
s.Struct.SetBit({{.Field.Slot.Offset}}, {{if .Default}}!{{end}}v)
}

View File

@@ -0,0 +1,22 @@
func (s {{.Node.Name}}) {{.Field.Name|title}}() ({{.FieldType}}, error) {
{{template "_checktag" . -}}
p, err := s.Struct.Ptr({{.Field.Slot.Offset}})
{{with .Default -}}
return {{$.FieldType}}(p.DataDefault({{printf "%#v" .}})), err
{{- else -}}
return {{.FieldType}}(p.Data()), err
{{- end}}
}
{{template "_hasfield" .}}
func (s {{.Node.Name}}) Set{{.Field.Name|title}}(v {{.FieldType}}) error {
{{template "_settag" . -}}
{{if .Default -}}
if v == nil {
v = []byte{}
}
{{end -}}
return s.Struct.SetData({{.Field.Slot.Offset}}, v)
}

View File

@@ -0,0 +1,17 @@
type {{.Node.Name}}_Which uint16
const (
{{range .Fields}} {{$.Node.Name}}_Which_{{.Name}} {{$.Node.Name}}_Which = {{.DiscriminantValue}}
{{end}}
)
func (w {{.Node.Name}}_Which) String() string {
const s = {{.EnumString.ValueString|printf "%q"}}
switch w {
{{range $i, $f := .Fields}}case {{$.Node.Name}}_Which_{{.Name}}:
return s{{$.EnumString.SliceFor $i}}
{{end}}
}
return "{{.Node.Name}}_Which(" + {{.G.Imports.Strconv}}.FormatUint(uint64(w), 10) + ")"
}

View File

@@ -0,0 +1,10 @@
func (s {{.Node.Name}}) {{.Field.Name|title}}() float{{.Bits}} {
{{template "_checktag" . -}}
return {{.G.Imports.Math}}.Float{{.Bits}}frombits(s.Struct.Uint{{.Bits}}({{.Offset}}){{with .Default}} ^ {{printf "%#x" .}}{{end}})
}
func (s {{.Node.Name}}) Set{{.Field.Name|title}}(v float{{.Bits}}) {
{{template "_settag" . -}}
s.Struct.SetUint{{.Bits}}({{.Offset}}, {{.G.Imports.Math}}.Float{{.Bits}}bits(v){{with .Default}}^{{printf "%#x" .}}{{end}})
}

View File

@@ -0,0 +1,5 @@
{{if gt .Node.StructNode.DiscriminantCount 0}}
func (s {{.Node.Name}}) Which() {{.Node.Name}}_Which {
return {{.Node.Name}}_Which(s.Struct.Uint16({{.Node.DiscriminantOffset}}))
}
{{end -}}

View File

@@ -0,0 +1,4 @@
func (s {{.Node.Name}}) {{.Field.Name|title}}() {{.Group.Name}} { return {{.Group.Name}}(s) }
{{if .Field.HasDiscriminant}}
func (s {{.Node.Name}}) Set{{.Field.Name|title}}() { {{template "_settag" .}} }
{{end}}

View File

@@ -0,0 +1,10 @@
func (s {{.Node.Name}}) {{.Field.Name|title}}() {{.ReturnType}} {
{{template "_checktag" . -}}
return {{.ReturnType}}(s.Struct.Uint{{.Bits}}({{.Offset}}){{with .Default}} ^ {{.}}{{end}})
}
func (s {{.Node.Name}}) Set{{.Field.Name|title}}(v {{.ReturnType}}) {
{{template "_settag" . -}}
s.Struct.SetUint{{.Bits}}({{.Offset}}, uint{{.Bits}}(v){{with .Default}}^{{.}}{{end}})
}

View File

@@ -0,0 +1,18 @@
func (s {{.Node.Name}}) {{.Field.Name|title}}() {{.FieldType}} {
{{template "_checktag" . -}}
p, _ := s.Struct.Ptr({{.Field.Slot.Offset}})
return {{.FieldType}}{Client: p.Interface().Client()}
}
{{template "_hasfield" .}}
func (s {{.Node.Name}}) Set{{.Field.Name|title}}(v {{.FieldType}}) error {
{{template "_settag" . -}}
if v.Client == nil {
return s.Struct.SetPtr({{.Field.Slot.Offset}}, capnp.Ptr{})
}
seg := s.Segment()
in := {{.G.Capnp}}.NewInterface(seg, seg.Message().AddCap(v.Client))
return s.Struct.SetPtr({{.Field.Slot.Offset}}, in.ToPtr())
}

View File

@@ -0,0 +1,19 @@
// {{.Node.Name}}_List is a list of {{.Node.Name}}.
type {{.Node.Name}}_List struct{ {{.G.Capnp}}.List }
// New{{.Node.Name}} creates a new list of {{.Node.Name}}.
func New{{.Node.Name}}_List(s *{{.G.Capnp}}.Segment, sz int32) ({{.Node.Name}}_List, error) {
l, err := {{.G.Capnp}}.NewCompositeList(s, {{.G.ObjectSize .Node}}, sz)
return {{.Node.Name}}_List{l}, err
}
func (s {{.Node.Name}}_List) At(i int) {{.Node.Name}} { return {{.Node.Name}}{ s.List.Struct(i) } }
func (s {{.Node.Name}}_List) Set(i int, v {{.Node.Name}}) error { return s.List.SetStruct(i, v.Struct) }
{{if .StringMethod}}
func (s {{.Node.Name}}_List) String() string {
str, _ := {{.G.Imports.Text}}.MarshalList({{.Node.Id|printf "%#x"}}, s.List)
return str
}
{{end}}

View File

@@ -0,0 +1,33 @@
func (s {{.Node.Name}}) {{.Field.Name|title}}() ({{.FieldType}}, error) {
{{template "_checktag" . -}}
p, err := s.Struct.Ptr({{.Field.Slot.Offset}})
{{if .Default.IsValid -}}
if err != nil {
return {{.FieldType}}{}, err
}
l, err := p.ListDefault({{.Default}})
return {{.FieldType}}{List: l}, err
{{- else -}}
return {{.FieldType}}{List: p.List()}, err
{{- end}}
}
{{template "_hasfield" .}}
func (s {{.Node.Name}}) Set{{.Field.Name|title}}(v {{.FieldType}}) error {
{{template "_settag" . -}}
return s.Struct.SetPtr({{.Field.Slot.Offset}}, v.List.ToPtr())
}
// New{{.Field.Name|title}} sets the {{.Field.Name}} field to a newly
// allocated {{.FieldType}}, preferring placement in s's segment.
func (s {{.Node.Name}}) New{{.Field.Name|title}}(n int32) ({{.FieldType}}, error) {
{{template "_settag" . -}}
l, err := {{.G.RemoteTypeNew .Field.Slot.Type .Node}}(s.Struct.Segment(), n)
if err != nil {
return {{.FieldType}}{}, err
}
err = s.Struct.SetPtr({{.Field.Slot.Offset}}, l.List.ToPtr())
return l, err
}

View File

@@ -0,0 +1,37 @@
func (s {{.Node.Name}}) {{.Field.Name|title}}() ({{.G.Capnp}}.Pointer, error) {
{{template "_checktag" . -}}
{{if .Default.IsValid -}}
p, err := s.Struct.Pointer({{.Field.Slot.Offset}})
if err != nil {
return nil, err
}
return {{.G.Capnp}}.PointerDefault(p, {{.Default}})
{{- else -}}
return s.Struct.Pointer({{.Field.Slot.Offset}})
{{- end}}
}
{{template "_hasfield" .}}
func (s {{.Node.Name}}) {{.Field.Name|title}}Ptr() ({{.G.Capnp}}.Ptr, error) {
{{if .Default.IsValid -}}
p, err := s.Struct.Ptr({{.Field.Slot.Offset}})
if err != nil {
return nil, err
}
return p.Default({{.Default}})
{{- else -}}
return s.Struct.Ptr({{.Field.Slot.Offset}})
{{- end}}
}
func (s {{.Node.Name}}) Set{{.Field.Name|title}}(v {{.G.Capnp}}.Pointer) error {
{{template "_settag" . -}}
return s.Struct.SetPointer({{.Field.Slot.Offset}}, v)
}
func (s {{.Node.Name}}) Set{{.Field.Name|title}}Ptr(v {{.G.Capnp}}.Ptr) error {
{{template "_settag" . -}}
return s.Struct.SetPtr({{.Field.Slot.Offset}}, v)
}

View File

@@ -0,0 +1,33 @@
func (s {{.Node.Name}}) {{.Field.Name|title}}() ({{.FieldType}}, error) {
{{template "_checktag" . -}}
p, err := s.Struct.Ptr({{.Field.Slot.Offset}})
{{if .Default.IsValid -}}
if err != nil {
return {{.FieldType}}{}, err
}
ss, err := p.StructDefault({{.Default}})
return {{.FieldType}}{Struct: ss}, err
{{- else -}}
return {{.FieldType}}{Struct: p.Struct()}, err
{{- end}}
}
{{template "_hasfield" .}}
func (s {{.Node.Name}}) Set{{.Field.Name|title}}(v {{.FieldType}}) error {
{{template "_settag" . -}}
return s.Struct.SetPtr({{.Field.Slot.Offset}}, v.Struct.ToPtr())
}
// New{{.Field.Name|title}} sets the {{.Field.Name}} field to a newly
// allocated {{.FieldType}} struct, preferring placement in s's segment.
func (s {{.Node.Name}}) New{{.Field.Name|title}}() ({{.FieldType}}, error) {
{{template "_settag" . -}}
ss, err := {{.G.RemoteNodeNew .TypeNode .Node}}(s.Struct.Segment())
if err != nil {
return {{.FieldType}}{}, err
}
err = s.Struct.SetPtr({{.Field.Slot.Offset}}, ss.Struct.ToPtr())
return ss, err
}

View File

@@ -0,0 +1,30 @@
func (s {{.Node.Name}}) {{.Field.Name|title}}() (string, error) {
{{template "_checktag" . -}}
p, err := s.Struct.Ptr({{.Field.Slot.Offset}})
{{with .Default -}}
return p.TextDefault({{printf "%q" .}}), err
{{- else -}}
return p.Text(), err
{{- end}}
}
{{template "_hasfield" .}}
func (s {{.Node.Name}}) {{.Field.Name|title}}Bytes() ([]byte, error) {
p, err := s.Struct.Ptr({{.Field.Slot.Offset}})
{{with .Default -}}
return p.TextBytesDefault({{printf "%q" .}}), err
{{- else -}}
return p.TextBytes(), err
{{- end}}
}
func (s {{.Node.Name}}) Set{{.Field.Name|title}}(v string) error {
{{template "_settag" . -}}
{{if .Default -}}
return s.Struct.SetNewText({{.Field.Slot.Offset}}, v)
{{- else -}}
return s.Struct.SetText({{.Field.Slot.Offset}}, v)
{{- end}}
}

View File

@@ -0,0 +1,8 @@
{{with .Annotations.Doc -}}
// {{.}}
{{end -}}
type {{.Node.Name}} {{if .IsBase -}}
struct{ {{.G.Capnp}}.Struct }
{{- else -}}
{{.BaseNode.Name}}
{{- end}}

View File

@@ -0,0 +1,10 @@
func (s {{.Node.Name}}) {{.Field.Name|title}}() uint{{.Bits}} {
{{template "_checktag" . -}}
return s.Struct.Uint{{.Bits}}({{.Offset}}){{with .Default}} ^ {{.}}{{end}}
}
func (s {{.Node.Name}}) Set{{.Field.Name|title}}(v uint{{.Bits}}) {
{{template "_settag" . -}}
s.Struct.SetUint{{.Bits}}({{.Offset}}, v{{with .Default}}^{{.}}{{end}})
}

View File

@@ -0,0 +1,2 @@
{{.G.RemoteNodeName .Typ .Node}}{Struct: {{.G.Capnp}}.MustUnmarshalRootPtr({{.Value}}).Struct()}
{{- /* no EOL */ -}}

View File

@@ -0,0 +1,6 @@
{{if .Field.HasDiscriminant -}}
func (s {{.Node.Name}}) Set{{.Field.Name|title}}() {
{{template "_settag" .}}
}
{{end -}}