TUN-3019: Remove declarative tunnel entry code

This commit is contained in:
cthuang
2020-05-29 17:21:03 +08:00
parent be0514c5c9
commit fb82b2ced5
36 changed files with 643 additions and 3955 deletions

2
vendor/modules.txt vendored
View File

@@ -299,7 +299,7 @@ gopkg.in/urfave/cli.v2
gopkg.in/urfave/cli.v2/altsrc
# gopkg.in/yaml.v2 v2.2.4
gopkg.in/yaml.v2
# zombiezen.com/go/capnproto2 v0.0.0-20180616160808-7cfd211c19c7
# zombiezen.com/go/capnproto2 v2.18.0+incompatible
zombiezen.com/go/capnproto2
zombiezen.com/go/capnproto2/encoding/text
zombiezen.com/go/capnproto2/internal/fulfiller

View File

@@ -10,8 +10,10 @@
# Please keep the list sorted.
Anapaya Systems AG
CloudFlare Inc.
Daniel Darabos <darabos.daniel@gmail.com>
Dominik Roos <domi.roos@gmail.com>
Eran Duchan <pavius@gmail.com>
Evan Shaw <edsrzf@gmail.com>
Google Inc.
@@ -20,8 +22,11 @@ James McKaskill <james@foobar.co.nz>
Jason E. Aten <j.e.aten@gmail.com>
Johan Hernandez <im@bithavoc.io>
Joonsung Lee <joonsung@devsisters.com>
Kiwi.com s.r.o.
Lev Radomislensky <lev.radomislensky@gmail.com>
Peter Waldschmidt <peterw@gnoso.com>
Tiit Pikma <pikma@hot.ee>
Tom Thorogood <me+github@tomthorogood.co.uk>
TJ Holowaychuk <tj@apex.sh>
William Laffin <william.laffin@gmail.com>
Colin Arnott <colin@urandom.co.uk>

View File

@@ -1,5 +1,10 @@
# Go Cap'n Proto Release Notes
## 2.17.3
- Clear read limits for `const` messages in schemas.
([#131](https://github.com/capnproto/go-capnproto2/pull/131))
## 2.17.0
- Add `capnp.Canonicalize` function that implements the

View File

@@ -18,6 +18,7 @@
Alan Braithwaite <alan@cloudflare.com>
Albert Strasheim <albert@cloudflare.com>
Daniel Darabos <darabos.daniel@gmail.com>
Dominik Roos <domi.roos@gmail.com>
Eran Duchan <pavius@gmail.com>
Evan Shaw <edsrzf@gmail.com>
Ian Denhardt <ian@zenhack.net>
@@ -26,8 +27,13 @@ Jason E. Aten <j.e.aten@gmail.com>
Johan Hernandez <im@bithavoc.io>
Joonsung Lee <joonsung@devsisters.com>
Lev Radomislensky <lev.radomislensky@gmail.com>
Lukas Vogel <vogel@anapaya.net> <lukedirtwalker@gmail.com>
Martin Sucha <martin.sucha@kiwi.com>
Peter Waldschmidt <peterw@gnoso.com>
Ross Light <light@google.com> <ross@zombiezen.com>
Stephen Shirley <kormat@anapaya.net> <kormat@gmail.com>
Tiit Pikma <pikma@hot.ee>
Tom Thorogood <me+github@tomthorogood.co.uk>
TJ Holowaychuk <tj@apex.sh>
William Laffin <william.laffin@gmail.com>
Colin Arnott <colin@urandom.co.uk>

View File

@@ -4,17 +4,17 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "io_bazel_rules_go",
sha256 = "8b68d0630d63d95dacc0016c3bb4b76154fe34fca93efd65d1c366de3fcb4294",
urls = ["https://github.com/bazelbuild/rules_go/releases/download/0.12.1/rules_go-0.12.1.tar.gz"],
sha256 = "86ae934bd4c43b99893fc64be9d9fc684b81461581df7ea8fc291c816f5ee8c5",
urls = ["https://github.com/bazelbuild/rules_go/releases/download/0.18.3/rules_go-0.18.3.tar.gz"],
)
http_archive(
name = "bazel_gazelle",
sha256 = "ddedc7aaeb61f2654d7d7d4fd7940052ea992ccdb031b8f9797ed143ac7e8d43",
urls = ["https://github.com/bazelbuild/bazel-gazelle/releases/download/0.12.0/bazel-gazelle-0.12.0.tar.gz"],
sha256 = "3c681998538231a2d24d0c07ed5a7658cb72bfb5fd4bf9911157c0e9ac6a2687",
urls = ["https://github.com/bazelbuild/bazel-gazelle/releases/download/0.17.0/bazel-gazelle-0.17.0.tar.gz"],
)
load("@io_bazel_rules_go//go:def.bzl", "go_register_toolchains", "go_rules_dependencies")
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
go_rules_dependencies()

View File

@@ -200,6 +200,9 @@ func (s *Segment) readListPtr(base Address, val rawPointer) (List, error) {
}
sz := hdr.structSize()
n := int32(hdr.offset())
if n < 0 {
return List{}, errListSize
}
// TODO(light): check that this has the same end address
if tsize, ok := sz.totalSize().times(n); !ok {
return List{}, errOverflow
@@ -214,11 +217,15 @@ func (s *Segment) readListPtr(base Address, val rawPointer) (List, error) {
flags: isCompositeList,
}, nil
}
n := val.numListElements()
if n < 0 {
return List{}, errListSize
}
if lt == bit1List {
return List{
seg: s,
off: addr,
length: val.numListElements(),
length: n,
flags: isBitList,
}, nil
}
@@ -226,7 +233,7 @@ func (s *Segment) readListPtr(base Address, val rawPointer) (List, error) {
seg: s,
size: val.elementSize(),
off: addr,
length: val.numListElements(),
length: n,
}, nil
}

View File

@@ -81,10 +81,10 @@ Structs
For the following schema:
struct Foo @0x8423424e9b01c0af {
num @0 :UInt32;
bar @1 :Foo;
}
struct Foo @0x8423424e9b01c0af {
num @0 :UInt32;
bar @1 :Foo;
}
capnpc-go will generate:
@@ -168,9 +168,9 @@ For each group a typedef is created with a different method set for just the
groups fields:
struct Foo {
group :Group {
field @0 :Bool;
}
group :Group {
field @0 :Bool;
}
}
generates the following:
@@ -194,10 +194,10 @@ Named unions are treated as a group with an inner unnamed union. Unnamed
unions generate an enum Type_Which and a corresponding Which() function:
struct Foo {
union {
a @0 :Bool;
b @1 :Bool;
}
union {
a @0 :Bool;
b @1 :Bool;
}
}
generates the following:
@@ -225,10 +225,10 @@ For voids in unions, there is a void setter that just sets the discriminator.
For example:
struct Foo {
union {
a @0 :Void;
b @1 :Void;
}
union {
a @0 :Void;
b @1 :Void;
}
}
generates the following:
@@ -241,14 +241,14 @@ the discriminator. This must be called before the group getter can be
used to set values. For example:
struct Foo {
union {
a :group {
v :Bool
}
b :group {
v :Bool
}
}
union {
a :group {
v :Bool
}
b :group {
v :Bool
}
}
}
and in usage:
@@ -293,10 +293,10 @@ but the tags can be customized with a $Go.tag or $Go.notag annotation.
For example:
enum ElementSize {
empty @0 $Go.tag("void");
bit @1 $Go.tag("1 bit");
byte @2 $Go.tag("8 bits");
inlineComposite @7 $Go.notag;
empty @0 $Go.tag("void");
bit @1 $Go.tag("1 bit");
byte @2 $Go.tag("8 bits");
inlineComposite @7 $Go.notag;
}
In the generated go file:

View File

@@ -42,14 +42,14 @@ func MarshalList(typeID uint64, l capnp.List) (string, error) {
// An Encoder writes the text format of Cap'n Proto messages to an output stream.
type Encoder struct {
w errWriter
w indentWriter
tmp []byte
nodes nodemap.Map
}
// NewEncoder returns a new encoder that writes to w.
func NewEncoder(w io.Writer) *Encoder {
return &Encoder{w: errWriter{w: w}}
return &Encoder{w: indentWriter{w: w}}
}
// UseRegistry changes the registry that the encoder consults for
@@ -58,6 +58,12 @@ func (enc *Encoder) UseRegistry(reg *schemas.Registry) {
enc.nodes.UseRegistry(reg)
}
// SetIndent sets string to indent each level with.
// An empty string disables indentation.
func (enc *Encoder) SetIndent(indent string) {
enc.w.indentPerLevel = indent
}
// Encode writes the text representation of s to the stream.
func (enc *Encoder) Encode(typeID uint64, s capnp.Struct) error {
if enc.w.err != nil {
@@ -133,8 +139,14 @@ func (enc *Encoder) marshalStruct(typeID uint64, s capnp.Struct) error {
if n.StructNode().DiscriminantCount() > 0 {
discriminant = s.Uint16(capnp.DataOffset(n.StructNode().DiscriminantOffset() * 2))
}
enc.w.WriteByte('(')
fields := codeOrderFields(n.StructNode())
if len(fields) == 0 {
enc.w.WriteString("()")
return nil
}
enc.w.WriteByte('(')
enc.w.Indent()
enc.w.NewLine()
first := true
for _, f := range fields {
if !(f.Which() == schema.Field_Which_slot || f.Which() == schema.Field_Which_group) {
@@ -144,7 +156,8 @@ func (enc *Encoder) marshalStruct(typeID uint64, s capnp.Struct) error {
continue
}
if !first {
enc.w.WriteString(", ")
enc.w.WriteByte(',')
enc.w.NewLineOrSpace()
}
first = false
name, err := f.NameBytes()
@@ -164,6 +177,8 @@ func (enc *Encoder) marshalStruct(typeID uint64, s capnp.Struct) error {
}
}
}
enc.w.NewLine()
enc.w.Unindent()
enc.w.WriteByte(')')
return nil
}
@@ -298,101 +313,154 @@ func codeOrderFields(s schema.Node_structNode) []schema.Field {
}
func (enc *Encoder) marshalList(elem schema.Type, l capnp.List) error {
switch elem.Which() {
case schema.Type_Which_void:
enc.w.WriteString(capnp.VoidList{List: l}.String())
case schema.Type_Which_bool:
enc.w.WriteString(capnp.BitList{List: l}.String())
case schema.Type_Which_int8:
enc.w.WriteString(capnp.Int8List{List: l}.String())
case schema.Type_Which_int16:
enc.w.WriteString(capnp.Int16List{List: l}.String())
case schema.Type_Which_int32:
enc.w.WriteString(capnp.Int32List{List: l}.String())
case schema.Type_Which_int64:
enc.w.WriteString(capnp.Int64List{List: l}.String())
case schema.Type_Which_uint8:
enc.w.WriteString(capnp.UInt8List{List: l}.String())
case schema.Type_Which_uint16:
enc.w.WriteString(capnp.UInt16List{List: l}.String())
case schema.Type_Which_uint32:
enc.w.WriteString(capnp.UInt32List{List: l}.String())
case schema.Type_Which_uint64:
enc.w.WriteString(capnp.UInt64List{List: l}.String())
case schema.Type_Which_float32:
enc.w.WriteString(capnp.Float32List{List: l}.String())
case schema.Type_Which_float64:
enc.w.WriteString(capnp.Float64List{List: l}.String())
case schema.Type_Which_data:
enc.w.WriteString(capnp.DataList{List: l}.String())
case schema.Type_Which_text:
enc.w.WriteString(capnp.TextList{List: l}.String())
case schema.Type_Which_structType:
writeListItems := func(writeItem func(i int) error) error {
if l.Len() == 0 {
_, err := enc.w.WriteString("[]")
return err
}
enc.w.WriteByte('[')
enc.w.Indent()
enc.w.NewLine()
for i := 0; i < l.Len(); i++ {
if i > 0 {
enc.w.WriteString(", ")
}
err := enc.marshalStruct(elem.StructType().TypeId(), l.Struct(i))
err := writeItem(i)
if err != nil {
return err
}
if i == l.Len()-1 {
enc.w.NewLine()
} else {
enc.w.WriteByte(',')
enc.w.NewLineOrSpace()
}
}
enc.w.Unindent()
enc.w.WriteByte(']')
return nil
}
writeListItemsN := func(writeItem func(i int) (int, error)) error {
return writeListItems(func(i int) error {
_, err := writeItem(i)
return err
})
}
switch elem.Which() {
case schema.Type_Which_void:
return writeListItemsN(func(_ int) (int, error) {
return enc.w.WriteString("void")
})
case schema.Type_Which_bool:
p := capnp.BitList{List: l}
return writeListItemsN(func(i int) (int, error) {
if p.At(i) {
return enc.w.WriteString("true")
} else {
return enc.w.WriteString("false")
}
})
case schema.Type_Which_int8:
p := capnp.Int8List{List: l}
return writeListItemsN(func(i int) (int, error) {
return enc.w.WriteString(strconv.FormatInt(int64(p.At(i)), 10))
})
case schema.Type_Which_int16:
p := capnp.Int16List{List: l}
return writeListItemsN(func(i int) (int, error) {
return enc.w.WriteString(strconv.FormatInt(int64(p.At(i)), 10))
})
case schema.Type_Which_int32:
p := capnp.Int32List{List: l}
return writeListItemsN(func(i int) (int, error) {
return enc.w.WriteString(strconv.FormatInt(int64(p.At(i)), 10))
})
case schema.Type_Which_int64:
p := capnp.Int64List{List: l}
return writeListItemsN(func(i int) (int, error) {
return enc.w.WriteString(strconv.FormatInt(p.At(i), 10))
})
case schema.Type_Which_uint8:
p := capnp.UInt8List{List: l}
return writeListItemsN(func(i int) (int, error) {
return enc.w.WriteString(strconv.FormatUint(uint64(p.At(i)), 10))
})
case schema.Type_Which_uint16:
p := capnp.UInt16List{List: l}
return writeListItemsN(func(i int) (int, error) {
return enc.w.WriteString(strconv.FormatUint(uint64(p.At(i)), 10))
})
case schema.Type_Which_uint32:
p := capnp.UInt32List{List: l}
return writeListItemsN(func(i int) (int, error) {
return enc.w.WriteString(strconv.FormatUint(uint64(p.At(i)), 10))
})
case schema.Type_Which_uint64:
p := capnp.UInt64List{List: l}
return writeListItemsN(func(i int) (int, error) {
return enc.w.WriteString(strconv.FormatUint(p.At(i), 10))
})
case schema.Type_Which_float32:
p := capnp.Float32List{List: l}
return writeListItemsN(func(i int) (int, error) {
return enc.w.WriteString(strconv.FormatFloat(float64(p.At(i)), 'g', -1, 32))
})
case schema.Type_Which_float64:
p := capnp.Float64List{List: l}
return writeListItemsN(func(i int) (int, error) {
return enc.w.WriteString(strconv.FormatFloat(p.At(i), 'g', -1, 64))
})
case schema.Type_Which_data:
p := capnp.DataList{List: l}
return writeListItemsN(func(i int) (int, error) {
s, err := p.At(i)
if err != nil {
return enc.w.WriteString("<error>")
}
buf := strquote.Append(nil, s)
return enc.w.Write(buf)
})
case schema.Type_Which_text:
p := capnp.TextList{List: l}
return writeListItemsN(func(i int) (int, error) {
s, err := p.BytesAt(i)
if err != nil {
return enc.w.WriteString("<error>")
}
buf := strquote.Append(nil, s)
return enc.w.Write(buf)
})
case schema.Type_Which_structType:
return writeListItems(func(i int) error {
return enc.marshalStruct(elem.StructType().TypeId(), l.Struct(i))
})
case schema.Type_Which_list:
enc.w.WriteByte('[')
ee, err := elem.List().ElementType()
if err != nil {
return err
}
for i := 0; i < l.Len(); i++ {
if i > 0 {
enc.w.WriteString(", ")
}
return writeListItems(func(i int) error {
p, err := capnp.PointerList{List: l}.PtrAt(i)
if err != nil {
return err
}
err = enc.marshalList(ee, p.List())
if err != nil {
return err
}
}
enc.w.WriteByte(']')
return enc.marshalList(ee, p.List())
})
case schema.Type_Which_enum:
enc.w.WriteByte('[')
il := capnp.UInt16List{List: l}
typ := elem.Enum().TypeId()
// TODO(light): only search for node once
for i := 0; i < il.Len(); i++ {
if i > 0 {
enc.w.WriteString(", ")
}
enc.marshalEnum(typ, il.At(i))
}
enc.w.WriteByte(']')
return writeListItems(func(i int) error {
return enc.marshalEnum(typ, il.At(i))
})
case schema.Type_Which_interface:
enc.w.WriteByte('[')
for i := 0; i < l.Len(); i++ {
if i > 0 {
enc.w.WriteString(", ")
}
enc.w.WriteString(interfaceMarker)
}
enc.w.WriteByte(']')
return writeListItemsN(func(_ int) (int, error) {
return enc.w.WriteString(interfaceMarker)
})
case schema.Type_Which_anyPointer:
enc.w.WriteByte('[')
for i := 0; i < l.Len(); i++ {
if i > 0 {
enc.w.WriteString(", ")
}
enc.w.WriteString(anyPointerMarker)
}
enc.w.WriteByte(']')
return writeListItemsN(func(_ int) (int, error) {
return enc.w.WriteString(anyPointerMarker)
})
default:
return fmt.Errorf("unknown list type %v", elem.Which())
}
return nil
}
func (enc *Encoder) marshalEnum(typ uint64, val uint16) error {
@@ -419,37 +487,96 @@ func (enc *Encoder) marshalEnum(typ uint64, val uint16) error {
return nil
}
type errWriter struct {
// indentWriter is helper for writing indented text
type indentWriter struct {
w io.Writer
err error
// indentPerLevel is a string to prepend to a line for every level of indentation.
indentPerLevel string
// current indent level
currentIndent int
// hasLineContent is true when we have written something on the current line.
hasLineContent bool
}
func (ew *errWriter) Write(p []byte) (int, error) {
if ew.err != nil {
return 0, ew.err
func (iw *indentWriter) beforeWrite() {
if iw.err != nil {
return
}
if len(iw.indentPerLevel) > 0 && !iw.hasLineContent {
iw.hasLineContent = true
for i := 0; i < iw.currentIndent; i++ {
_, err := iw.w.Write([]byte(iw.indentPerLevel))
if err != nil {
iw.err = err
return
}
}
}
}
func (iw *indentWriter) Write(p []byte) (int, error) {
iw.beforeWrite()
if iw.err != nil {
return 0, iw.err
}
var n int
n, ew.err = ew.w.Write(p)
return n, ew.err
n, iw.err = iw.w.Write(p)
return n, iw.err
}
func (ew *errWriter) WriteString(s string) (int, error) {
if ew.err != nil {
return 0, ew.err
func (iw *indentWriter) WriteString(s string) (int, error) {
iw.beforeWrite()
if iw.err != nil {
return 0, iw.err
}
var n int
n, ew.err = io.WriteString(ew.w, s)
return n, ew.err
n, iw.err = io.WriteString(iw.w, s)
return n, iw.err
}
func (ew *errWriter) WriteByte(b byte) error {
if ew.err != nil {
return ew.err
func (iw *indentWriter) WriteByte(b byte) error {
iw.beforeWrite()
if iw.err != nil {
return iw.err
}
if bw, ok := ew.w.(io.ByteWriter); ok {
ew.err = bw.WriteByte(b)
if bw, ok := iw.w.(io.ByteWriter); ok {
iw.err = bw.WriteByte(b)
} else {
_, ew.err = ew.w.Write([]byte{b})
_, iw.err = iw.w.Write([]byte{b})
}
return iw.err
}
func (iw *indentWriter) Indent() {
iw.currentIndent++
}
func (iw *indentWriter) Unindent() {
iw.currentIndent--
}
func (iw *indentWriter) NewLine() {
if len(iw.indentPerLevel) > 0 && iw.hasLineContent {
if iw.err != nil {
return
}
if bw, ok := iw.w.(io.ByteWriter); ok {
iw.err = bw.WriteByte('\n')
} else {
_, iw.err = iw.w.Write([]byte{'\n'})
}
iw.hasLineContent = false
}
}
func (iw *indentWriter) NewLineOrSpace() {
if len(iw.indentPerLevel) > 0 {
iw.NewLine()
} else {
iw.WriteByte(' ')
}
return ew.err
}

View File

@@ -1,6 +0,0 @@
module "zombiezen.com/go/capnproto2"
require (
"github.com/kylelemons/godebug" v0.0.0-20170820004349-d65d576e9348
"golang.org/x/net" v0.0.0-20180218175443-cbe0f9307d01
)

8
vendor/zombiezen.com/go/capnproto2/go.sum generated vendored Normal file
View File

@@ -0,0 +1,8 @@
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/philhofer/fwd v1.0.0 h1:UbZqGr5Y38ApvM/V/jEljVxwocdweyH+vmYvRPBnbqQ=
github.com/philhofer/fwd v1.0.0/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU=
github.com/tinylib/msgp v1.1.0 h1:9fQd+ICuRIu/ue4vxJZu6/LzxN0HwMds2nq/0cFvxHU=
github.com/tinylib/msgp v1.1.0/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE=
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01 h1:po1f06KS05FvIQQA2pMuOWZAUXiy1KYdIf0ElUU2Hhc=
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=

View File

@@ -142,6 +142,9 @@ func Unpack(dst, src []byte) ([]byte, error) {
dst = allocWords(dst, int(src[0]))
src = src[1:]
n := copy(dst[start:], src)
if n < len(dst)-start {
return dst, io.ErrUnexpectedEOF
}
src = src[n:]
}
}
@@ -281,22 +284,22 @@ func (r *Reader) ReadWord(p []byte) error {
switch tag {
case zeroTag:
z, err := r.rd.ReadByte()
if err == io.EOF {
r.err = io.ErrUnexpectedEOF
return nil
} else if err != nil {
if err != nil {
if err == io.EOF {
err = io.ErrUnexpectedEOF
}
r.err = err
return nil
return err
}
r.zeroes = int(z)
case unpackedTag:
l, err := r.rd.ReadByte()
if err == io.EOF {
r.err = io.ErrUnexpectedEOF
return nil
} else if err != nil {
if err != nil {
if err == io.EOF {
err = io.ErrUnexpectedEOF
}
r.err = err
return nil
return err
}
r.literal = int(l)
}

View File

@@ -360,7 +360,7 @@ func (ssa *singleSegmentArena) Allocate(sz Size, segs map[SegmentID]*Segment) (S
if hasCapacity(data, sz) {
return 0, data, nil
}
inc, err := nextAlloc(int64(len(data)), int64(maxSegmentSize()), sz)
inc, err := nextAlloc(int64(cap(data)), int64(maxSegmentSize()), sz)
if err != nil {
return 0, nil, fmt.Errorf("capnp: alloc %d bytes: %v", sz, err)
}

View File

@@ -155,7 +155,7 @@ func (p Ptr) text() (b []byte, ok bool) {
// Text must be null-terminated.
return nil, false
}
return b[:len(b)-1 : len(b)], true
return b[: len(b)-1 : len(b)], true
}
// Data attempts to convert p into Data, returning nil if p is not a

View File

@@ -112,7 +112,7 @@ func (r *record) read() ([]byte, error) {
}
p := packed.NewReader(bufio.NewReader(z))
r.data, r.err = ioutil.ReadAll(p)
if err != nil {
if r.err != nil {
r.data = nil
return
}