mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-28 16:23:41 +00:00
Update/add vendor
This commit is contained in:
2
vendor/github.com/aws/aws-sdk-go/aws/version.go
generated
vendored
2
vendor/github.com/aws/aws-sdk-go/aws/version.go
generated
vendored
@@ -5,4 +5,4 @@ package aws
|
|||||||
const SDKName = "aws-sdk-go"
|
const SDKName = "aws-sdk-go"
|
||||||
|
|
||||||
// SDKVersion is the version of this SDK
|
// SDKVersion is the version of this SDK
|
||||||
const SDKVersion = "1.1.31"
|
const SDKVersion = "1.1.32"
|
||||||
|
|||||||
28
vendor/github.com/aws/aws-sdk-go/service/ec2/api.go
generated
vendored
28
vendor/github.com/aws/aws-sdk-go/service/ec2/api.go
generated
vendored
@@ -5389,10 +5389,9 @@ func (c *EC2) GetConsoleScreenshotRequest(input *GetConsoleScreenshotInput) (req
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve a JPG-format screenshot of an instance to help with troubleshooting.
|
// Retrieve a JPG-format screenshot of a running instance to help with troubleshooting.
|
||||||
//
|
//
|
||||||
// For API calls, the returned content is base64-encoded. For command line
|
// The returned content is base64-encoded.
|
||||||
// tools, the decoding is performed for you.
|
|
||||||
func (c *EC2) GetConsoleScreenshot(input *GetConsoleScreenshotInput) (*GetConsoleScreenshotOutput, error) {
|
func (c *EC2) GetConsoleScreenshot(input *GetConsoleScreenshotInput) (*GetConsoleScreenshotOutput, error) {
|
||||||
req, out := c.GetConsoleScreenshotRequest(input)
|
req, out := c.GetConsoleScreenshotRequest(input)
|
||||||
err := req.Send()
|
err := req.Send()
|
||||||
@@ -18608,7 +18607,7 @@ type GetConsoleOutputOutput struct {
|
|||||||
// The ID of the instance.
|
// The ID of the instance.
|
||||||
InstanceId *string `locationName:"instanceId" type:"string"`
|
InstanceId *string `locationName:"instanceId" type:"string"`
|
||||||
|
|
||||||
// The console output, Base64 encoded. If using a command line tool, the tools
|
// The console output, base64-encoded. If using a command line tool, the tools
|
||||||
// decode the output for you.
|
// decode the output for you.
|
||||||
Output *string `locationName:"output" type:"string"`
|
Output *string `locationName:"output" type:"string"`
|
||||||
|
|
||||||
@@ -25931,6 +25930,10 @@ type SpotFleetRequestConfigData struct {
|
|||||||
// the Spot fleet.
|
// the Spot fleet.
|
||||||
ExcessCapacityTerminationPolicy *string `locationName:"excessCapacityTerminationPolicy" type:"string" enum:"ExcessCapacityTerminationPolicy"`
|
ExcessCapacityTerminationPolicy *string `locationName:"excessCapacityTerminationPolicy" type:"string" enum:"ExcessCapacityTerminationPolicy"`
|
||||||
|
|
||||||
|
// The number of units fulfilled by this request compared to the set target
|
||||||
|
// capacity.
|
||||||
|
FulfilledCapacity *float64 `locationName:"fulfilledCapacity" type:"double"`
|
||||||
|
|
||||||
// Grants the Spot fleet permission to terminate Spot instances on your behalf
|
// Grants the Spot fleet permission to terminate Spot instances on your behalf
|
||||||
// when you cancel its Spot fleet request using CancelSpotFleetRequests or when
|
// when you cancel its Spot fleet request using CancelSpotFleetRequests or when
|
||||||
// the Spot fleet request expires, if you set terminateInstancesWithExpiration.
|
// the Spot fleet request expires, if you set terminateInstancesWithExpiration.
|
||||||
@@ -25951,6 +25954,16 @@ type SpotFleetRequestConfigData struct {
|
|||||||
// fleet request expires.
|
// fleet request expires.
|
||||||
TerminateInstancesWithExpiration *bool `locationName:"terminateInstancesWithExpiration" type:"boolean"`
|
TerminateInstancesWithExpiration *bool `locationName:"terminateInstancesWithExpiration" type:"boolean"`
|
||||||
|
|
||||||
|
// The type of request. Indicates whether the fleet will only request the target
|
||||||
|
// capacity or also attempt to maintain it. When you request a certain target
|
||||||
|
// capacity, the fleet will only place the required bids. It will not attempt
|
||||||
|
// to replenish Spot instances if capacity is diminished, nor will it submit
|
||||||
|
// bids in alternative Spot pools if capacity is not available. When you want
|
||||||
|
// to maintain a certain target capacity, fleet will place the required bids
|
||||||
|
// to meet this target capacity. It will also automatically replenish any interrupted
|
||||||
|
// instances. Default: maintain.
|
||||||
|
Type *string `locationName:"type" type:"string" enum:"FleetType"`
|
||||||
|
|
||||||
// The start date and time of the request, in UTC format (for example, YYYY-MM-DDTHH:MM:SSZ).
|
// The start date and time of the request, in UTC format (for example, YYYY-MM-DDTHH:MM:SSZ).
|
||||||
// The default is to start fulfilling the request immediately.
|
// The default is to start fulfilling the request immediately.
|
||||||
ValidFrom *time.Time `locationName:"validFrom" type:"timestamp" timestampFormat:"iso8601"`
|
ValidFrom *time.Time `locationName:"validFrom" type:"timestamp" timestampFormat:"iso8601"`
|
||||||
@@ -27733,6 +27746,13 @@ const (
|
|||||||
ExportTaskStateCompleted = "completed"
|
ExportTaskStateCompleted = "completed"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// @enum FleetType
|
||||||
|
FleetTypeRequest = "request"
|
||||||
|
// @enum FleetType
|
||||||
|
FleetTypeMaintain = "maintain"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// @enum FlowLogsResourceType
|
// @enum FlowLogsResourceType
|
||||||
FlowLogsResourceTypeVpc = "VPC"
|
FlowLogsResourceTypeVpc = "VPC"
|
||||||
|
|||||||
2
vendor/github.com/coreos/etcd/pkg/transport/listener.go
generated
vendored
2
vendor/github.com/coreos/etcd/pkg/transport/listener.go
generated
vendored
@@ -184,7 +184,7 @@ func (info TLSInfo) baseConfig() (*tls.Config, error) {
|
|||||||
|
|
||||||
cfg := &tls.Config{
|
cfg := &tls.Config{
|
||||||
Certificates: []tls.Certificate{*tlsCert},
|
Certificates: []tls.Certificate{*tlsCert},
|
||||||
MinVersion: tls.VersionTLS10,
|
MinVersion: tls.VersionTLS12,
|
||||||
}
|
}
|
||||||
return cfg, nil
|
return cfg, nil
|
||||||
}
|
}
|
||||||
|
|||||||
6
vendor/github.com/go-ini/ini/README.md
generated
vendored
6
vendor/github.com/go-ini/ini/README.md
generated
vendored
@@ -395,6 +395,12 @@ CLONE_URL = https://%(IMPORT_PATH)s
|
|||||||
cfg.Section("package.sub").Key("CLONE_URL").String() // https://gopkg.in/ini.v1
|
cfg.Section("package.sub").Key("CLONE_URL").String() // https://gopkg.in/ini.v1
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Retrieve parent keys available to a child section
|
||||||
|
|
||||||
|
```go
|
||||||
|
cfg.Section("package.sub").ParentKeys() // ["CLONE_URL"]
|
||||||
|
```
|
||||||
|
|
||||||
### Auto-increment Key Names
|
### Auto-increment Key Names
|
||||||
|
|
||||||
If key name is `-` in data source, then it would be seen as special syntax for auto-increment key name start from 1, and every section is independent on counter.
|
If key name is `-` in data source, then it would be seen as special syntax for auto-increment key name start from 1, and every section is independent on counter.
|
||||||
|
|||||||
6
vendor/github.com/go-ini/ini/README_ZH.md
generated
vendored
6
vendor/github.com/go-ini/ini/README_ZH.md
generated
vendored
@@ -388,6 +388,12 @@ CLONE_URL = https://%(IMPORT_PATH)s
|
|||||||
cfg.Section("package.sub").Key("CLONE_URL").String() // https://gopkg.in/ini.v1
|
cfg.Section("package.sub").Key("CLONE_URL").String() // https://gopkg.in/ini.v1
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### 获取上级父分区下的所有键名
|
||||||
|
|
||||||
|
```go
|
||||||
|
cfg.Section("package.sub").ParentKeys() // ["CLONE_URL"]
|
||||||
|
```
|
||||||
|
|
||||||
#### 读取自增键名
|
#### 读取自增键名
|
||||||
|
|
||||||
如果数据源中的键名为 `-`,则认为该键使用了自增键名的特殊语法。计数器从 1 开始,并且分区之间是相互独立的。
|
如果数据源中的键名为 `-`,则认为该键使用了自增键名的特殊语法。计数器从 1 开始,并且分区之间是相互独立的。
|
||||||
|
|||||||
2
vendor/github.com/go-ini/ini/ini.go
generated
vendored
2
vendor/github.com/go-ini/ini/ini.go
generated
vendored
@@ -36,7 +36,7 @@ const (
|
|||||||
|
|
||||||
// Maximum allowed depth when recursively substituing variable names.
|
// Maximum allowed depth when recursively substituing variable names.
|
||||||
_DEPTH_VALUES = 99
|
_DEPTH_VALUES = 99
|
||||||
_VERSION = "1.11.0"
|
_VERSION = "1.12.0"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Version returns current package version literal.
|
// Version returns current package version literal.
|
||||||
|
|||||||
20
vendor/github.com/go-ini/ini/section.go
generated
vendored
20
vendor/github.com/go-ini/ini/section.go
generated
vendored
@@ -139,6 +139,26 @@ func (s *Section) Keys() []*Key {
|
|||||||
return keys
|
return keys
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ParentKeys returns list of keys of parent section.
|
||||||
|
func (s * Section) ParentKeys() []*Key {
|
||||||
|
var parentKeys []*Key
|
||||||
|
sname := s.name
|
||||||
|
for {
|
||||||
|
if i := strings.LastIndex(sname, "."); i > -1 {
|
||||||
|
sname = sname[:i]
|
||||||
|
sec, err := s.f.GetSection(sname)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
parentKeys = append(parentKeys, sec.Keys()...)
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return parentKeys
|
||||||
|
}
|
||||||
|
|
||||||
// KeyStrings returns list of key names of section.
|
// KeyStrings returns list of key names of section.
|
||||||
func (s *Section) KeyStrings() []string {
|
func (s *Section) KeyStrings() []string {
|
||||||
list := make([]string, len(s.keyList))
|
list := make([]string, len(s.keyList))
|
||||||
|
|||||||
25
vendor/github.com/hashicorp/go-msgpack/LICENSE
generated
vendored
Normal file
25
vendor/github.com/hashicorp/go-msgpack/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
Copyright (c) 2012, 2013 Ugorji Nwoke.
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
* Neither the name of the author nor the names of its contributors may be used
|
||||||
|
to endorse or promote products derived from this software
|
||||||
|
without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||||
|
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
143
vendor/github.com/hashicorp/go-msgpack/codec/0doc.go
generated
vendored
Normal file
143
vendor/github.com/hashicorp/go-msgpack/codec/0doc.go
generated
vendored
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
// Copyright (c) 2012, 2013 Ugorji Nwoke. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*
|
||||||
|
High Performance, Feature-Rich Idiomatic Go encoding library for msgpack and binc .
|
||||||
|
|
||||||
|
Supported Serialization formats are:
|
||||||
|
|
||||||
|
- msgpack: [https://github.com/msgpack/msgpack]
|
||||||
|
- binc: [http://github.com/ugorji/binc]
|
||||||
|
|
||||||
|
To install:
|
||||||
|
|
||||||
|
go get github.com/ugorji/go/codec
|
||||||
|
|
||||||
|
The idiomatic Go support is as seen in other encoding packages in
|
||||||
|
the standard library (ie json, xml, gob, etc).
|
||||||
|
|
||||||
|
Rich Feature Set includes:
|
||||||
|
|
||||||
|
- Simple but extremely powerful and feature-rich API
|
||||||
|
- Very High Performance.
|
||||||
|
Our extensive benchmarks show us outperforming Gob, Json and Bson by 2-4X.
|
||||||
|
This was achieved by taking extreme care on:
|
||||||
|
- managing allocation
|
||||||
|
- function frame size (important due to Go's use of split stacks),
|
||||||
|
- reflection use (and by-passing reflection for common types)
|
||||||
|
- recursion implications
|
||||||
|
- zero-copy mode (encoding/decoding to byte slice without using temp buffers)
|
||||||
|
- Correct.
|
||||||
|
Care was taken to precisely handle corner cases like:
|
||||||
|
overflows, nil maps and slices, nil value in stream, etc.
|
||||||
|
- Efficient zero-copying into temporary byte buffers
|
||||||
|
when encoding into or decoding from a byte slice.
|
||||||
|
- Standard field renaming via tags
|
||||||
|
- Encoding from any value
|
||||||
|
(struct, slice, map, primitives, pointers, interface{}, etc)
|
||||||
|
- Decoding into pointer to any non-nil typed value
|
||||||
|
(struct, slice, map, int, float32, bool, string, reflect.Value, etc)
|
||||||
|
- Supports extension functions to handle the encode/decode of custom types
|
||||||
|
- Support Go 1.2 encoding.BinaryMarshaler/BinaryUnmarshaler
|
||||||
|
- Schema-less decoding
|
||||||
|
(decode into a pointer to a nil interface{} as opposed to a typed non-nil value).
|
||||||
|
Includes Options to configure what specific map or slice type to use
|
||||||
|
when decoding an encoded list or map into a nil interface{}
|
||||||
|
- Provides a RPC Server and Client Codec for net/rpc communication protocol.
|
||||||
|
- Msgpack Specific:
|
||||||
|
- Provides extension functions to handle spec-defined extensions (binary, timestamp)
|
||||||
|
- Options to resolve ambiguities in handling raw bytes (as string or []byte)
|
||||||
|
during schema-less decoding (decoding into a nil interface{})
|
||||||
|
- RPC Server/Client Codec for msgpack-rpc protocol defined at:
|
||||||
|
https://github.com/msgpack-rpc/msgpack-rpc/blob/master/spec.md
|
||||||
|
- Fast Paths for some container types:
|
||||||
|
For some container types, we circumvent reflection and its associated overhead
|
||||||
|
and allocation costs, and encode/decode directly. These types are:
|
||||||
|
[]interface{}
|
||||||
|
[]int
|
||||||
|
[]string
|
||||||
|
map[interface{}]interface{}
|
||||||
|
map[int]interface{}
|
||||||
|
map[string]interface{}
|
||||||
|
|
||||||
|
Extension Support
|
||||||
|
|
||||||
|
Users can register a function to handle the encoding or decoding of
|
||||||
|
their custom types.
|
||||||
|
|
||||||
|
There are no restrictions on what the custom type can be. Some examples:
|
||||||
|
|
||||||
|
type BisSet []int
|
||||||
|
type BitSet64 uint64
|
||||||
|
type UUID string
|
||||||
|
type MyStructWithUnexportedFields struct { a int; b bool; c []int; }
|
||||||
|
type GifImage struct { ... }
|
||||||
|
|
||||||
|
As an illustration, MyStructWithUnexportedFields would normally be
|
||||||
|
encoded as an empty map because it has no exported fields, while UUID
|
||||||
|
would be encoded as a string. However, with extension support, you can
|
||||||
|
encode any of these however you like.
|
||||||
|
|
||||||
|
RPC
|
||||||
|
|
||||||
|
RPC Client and Server Codecs are implemented, so the codecs can be used
|
||||||
|
with the standard net/rpc package.
|
||||||
|
|
||||||
|
Usage
|
||||||
|
|
||||||
|
Typical usage model:
|
||||||
|
|
||||||
|
// create and configure Handle
|
||||||
|
var (
|
||||||
|
bh codec.BincHandle
|
||||||
|
mh codec.MsgpackHandle
|
||||||
|
)
|
||||||
|
|
||||||
|
mh.MapType = reflect.TypeOf(map[string]interface{}(nil))
|
||||||
|
|
||||||
|
// configure extensions
|
||||||
|
// e.g. for msgpack, define functions and enable Time support for tag 1
|
||||||
|
// mh.AddExt(reflect.TypeOf(time.Time{}), 1, myMsgpackTimeEncodeExtFn, myMsgpackTimeDecodeExtFn)
|
||||||
|
|
||||||
|
// create and use decoder/encoder
|
||||||
|
var (
|
||||||
|
r io.Reader
|
||||||
|
w io.Writer
|
||||||
|
b []byte
|
||||||
|
h = &bh // or mh to use msgpack
|
||||||
|
)
|
||||||
|
|
||||||
|
dec = codec.NewDecoder(r, h)
|
||||||
|
dec = codec.NewDecoderBytes(b, h)
|
||||||
|
err = dec.Decode(&v)
|
||||||
|
|
||||||
|
enc = codec.NewEncoder(w, h)
|
||||||
|
enc = codec.NewEncoderBytes(&b, h)
|
||||||
|
err = enc.Encode(v)
|
||||||
|
|
||||||
|
//RPC Server
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
conn, err := listener.Accept()
|
||||||
|
rpcCodec := codec.GoRpc.ServerCodec(conn, h)
|
||||||
|
//OR rpcCodec := codec.MsgpackSpecRpc.ServerCodec(conn, h)
|
||||||
|
rpc.ServeCodec(rpcCodec)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
//RPC Communication (client side)
|
||||||
|
conn, err = net.Dial("tcp", "localhost:5555")
|
||||||
|
rpcCodec := codec.GoRpc.ClientCodec(conn, h)
|
||||||
|
//OR rpcCodec := codec.MsgpackSpecRpc.ClientCodec(conn, h)
|
||||||
|
client := rpc.NewClientWithCodec(rpcCodec)
|
||||||
|
|
||||||
|
Representative Benchmark Results
|
||||||
|
|
||||||
|
Run the benchmark suite using:
|
||||||
|
go test -bi -bench=. -benchmem
|
||||||
|
|
||||||
|
To run full benchmark suite (including against vmsgpack and bson),
|
||||||
|
see notes in ext_dep_test.go
|
||||||
|
|
||||||
|
*/
|
||||||
|
package codec
|
||||||
174
vendor/github.com/hashicorp/go-msgpack/codec/README.md
generated
vendored
Normal file
174
vendor/github.com/hashicorp/go-msgpack/codec/README.md
generated
vendored
Normal file
@@ -0,0 +1,174 @@
|
|||||||
|
# Codec
|
||||||
|
|
||||||
|
High Performance and Feature-Rich Idiomatic Go Library providing
|
||||||
|
encode/decode support for different serialization formats.
|
||||||
|
|
||||||
|
Supported Serialization formats are:
|
||||||
|
|
||||||
|
- msgpack: [https://github.com/msgpack/msgpack]
|
||||||
|
- binc: [http://github.com/ugorji/binc]
|
||||||
|
|
||||||
|
To install:
|
||||||
|
|
||||||
|
go get github.com/ugorji/go/codec
|
||||||
|
|
||||||
|
Online documentation: [http://godoc.org/github.com/ugorji/go/codec]
|
||||||
|
|
||||||
|
The idiomatic Go support is as seen in other encoding packages in
|
||||||
|
the standard library (ie json, xml, gob, etc).
|
||||||
|
|
||||||
|
Rich Feature Set includes:
|
||||||
|
|
||||||
|
- Simple but extremely powerful and feature-rich API
|
||||||
|
- Very High Performance.
|
||||||
|
Our extensive benchmarks show us outperforming Gob, Json and Bson by 2-4X.
|
||||||
|
This was achieved by taking extreme care on:
|
||||||
|
- managing allocation
|
||||||
|
- function frame size (important due to Go's use of split stacks),
|
||||||
|
- reflection use (and by-passing reflection for common types)
|
||||||
|
- recursion implications
|
||||||
|
- zero-copy mode (encoding/decoding to byte slice without using temp buffers)
|
||||||
|
- Correct.
|
||||||
|
Care was taken to precisely handle corner cases like:
|
||||||
|
overflows, nil maps and slices, nil value in stream, etc.
|
||||||
|
- Efficient zero-copying into temporary byte buffers
|
||||||
|
when encoding into or decoding from a byte slice.
|
||||||
|
- Standard field renaming via tags
|
||||||
|
- Encoding from any value
|
||||||
|
(struct, slice, map, primitives, pointers, interface{}, etc)
|
||||||
|
- Decoding into pointer to any non-nil typed value
|
||||||
|
(struct, slice, map, int, float32, bool, string, reflect.Value, etc)
|
||||||
|
- Supports extension functions to handle the encode/decode of custom types
|
||||||
|
- Support Go 1.2 encoding.BinaryMarshaler/BinaryUnmarshaler
|
||||||
|
- Schema-less decoding
|
||||||
|
(decode into a pointer to a nil interface{} as opposed to a typed non-nil value).
|
||||||
|
Includes Options to configure what specific map or slice type to use
|
||||||
|
when decoding an encoded list or map into a nil interface{}
|
||||||
|
- Provides a RPC Server and Client Codec for net/rpc communication protocol.
|
||||||
|
- Msgpack Specific:
|
||||||
|
- Provides extension functions to handle spec-defined extensions (binary, timestamp)
|
||||||
|
- Options to resolve ambiguities in handling raw bytes (as string or []byte)
|
||||||
|
during schema-less decoding (decoding into a nil interface{})
|
||||||
|
- RPC Server/Client Codec for msgpack-rpc protocol defined at:
|
||||||
|
https://github.com/msgpack-rpc/msgpack-rpc/blob/master/spec.md
|
||||||
|
- Fast Paths for some container types:
|
||||||
|
For some container types, we circumvent reflection and its associated overhead
|
||||||
|
and allocation costs, and encode/decode directly. These types are:
|
||||||
|
[]interface{}
|
||||||
|
[]int
|
||||||
|
[]string
|
||||||
|
map[interface{}]interface{}
|
||||||
|
map[int]interface{}
|
||||||
|
map[string]interface{}
|
||||||
|
|
||||||
|
## Extension Support
|
||||||
|
|
||||||
|
Users can register a function to handle the encoding or decoding of
|
||||||
|
their custom types.
|
||||||
|
|
||||||
|
There are no restrictions on what the custom type can be. Some examples:
|
||||||
|
|
||||||
|
type BisSet []int
|
||||||
|
type BitSet64 uint64
|
||||||
|
type UUID string
|
||||||
|
type MyStructWithUnexportedFields struct { a int; b bool; c []int; }
|
||||||
|
type GifImage struct { ... }
|
||||||
|
|
||||||
|
As an illustration, MyStructWithUnexportedFields would normally be
|
||||||
|
encoded as an empty map because it has no exported fields, while UUID
|
||||||
|
would be encoded as a string. However, with extension support, you can
|
||||||
|
encode any of these however you like.
|
||||||
|
|
||||||
|
## RPC
|
||||||
|
|
||||||
|
RPC Client and Server Codecs are implemented, so the codecs can be used
|
||||||
|
with the standard net/rpc package.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Typical usage model:
|
||||||
|
|
||||||
|
// create and configure Handle
|
||||||
|
var (
|
||||||
|
bh codec.BincHandle
|
||||||
|
mh codec.MsgpackHandle
|
||||||
|
)
|
||||||
|
|
||||||
|
mh.MapType = reflect.TypeOf(map[string]interface{}(nil))
|
||||||
|
|
||||||
|
// configure extensions
|
||||||
|
// e.g. for msgpack, define functions and enable Time support for tag 1
|
||||||
|
// mh.AddExt(reflect.TypeOf(time.Time{}), 1, myMsgpackTimeEncodeExtFn, myMsgpackTimeDecodeExtFn)
|
||||||
|
|
||||||
|
// create and use decoder/encoder
|
||||||
|
var (
|
||||||
|
r io.Reader
|
||||||
|
w io.Writer
|
||||||
|
b []byte
|
||||||
|
h = &bh // or mh to use msgpack
|
||||||
|
)
|
||||||
|
|
||||||
|
dec = codec.NewDecoder(r, h)
|
||||||
|
dec = codec.NewDecoderBytes(b, h)
|
||||||
|
err = dec.Decode(&v)
|
||||||
|
|
||||||
|
enc = codec.NewEncoder(w, h)
|
||||||
|
enc = codec.NewEncoderBytes(&b, h)
|
||||||
|
err = enc.Encode(v)
|
||||||
|
|
||||||
|
//RPC Server
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
conn, err := listener.Accept()
|
||||||
|
rpcCodec := codec.GoRpc.ServerCodec(conn, h)
|
||||||
|
//OR rpcCodec := codec.MsgpackSpecRpc.ServerCodec(conn, h)
|
||||||
|
rpc.ServeCodec(rpcCodec)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
//RPC Communication (client side)
|
||||||
|
conn, err = net.Dial("tcp", "localhost:5555")
|
||||||
|
rpcCodec := codec.GoRpc.ClientCodec(conn, h)
|
||||||
|
//OR rpcCodec := codec.MsgpackSpecRpc.ClientCodec(conn, h)
|
||||||
|
client := rpc.NewClientWithCodec(rpcCodec)
|
||||||
|
|
||||||
|
## Representative Benchmark Results
|
||||||
|
|
||||||
|
A sample run of benchmark using "go test -bi -bench=. -benchmem":
|
||||||
|
|
||||||
|
/proc/cpuinfo: Intel(R) Core(TM) i7-2630QM CPU @ 2.00GHz (HT)
|
||||||
|
|
||||||
|
..............................................
|
||||||
|
BENCHMARK INIT: 2013-10-16 11:02:50.345970786 -0400 EDT
|
||||||
|
To run full benchmark comparing encodings (MsgPack, Binc, JSON, GOB, etc), use: "go test -bench=."
|
||||||
|
Benchmark:
|
||||||
|
Struct recursive Depth: 1
|
||||||
|
ApproxDeepSize Of benchmark Struct: 4694 bytes
|
||||||
|
Benchmark One-Pass Run:
|
||||||
|
v-msgpack: len: 1600 bytes
|
||||||
|
bson: len: 3025 bytes
|
||||||
|
msgpack: len: 1560 bytes
|
||||||
|
binc: len: 1187 bytes
|
||||||
|
gob: len: 1972 bytes
|
||||||
|
json: len: 2538 bytes
|
||||||
|
..............................................
|
||||||
|
PASS
|
||||||
|
Benchmark__Msgpack____Encode 50000 54359 ns/op 14953 B/op 83 allocs/op
|
||||||
|
Benchmark__Msgpack____Decode 10000 106531 ns/op 14990 B/op 410 allocs/op
|
||||||
|
Benchmark__Binc_NoSym_Encode 50000 53956 ns/op 14966 B/op 83 allocs/op
|
||||||
|
Benchmark__Binc_NoSym_Decode 10000 103751 ns/op 14529 B/op 386 allocs/op
|
||||||
|
Benchmark__Binc_Sym___Encode 50000 65961 ns/op 17130 B/op 88 allocs/op
|
||||||
|
Benchmark__Binc_Sym___Decode 10000 106310 ns/op 15857 B/op 287 allocs/op
|
||||||
|
Benchmark__Gob________Encode 10000 135944 ns/op 21189 B/op 237 allocs/op
|
||||||
|
Benchmark__Gob________Decode 5000 405390 ns/op 83460 B/op 1841 allocs/op
|
||||||
|
Benchmark__Json_______Encode 20000 79412 ns/op 13874 B/op 102 allocs/op
|
||||||
|
Benchmark__Json_______Decode 10000 247979 ns/op 14202 B/op 493 allocs/op
|
||||||
|
Benchmark__Bson_______Encode 10000 121762 ns/op 27814 B/op 514 allocs/op
|
||||||
|
Benchmark__Bson_______Decode 10000 162126 ns/op 16514 B/op 789 allocs/op
|
||||||
|
Benchmark__VMsgpack___Encode 50000 69155 ns/op 12370 B/op 344 allocs/op
|
||||||
|
Benchmark__VMsgpack___Decode 10000 151609 ns/op 20307 B/op 571 allocs/op
|
||||||
|
ok ugorji.net/codec 30.827s
|
||||||
|
|
||||||
|
To run full benchmark suite (including against vmsgpack and bson),
|
||||||
|
see notes in ext\_dep\_test.go
|
||||||
|
|
||||||
786
vendor/github.com/hashicorp/go-msgpack/codec/binc.go
generated
vendored
Normal file
786
vendor/github.com/hashicorp/go-msgpack/codec/binc.go
generated
vendored
Normal file
@@ -0,0 +1,786 @@
|
|||||||
|
// Copyright (c) 2012, 2013 Ugorji Nwoke. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license found in the LICENSE file.
|
||||||
|
|
||||||
|
package codec
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math"
|
||||||
|
// "reflect"
|
||||||
|
// "sync/atomic"
|
||||||
|
"time"
|
||||||
|
//"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
const bincDoPrune = true // No longer needed. Needed before as C lib did not support pruning.
|
||||||
|
|
||||||
|
//var _ = fmt.Printf
|
||||||
|
|
||||||
|
// vd as low 4 bits (there are 16 slots)
|
||||||
|
const (
|
||||||
|
bincVdSpecial byte = iota
|
||||||
|
bincVdPosInt
|
||||||
|
bincVdNegInt
|
||||||
|
bincVdFloat
|
||||||
|
|
||||||
|
bincVdString
|
||||||
|
bincVdByteArray
|
||||||
|
bincVdArray
|
||||||
|
bincVdMap
|
||||||
|
|
||||||
|
bincVdTimestamp
|
||||||
|
bincVdSmallInt
|
||||||
|
bincVdUnicodeOther
|
||||||
|
bincVdSymbol
|
||||||
|
|
||||||
|
bincVdDecimal
|
||||||
|
_ // open slot
|
||||||
|
_ // open slot
|
||||||
|
bincVdCustomExt = 0x0f
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
bincSpNil byte = iota
|
||||||
|
bincSpFalse
|
||||||
|
bincSpTrue
|
||||||
|
bincSpNan
|
||||||
|
bincSpPosInf
|
||||||
|
bincSpNegInf
|
||||||
|
bincSpZeroFloat
|
||||||
|
bincSpZero
|
||||||
|
bincSpNegOne
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
bincFlBin16 byte = iota
|
||||||
|
bincFlBin32
|
||||||
|
_ // bincFlBin32e
|
||||||
|
bincFlBin64
|
||||||
|
_ // bincFlBin64e
|
||||||
|
// others not currently supported
|
||||||
|
)
|
||||||
|
|
||||||
|
type bincEncDriver struct {
|
||||||
|
w encWriter
|
||||||
|
m map[string]uint16 // symbols
|
||||||
|
s uint32 // symbols sequencer
|
||||||
|
b [8]byte
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *bincEncDriver) isBuiltinType(rt uintptr) bool {
|
||||||
|
return rt == timeTypId
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *bincEncDriver) encodeBuiltin(rt uintptr, v interface{}) {
|
||||||
|
switch rt {
|
||||||
|
case timeTypId:
|
||||||
|
bs := encodeTime(v.(time.Time))
|
||||||
|
e.w.writen1(bincVdTimestamp<<4 | uint8(len(bs)))
|
||||||
|
e.w.writeb(bs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *bincEncDriver) encodeNil() {
|
||||||
|
e.w.writen1(bincVdSpecial<<4 | bincSpNil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *bincEncDriver) encodeBool(b bool) {
|
||||||
|
if b {
|
||||||
|
e.w.writen1(bincVdSpecial<<4 | bincSpTrue)
|
||||||
|
} else {
|
||||||
|
e.w.writen1(bincVdSpecial<<4 | bincSpFalse)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *bincEncDriver) encodeFloat32(f float32) {
|
||||||
|
if f == 0 {
|
||||||
|
e.w.writen1(bincVdSpecial<<4 | bincSpZeroFloat)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
e.w.writen1(bincVdFloat<<4 | bincFlBin32)
|
||||||
|
e.w.writeUint32(math.Float32bits(f))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *bincEncDriver) encodeFloat64(f float64) {
|
||||||
|
if f == 0 {
|
||||||
|
e.w.writen1(bincVdSpecial<<4 | bincSpZeroFloat)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
bigen.PutUint64(e.b[:], math.Float64bits(f))
|
||||||
|
if bincDoPrune {
|
||||||
|
i := 7
|
||||||
|
for ; i >= 0 && (e.b[i] == 0); i-- {
|
||||||
|
}
|
||||||
|
i++
|
||||||
|
if i <= 6 {
|
||||||
|
e.w.writen1(bincVdFloat<<4 | 0x8 | bincFlBin64)
|
||||||
|
e.w.writen1(byte(i))
|
||||||
|
e.w.writeb(e.b[:i])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
e.w.writen1(bincVdFloat<<4 | bincFlBin64)
|
||||||
|
e.w.writeb(e.b[:])
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *bincEncDriver) encIntegerPrune(bd byte, pos bool, v uint64, lim uint8) {
|
||||||
|
if lim == 4 {
|
||||||
|
bigen.PutUint32(e.b[:lim], uint32(v))
|
||||||
|
} else {
|
||||||
|
bigen.PutUint64(e.b[:lim], v)
|
||||||
|
}
|
||||||
|
if bincDoPrune {
|
||||||
|
i := pruneSignExt(e.b[:lim], pos)
|
||||||
|
e.w.writen1(bd | lim - 1 - byte(i))
|
||||||
|
e.w.writeb(e.b[i:lim])
|
||||||
|
} else {
|
||||||
|
e.w.writen1(bd | lim - 1)
|
||||||
|
e.w.writeb(e.b[:lim])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *bincEncDriver) encodeInt(v int64) {
|
||||||
|
const nbd byte = bincVdNegInt << 4
|
||||||
|
switch {
|
||||||
|
case v >= 0:
|
||||||
|
e.encUint(bincVdPosInt<<4, true, uint64(v))
|
||||||
|
case v == -1:
|
||||||
|
e.w.writen1(bincVdSpecial<<4 | bincSpNegOne)
|
||||||
|
default:
|
||||||
|
e.encUint(bincVdNegInt<<4, false, uint64(-v))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *bincEncDriver) encodeUint(v uint64) {
|
||||||
|
e.encUint(bincVdPosInt<<4, true, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *bincEncDriver) encUint(bd byte, pos bool, v uint64) {
|
||||||
|
switch {
|
||||||
|
case v == 0:
|
||||||
|
e.w.writen1(bincVdSpecial<<4 | bincSpZero)
|
||||||
|
case pos && v >= 1 && v <= 16:
|
||||||
|
e.w.writen1(bincVdSmallInt<<4 | byte(v-1))
|
||||||
|
case v <= math.MaxUint8:
|
||||||
|
e.w.writen2(bd|0x0, byte(v))
|
||||||
|
case v <= math.MaxUint16:
|
||||||
|
e.w.writen1(bd | 0x01)
|
||||||
|
e.w.writeUint16(uint16(v))
|
||||||
|
case v <= math.MaxUint32:
|
||||||
|
e.encIntegerPrune(bd, pos, v, 4)
|
||||||
|
default:
|
||||||
|
e.encIntegerPrune(bd, pos, v, 8)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *bincEncDriver) encodeExtPreamble(xtag byte, length int) {
|
||||||
|
e.encLen(bincVdCustomExt<<4, uint64(length))
|
||||||
|
e.w.writen1(xtag)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *bincEncDriver) encodeArrayPreamble(length int) {
|
||||||
|
e.encLen(bincVdArray<<4, uint64(length))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *bincEncDriver) encodeMapPreamble(length int) {
|
||||||
|
e.encLen(bincVdMap<<4, uint64(length))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *bincEncDriver) encodeString(c charEncoding, v string) {
|
||||||
|
l := uint64(len(v))
|
||||||
|
e.encBytesLen(c, l)
|
||||||
|
if l > 0 {
|
||||||
|
e.w.writestr(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *bincEncDriver) encodeSymbol(v string) {
|
||||||
|
// if WriteSymbolsNoRefs {
|
||||||
|
// e.encodeString(c_UTF8, v)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
|
||||||
|
//symbols only offer benefit when string length > 1.
|
||||||
|
//This is because strings with length 1 take only 2 bytes to store
|
||||||
|
//(bd with embedded length, and single byte for string val).
|
||||||
|
|
||||||
|
l := len(v)
|
||||||
|
switch l {
|
||||||
|
case 0:
|
||||||
|
e.encBytesLen(c_UTF8, 0)
|
||||||
|
return
|
||||||
|
case 1:
|
||||||
|
e.encBytesLen(c_UTF8, 1)
|
||||||
|
e.w.writen1(v[0])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if e.m == nil {
|
||||||
|
e.m = make(map[string]uint16, 16)
|
||||||
|
}
|
||||||
|
ui, ok := e.m[v]
|
||||||
|
if ok {
|
||||||
|
if ui <= math.MaxUint8 {
|
||||||
|
e.w.writen2(bincVdSymbol<<4, byte(ui))
|
||||||
|
} else {
|
||||||
|
e.w.writen1(bincVdSymbol<<4 | 0x8)
|
||||||
|
e.w.writeUint16(ui)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
e.s++
|
||||||
|
ui = uint16(e.s)
|
||||||
|
//ui = uint16(atomic.AddUint32(&e.s, 1))
|
||||||
|
e.m[v] = ui
|
||||||
|
var lenprec uint8
|
||||||
|
switch {
|
||||||
|
case l <= math.MaxUint8:
|
||||||
|
// lenprec = 0
|
||||||
|
case l <= math.MaxUint16:
|
||||||
|
lenprec = 1
|
||||||
|
case int64(l) <= math.MaxUint32:
|
||||||
|
lenprec = 2
|
||||||
|
default:
|
||||||
|
lenprec = 3
|
||||||
|
}
|
||||||
|
if ui <= math.MaxUint8 {
|
||||||
|
e.w.writen2(bincVdSymbol<<4|0x0|0x4|lenprec, byte(ui))
|
||||||
|
} else {
|
||||||
|
e.w.writen1(bincVdSymbol<<4 | 0x8 | 0x4 | lenprec)
|
||||||
|
e.w.writeUint16(ui)
|
||||||
|
}
|
||||||
|
switch lenprec {
|
||||||
|
case 0:
|
||||||
|
e.w.writen1(byte(l))
|
||||||
|
case 1:
|
||||||
|
e.w.writeUint16(uint16(l))
|
||||||
|
case 2:
|
||||||
|
e.w.writeUint32(uint32(l))
|
||||||
|
default:
|
||||||
|
e.w.writeUint64(uint64(l))
|
||||||
|
}
|
||||||
|
e.w.writestr(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *bincEncDriver) encodeStringBytes(c charEncoding, v []byte) {
|
||||||
|
l := uint64(len(v))
|
||||||
|
e.encBytesLen(c, l)
|
||||||
|
if l > 0 {
|
||||||
|
e.w.writeb(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *bincEncDriver) encBytesLen(c charEncoding, length uint64) {
|
||||||
|
//TODO: support bincUnicodeOther (for now, just use string or bytearray)
|
||||||
|
if c == c_RAW {
|
||||||
|
e.encLen(bincVdByteArray<<4, length)
|
||||||
|
} else {
|
||||||
|
e.encLen(bincVdString<<4, length)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *bincEncDriver) encLen(bd byte, l uint64) {
|
||||||
|
if l < 12 {
|
||||||
|
e.w.writen1(bd | uint8(l+4))
|
||||||
|
} else {
|
||||||
|
e.encLenNumber(bd, l)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *bincEncDriver) encLenNumber(bd byte, v uint64) {
|
||||||
|
switch {
|
||||||
|
case v <= math.MaxUint8:
|
||||||
|
e.w.writen2(bd, byte(v))
|
||||||
|
case v <= math.MaxUint16:
|
||||||
|
e.w.writen1(bd | 0x01)
|
||||||
|
e.w.writeUint16(uint16(v))
|
||||||
|
case v <= math.MaxUint32:
|
||||||
|
e.w.writen1(bd | 0x02)
|
||||||
|
e.w.writeUint32(uint32(v))
|
||||||
|
default:
|
||||||
|
e.w.writen1(bd | 0x03)
|
||||||
|
e.w.writeUint64(uint64(v))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------
|
||||||
|
|
||||||
|
type bincDecDriver struct {
|
||||||
|
r decReader
|
||||||
|
bdRead bool
|
||||||
|
bdType valueType
|
||||||
|
bd byte
|
||||||
|
vd byte
|
||||||
|
vs byte
|
||||||
|
b [8]byte
|
||||||
|
m map[uint32]string // symbols (use uint32 as key, as map optimizes for it)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *bincDecDriver) initReadNext() {
|
||||||
|
if d.bdRead {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
d.bd = d.r.readn1()
|
||||||
|
d.vd = d.bd >> 4
|
||||||
|
d.vs = d.bd & 0x0f
|
||||||
|
d.bdRead = true
|
||||||
|
d.bdType = valueTypeUnset
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *bincDecDriver) currentEncodedType() valueType {
|
||||||
|
if d.bdType == valueTypeUnset {
|
||||||
|
switch d.vd {
|
||||||
|
case bincVdSpecial:
|
||||||
|
switch d.vs {
|
||||||
|
case bincSpNil:
|
||||||
|
d.bdType = valueTypeNil
|
||||||
|
case bincSpFalse, bincSpTrue:
|
||||||
|
d.bdType = valueTypeBool
|
||||||
|
case bincSpNan, bincSpNegInf, bincSpPosInf, bincSpZeroFloat:
|
||||||
|
d.bdType = valueTypeFloat
|
||||||
|
case bincSpZero:
|
||||||
|
d.bdType = valueTypeUint
|
||||||
|
case bincSpNegOne:
|
||||||
|
d.bdType = valueTypeInt
|
||||||
|
default:
|
||||||
|
decErr("currentEncodedType: Unrecognized special value 0x%x", d.vs)
|
||||||
|
}
|
||||||
|
case bincVdSmallInt:
|
||||||
|
d.bdType = valueTypeUint
|
||||||
|
case bincVdPosInt:
|
||||||
|
d.bdType = valueTypeUint
|
||||||
|
case bincVdNegInt:
|
||||||
|
d.bdType = valueTypeInt
|
||||||
|
case bincVdFloat:
|
||||||
|
d.bdType = valueTypeFloat
|
||||||
|
case bincVdString:
|
||||||
|
d.bdType = valueTypeString
|
||||||
|
case bincVdSymbol:
|
||||||
|
d.bdType = valueTypeSymbol
|
||||||
|
case bincVdByteArray:
|
||||||
|
d.bdType = valueTypeBytes
|
||||||
|
case bincVdTimestamp:
|
||||||
|
d.bdType = valueTypeTimestamp
|
||||||
|
case bincVdCustomExt:
|
||||||
|
d.bdType = valueTypeExt
|
||||||
|
case bincVdArray:
|
||||||
|
d.bdType = valueTypeArray
|
||||||
|
case bincVdMap:
|
||||||
|
d.bdType = valueTypeMap
|
||||||
|
default:
|
||||||
|
decErr("currentEncodedType: Unrecognized d.vd: 0x%x", d.vd)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return d.bdType
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *bincDecDriver) tryDecodeAsNil() bool {
|
||||||
|
if d.bd == bincVdSpecial<<4|bincSpNil {
|
||||||
|
d.bdRead = false
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *bincDecDriver) isBuiltinType(rt uintptr) bool {
|
||||||
|
return rt == timeTypId
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *bincDecDriver) decodeBuiltin(rt uintptr, v interface{}) {
|
||||||
|
switch rt {
|
||||||
|
case timeTypId:
|
||||||
|
if d.vd != bincVdTimestamp {
|
||||||
|
decErr("Invalid d.vd. Expecting 0x%x. Received: 0x%x", bincVdTimestamp, d.vd)
|
||||||
|
}
|
||||||
|
tt, err := decodeTime(d.r.readn(int(d.vs)))
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
var vt *time.Time = v.(*time.Time)
|
||||||
|
*vt = tt
|
||||||
|
d.bdRead = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *bincDecDriver) decFloatPre(vs, defaultLen byte) {
|
||||||
|
if vs&0x8 == 0 {
|
||||||
|
d.r.readb(d.b[0:defaultLen])
|
||||||
|
} else {
|
||||||
|
l := d.r.readn1()
|
||||||
|
if l > 8 {
|
||||||
|
decErr("At most 8 bytes used to represent float. Received: %v bytes", l)
|
||||||
|
}
|
||||||
|
for i := l; i < 8; i++ {
|
||||||
|
d.b[i] = 0
|
||||||
|
}
|
||||||
|
d.r.readb(d.b[0:l])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *bincDecDriver) decFloat() (f float64) {
|
||||||
|
//if true { f = math.Float64frombits(d.r.readUint64()); break; }
|
||||||
|
switch vs := d.vs; vs & 0x7 {
|
||||||
|
case bincFlBin32:
|
||||||
|
d.decFloatPre(vs, 4)
|
||||||
|
f = float64(math.Float32frombits(bigen.Uint32(d.b[0:4])))
|
||||||
|
case bincFlBin64:
|
||||||
|
d.decFloatPre(vs, 8)
|
||||||
|
f = math.Float64frombits(bigen.Uint64(d.b[0:8]))
|
||||||
|
default:
|
||||||
|
decErr("only float32 and float64 are supported. d.vd: 0x%x, d.vs: 0x%x", d.vd, d.vs)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *bincDecDriver) decUint() (v uint64) {
|
||||||
|
// need to inline the code (interface conversion and type assertion expensive)
|
||||||
|
switch d.vs {
|
||||||
|
case 0:
|
||||||
|
v = uint64(d.r.readn1())
|
||||||
|
case 1:
|
||||||
|
d.r.readb(d.b[6:])
|
||||||
|
v = uint64(bigen.Uint16(d.b[6:]))
|
||||||
|
case 2:
|
||||||
|
d.b[4] = 0
|
||||||
|
d.r.readb(d.b[5:])
|
||||||
|
v = uint64(bigen.Uint32(d.b[4:]))
|
||||||
|
case 3:
|
||||||
|
d.r.readb(d.b[4:])
|
||||||
|
v = uint64(bigen.Uint32(d.b[4:]))
|
||||||
|
case 4, 5, 6:
|
||||||
|
lim := int(7 - d.vs)
|
||||||
|
d.r.readb(d.b[lim:])
|
||||||
|
for i := 0; i < lim; i++ {
|
||||||
|
d.b[i] = 0
|
||||||
|
}
|
||||||
|
v = uint64(bigen.Uint64(d.b[:]))
|
||||||
|
case 7:
|
||||||
|
d.r.readb(d.b[:])
|
||||||
|
v = uint64(bigen.Uint64(d.b[:]))
|
||||||
|
default:
|
||||||
|
decErr("unsigned integers with greater than 64 bits of precision not supported")
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *bincDecDriver) decIntAny() (ui uint64, i int64, neg bool) {
|
||||||
|
switch d.vd {
|
||||||
|
case bincVdPosInt:
|
||||||
|
ui = d.decUint()
|
||||||
|
i = int64(ui)
|
||||||
|
case bincVdNegInt:
|
||||||
|
ui = d.decUint()
|
||||||
|
i = -(int64(ui))
|
||||||
|
neg = true
|
||||||
|
case bincVdSmallInt:
|
||||||
|
i = int64(d.vs) + 1
|
||||||
|
ui = uint64(d.vs) + 1
|
||||||
|
case bincVdSpecial:
|
||||||
|
switch d.vs {
|
||||||
|
case bincSpZero:
|
||||||
|
//i = 0
|
||||||
|
case bincSpNegOne:
|
||||||
|
neg = true
|
||||||
|
ui = 1
|
||||||
|
i = -1
|
||||||
|
default:
|
||||||
|
decErr("numeric decode fails for special value: d.vs: 0x%x", d.vs)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
decErr("number can only be decoded from uint or int values. d.bd: 0x%x, d.vd: 0x%x", d.bd, d.vd)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *bincDecDriver) decodeInt(bitsize uint8) (i int64) {
|
||||||
|
_, i, _ = d.decIntAny()
|
||||||
|
checkOverflow(0, i, bitsize)
|
||||||
|
d.bdRead = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *bincDecDriver) decodeUint(bitsize uint8) (ui uint64) {
|
||||||
|
ui, i, neg := d.decIntAny()
|
||||||
|
if neg {
|
||||||
|
decErr("Assigning negative signed value: %v, to unsigned type", i)
|
||||||
|
}
|
||||||
|
checkOverflow(ui, 0, bitsize)
|
||||||
|
d.bdRead = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *bincDecDriver) decodeFloat(chkOverflow32 bool) (f float64) {
|
||||||
|
switch d.vd {
|
||||||
|
case bincVdSpecial:
|
||||||
|
d.bdRead = false
|
||||||
|
switch d.vs {
|
||||||
|
case bincSpNan:
|
||||||
|
return math.NaN()
|
||||||
|
case bincSpPosInf:
|
||||||
|
return math.Inf(1)
|
||||||
|
case bincSpZeroFloat, bincSpZero:
|
||||||
|
return
|
||||||
|
case bincSpNegInf:
|
||||||
|
return math.Inf(-1)
|
||||||
|
default:
|
||||||
|
decErr("Invalid d.vs decoding float where d.vd=bincVdSpecial: %v", d.vs)
|
||||||
|
}
|
||||||
|
case bincVdFloat:
|
||||||
|
f = d.decFloat()
|
||||||
|
default:
|
||||||
|
_, i, _ := d.decIntAny()
|
||||||
|
f = float64(i)
|
||||||
|
}
|
||||||
|
checkOverflowFloat32(f, chkOverflow32)
|
||||||
|
d.bdRead = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// bool can be decoded from bool only (single byte).
|
||||||
|
func (d *bincDecDriver) decodeBool() (b bool) {
|
||||||
|
switch d.bd {
|
||||||
|
case (bincVdSpecial | bincSpFalse):
|
||||||
|
// b = false
|
||||||
|
case (bincVdSpecial | bincSpTrue):
|
||||||
|
b = true
|
||||||
|
default:
|
||||||
|
decErr("Invalid single-byte value for bool: %s: %x", msgBadDesc, d.bd)
|
||||||
|
}
|
||||||
|
d.bdRead = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *bincDecDriver) readMapLen() (length int) {
|
||||||
|
if d.vd != bincVdMap {
|
||||||
|
decErr("Invalid d.vd for map. Expecting 0x%x. Got: 0x%x", bincVdMap, d.vd)
|
||||||
|
}
|
||||||
|
length = d.decLen()
|
||||||
|
d.bdRead = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *bincDecDriver) readArrayLen() (length int) {
|
||||||
|
if d.vd != bincVdArray {
|
||||||
|
decErr("Invalid d.vd for array. Expecting 0x%x. Got: 0x%x", bincVdArray, d.vd)
|
||||||
|
}
|
||||||
|
length = d.decLen()
|
||||||
|
d.bdRead = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *bincDecDriver) decLen() int {
|
||||||
|
if d.vs <= 3 {
|
||||||
|
return int(d.decUint())
|
||||||
|
}
|
||||||
|
return int(d.vs - 4)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *bincDecDriver) decodeString() (s string) {
|
||||||
|
switch d.vd {
|
||||||
|
case bincVdString, bincVdByteArray:
|
||||||
|
if length := d.decLen(); length > 0 {
|
||||||
|
s = string(d.r.readn(length))
|
||||||
|
}
|
||||||
|
case bincVdSymbol:
|
||||||
|
//from vs: extract numSymbolBytes, containsStringVal, strLenPrecision,
|
||||||
|
//extract symbol
|
||||||
|
//if containsStringVal, read it and put in map
|
||||||
|
//else look in map for string value
|
||||||
|
var symbol uint32
|
||||||
|
vs := d.vs
|
||||||
|
//fmt.Printf(">>>> d.vs: 0b%b, & 0x8: %v, & 0x4: %v\n", d.vs, vs & 0x8, vs & 0x4)
|
||||||
|
if vs&0x8 == 0 {
|
||||||
|
symbol = uint32(d.r.readn1())
|
||||||
|
} else {
|
||||||
|
symbol = uint32(d.r.readUint16())
|
||||||
|
}
|
||||||
|
if d.m == nil {
|
||||||
|
d.m = make(map[uint32]string, 16)
|
||||||
|
}
|
||||||
|
|
||||||
|
if vs&0x4 == 0 {
|
||||||
|
s = d.m[symbol]
|
||||||
|
} else {
|
||||||
|
var slen int
|
||||||
|
switch vs & 0x3 {
|
||||||
|
case 0:
|
||||||
|
slen = int(d.r.readn1())
|
||||||
|
case 1:
|
||||||
|
slen = int(d.r.readUint16())
|
||||||
|
case 2:
|
||||||
|
slen = int(d.r.readUint32())
|
||||||
|
case 3:
|
||||||
|
slen = int(d.r.readUint64())
|
||||||
|
}
|
||||||
|
s = string(d.r.readn(slen))
|
||||||
|
d.m[symbol] = s
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
decErr("Invalid d.vd for string. Expecting string:0x%x, bytearray:0x%x or symbol: 0x%x. Got: 0x%x",
|
||||||
|
bincVdString, bincVdByteArray, bincVdSymbol, d.vd)
|
||||||
|
}
|
||||||
|
d.bdRead = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *bincDecDriver) decodeBytes(bs []byte) (bsOut []byte, changed bool) {
|
||||||
|
var clen int
|
||||||
|
switch d.vd {
|
||||||
|
case bincVdString, bincVdByteArray:
|
||||||
|
clen = d.decLen()
|
||||||
|
default:
|
||||||
|
decErr("Invalid d.vd for bytes. Expecting string:0x%x or bytearray:0x%x. Got: 0x%x",
|
||||||
|
bincVdString, bincVdByteArray, d.vd)
|
||||||
|
}
|
||||||
|
if clen > 0 {
|
||||||
|
// if no contents in stream, don't update the passed byteslice
|
||||||
|
if len(bs) != clen {
|
||||||
|
if len(bs) > clen {
|
||||||
|
bs = bs[:clen]
|
||||||
|
} else {
|
||||||
|
bs = make([]byte, clen)
|
||||||
|
}
|
||||||
|
bsOut = bs
|
||||||
|
changed = true
|
||||||
|
}
|
||||||
|
d.r.readb(bs)
|
||||||
|
}
|
||||||
|
d.bdRead = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *bincDecDriver) decodeExt(verifyTag bool, tag byte) (xtag byte, xbs []byte) {
|
||||||
|
switch d.vd {
|
||||||
|
case bincVdCustomExt:
|
||||||
|
l := d.decLen()
|
||||||
|
xtag = d.r.readn1()
|
||||||
|
if verifyTag && xtag != tag {
|
||||||
|
decErr("Wrong extension tag. Got %b. Expecting: %v", xtag, tag)
|
||||||
|
}
|
||||||
|
xbs = d.r.readn(l)
|
||||||
|
case bincVdByteArray:
|
||||||
|
xbs, _ = d.decodeBytes(nil)
|
||||||
|
default:
|
||||||
|
decErr("Invalid d.vd for extensions (Expecting extensions or byte array). Got: 0x%x", d.vd)
|
||||||
|
}
|
||||||
|
d.bdRead = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *bincDecDriver) decodeNaked() (v interface{}, vt valueType, decodeFurther bool) {
|
||||||
|
d.initReadNext()
|
||||||
|
|
||||||
|
switch d.vd {
|
||||||
|
case bincVdSpecial:
|
||||||
|
switch d.vs {
|
||||||
|
case bincSpNil:
|
||||||
|
vt = valueTypeNil
|
||||||
|
case bincSpFalse:
|
||||||
|
vt = valueTypeBool
|
||||||
|
v = false
|
||||||
|
case bincSpTrue:
|
||||||
|
vt = valueTypeBool
|
||||||
|
v = true
|
||||||
|
case bincSpNan:
|
||||||
|
vt = valueTypeFloat
|
||||||
|
v = math.NaN()
|
||||||
|
case bincSpPosInf:
|
||||||
|
vt = valueTypeFloat
|
||||||
|
v = math.Inf(1)
|
||||||
|
case bincSpNegInf:
|
||||||
|
vt = valueTypeFloat
|
||||||
|
v = math.Inf(-1)
|
||||||
|
case bincSpZeroFloat:
|
||||||
|
vt = valueTypeFloat
|
||||||
|
v = float64(0)
|
||||||
|
case bincSpZero:
|
||||||
|
vt = valueTypeUint
|
||||||
|
v = int64(0) // int8(0)
|
||||||
|
case bincSpNegOne:
|
||||||
|
vt = valueTypeInt
|
||||||
|
v = int64(-1) // int8(-1)
|
||||||
|
default:
|
||||||
|
decErr("decodeNaked: Unrecognized special value 0x%x", d.vs)
|
||||||
|
}
|
||||||
|
case bincVdSmallInt:
|
||||||
|
vt = valueTypeUint
|
||||||
|
v = uint64(int8(d.vs)) + 1 // int8(d.vs) + 1
|
||||||
|
case bincVdPosInt:
|
||||||
|
vt = valueTypeUint
|
||||||
|
v = d.decUint()
|
||||||
|
case bincVdNegInt:
|
||||||
|
vt = valueTypeInt
|
||||||
|
v = -(int64(d.decUint()))
|
||||||
|
case bincVdFloat:
|
||||||
|
vt = valueTypeFloat
|
||||||
|
v = d.decFloat()
|
||||||
|
case bincVdSymbol:
|
||||||
|
vt = valueTypeSymbol
|
||||||
|
v = d.decodeString()
|
||||||
|
case bincVdString:
|
||||||
|
vt = valueTypeString
|
||||||
|
v = d.decodeString()
|
||||||
|
case bincVdByteArray:
|
||||||
|
vt = valueTypeBytes
|
||||||
|
v, _ = d.decodeBytes(nil)
|
||||||
|
case bincVdTimestamp:
|
||||||
|
vt = valueTypeTimestamp
|
||||||
|
tt, err := decodeTime(d.r.readn(int(d.vs)))
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
v = tt
|
||||||
|
case bincVdCustomExt:
|
||||||
|
vt = valueTypeExt
|
||||||
|
l := d.decLen()
|
||||||
|
var re RawExt
|
||||||
|
re.Tag = d.r.readn1()
|
||||||
|
re.Data = d.r.readn(l)
|
||||||
|
v = &re
|
||||||
|
vt = valueTypeExt
|
||||||
|
case bincVdArray:
|
||||||
|
vt = valueTypeArray
|
||||||
|
decodeFurther = true
|
||||||
|
case bincVdMap:
|
||||||
|
vt = valueTypeMap
|
||||||
|
decodeFurther = true
|
||||||
|
default:
|
||||||
|
decErr("decodeNaked: Unrecognized d.vd: 0x%x", d.vd)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !decodeFurther {
|
||||||
|
d.bdRead = false
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------
|
||||||
|
|
||||||
|
//BincHandle is a Handle for the Binc Schema-Free Encoding Format
|
||||||
|
//defined at https://github.com/ugorji/binc .
|
||||||
|
//
|
||||||
|
//BincHandle currently supports all Binc features with the following EXCEPTIONS:
|
||||||
|
// - only integers up to 64 bits of precision are supported.
|
||||||
|
// big integers are unsupported.
|
||||||
|
// - Only IEEE 754 binary32 and binary64 floats are supported (ie Go float32 and float64 types).
|
||||||
|
// extended precision and decimal IEEE 754 floats are unsupported.
|
||||||
|
// - Only UTF-8 strings supported.
|
||||||
|
// Unicode_Other Binc types (UTF16, UTF32) are currently unsupported.
|
||||||
|
//Note that these EXCEPTIONS are temporary and full support is possible and may happen soon.
|
||||||
|
type BincHandle struct {
|
||||||
|
BasicHandle
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *BincHandle) newEncDriver(w encWriter) encDriver {
|
||||||
|
return &bincEncDriver{w: w}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *BincHandle) newDecDriver(r decReader) decDriver {
|
||||||
|
return &bincDecDriver{r: r}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_ *BincHandle) writeExt() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *BincHandle) getBasicHandle() *BasicHandle {
|
||||||
|
return &h.BasicHandle
|
||||||
|
}
|
||||||
1048
vendor/github.com/hashicorp/go-msgpack/codec/decode.go
generated
vendored
Normal file
1048
vendor/github.com/hashicorp/go-msgpack/codec/decode.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1001
vendor/github.com/hashicorp/go-msgpack/codec/encode.go
generated
vendored
Normal file
1001
vendor/github.com/hashicorp/go-msgpack/codec/encode.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
589
vendor/github.com/hashicorp/go-msgpack/codec/helper.go
generated
vendored
Normal file
589
vendor/github.com/hashicorp/go-msgpack/codec/helper.go
generated
vendored
Normal file
@@ -0,0 +1,589 @@
|
|||||||
|
// Copyright (c) 2012, 2013 Ugorji Nwoke. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license found in the LICENSE file.
|
||||||
|
|
||||||
|
package codec
|
||||||
|
|
||||||
|
// Contains code shared by both encode and decode.
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/binary"
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
"reflect"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
"unicode"
|
||||||
|
"unicode/utf8"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
structTagName = "codec"
|
||||||
|
|
||||||
|
// Support
|
||||||
|
// encoding.BinaryMarshaler: MarshalBinary() (data []byte, err error)
|
||||||
|
// encoding.BinaryUnmarshaler: UnmarshalBinary(data []byte) error
|
||||||
|
// This constant flag will enable or disable it.
|
||||||
|
supportBinaryMarshal = true
|
||||||
|
|
||||||
|
// Each Encoder or Decoder uses a cache of functions based on conditionals,
|
||||||
|
// so that the conditionals are not run every time.
|
||||||
|
//
|
||||||
|
// Either a map or a slice is used to keep track of the functions.
|
||||||
|
// The map is more natural, but has a higher cost than a slice/array.
|
||||||
|
// This flag (useMapForCodecCache) controls which is used.
|
||||||
|
useMapForCodecCache = false
|
||||||
|
|
||||||
|
// For some common container types, we can short-circuit an elaborate
|
||||||
|
// reflection dance and call encode/decode directly.
|
||||||
|
// The currently supported types are:
|
||||||
|
// - slices of strings, or id's (int64,uint64) or interfaces.
|
||||||
|
// - maps of str->str, str->intf, id(int64,uint64)->intf, intf->intf
|
||||||
|
shortCircuitReflectToFastPath = true
|
||||||
|
|
||||||
|
// for debugging, set this to false, to catch panic traces.
|
||||||
|
// Note that this will always cause rpc tests to fail, since they need io.EOF sent via panic.
|
||||||
|
recoverPanicToErr = true
|
||||||
|
)
|
||||||
|
|
||||||
|
type charEncoding uint8
|
||||||
|
|
||||||
|
const (
|
||||||
|
c_RAW charEncoding = iota
|
||||||
|
c_UTF8
|
||||||
|
c_UTF16LE
|
||||||
|
c_UTF16BE
|
||||||
|
c_UTF32LE
|
||||||
|
c_UTF32BE
|
||||||
|
)
|
||||||
|
|
||||||
|
// valueType is the stream type
|
||||||
|
type valueType uint8
|
||||||
|
|
||||||
|
const (
|
||||||
|
valueTypeUnset valueType = iota
|
||||||
|
valueTypeNil
|
||||||
|
valueTypeInt
|
||||||
|
valueTypeUint
|
||||||
|
valueTypeFloat
|
||||||
|
valueTypeBool
|
||||||
|
valueTypeString
|
||||||
|
valueTypeSymbol
|
||||||
|
valueTypeBytes
|
||||||
|
valueTypeMap
|
||||||
|
valueTypeArray
|
||||||
|
valueTypeTimestamp
|
||||||
|
valueTypeExt
|
||||||
|
|
||||||
|
valueTypeInvalid = 0xff
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
bigen = binary.BigEndian
|
||||||
|
structInfoFieldName = "_struct"
|
||||||
|
|
||||||
|
cachedTypeInfo = make(map[uintptr]*typeInfo, 4)
|
||||||
|
cachedTypeInfoMutex sync.RWMutex
|
||||||
|
|
||||||
|
intfSliceTyp = reflect.TypeOf([]interface{}(nil))
|
||||||
|
intfTyp = intfSliceTyp.Elem()
|
||||||
|
|
||||||
|
strSliceTyp = reflect.TypeOf([]string(nil))
|
||||||
|
boolSliceTyp = reflect.TypeOf([]bool(nil))
|
||||||
|
uintSliceTyp = reflect.TypeOf([]uint(nil))
|
||||||
|
uint8SliceTyp = reflect.TypeOf([]uint8(nil))
|
||||||
|
uint16SliceTyp = reflect.TypeOf([]uint16(nil))
|
||||||
|
uint32SliceTyp = reflect.TypeOf([]uint32(nil))
|
||||||
|
uint64SliceTyp = reflect.TypeOf([]uint64(nil))
|
||||||
|
intSliceTyp = reflect.TypeOf([]int(nil))
|
||||||
|
int8SliceTyp = reflect.TypeOf([]int8(nil))
|
||||||
|
int16SliceTyp = reflect.TypeOf([]int16(nil))
|
||||||
|
int32SliceTyp = reflect.TypeOf([]int32(nil))
|
||||||
|
int64SliceTyp = reflect.TypeOf([]int64(nil))
|
||||||
|
float32SliceTyp = reflect.TypeOf([]float32(nil))
|
||||||
|
float64SliceTyp = reflect.TypeOf([]float64(nil))
|
||||||
|
|
||||||
|
mapIntfIntfTyp = reflect.TypeOf(map[interface{}]interface{}(nil))
|
||||||
|
mapStrIntfTyp = reflect.TypeOf(map[string]interface{}(nil))
|
||||||
|
mapStrStrTyp = reflect.TypeOf(map[string]string(nil))
|
||||||
|
|
||||||
|
mapIntIntfTyp = reflect.TypeOf(map[int]interface{}(nil))
|
||||||
|
mapInt64IntfTyp = reflect.TypeOf(map[int64]interface{}(nil))
|
||||||
|
mapUintIntfTyp = reflect.TypeOf(map[uint]interface{}(nil))
|
||||||
|
mapUint64IntfTyp = reflect.TypeOf(map[uint64]interface{}(nil))
|
||||||
|
|
||||||
|
stringTyp = reflect.TypeOf("")
|
||||||
|
timeTyp = reflect.TypeOf(time.Time{})
|
||||||
|
rawExtTyp = reflect.TypeOf(RawExt{})
|
||||||
|
|
||||||
|
mapBySliceTyp = reflect.TypeOf((*MapBySlice)(nil)).Elem()
|
||||||
|
binaryMarshalerTyp = reflect.TypeOf((*binaryMarshaler)(nil)).Elem()
|
||||||
|
binaryUnmarshalerTyp = reflect.TypeOf((*binaryUnmarshaler)(nil)).Elem()
|
||||||
|
|
||||||
|
rawExtTypId = reflect.ValueOf(rawExtTyp).Pointer()
|
||||||
|
intfTypId = reflect.ValueOf(intfTyp).Pointer()
|
||||||
|
timeTypId = reflect.ValueOf(timeTyp).Pointer()
|
||||||
|
|
||||||
|
intfSliceTypId = reflect.ValueOf(intfSliceTyp).Pointer()
|
||||||
|
strSliceTypId = reflect.ValueOf(strSliceTyp).Pointer()
|
||||||
|
|
||||||
|
boolSliceTypId = reflect.ValueOf(boolSliceTyp).Pointer()
|
||||||
|
uintSliceTypId = reflect.ValueOf(uintSliceTyp).Pointer()
|
||||||
|
uint8SliceTypId = reflect.ValueOf(uint8SliceTyp).Pointer()
|
||||||
|
uint16SliceTypId = reflect.ValueOf(uint16SliceTyp).Pointer()
|
||||||
|
uint32SliceTypId = reflect.ValueOf(uint32SliceTyp).Pointer()
|
||||||
|
uint64SliceTypId = reflect.ValueOf(uint64SliceTyp).Pointer()
|
||||||
|
intSliceTypId = reflect.ValueOf(intSliceTyp).Pointer()
|
||||||
|
int8SliceTypId = reflect.ValueOf(int8SliceTyp).Pointer()
|
||||||
|
int16SliceTypId = reflect.ValueOf(int16SliceTyp).Pointer()
|
||||||
|
int32SliceTypId = reflect.ValueOf(int32SliceTyp).Pointer()
|
||||||
|
int64SliceTypId = reflect.ValueOf(int64SliceTyp).Pointer()
|
||||||
|
float32SliceTypId = reflect.ValueOf(float32SliceTyp).Pointer()
|
||||||
|
float64SliceTypId = reflect.ValueOf(float64SliceTyp).Pointer()
|
||||||
|
|
||||||
|
mapStrStrTypId = reflect.ValueOf(mapStrStrTyp).Pointer()
|
||||||
|
mapIntfIntfTypId = reflect.ValueOf(mapIntfIntfTyp).Pointer()
|
||||||
|
mapStrIntfTypId = reflect.ValueOf(mapStrIntfTyp).Pointer()
|
||||||
|
mapIntIntfTypId = reflect.ValueOf(mapIntIntfTyp).Pointer()
|
||||||
|
mapInt64IntfTypId = reflect.ValueOf(mapInt64IntfTyp).Pointer()
|
||||||
|
mapUintIntfTypId = reflect.ValueOf(mapUintIntfTyp).Pointer()
|
||||||
|
mapUint64IntfTypId = reflect.ValueOf(mapUint64IntfTyp).Pointer()
|
||||||
|
// Id = reflect.ValueOf().Pointer()
|
||||||
|
// mapBySliceTypId = reflect.ValueOf(mapBySliceTyp).Pointer()
|
||||||
|
|
||||||
|
binaryMarshalerTypId = reflect.ValueOf(binaryMarshalerTyp).Pointer()
|
||||||
|
binaryUnmarshalerTypId = reflect.ValueOf(binaryUnmarshalerTyp).Pointer()
|
||||||
|
|
||||||
|
intBitsize uint8 = uint8(reflect.TypeOf(int(0)).Bits())
|
||||||
|
uintBitsize uint8 = uint8(reflect.TypeOf(uint(0)).Bits())
|
||||||
|
|
||||||
|
bsAll0x00 = []byte{0, 0, 0, 0, 0, 0, 0, 0}
|
||||||
|
bsAll0xff = []byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
|
||||||
|
)
|
||||||
|
|
||||||
|
type binaryUnmarshaler interface {
|
||||||
|
UnmarshalBinary(data []byte) error
|
||||||
|
}
|
||||||
|
|
||||||
|
type binaryMarshaler interface {
|
||||||
|
MarshalBinary() (data []byte, err error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MapBySlice represents a slice which should be encoded as a map in the stream.
|
||||||
|
// The slice contains a sequence of key-value pairs.
|
||||||
|
type MapBySlice interface {
|
||||||
|
MapBySlice()
|
||||||
|
}
|
||||||
|
|
||||||
|
// WARNING: DO NOT USE DIRECTLY. EXPORTED FOR GODOC BENEFIT. WILL BE REMOVED.
|
||||||
|
//
|
||||||
|
// BasicHandle encapsulates the common options and extension functions.
|
||||||
|
type BasicHandle struct {
|
||||||
|
extHandle
|
||||||
|
EncodeOptions
|
||||||
|
DecodeOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle is the interface for a specific encoding format.
|
||||||
|
//
|
||||||
|
// Typically, a Handle is pre-configured before first time use,
|
||||||
|
// and not modified while in use. Such a pre-configured Handle
|
||||||
|
// is safe for concurrent access.
|
||||||
|
type Handle interface {
|
||||||
|
writeExt() bool
|
||||||
|
getBasicHandle() *BasicHandle
|
||||||
|
newEncDriver(w encWriter) encDriver
|
||||||
|
newDecDriver(r decReader) decDriver
|
||||||
|
}
|
||||||
|
|
||||||
|
// RawExt represents raw unprocessed extension data.
|
||||||
|
type RawExt struct {
|
||||||
|
Tag byte
|
||||||
|
Data []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
type extTypeTagFn struct {
|
||||||
|
rtid uintptr
|
||||||
|
rt reflect.Type
|
||||||
|
tag byte
|
||||||
|
encFn func(reflect.Value) ([]byte, error)
|
||||||
|
decFn func(reflect.Value, []byte) error
|
||||||
|
}
|
||||||
|
|
||||||
|
type extHandle []*extTypeTagFn
|
||||||
|
|
||||||
|
// AddExt registers an encode and decode function for a reflect.Type.
|
||||||
|
// Note that the type must be a named type, and specifically not
|
||||||
|
// a pointer or Interface. An error is returned if that is not honored.
|
||||||
|
//
|
||||||
|
// To Deregister an ext, call AddExt with 0 tag, nil encfn and nil decfn.
|
||||||
|
func (o *extHandle) AddExt(
|
||||||
|
rt reflect.Type,
|
||||||
|
tag byte,
|
||||||
|
encfn func(reflect.Value) ([]byte, error),
|
||||||
|
decfn func(reflect.Value, []byte) error,
|
||||||
|
) (err error) {
|
||||||
|
// o is a pointer, because we may need to initialize it
|
||||||
|
if rt.PkgPath() == "" || rt.Kind() == reflect.Interface {
|
||||||
|
err = fmt.Errorf("codec.Handle.AddExt: Takes named type, especially not a pointer or interface: %T",
|
||||||
|
reflect.Zero(rt).Interface())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// o cannot be nil, since it is always embedded in a Handle.
|
||||||
|
// if nil, let it panic.
|
||||||
|
// if o == nil {
|
||||||
|
// err = errors.New("codec.Handle.AddExt: extHandle cannot be a nil pointer.")
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
|
||||||
|
rtid := reflect.ValueOf(rt).Pointer()
|
||||||
|
for _, v := range *o {
|
||||||
|
if v.rtid == rtid {
|
||||||
|
v.tag, v.encFn, v.decFn = tag, encfn, decfn
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*o = append(*o, &extTypeTagFn{rtid, rt, tag, encfn, decfn})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o extHandle) getExt(rtid uintptr) *extTypeTagFn {
|
||||||
|
for _, v := range o {
|
||||||
|
if v.rtid == rtid {
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o extHandle) getExtForTag(tag byte) *extTypeTagFn {
|
||||||
|
for _, v := range o {
|
||||||
|
if v.tag == tag {
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o extHandle) getDecodeExtForTag(tag byte) (
|
||||||
|
rv reflect.Value, fn func(reflect.Value, []byte) error) {
|
||||||
|
if x := o.getExtForTag(tag); x != nil {
|
||||||
|
// ext is only registered for base
|
||||||
|
rv = reflect.New(x.rt).Elem()
|
||||||
|
fn = x.decFn
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o extHandle) getDecodeExt(rtid uintptr) (tag byte, fn func(reflect.Value, []byte) error) {
|
||||||
|
if x := o.getExt(rtid); x != nil {
|
||||||
|
tag = x.tag
|
||||||
|
fn = x.decFn
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o extHandle) getEncodeExt(rtid uintptr) (tag byte, fn func(reflect.Value) ([]byte, error)) {
|
||||||
|
if x := o.getExt(rtid); x != nil {
|
||||||
|
tag = x.tag
|
||||||
|
fn = x.encFn
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
type structFieldInfo struct {
|
||||||
|
encName string // encode name
|
||||||
|
|
||||||
|
// only one of 'i' or 'is' can be set. If 'i' is -1, then 'is' has been set.
|
||||||
|
|
||||||
|
is []int // (recursive/embedded) field index in struct
|
||||||
|
i int16 // field index in struct
|
||||||
|
omitEmpty bool
|
||||||
|
toArray bool // if field is _struct, is the toArray set?
|
||||||
|
|
||||||
|
// tag string // tag
|
||||||
|
// name string // field name
|
||||||
|
// encNameBs []byte // encoded name as byte stream
|
||||||
|
// ikind int // kind of the field as an int i.e. int(reflect.Kind)
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseStructFieldInfo(fname string, stag string) *structFieldInfo {
|
||||||
|
if fname == "" {
|
||||||
|
panic("parseStructFieldInfo: No Field Name")
|
||||||
|
}
|
||||||
|
si := structFieldInfo{
|
||||||
|
// name: fname,
|
||||||
|
encName: fname,
|
||||||
|
// tag: stag,
|
||||||
|
}
|
||||||
|
|
||||||
|
if stag != "" {
|
||||||
|
for i, s := range strings.Split(stag, ",") {
|
||||||
|
if i == 0 {
|
||||||
|
if s != "" {
|
||||||
|
si.encName = s
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
switch s {
|
||||||
|
case "omitempty":
|
||||||
|
si.omitEmpty = true
|
||||||
|
case "toarray":
|
||||||
|
si.toArray = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// si.encNameBs = []byte(si.encName)
|
||||||
|
return &si
|
||||||
|
}
|
||||||
|
|
||||||
|
type sfiSortedByEncName []*structFieldInfo
|
||||||
|
|
||||||
|
func (p sfiSortedByEncName) Len() int {
|
||||||
|
return len(p)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p sfiSortedByEncName) Less(i, j int) bool {
|
||||||
|
return p[i].encName < p[j].encName
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p sfiSortedByEncName) Swap(i, j int) {
|
||||||
|
p[i], p[j] = p[j], p[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
// typeInfo keeps information about each type referenced in the encode/decode sequence.
|
||||||
|
//
|
||||||
|
// During an encode/decode sequence, we work as below:
|
||||||
|
// - If base is a built in type, en/decode base value
|
||||||
|
// - If base is registered as an extension, en/decode base value
|
||||||
|
// - If type is binary(M/Unm)arshaler, call Binary(M/Unm)arshal method
|
||||||
|
// - Else decode appropriately based on the reflect.Kind
|
||||||
|
type typeInfo struct {
|
||||||
|
sfi []*structFieldInfo // sorted. Used when enc/dec struct to map.
|
||||||
|
sfip []*structFieldInfo // unsorted. Used when enc/dec struct to array.
|
||||||
|
|
||||||
|
rt reflect.Type
|
||||||
|
rtid uintptr
|
||||||
|
|
||||||
|
// baseId gives pointer to the base reflect.Type, after deferencing
|
||||||
|
// the pointers. E.g. base type of ***time.Time is time.Time.
|
||||||
|
base reflect.Type
|
||||||
|
baseId uintptr
|
||||||
|
baseIndir int8 // number of indirections to get to base
|
||||||
|
|
||||||
|
mbs bool // base type (T or *T) is a MapBySlice
|
||||||
|
|
||||||
|
m bool // base type (T or *T) is a binaryMarshaler
|
||||||
|
unm bool // base type (T or *T) is a binaryUnmarshaler
|
||||||
|
mIndir int8 // number of indirections to get to binaryMarshaler type
|
||||||
|
unmIndir int8 // number of indirections to get to binaryUnmarshaler type
|
||||||
|
toArray bool // whether this (struct) type should be encoded as an array
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ti *typeInfo) indexForEncName(name string) int {
|
||||||
|
//tisfi := ti.sfi
|
||||||
|
const binarySearchThreshold = 16
|
||||||
|
if sfilen := len(ti.sfi); sfilen < binarySearchThreshold {
|
||||||
|
// linear search. faster than binary search in my testing up to 16-field structs.
|
||||||
|
for i, si := range ti.sfi {
|
||||||
|
if si.encName == name {
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// binary search. adapted from sort/search.go.
|
||||||
|
h, i, j := 0, 0, sfilen
|
||||||
|
for i < j {
|
||||||
|
h = i + (j-i)/2
|
||||||
|
if ti.sfi[h].encName < name {
|
||||||
|
i = h + 1
|
||||||
|
} else {
|
||||||
|
j = h
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if i < sfilen && ti.sfi[i].encName == name {
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
func getTypeInfo(rtid uintptr, rt reflect.Type) (pti *typeInfo) {
|
||||||
|
var ok bool
|
||||||
|
cachedTypeInfoMutex.RLock()
|
||||||
|
pti, ok = cachedTypeInfo[rtid]
|
||||||
|
cachedTypeInfoMutex.RUnlock()
|
||||||
|
if ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
cachedTypeInfoMutex.Lock()
|
||||||
|
defer cachedTypeInfoMutex.Unlock()
|
||||||
|
if pti, ok = cachedTypeInfo[rtid]; ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ti := typeInfo{rt: rt, rtid: rtid}
|
||||||
|
pti = &ti
|
||||||
|
|
||||||
|
var indir int8
|
||||||
|
if ok, indir = implementsIntf(rt, binaryMarshalerTyp); ok {
|
||||||
|
ti.m, ti.mIndir = true, indir
|
||||||
|
}
|
||||||
|
if ok, indir = implementsIntf(rt, binaryUnmarshalerTyp); ok {
|
||||||
|
ti.unm, ti.unmIndir = true, indir
|
||||||
|
}
|
||||||
|
if ok, _ = implementsIntf(rt, mapBySliceTyp); ok {
|
||||||
|
ti.mbs = true
|
||||||
|
}
|
||||||
|
|
||||||
|
pt := rt
|
||||||
|
var ptIndir int8
|
||||||
|
// for ; pt.Kind() == reflect.Ptr; pt, ptIndir = pt.Elem(), ptIndir+1 { }
|
||||||
|
for pt.Kind() == reflect.Ptr {
|
||||||
|
pt = pt.Elem()
|
||||||
|
ptIndir++
|
||||||
|
}
|
||||||
|
if ptIndir == 0 {
|
||||||
|
ti.base = rt
|
||||||
|
ti.baseId = rtid
|
||||||
|
} else {
|
||||||
|
ti.base = pt
|
||||||
|
ti.baseId = reflect.ValueOf(pt).Pointer()
|
||||||
|
ti.baseIndir = ptIndir
|
||||||
|
}
|
||||||
|
|
||||||
|
if rt.Kind() == reflect.Struct {
|
||||||
|
var siInfo *structFieldInfo
|
||||||
|
if f, ok := rt.FieldByName(structInfoFieldName); ok {
|
||||||
|
siInfo = parseStructFieldInfo(structInfoFieldName, f.Tag.Get(structTagName))
|
||||||
|
ti.toArray = siInfo.toArray
|
||||||
|
}
|
||||||
|
sfip := make([]*structFieldInfo, 0, rt.NumField())
|
||||||
|
rgetTypeInfo(rt, nil, make(map[string]bool), &sfip, siInfo)
|
||||||
|
|
||||||
|
// // try to put all si close together
|
||||||
|
// const tryToPutAllStructFieldInfoTogether = true
|
||||||
|
// if tryToPutAllStructFieldInfoTogether {
|
||||||
|
// sfip2 := make([]structFieldInfo, len(sfip))
|
||||||
|
// for i, si := range sfip {
|
||||||
|
// sfip2[i] = *si
|
||||||
|
// }
|
||||||
|
// for i := range sfip {
|
||||||
|
// sfip[i] = &sfip2[i]
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
ti.sfip = make([]*structFieldInfo, len(sfip))
|
||||||
|
ti.sfi = make([]*structFieldInfo, len(sfip))
|
||||||
|
copy(ti.sfip, sfip)
|
||||||
|
sort.Sort(sfiSortedByEncName(sfip))
|
||||||
|
copy(ti.sfi, sfip)
|
||||||
|
}
|
||||||
|
// sfi = sfip
|
||||||
|
cachedTypeInfo[rtid] = pti
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func rgetTypeInfo(rt reflect.Type, indexstack []int, fnameToHastag map[string]bool,
|
||||||
|
sfi *[]*structFieldInfo, siInfo *structFieldInfo,
|
||||||
|
) {
|
||||||
|
// for rt.Kind() == reflect.Ptr {
|
||||||
|
// // indexstack = append(indexstack, 0)
|
||||||
|
// rt = rt.Elem()
|
||||||
|
// }
|
||||||
|
for j := 0; j < rt.NumField(); j++ {
|
||||||
|
f := rt.Field(j)
|
||||||
|
stag := f.Tag.Get(structTagName)
|
||||||
|
if stag == "-" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if r1, _ := utf8.DecodeRuneInString(f.Name); r1 == utf8.RuneError || !unicode.IsUpper(r1) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// if anonymous and there is no struct tag and its a struct (or pointer to struct), inline it.
|
||||||
|
if f.Anonymous && stag == "" {
|
||||||
|
ft := f.Type
|
||||||
|
for ft.Kind() == reflect.Ptr {
|
||||||
|
ft = ft.Elem()
|
||||||
|
}
|
||||||
|
if ft.Kind() == reflect.Struct {
|
||||||
|
indexstack2 := append(append(make([]int, 0, len(indexstack)+4), indexstack...), j)
|
||||||
|
rgetTypeInfo(ft, indexstack2, fnameToHastag, sfi, siInfo)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// do not let fields with same name in embedded structs override field at higher level.
|
||||||
|
// this must be done after anonymous check, to allow anonymous field
|
||||||
|
// still include their child fields
|
||||||
|
if _, ok := fnameToHastag[f.Name]; ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
si := parseStructFieldInfo(f.Name, stag)
|
||||||
|
// si.ikind = int(f.Type.Kind())
|
||||||
|
if len(indexstack) == 0 {
|
||||||
|
si.i = int16(j)
|
||||||
|
} else {
|
||||||
|
si.i = -1
|
||||||
|
si.is = append(append(make([]int, 0, len(indexstack)+4), indexstack...), j)
|
||||||
|
}
|
||||||
|
|
||||||
|
if siInfo != nil {
|
||||||
|
if siInfo.omitEmpty {
|
||||||
|
si.omitEmpty = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*sfi = append(*sfi, si)
|
||||||
|
fnameToHastag[f.Name] = stag != ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func panicToErr(err *error) {
|
||||||
|
if recoverPanicToErr {
|
||||||
|
if x := recover(); x != nil {
|
||||||
|
//debug.PrintStack()
|
||||||
|
panicValToErr(x, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func doPanic(tag string, format string, params ...interface{}) {
|
||||||
|
params2 := make([]interface{}, len(params)+1)
|
||||||
|
params2[0] = tag
|
||||||
|
copy(params2[1:], params)
|
||||||
|
panic(fmt.Errorf("%s: "+format, params2...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkOverflowFloat32(f float64, doCheck bool) {
|
||||||
|
if !doCheck {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// check overflow (logic adapted from std pkg reflect/value.go OverflowFloat()
|
||||||
|
f2 := f
|
||||||
|
if f2 < 0 {
|
||||||
|
f2 = -f
|
||||||
|
}
|
||||||
|
if math.MaxFloat32 < f2 && f2 <= math.MaxFloat64 {
|
||||||
|
decErr("Overflow float32 value: %v", f2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkOverflow(ui uint64, i int64, bitsize uint8) {
|
||||||
|
// check overflow (logic adapted from std pkg reflect/value.go OverflowUint()
|
||||||
|
if bitsize == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if i != 0 {
|
||||||
|
if trunc := (i << (64 - bitsize)) >> (64 - bitsize); i != trunc {
|
||||||
|
decErr("Overflow int value: %v", i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ui != 0 {
|
||||||
|
if trunc := (ui << (64 - bitsize)) >> (64 - bitsize); ui != trunc {
|
||||||
|
decErr("Overflow uint value: %v", ui)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
127
vendor/github.com/hashicorp/go-msgpack/codec/helper_internal.go
generated
vendored
Normal file
127
vendor/github.com/hashicorp/go-msgpack/codec/helper_internal.go
generated
vendored
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
// Copyright (c) 2012, 2013 Ugorji Nwoke. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license found in the LICENSE file.
|
||||||
|
|
||||||
|
package codec
|
||||||
|
|
||||||
|
// All non-std package dependencies live in this file,
|
||||||
|
// so porting to different environment is easy (just update functions).
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
"reflect"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
raisePanicAfterRecover = false
|
||||||
|
debugging = true
|
||||||
|
)
|
||||||
|
|
||||||
|
func panicValToErr(panicVal interface{}, err *error) {
|
||||||
|
switch xerr := panicVal.(type) {
|
||||||
|
case error:
|
||||||
|
*err = xerr
|
||||||
|
case string:
|
||||||
|
*err = errors.New(xerr)
|
||||||
|
default:
|
||||||
|
*err = fmt.Errorf("%v", panicVal)
|
||||||
|
}
|
||||||
|
if raisePanicAfterRecover {
|
||||||
|
panic(panicVal)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func isEmptyValueDeref(v reflect.Value, deref bool) bool {
|
||||||
|
switch v.Kind() {
|
||||||
|
case reflect.Array, reflect.Map, reflect.Slice, reflect.String:
|
||||||
|
return v.Len() == 0
|
||||||
|
case reflect.Bool:
|
||||||
|
return !v.Bool()
|
||||||
|
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||||
|
return v.Int() == 0
|
||||||
|
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
||||||
|
return v.Uint() == 0
|
||||||
|
case reflect.Float32, reflect.Float64:
|
||||||
|
return v.Float() == 0
|
||||||
|
case reflect.Interface, reflect.Ptr:
|
||||||
|
if deref {
|
||||||
|
if v.IsNil() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return isEmptyValueDeref(v.Elem(), deref)
|
||||||
|
} else {
|
||||||
|
return v.IsNil()
|
||||||
|
}
|
||||||
|
case reflect.Struct:
|
||||||
|
// return true if all fields are empty. else return false.
|
||||||
|
|
||||||
|
// we cannot use equality check, because some fields may be maps/slices/etc
|
||||||
|
// and consequently the structs are not comparable.
|
||||||
|
// return v.Interface() == reflect.Zero(v.Type()).Interface()
|
||||||
|
for i, n := 0, v.NumField(); i < n; i++ {
|
||||||
|
if !isEmptyValueDeref(v.Field(i), deref) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func isEmptyValue(v reflect.Value) bool {
|
||||||
|
return isEmptyValueDeref(v, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func debugf(format string, args ...interface{}) {
|
||||||
|
if debugging {
|
||||||
|
if len(format) == 0 || format[len(format)-1] != '\n' {
|
||||||
|
format = format + "\n"
|
||||||
|
}
|
||||||
|
fmt.Printf(format, args...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func pruneSignExt(v []byte, pos bool) (n int) {
|
||||||
|
if len(v) < 2 {
|
||||||
|
} else if pos && v[0] == 0 {
|
||||||
|
for ; v[n] == 0 && n+1 < len(v) && (v[n+1]&(1<<7) == 0); n++ {
|
||||||
|
}
|
||||||
|
} else if !pos && v[0] == 0xff {
|
||||||
|
for ; v[n] == 0xff && n+1 < len(v) && (v[n+1]&(1<<7) != 0); n++ {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func implementsIntf(typ, iTyp reflect.Type) (success bool, indir int8) {
|
||||||
|
if typ == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
rt := typ
|
||||||
|
// The type might be a pointer and we need to keep
|
||||||
|
// dereferencing to the base type until we find an implementation.
|
||||||
|
for {
|
||||||
|
if rt.Implements(iTyp) {
|
||||||
|
return true, indir
|
||||||
|
}
|
||||||
|
if p := rt; p.Kind() == reflect.Ptr {
|
||||||
|
indir++
|
||||||
|
if indir >= math.MaxInt8 { // insane number of indirections
|
||||||
|
return false, 0
|
||||||
|
}
|
||||||
|
rt = p.Elem()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
// No luck yet, but if this is a base type (non-pointer), the pointer might satisfy.
|
||||||
|
if typ.Kind() != reflect.Ptr {
|
||||||
|
// Not a pointer, but does the pointer work?
|
||||||
|
if reflect.PtrTo(typ).Implements(iTyp) {
|
||||||
|
return true, -1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false, 0
|
||||||
|
}
|
||||||
816
vendor/github.com/hashicorp/go-msgpack/codec/msgpack.go
generated
vendored
Normal file
816
vendor/github.com/hashicorp/go-msgpack/codec/msgpack.go
generated
vendored
Normal file
@@ -0,0 +1,816 @@
|
|||||||
|
// Copyright (c) 2012, 2013 Ugorji Nwoke. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*
|
||||||
|
MSGPACK
|
||||||
|
|
||||||
|
Msgpack-c implementation powers the c, c++, python, ruby, etc libraries.
|
||||||
|
We need to maintain compatibility with it and how it encodes integer values
|
||||||
|
without caring about the type.
|
||||||
|
|
||||||
|
For compatibility with behaviour of msgpack-c reference implementation:
|
||||||
|
- Go intX (>0) and uintX
|
||||||
|
IS ENCODED AS
|
||||||
|
msgpack +ve fixnum, unsigned
|
||||||
|
- Go intX (<0)
|
||||||
|
IS ENCODED AS
|
||||||
|
msgpack -ve fixnum, signed
|
||||||
|
|
||||||
|
*/
|
||||||
|
package codec
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"math"
|
||||||
|
"net/rpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
mpPosFixNumMin byte = 0x00
|
||||||
|
mpPosFixNumMax = 0x7f
|
||||||
|
mpFixMapMin = 0x80
|
||||||
|
mpFixMapMax = 0x8f
|
||||||
|
mpFixArrayMin = 0x90
|
||||||
|
mpFixArrayMax = 0x9f
|
||||||
|
mpFixStrMin = 0xa0
|
||||||
|
mpFixStrMax = 0xbf
|
||||||
|
mpNil = 0xc0
|
||||||
|
_ = 0xc1
|
||||||
|
mpFalse = 0xc2
|
||||||
|
mpTrue = 0xc3
|
||||||
|
mpFloat = 0xca
|
||||||
|
mpDouble = 0xcb
|
||||||
|
mpUint8 = 0xcc
|
||||||
|
mpUint16 = 0xcd
|
||||||
|
mpUint32 = 0xce
|
||||||
|
mpUint64 = 0xcf
|
||||||
|
mpInt8 = 0xd0
|
||||||
|
mpInt16 = 0xd1
|
||||||
|
mpInt32 = 0xd2
|
||||||
|
mpInt64 = 0xd3
|
||||||
|
|
||||||
|
// extensions below
|
||||||
|
mpBin8 = 0xc4
|
||||||
|
mpBin16 = 0xc5
|
||||||
|
mpBin32 = 0xc6
|
||||||
|
mpExt8 = 0xc7
|
||||||
|
mpExt16 = 0xc8
|
||||||
|
mpExt32 = 0xc9
|
||||||
|
mpFixExt1 = 0xd4
|
||||||
|
mpFixExt2 = 0xd5
|
||||||
|
mpFixExt4 = 0xd6
|
||||||
|
mpFixExt8 = 0xd7
|
||||||
|
mpFixExt16 = 0xd8
|
||||||
|
|
||||||
|
mpStr8 = 0xd9 // new
|
||||||
|
mpStr16 = 0xda
|
||||||
|
mpStr32 = 0xdb
|
||||||
|
|
||||||
|
mpArray16 = 0xdc
|
||||||
|
mpArray32 = 0xdd
|
||||||
|
|
||||||
|
mpMap16 = 0xde
|
||||||
|
mpMap32 = 0xdf
|
||||||
|
|
||||||
|
mpNegFixNumMin = 0xe0
|
||||||
|
mpNegFixNumMax = 0xff
|
||||||
|
)
|
||||||
|
|
||||||
|
// MsgpackSpecRpcMultiArgs is a special type which signifies to the MsgpackSpecRpcCodec
|
||||||
|
// that the backend RPC service takes multiple arguments, which have been arranged
|
||||||
|
// in sequence in the slice.
|
||||||
|
//
|
||||||
|
// The Codec then passes it AS-IS to the rpc service (without wrapping it in an
|
||||||
|
// array of 1 element).
|
||||||
|
type MsgpackSpecRpcMultiArgs []interface{}
|
||||||
|
|
||||||
|
// A MsgpackContainer type specifies the different types of msgpackContainers.
|
||||||
|
type msgpackContainerType struct {
|
||||||
|
fixCutoff int
|
||||||
|
bFixMin, b8, b16, b32 byte
|
||||||
|
hasFixMin, has8, has8Always bool
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
msgpackContainerStr = msgpackContainerType{32, mpFixStrMin, mpStr8, mpStr16, mpStr32, true, true, false}
|
||||||
|
msgpackContainerBin = msgpackContainerType{0, 0, mpBin8, mpBin16, mpBin32, false, true, true}
|
||||||
|
msgpackContainerList = msgpackContainerType{16, mpFixArrayMin, 0, mpArray16, mpArray32, true, false, false}
|
||||||
|
msgpackContainerMap = msgpackContainerType{16, mpFixMapMin, 0, mpMap16, mpMap32, true, false, false}
|
||||||
|
)
|
||||||
|
|
||||||
|
//---------------------------------------------
|
||||||
|
|
||||||
|
type msgpackEncDriver struct {
|
||||||
|
w encWriter
|
||||||
|
h *MsgpackHandle
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *msgpackEncDriver) isBuiltinType(rt uintptr) bool {
|
||||||
|
//no builtin types. All encodings are based on kinds. Types supported as extensions.
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *msgpackEncDriver) encodeBuiltin(rt uintptr, v interface{}) {}
|
||||||
|
|
||||||
|
func (e *msgpackEncDriver) encodeNil() {
|
||||||
|
e.w.writen1(mpNil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *msgpackEncDriver) encodeInt(i int64) {
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case i >= 0:
|
||||||
|
e.encodeUint(uint64(i))
|
||||||
|
case i >= -32:
|
||||||
|
e.w.writen1(byte(i))
|
||||||
|
case i >= math.MinInt8:
|
||||||
|
e.w.writen2(mpInt8, byte(i))
|
||||||
|
case i >= math.MinInt16:
|
||||||
|
e.w.writen1(mpInt16)
|
||||||
|
e.w.writeUint16(uint16(i))
|
||||||
|
case i >= math.MinInt32:
|
||||||
|
e.w.writen1(mpInt32)
|
||||||
|
e.w.writeUint32(uint32(i))
|
||||||
|
default:
|
||||||
|
e.w.writen1(mpInt64)
|
||||||
|
e.w.writeUint64(uint64(i))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *msgpackEncDriver) encodeUint(i uint64) {
|
||||||
|
switch {
|
||||||
|
case i <= math.MaxInt8:
|
||||||
|
e.w.writen1(byte(i))
|
||||||
|
case i <= math.MaxUint8:
|
||||||
|
e.w.writen2(mpUint8, byte(i))
|
||||||
|
case i <= math.MaxUint16:
|
||||||
|
e.w.writen1(mpUint16)
|
||||||
|
e.w.writeUint16(uint16(i))
|
||||||
|
case i <= math.MaxUint32:
|
||||||
|
e.w.writen1(mpUint32)
|
||||||
|
e.w.writeUint32(uint32(i))
|
||||||
|
default:
|
||||||
|
e.w.writen1(mpUint64)
|
||||||
|
e.w.writeUint64(uint64(i))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *msgpackEncDriver) encodeBool(b bool) {
|
||||||
|
if b {
|
||||||
|
e.w.writen1(mpTrue)
|
||||||
|
} else {
|
||||||
|
e.w.writen1(mpFalse)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *msgpackEncDriver) encodeFloat32(f float32) {
|
||||||
|
e.w.writen1(mpFloat)
|
||||||
|
e.w.writeUint32(math.Float32bits(f))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *msgpackEncDriver) encodeFloat64(f float64) {
|
||||||
|
e.w.writen1(mpDouble)
|
||||||
|
e.w.writeUint64(math.Float64bits(f))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *msgpackEncDriver) encodeExtPreamble(xtag byte, l int) {
|
||||||
|
switch {
|
||||||
|
case l == 1:
|
||||||
|
e.w.writen2(mpFixExt1, xtag)
|
||||||
|
case l == 2:
|
||||||
|
e.w.writen2(mpFixExt2, xtag)
|
||||||
|
case l == 4:
|
||||||
|
e.w.writen2(mpFixExt4, xtag)
|
||||||
|
case l == 8:
|
||||||
|
e.w.writen2(mpFixExt8, xtag)
|
||||||
|
case l == 16:
|
||||||
|
e.w.writen2(mpFixExt16, xtag)
|
||||||
|
case l < 256:
|
||||||
|
e.w.writen2(mpExt8, byte(l))
|
||||||
|
e.w.writen1(xtag)
|
||||||
|
case l < 65536:
|
||||||
|
e.w.writen1(mpExt16)
|
||||||
|
e.w.writeUint16(uint16(l))
|
||||||
|
e.w.writen1(xtag)
|
||||||
|
default:
|
||||||
|
e.w.writen1(mpExt32)
|
||||||
|
e.w.writeUint32(uint32(l))
|
||||||
|
e.w.writen1(xtag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *msgpackEncDriver) encodeArrayPreamble(length int) {
|
||||||
|
e.writeContainerLen(msgpackContainerList, length)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *msgpackEncDriver) encodeMapPreamble(length int) {
|
||||||
|
e.writeContainerLen(msgpackContainerMap, length)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *msgpackEncDriver) encodeString(c charEncoding, s string) {
|
||||||
|
if c == c_RAW && e.h.WriteExt {
|
||||||
|
e.writeContainerLen(msgpackContainerBin, len(s))
|
||||||
|
} else {
|
||||||
|
e.writeContainerLen(msgpackContainerStr, len(s))
|
||||||
|
}
|
||||||
|
if len(s) > 0 {
|
||||||
|
e.w.writestr(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *msgpackEncDriver) encodeSymbol(v string) {
|
||||||
|
e.encodeString(c_UTF8, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *msgpackEncDriver) encodeStringBytes(c charEncoding, bs []byte) {
|
||||||
|
if c == c_RAW && e.h.WriteExt {
|
||||||
|
e.writeContainerLen(msgpackContainerBin, len(bs))
|
||||||
|
} else {
|
||||||
|
e.writeContainerLen(msgpackContainerStr, len(bs))
|
||||||
|
}
|
||||||
|
if len(bs) > 0 {
|
||||||
|
e.w.writeb(bs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *msgpackEncDriver) writeContainerLen(ct msgpackContainerType, l int) {
|
||||||
|
switch {
|
||||||
|
case ct.hasFixMin && l < ct.fixCutoff:
|
||||||
|
e.w.writen1(ct.bFixMin | byte(l))
|
||||||
|
case ct.has8 && l < 256 && (ct.has8Always || e.h.WriteExt):
|
||||||
|
e.w.writen2(ct.b8, uint8(l))
|
||||||
|
case l < 65536:
|
||||||
|
e.w.writen1(ct.b16)
|
||||||
|
e.w.writeUint16(uint16(l))
|
||||||
|
default:
|
||||||
|
e.w.writen1(ct.b32)
|
||||||
|
e.w.writeUint32(uint32(l))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------
|
||||||
|
|
||||||
|
type msgpackDecDriver struct {
|
||||||
|
r decReader
|
||||||
|
h *MsgpackHandle
|
||||||
|
bd byte
|
||||||
|
bdRead bool
|
||||||
|
bdType valueType
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *msgpackDecDriver) isBuiltinType(rt uintptr) bool {
|
||||||
|
//no builtin types. All encodings are based on kinds. Types supported as extensions.
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *msgpackDecDriver) decodeBuiltin(rt uintptr, v interface{}) {}
|
||||||
|
|
||||||
|
// Note: This returns either a primitive (int, bool, etc) for non-containers,
|
||||||
|
// or a containerType, or a specific type denoting nil or extension.
|
||||||
|
// It is called when a nil interface{} is passed, leaving it up to the DecDriver
|
||||||
|
// to introspect the stream and decide how best to decode.
|
||||||
|
// It deciphers the value by looking at the stream first.
|
||||||
|
func (d *msgpackDecDriver) decodeNaked() (v interface{}, vt valueType, decodeFurther bool) {
|
||||||
|
d.initReadNext()
|
||||||
|
bd := d.bd
|
||||||
|
|
||||||
|
switch bd {
|
||||||
|
case mpNil:
|
||||||
|
vt = valueTypeNil
|
||||||
|
d.bdRead = false
|
||||||
|
case mpFalse:
|
||||||
|
vt = valueTypeBool
|
||||||
|
v = false
|
||||||
|
case mpTrue:
|
||||||
|
vt = valueTypeBool
|
||||||
|
v = true
|
||||||
|
|
||||||
|
case mpFloat:
|
||||||
|
vt = valueTypeFloat
|
||||||
|
v = float64(math.Float32frombits(d.r.readUint32()))
|
||||||
|
case mpDouble:
|
||||||
|
vt = valueTypeFloat
|
||||||
|
v = math.Float64frombits(d.r.readUint64())
|
||||||
|
|
||||||
|
case mpUint8:
|
||||||
|
vt = valueTypeUint
|
||||||
|
v = uint64(d.r.readn1())
|
||||||
|
case mpUint16:
|
||||||
|
vt = valueTypeUint
|
||||||
|
v = uint64(d.r.readUint16())
|
||||||
|
case mpUint32:
|
||||||
|
vt = valueTypeUint
|
||||||
|
v = uint64(d.r.readUint32())
|
||||||
|
case mpUint64:
|
||||||
|
vt = valueTypeUint
|
||||||
|
v = uint64(d.r.readUint64())
|
||||||
|
|
||||||
|
case mpInt8:
|
||||||
|
vt = valueTypeInt
|
||||||
|
v = int64(int8(d.r.readn1()))
|
||||||
|
case mpInt16:
|
||||||
|
vt = valueTypeInt
|
||||||
|
v = int64(int16(d.r.readUint16()))
|
||||||
|
case mpInt32:
|
||||||
|
vt = valueTypeInt
|
||||||
|
v = int64(int32(d.r.readUint32()))
|
||||||
|
case mpInt64:
|
||||||
|
vt = valueTypeInt
|
||||||
|
v = int64(int64(d.r.readUint64()))
|
||||||
|
|
||||||
|
default:
|
||||||
|
switch {
|
||||||
|
case bd >= mpPosFixNumMin && bd <= mpPosFixNumMax:
|
||||||
|
// positive fixnum (always signed)
|
||||||
|
vt = valueTypeInt
|
||||||
|
v = int64(int8(bd))
|
||||||
|
case bd >= mpNegFixNumMin && bd <= mpNegFixNumMax:
|
||||||
|
// negative fixnum
|
||||||
|
vt = valueTypeInt
|
||||||
|
v = int64(int8(bd))
|
||||||
|
case bd == mpStr8, bd == mpStr16, bd == mpStr32, bd >= mpFixStrMin && bd <= mpFixStrMax:
|
||||||
|
if d.h.RawToString {
|
||||||
|
var rvm string
|
||||||
|
vt = valueTypeString
|
||||||
|
v = &rvm
|
||||||
|
} else {
|
||||||
|
var rvm = []byte{}
|
||||||
|
vt = valueTypeBytes
|
||||||
|
v = &rvm
|
||||||
|
}
|
||||||
|
decodeFurther = true
|
||||||
|
case bd == mpBin8, bd == mpBin16, bd == mpBin32:
|
||||||
|
var rvm = []byte{}
|
||||||
|
vt = valueTypeBytes
|
||||||
|
v = &rvm
|
||||||
|
decodeFurther = true
|
||||||
|
case bd == mpArray16, bd == mpArray32, bd >= mpFixArrayMin && bd <= mpFixArrayMax:
|
||||||
|
vt = valueTypeArray
|
||||||
|
decodeFurther = true
|
||||||
|
case bd == mpMap16, bd == mpMap32, bd >= mpFixMapMin && bd <= mpFixMapMax:
|
||||||
|
vt = valueTypeMap
|
||||||
|
decodeFurther = true
|
||||||
|
case bd >= mpFixExt1 && bd <= mpFixExt16, bd >= mpExt8 && bd <= mpExt32:
|
||||||
|
clen := d.readExtLen()
|
||||||
|
var re RawExt
|
||||||
|
re.Tag = d.r.readn1()
|
||||||
|
re.Data = d.r.readn(clen)
|
||||||
|
v = &re
|
||||||
|
vt = valueTypeExt
|
||||||
|
default:
|
||||||
|
decErr("Nil-Deciphered DecodeValue: %s: hex: %x, dec: %d", msgBadDesc, bd, bd)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !decodeFurther {
|
||||||
|
d.bdRead = false
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// int can be decoded from msgpack type: intXXX or uintXXX
|
||||||
|
func (d *msgpackDecDriver) decodeInt(bitsize uint8) (i int64) {
|
||||||
|
switch d.bd {
|
||||||
|
case mpUint8:
|
||||||
|
i = int64(uint64(d.r.readn1()))
|
||||||
|
case mpUint16:
|
||||||
|
i = int64(uint64(d.r.readUint16()))
|
||||||
|
case mpUint32:
|
||||||
|
i = int64(uint64(d.r.readUint32()))
|
||||||
|
case mpUint64:
|
||||||
|
i = int64(d.r.readUint64())
|
||||||
|
case mpInt8:
|
||||||
|
i = int64(int8(d.r.readn1()))
|
||||||
|
case mpInt16:
|
||||||
|
i = int64(int16(d.r.readUint16()))
|
||||||
|
case mpInt32:
|
||||||
|
i = int64(int32(d.r.readUint32()))
|
||||||
|
case mpInt64:
|
||||||
|
i = int64(d.r.readUint64())
|
||||||
|
default:
|
||||||
|
switch {
|
||||||
|
case d.bd >= mpPosFixNumMin && d.bd <= mpPosFixNumMax:
|
||||||
|
i = int64(int8(d.bd))
|
||||||
|
case d.bd >= mpNegFixNumMin && d.bd <= mpNegFixNumMax:
|
||||||
|
i = int64(int8(d.bd))
|
||||||
|
default:
|
||||||
|
decErr("Unhandled single-byte unsigned integer value: %s: %x", msgBadDesc, d.bd)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// check overflow (logic adapted from std pkg reflect/value.go OverflowUint()
|
||||||
|
if bitsize > 0 {
|
||||||
|
if trunc := (i << (64 - bitsize)) >> (64 - bitsize); i != trunc {
|
||||||
|
decErr("Overflow int value: %v", i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
d.bdRead = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// uint can be decoded from msgpack type: intXXX or uintXXX
|
||||||
|
func (d *msgpackDecDriver) decodeUint(bitsize uint8) (ui uint64) {
|
||||||
|
switch d.bd {
|
||||||
|
case mpUint8:
|
||||||
|
ui = uint64(d.r.readn1())
|
||||||
|
case mpUint16:
|
||||||
|
ui = uint64(d.r.readUint16())
|
||||||
|
case mpUint32:
|
||||||
|
ui = uint64(d.r.readUint32())
|
||||||
|
case mpUint64:
|
||||||
|
ui = d.r.readUint64()
|
||||||
|
case mpInt8:
|
||||||
|
if i := int64(int8(d.r.readn1())); i >= 0 {
|
||||||
|
ui = uint64(i)
|
||||||
|
} else {
|
||||||
|
decErr("Assigning negative signed value: %v, to unsigned type", i)
|
||||||
|
}
|
||||||
|
case mpInt16:
|
||||||
|
if i := int64(int16(d.r.readUint16())); i >= 0 {
|
||||||
|
ui = uint64(i)
|
||||||
|
} else {
|
||||||
|
decErr("Assigning negative signed value: %v, to unsigned type", i)
|
||||||
|
}
|
||||||
|
case mpInt32:
|
||||||
|
if i := int64(int32(d.r.readUint32())); i >= 0 {
|
||||||
|
ui = uint64(i)
|
||||||
|
} else {
|
||||||
|
decErr("Assigning negative signed value: %v, to unsigned type", i)
|
||||||
|
}
|
||||||
|
case mpInt64:
|
||||||
|
if i := int64(d.r.readUint64()); i >= 0 {
|
||||||
|
ui = uint64(i)
|
||||||
|
} else {
|
||||||
|
decErr("Assigning negative signed value: %v, to unsigned type", i)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
switch {
|
||||||
|
case d.bd >= mpPosFixNumMin && d.bd <= mpPosFixNumMax:
|
||||||
|
ui = uint64(d.bd)
|
||||||
|
case d.bd >= mpNegFixNumMin && d.bd <= mpNegFixNumMax:
|
||||||
|
decErr("Assigning negative signed value: %v, to unsigned type", int(d.bd))
|
||||||
|
default:
|
||||||
|
decErr("Unhandled single-byte unsigned integer value: %s: %x", msgBadDesc, d.bd)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// check overflow (logic adapted from std pkg reflect/value.go OverflowUint()
|
||||||
|
if bitsize > 0 {
|
||||||
|
if trunc := (ui << (64 - bitsize)) >> (64 - bitsize); ui != trunc {
|
||||||
|
decErr("Overflow uint value: %v", ui)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
d.bdRead = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// float can either be decoded from msgpack type: float, double or intX
|
||||||
|
func (d *msgpackDecDriver) decodeFloat(chkOverflow32 bool) (f float64) {
|
||||||
|
switch d.bd {
|
||||||
|
case mpFloat:
|
||||||
|
f = float64(math.Float32frombits(d.r.readUint32()))
|
||||||
|
case mpDouble:
|
||||||
|
f = math.Float64frombits(d.r.readUint64())
|
||||||
|
default:
|
||||||
|
f = float64(d.decodeInt(0))
|
||||||
|
}
|
||||||
|
checkOverflowFloat32(f, chkOverflow32)
|
||||||
|
d.bdRead = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// bool can be decoded from bool, fixnum 0 or 1.
|
||||||
|
func (d *msgpackDecDriver) decodeBool() (b bool) {
|
||||||
|
switch d.bd {
|
||||||
|
case mpFalse, 0:
|
||||||
|
// b = false
|
||||||
|
case mpTrue, 1:
|
||||||
|
b = true
|
||||||
|
default:
|
||||||
|
decErr("Invalid single-byte value for bool: %s: %x", msgBadDesc, d.bd)
|
||||||
|
}
|
||||||
|
d.bdRead = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *msgpackDecDriver) decodeString() (s string) {
|
||||||
|
clen := d.readContainerLen(msgpackContainerStr)
|
||||||
|
if clen > 0 {
|
||||||
|
s = string(d.r.readn(clen))
|
||||||
|
}
|
||||||
|
d.bdRead = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Callers must check if changed=true (to decide whether to replace the one they have)
|
||||||
|
func (d *msgpackDecDriver) decodeBytes(bs []byte) (bsOut []byte, changed bool) {
|
||||||
|
// bytes can be decoded from msgpackContainerStr or msgpackContainerBin
|
||||||
|
var clen int
|
||||||
|
switch d.bd {
|
||||||
|
case mpBin8, mpBin16, mpBin32:
|
||||||
|
clen = d.readContainerLen(msgpackContainerBin)
|
||||||
|
default:
|
||||||
|
clen = d.readContainerLen(msgpackContainerStr)
|
||||||
|
}
|
||||||
|
// if clen < 0 {
|
||||||
|
// changed = true
|
||||||
|
// panic("length cannot be zero. this cannot be nil.")
|
||||||
|
// }
|
||||||
|
if clen > 0 {
|
||||||
|
// if no contents in stream, don't update the passed byteslice
|
||||||
|
if len(bs) != clen {
|
||||||
|
// Return changed=true if length of passed slice diff from length of bytes in stream
|
||||||
|
if len(bs) > clen {
|
||||||
|
bs = bs[:clen]
|
||||||
|
} else {
|
||||||
|
bs = make([]byte, clen)
|
||||||
|
}
|
||||||
|
bsOut = bs
|
||||||
|
changed = true
|
||||||
|
}
|
||||||
|
d.r.readb(bs)
|
||||||
|
}
|
||||||
|
d.bdRead = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Every top-level decode funcs (i.e. decodeValue, decode) must call this first.
|
||||||
|
func (d *msgpackDecDriver) initReadNext() {
|
||||||
|
if d.bdRead {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
d.bd = d.r.readn1()
|
||||||
|
d.bdRead = true
|
||||||
|
d.bdType = valueTypeUnset
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *msgpackDecDriver) currentEncodedType() valueType {
|
||||||
|
if d.bdType == valueTypeUnset {
|
||||||
|
bd := d.bd
|
||||||
|
switch bd {
|
||||||
|
case mpNil:
|
||||||
|
d.bdType = valueTypeNil
|
||||||
|
case mpFalse, mpTrue:
|
||||||
|
d.bdType = valueTypeBool
|
||||||
|
case mpFloat, mpDouble:
|
||||||
|
d.bdType = valueTypeFloat
|
||||||
|
case mpUint8, mpUint16, mpUint32, mpUint64:
|
||||||
|
d.bdType = valueTypeUint
|
||||||
|
case mpInt8, mpInt16, mpInt32, mpInt64:
|
||||||
|
d.bdType = valueTypeInt
|
||||||
|
default:
|
||||||
|
switch {
|
||||||
|
case bd >= mpPosFixNumMin && bd <= mpPosFixNumMax:
|
||||||
|
d.bdType = valueTypeInt
|
||||||
|
case bd >= mpNegFixNumMin && bd <= mpNegFixNumMax:
|
||||||
|
d.bdType = valueTypeInt
|
||||||
|
case bd == mpStr8, bd == mpStr16, bd == mpStr32, bd >= mpFixStrMin && bd <= mpFixStrMax:
|
||||||
|
if d.h.RawToString {
|
||||||
|
d.bdType = valueTypeString
|
||||||
|
} else {
|
||||||
|
d.bdType = valueTypeBytes
|
||||||
|
}
|
||||||
|
case bd == mpBin8, bd == mpBin16, bd == mpBin32:
|
||||||
|
d.bdType = valueTypeBytes
|
||||||
|
case bd == mpArray16, bd == mpArray32, bd >= mpFixArrayMin && bd <= mpFixArrayMax:
|
||||||
|
d.bdType = valueTypeArray
|
||||||
|
case bd == mpMap16, bd == mpMap32, bd >= mpFixMapMin && bd <= mpFixMapMax:
|
||||||
|
d.bdType = valueTypeMap
|
||||||
|
case bd >= mpFixExt1 && bd <= mpFixExt16, bd >= mpExt8 && bd <= mpExt32:
|
||||||
|
d.bdType = valueTypeExt
|
||||||
|
default:
|
||||||
|
decErr("currentEncodedType: Undeciphered descriptor: %s: hex: %x, dec: %d", msgBadDesc, bd, bd)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return d.bdType
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *msgpackDecDriver) tryDecodeAsNil() bool {
|
||||||
|
if d.bd == mpNil {
|
||||||
|
d.bdRead = false
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *msgpackDecDriver) readContainerLen(ct msgpackContainerType) (clen int) {
|
||||||
|
bd := d.bd
|
||||||
|
switch {
|
||||||
|
case bd == mpNil:
|
||||||
|
clen = -1 // to represent nil
|
||||||
|
case bd == ct.b8:
|
||||||
|
clen = int(d.r.readn1())
|
||||||
|
case bd == ct.b16:
|
||||||
|
clen = int(d.r.readUint16())
|
||||||
|
case bd == ct.b32:
|
||||||
|
clen = int(d.r.readUint32())
|
||||||
|
case (ct.bFixMin & bd) == ct.bFixMin:
|
||||||
|
clen = int(ct.bFixMin ^ bd)
|
||||||
|
default:
|
||||||
|
decErr("readContainerLen: %s: hex: %x, dec: %d", msgBadDesc, bd, bd)
|
||||||
|
}
|
||||||
|
d.bdRead = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *msgpackDecDriver) readMapLen() int {
|
||||||
|
return d.readContainerLen(msgpackContainerMap)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *msgpackDecDriver) readArrayLen() int {
|
||||||
|
return d.readContainerLen(msgpackContainerList)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *msgpackDecDriver) readExtLen() (clen int) {
|
||||||
|
switch d.bd {
|
||||||
|
case mpNil:
|
||||||
|
clen = -1 // to represent nil
|
||||||
|
case mpFixExt1:
|
||||||
|
clen = 1
|
||||||
|
case mpFixExt2:
|
||||||
|
clen = 2
|
||||||
|
case mpFixExt4:
|
||||||
|
clen = 4
|
||||||
|
case mpFixExt8:
|
||||||
|
clen = 8
|
||||||
|
case mpFixExt16:
|
||||||
|
clen = 16
|
||||||
|
case mpExt8:
|
||||||
|
clen = int(d.r.readn1())
|
||||||
|
case mpExt16:
|
||||||
|
clen = int(d.r.readUint16())
|
||||||
|
case mpExt32:
|
||||||
|
clen = int(d.r.readUint32())
|
||||||
|
default:
|
||||||
|
decErr("decoding ext bytes: found unexpected byte: %x", d.bd)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *msgpackDecDriver) decodeExt(verifyTag bool, tag byte) (xtag byte, xbs []byte) {
|
||||||
|
xbd := d.bd
|
||||||
|
switch {
|
||||||
|
case xbd == mpBin8, xbd == mpBin16, xbd == mpBin32:
|
||||||
|
xbs, _ = d.decodeBytes(nil)
|
||||||
|
case xbd == mpStr8, xbd == mpStr16, xbd == mpStr32,
|
||||||
|
xbd >= mpFixStrMin && xbd <= mpFixStrMax:
|
||||||
|
xbs = []byte(d.decodeString())
|
||||||
|
default:
|
||||||
|
clen := d.readExtLen()
|
||||||
|
xtag = d.r.readn1()
|
||||||
|
if verifyTag && xtag != tag {
|
||||||
|
decErr("Wrong extension tag. Got %b. Expecting: %v", xtag, tag)
|
||||||
|
}
|
||||||
|
xbs = d.r.readn(clen)
|
||||||
|
}
|
||||||
|
d.bdRead = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
|
//MsgpackHandle is a Handle for the Msgpack Schema-Free Encoding Format.
|
||||||
|
type MsgpackHandle struct {
|
||||||
|
BasicHandle
|
||||||
|
|
||||||
|
// RawToString controls how raw bytes are decoded into a nil interface{}.
|
||||||
|
RawToString bool
|
||||||
|
// WriteExt flag supports encoding configured extensions with extension tags.
|
||||||
|
// It also controls whether other elements of the new spec are encoded (ie Str8).
|
||||||
|
//
|
||||||
|
// With WriteExt=false, configured extensions are serialized as raw bytes
|
||||||
|
// and Str8 is not encoded.
|
||||||
|
//
|
||||||
|
// A stream can still be decoded into a typed value, provided an appropriate value
|
||||||
|
// is provided, but the type cannot be inferred from the stream. If no appropriate
|
||||||
|
// type is provided (e.g. decoding into a nil interface{}), you get back
|
||||||
|
// a []byte or string based on the setting of RawToString.
|
||||||
|
WriteExt bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *MsgpackHandle) newEncDriver(w encWriter) encDriver {
|
||||||
|
return &msgpackEncDriver{w: w, h: h}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *MsgpackHandle) newDecDriver(r decReader) decDriver {
|
||||||
|
return &msgpackDecDriver{r: r, h: h}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *MsgpackHandle) writeExt() bool {
|
||||||
|
return h.WriteExt
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *MsgpackHandle) getBasicHandle() *BasicHandle {
|
||||||
|
return &h.BasicHandle
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
|
type msgpackSpecRpcCodec struct {
|
||||||
|
rpcCodec
|
||||||
|
}
|
||||||
|
|
||||||
|
// /////////////// Spec RPC Codec ///////////////////
|
||||||
|
func (c *msgpackSpecRpcCodec) WriteRequest(r *rpc.Request, body interface{}) error {
|
||||||
|
// WriteRequest can write to both a Go service, and other services that do
|
||||||
|
// not abide by the 1 argument rule of a Go service.
|
||||||
|
// We discriminate based on if the body is a MsgpackSpecRpcMultiArgs
|
||||||
|
var bodyArr []interface{}
|
||||||
|
if m, ok := body.(MsgpackSpecRpcMultiArgs); ok {
|
||||||
|
bodyArr = ([]interface{})(m)
|
||||||
|
} else {
|
||||||
|
bodyArr = []interface{}{body}
|
||||||
|
}
|
||||||
|
r2 := []interface{}{0, uint32(r.Seq), r.ServiceMethod, bodyArr}
|
||||||
|
return c.write(r2, nil, false, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *msgpackSpecRpcCodec) WriteResponse(r *rpc.Response, body interface{}) error {
|
||||||
|
var moe interface{}
|
||||||
|
if r.Error != "" {
|
||||||
|
moe = r.Error
|
||||||
|
}
|
||||||
|
if moe != nil && body != nil {
|
||||||
|
body = nil
|
||||||
|
}
|
||||||
|
r2 := []interface{}{1, uint32(r.Seq), moe, body}
|
||||||
|
return c.write(r2, nil, false, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *msgpackSpecRpcCodec) ReadResponseHeader(r *rpc.Response) error {
|
||||||
|
return c.parseCustomHeader(1, &r.Seq, &r.Error)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *msgpackSpecRpcCodec) ReadRequestHeader(r *rpc.Request) error {
|
||||||
|
return c.parseCustomHeader(0, &r.Seq, &r.ServiceMethod)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *msgpackSpecRpcCodec) ReadRequestBody(body interface{}) error {
|
||||||
|
if body == nil { // read and discard
|
||||||
|
return c.read(nil)
|
||||||
|
}
|
||||||
|
bodyArr := []interface{}{body}
|
||||||
|
return c.read(&bodyArr)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *msgpackSpecRpcCodec) parseCustomHeader(expectTypeByte byte, msgid *uint64, methodOrError *string) (err error) {
|
||||||
|
|
||||||
|
if c.cls {
|
||||||
|
return io.EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
// We read the response header by hand
|
||||||
|
// so that the body can be decoded on its own from the stream at a later time.
|
||||||
|
|
||||||
|
const fia byte = 0x94 //four item array descriptor value
|
||||||
|
// Not sure why the panic of EOF is swallowed above.
|
||||||
|
// if bs1 := c.dec.r.readn1(); bs1 != fia {
|
||||||
|
// err = fmt.Errorf("Unexpected value for array descriptor: Expecting %v. Received %v", fia, bs1)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
var b byte
|
||||||
|
b, err = c.br.ReadByte()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if b != fia {
|
||||||
|
err = fmt.Errorf("Unexpected value for array descriptor: Expecting %v. Received %v", fia, b)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = c.read(&b); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if b != expectTypeByte {
|
||||||
|
err = fmt.Errorf("Unexpected byte descriptor in header. Expecting %v. Received %v", expectTypeByte, b)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = c.read(msgid); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = c.read(methodOrError); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
|
// msgpackSpecRpc is the implementation of Rpc that uses custom communication protocol
|
||||||
|
// as defined in the msgpack spec at https://github.com/msgpack-rpc/msgpack-rpc/blob/master/spec.md
|
||||||
|
type msgpackSpecRpc struct{}
|
||||||
|
|
||||||
|
// MsgpackSpecRpc implements Rpc using the communication protocol defined in
|
||||||
|
// the msgpack spec at https://github.com/msgpack-rpc/msgpack-rpc/blob/master/spec.md .
|
||||||
|
// Its methods (ServerCodec and ClientCodec) return values that implement RpcCodecBuffered.
|
||||||
|
var MsgpackSpecRpc msgpackSpecRpc
|
||||||
|
|
||||||
|
func (x msgpackSpecRpc) ServerCodec(conn io.ReadWriteCloser, h Handle) rpc.ServerCodec {
|
||||||
|
return &msgpackSpecRpcCodec{newRPCCodec(conn, h)}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x msgpackSpecRpc) ClientCodec(conn io.ReadWriteCloser, h Handle) rpc.ClientCodec {
|
||||||
|
return &msgpackSpecRpcCodec{newRPCCodec(conn, h)}
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ decDriver = (*msgpackDecDriver)(nil)
|
||||||
|
var _ encDriver = (*msgpackEncDriver)(nil)
|
||||||
110
vendor/github.com/hashicorp/go-msgpack/codec/msgpack_test.py
generated
vendored
Executable file
110
vendor/github.com/hashicorp/go-msgpack/codec/msgpack_test.py
generated
vendored
Executable file
@@ -0,0 +1,110 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
# This will create golden files in a directory passed to it.
|
||||||
|
# A Test calls this internally to create the golden files
|
||||||
|
# So it can process them (so we don't have to checkin the files).
|
||||||
|
|
||||||
|
import msgpack, msgpackrpc, sys, os, threading
|
||||||
|
|
||||||
|
def get_test_data_list():
|
||||||
|
# get list with all primitive types, and a combo type
|
||||||
|
l0 = [
|
||||||
|
-8,
|
||||||
|
-1616,
|
||||||
|
-32323232,
|
||||||
|
-6464646464646464,
|
||||||
|
192,
|
||||||
|
1616,
|
||||||
|
32323232,
|
||||||
|
6464646464646464,
|
||||||
|
192,
|
||||||
|
-3232.0,
|
||||||
|
-6464646464.0,
|
||||||
|
3232.0,
|
||||||
|
6464646464.0,
|
||||||
|
False,
|
||||||
|
True,
|
||||||
|
None,
|
||||||
|
"someday",
|
||||||
|
"",
|
||||||
|
"bytestring",
|
||||||
|
1328176922000002000,
|
||||||
|
-2206187877999998000,
|
||||||
|
0,
|
||||||
|
-6795364578871345152
|
||||||
|
]
|
||||||
|
l1 = [
|
||||||
|
{ "true": True,
|
||||||
|
"false": False },
|
||||||
|
{ "true": "True",
|
||||||
|
"false": False,
|
||||||
|
"uint16(1616)": 1616 },
|
||||||
|
{ "list": [1616, 32323232, True, -3232.0, {"TRUE":True, "FALSE":False}, [True, False] ],
|
||||||
|
"int32":32323232, "bool": True,
|
||||||
|
"LONG STRING": "123456789012345678901234567890123456789012345678901234567890",
|
||||||
|
"SHORT STRING": "1234567890" },
|
||||||
|
{ True: "true", 8: False, "false": 0 }
|
||||||
|
]
|
||||||
|
|
||||||
|
l = []
|
||||||
|
l.extend(l0)
|
||||||
|
l.append(l0)
|
||||||
|
l.extend(l1)
|
||||||
|
return l
|
||||||
|
|
||||||
|
def build_test_data(destdir):
|
||||||
|
l = get_test_data_list()
|
||||||
|
for i in range(len(l)):
|
||||||
|
packer = msgpack.Packer()
|
||||||
|
serialized = packer.pack(l[i])
|
||||||
|
f = open(os.path.join(destdir, str(i) + '.golden'), 'wb')
|
||||||
|
f.write(serialized)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
def doRpcServer(port, stopTimeSec):
|
||||||
|
class EchoHandler(object):
|
||||||
|
def Echo123(self, msg1, msg2, msg3):
|
||||||
|
return ("1:%s 2:%s 3:%s" % (msg1, msg2, msg3))
|
||||||
|
def EchoStruct(self, msg):
|
||||||
|
return ("%s" % msg)
|
||||||
|
|
||||||
|
addr = msgpackrpc.Address('localhost', port)
|
||||||
|
server = msgpackrpc.Server(EchoHandler())
|
||||||
|
server.listen(addr)
|
||||||
|
# run thread to stop it after stopTimeSec seconds if > 0
|
||||||
|
if stopTimeSec > 0:
|
||||||
|
def myStopRpcServer():
|
||||||
|
server.stop()
|
||||||
|
t = threading.Timer(stopTimeSec, myStopRpcServer)
|
||||||
|
t.start()
|
||||||
|
server.start()
|
||||||
|
|
||||||
|
def doRpcClientToPythonSvc(port):
|
||||||
|
address = msgpackrpc.Address('localhost', port)
|
||||||
|
client = msgpackrpc.Client(address, unpack_encoding='utf-8')
|
||||||
|
print client.call("Echo123", "A1", "B2", "C3")
|
||||||
|
print client.call("EchoStruct", {"A" :"Aa", "B":"Bb", "C":"Cc"})
|
||||||
|
|
||||||
|
def doRpcClientToGoSvc(port):
|
||||||
|
# print ">>>> port: ", port, " <<<<<"
|
||||||
|
address = msgpackrpc.Address('localhost', port)
|
||||||
|
client = msgpackrpc.Client(address, unpack_encoding='utf-8')
|
||||||
|
print client.call("TestRpcInt.Echo123", ["A1", "B2", "C3"])
|
||||||
|
print client.call("TestRpcInt.EchoStruct", {"A" :"Aa", "B":"Bb", "C":"Cc"})
|
||||||
|
|
||||||
|
def doMain(args):
|
||||||
|
if len(args) == 2 and args[0] == "testdata":
|
||||||
|
build_test_data(args[1])
|
||||||
|
elif len(args) == 3 and args[0] == "rpc-server":
|
||||||
|
doRpcServer(int(args[1]), int(args[2]))
|
||||||
|
elif len(args) == 2 and args[0] == "rpc-client-python-service":
|
||||||
|
doRpcClientToPythonSvc(int(args[1]))
|
||||||
|
elif len(args) == 2 and args[0] == "rpc-client-go-service":
|
||||||
|
doRpcClientToGoSvc(int(args[1]))
|
||||||
|
else:
|
||||||
|
print("Usage: msgpack_test.py " +
|
||||||
|
"[testdata|rpc-server|rpc-client-python-service|rpc-client-go-service] ...")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
doMain(sys.argv[1:])
|
||||||
|
|
||||||
152
vendor/github.com/hashicorp/go-msgpack/codec/rpc.go
generated
vendored
Normal file
152
vendor/github.com/hashicorp/go-msgpack/codec/rpc.go
generated
vendored
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
// Copyright (c) 2012, 2013 Ugorji Nwoke. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license found in the LICENSE file.
|
||||||
|
|
||||||
|
package codec
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"io"
|
||||||
|
"net/rpc"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Rpc provides a rpc Server or Client Codec for rpc communication.
|
||||||
|
type Rpc interface {
|
||||||
|
ServerCodec(conn io.ReadWriteCloser, h Handle) rpc.ServerCodec
|
||||||
|
ClientCodec(conn io.ReadWriteCloser, h Handle) rpc.ClientCodec
|
||||||
|
}
|
||||||
|
|
||||||
|
// RpcCodecBuffered allows access to the underlying bufio.Reader/Writer
|
||||||
|
// used by the rpc connection. It accomodates use-cases where the connection
|
||||||
|
// should be used by rpc and non-rpc functions, e.g. streaming a file after
|
||||||
|
// sending an rpc response.
|
||||||
|
type RpcCodecBuffered interface {
|
||||||
|
BufferedReader() *bufio.Reader
|
||||||
|
BufferedWriter() *bufio.Writer
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------
|
||||||
|
|
||||||
|
// rpcCodec defines the struct members and common methods.
|
||||||
|
type rpcCodec struct {
|
||||||
|
rwc io.ReadWriteCloser
|
||||||
|
dec *Decoder
|
||||||
|
enc *Encoder
|
||||||
|
bw *bufio.Writer
|
||||||
|
br *bufio.Reader
|
||||||
|
mu sync.Mutex
|
||||||
|
cls bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func newRPCCodec(conn io.ReadWriteCloser, h Handle) rpcCodec {
|
||||||
|
bw := bufio.NewWriter(conn)
|
||||||
|
br := bufio.NewReader(conn)
|
||||||
|
return rpcCodec{
|
||||||
|
rwc: conn,
|
||||||
|
bw: bw,
|
||||||
|
br: br,
|
||||||
|
enc: NewEncoder(bw, h),
|
||||||
|
dec: NewDecoder(br, h),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *rpcCodec) BufferedReader() *bufio.Reader {
|
||||||
|
return c.br
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *rpcCodec) BufferedWriter() *bufio.Writer {
|
||||||
|
return c.bw
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *rpcCodec) write(obj1, obj2 interface{}, writeObj2, doFlush bool) (err error) {
|
||||||
|
if c.cls {
|
||||||
|
return io.EOF
|
||||||
|
}
|
||||||
|
if err = c.enc.Encode(obj1); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if writeObj2 {
|
||||||
|
if err = c.enc.Encode(obj2); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if doFlush && c.bw != nil {
|
||||||
|
return c.bw.Flush()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *rpcCodec) read(obj interface{}) (err error) {
|
||||||
|
if c.cls {
|
||||||
|
return io.EOF
|
||||||
|
}
|
||||||
|
//If nil is passed in, we should still attempt to read content to nowhere.
|
||||||
|
if obj == nil {
|
||||||
|
var obj2 interface{}
|
||||||
|
return c.dec.Decode(&obj2)
|
||||||
|
}
|
||||||
|
return c.dec.Decode(obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *rpcCodec) Close() error {
|
||||||
|
if c.cls {
|
||||||
|
return io.EOF
|
||||||
|
}
|
||||||
|
c.cls = true
|
||||||
|
return c.rwc.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *rpcCodec) ReadResponseBody(body interface{}) error {
|
||||||
|
return c.read(body)
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------
|
||||||
|
|
||||||
|
type goRpcCodec struct {
|
||||||
|
rpcCodec
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *goRpcCodec) WriteRequest(r *rpc.Request, body interface{}) error {
|
||||||
|
// Must protect for concurrent access as per API
|
||||||
|
c.mu.Lock()
|
||||||
|
defer c.mu.Unlock()
|
||||||
|
return c.write(r, body, true, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *goRpcCodec) WriteResponse(r *rpc.Response, body interface{}) error {
|
||||||
|
c.mu.Lock()
|
||||||
|
defer c.mu.Unlock()
|
||||||
|
return c.write(r, body, true, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *goRpcCodec) ReadResponseHeader(r *rpc.Response) error {
|
||||||
|
return c.read(r)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *goRpcCodec) ReadRequestHeader(r *rpc.Request) error {
|
||||||
|
return c.read(r)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *goRpcCodec) ReadRequestBody(body interface{}) error {
|
||||||
|
return c.read(body)
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------
|
||||||
|
|
||||||
|
// goRpc is the implementation of Rpc that uses the communication protocol
|
||||||
|
// as defined in net/rpc package.
|
||||||
|
type goRpc struct{}
|
||||||
|
|
||||||
|
// GoRpc implements Rpc using the communication protocol defined in net/rpc package.
|
||||||
|
// Its methods (ServerCodec and ClientCodec) return values that implement RpcCodecBuffered.
|
||||||
|
var GoRpc goRpc
|
||||||
|
|
||||||
|
func (x goRpc) ServerCodec(conn io.ReadWriteCloser, h Handle) rpc.ServerCodec {
|
||||||
|
return &goRpcCodec{newRPCCodec(conn, h)}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x goRpc) ClientCodec(conn io.ReadWriteCloser, h Handle) rpc.ClientCodec {
|
||||||
|
return &goRpcCodec{newRPCCodec(conn, h)}
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ RpcCodecBuffered = (*rpcCodec)(nil) // ensure *rpcCodec implements RpcCodecBuffered
|
||||||
461
vendor/github.com/hashicorp/go-msgpack/codec/simple.go
generated
vendored
Normal file
461
vendor/github.com/hashicorp/go-msgpack/codec/simple.go
generated
vendored
Normal file
@@ -0,0 +1,461 @@
|
|||||||
|
// Copyright (c) 2012, 2013 Ugorji Nwoke. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license found in the LICENSE file.
|
||||||
|
|
||||||
|
package codec
|
||||||
|
|
||||||
|
import "math"
|
||||||
|
|
||||||
|
const (
|
||||||
|
_ uint8 = iota
|
||||||
|
simpleVdNil = 1
|
||||||
|
simpleVdFalse = 2
|
||||||
|
simpleVdTrue = 3
|
||||||
|
simpleVdFloat32 = 4
|
||||||
|
simpleVdFloat64 = 5
|
||||||
|
|
||||||
|
// each lasts for 4 (ie n, n+1, n+2, n+3)
|
||||||
|
simpleVdPosInt = 8
|
||||||
|
simpleVdNegInt = 12
|
||||||
|
|
||||||
|
// containers: each lasts for 4 (ie n, n+1, n+2, ... n+7)
|
||||||
|
simpleVdString = 216
|
||||||
|
simpleVdByteArray = 224
|
||||||
|
simpleVdArray = 232
|
||||||
|
simpleVdMap = 240
|
||||||
|
simpleVdExt = 248
|
||||||
|
)
|
||||||
|
|
||||||
|
type simpleEncDriver struct {
|
||||||
|
h *SimpleHandle
|
||||||
|
w encWriter
|
||||||
|
//b [8]byte
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *simpleEncDriver) isBuiltinType(rt uintptr) bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *simpleEncDriver) encodeBuiltin(rt uintptr, v interface{}) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *simpleEncDriver) encodeNil() {
|
||||||
|
e.w.writen1(simpleVdNil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *simpleEncDriver) encodeBool(b bool) {
|
||||||
|
if b {
|
||||||
|
e.w.writen1(simpleVdTrue)
|
||||||
|
} else {
|
||||||
|
e.w.writen1(simpleVdFalse)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *simpleEncDriver) encodeFloat32(f float32) {
|
||||||
|
e.w.writen1(simpleVdFloat32)
|
||||||
|
e.w.writeUint32(math.Float32bits(f))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *simpleEncDriver) encodeFloat64(f float64) {
|
||||||
|
e.w.writen1(simpleVdFloat64)
|
||||||
|
e.w.writeUint64(math.Float64bits(f))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *simpleEncDriver) encodeInt(v int64) {
|
||||||
|
if v < 0 {
|
||||||
|
e.encUint(uint64(-v), simpleVdNegInt)
|
||||||
|
} else {
|
||||||
|
e.encUint(uint64(v), simpleVdPosInt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *simpleEncDriver) encodeUint(v uint64) {
|
||||||
|
e.encUint(v, simpleVdPosInt)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *simpleEncDriver) encUint(v uint64, bd uint8) {
|
||||||
|
switch {
|
||||||
|
case v <= math.MaxUint8:
|
||||||
|
e.w.writen2(bd, uint8(v))
|
||||||
|
case v <= math.MaxUint16:
|
||||||
|
e.w.writen1(bd + 1)
|
||||||
|
e.w.writeUint16(uint16(v))
|
||||||
|
case v <= math.MaxUint32:
|
||||||
|
e.w.writen1(bd + 2)
|
||||||
|
e.w.writeUint32(uint32(v))
|
||||||
|
case v <= math.MaxUint64:
|
||||||
|
e.w.writen1(bd + 3)
|
||||||
|
e.w.writeUint64(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *simpleEncDriver) encLen(bd byte, length int) {
|
||||||
|
switch {
|
||||||
|
case length == 0:
|
||||||
|
e.w.writen1(bd)
|
||||||
|
case length <= math.MaxUint8:
|
||||||
|
e.w.writen1(bd + 1)
|
||||||
|
e.w.writen1(uint8(length))
|
||||||
|
case length <= math.MaxUint16:
|
||||||
|
e.w.writen1(bd + 2)
|
||||||
|
e.w.writeUint16(uint16(length))
|
||||||
|
case int64(length) <= math.MaxUint32:
|
||||||
|
e.w.writen1(bd + 3)
|
||||||
|
e.w.writeUint32(uint32(length))
|
||||||
|
default:
|
||||||
|
e.w.writen1(bd + 4)
|
||||||
|
e.w.writeUint64(uint64(length))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *simpleEncDriver) encodeExtPreamble(xtag byte, length int) {
|
||||||
|
e.encLen(simpleVdExt, length)
|
||||||
|
e.w.writen1(xtag)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *simpleEncDriver) encodeArrayPreamble(length int) {
|
||||||
|
e.encLen(simpleVdArray, length)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *simpleEncDriver) encodeMapPreamble(length int) {
|
||||||
|
e.encLen(simpleVdMap, length)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *simpleEncDriver) encodeString(c charEncoding, v string) {
|
||||||
|
e.encLen(simpleVdString, len(v))
|
||||||
|
e.w.writestr(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *simpleEncDriver) encodeSymbol(v string) {
|
||||||
|
e.encodeString(c_UTF8, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *simpleEncDriver) encodeStringBytes(c charEncoding, v []byte) {
|
||||||
|
e.encLen(simpleVdByteArray, len(v))
|
||||||
|
e.w.writeb(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------
|
||||||
|
|
||||||
|
type simpleDecDriver struct {
|
||||||
|
h *SimpleHandle
|
||||||
|
r decReader
|
||||||
|
bdRead bool
|
||||||
|
bdType valueType
|
||||||
|
bd byte
|
||||||
|
//b [8]byte
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *simpleDecDriver) initReadNext() {
|
||||||
|
if d.bdRead {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
d.bd = d.r.readn1()
|
||||||
|
d.bdRead = true
|
||||||
|
d.bdType = valueTypeUnset
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *simpleDecDriver) currentEncodedType() valueType {
|
||||||
|
if d.bdType == valueTypeUnset {
|
||||||
|
switch d.bd {
|
||||||
|
case simpleVdNil:
|
||||||
|
d.bdType = valueTypeNil
|
||||||
|
case simpleVdTrue, simpleVdFalse:
|
||||||
|
d.bdType = valueTypeBool
|
||||||
|
case simpleVdPosInt, simpleVdPosInt + 1, simpleVdPosInt + 2, simpleVdPosInt + 3:
|
||||||
|
d.bdType = valueTypeUint
|
||||||
|
case simpleVdNegInt, simpleVdNegInt + 1, simpleVdNegInt + 2, simpleVdNegInt + 3:
|
||||||
|
d.bdType = valueTypeInt
|
||||||
|
case simpleVdFloat32, simpleVdFloat64:
|
||||||
|
d.bdType = valueTypeFloat
|
||||||
|
case simpleVdString, simpleVdString + 1, simpleVdString + 2, simpleVdString + 3, simpleVdString + 4:
|
||||||
|
d.bdType = valueTypeString
|
||||||
|
case simpleVdByteArray, simpleVdByteArray + 1, simpleVdByteArray + 2, simpleVdByteArray + 3, simpleVdByteArray + 4:
|
||||||
|
d.bdType = valueTypeBytes
|
||||||
|
case simpleVdExt, simpleVdExt + 1, simpleVdExt + 2, simpleVdExt + 3, simpleVdExt + 4:
|
||||||
|
d.bdType = valueTypeExt
|
||||||
|
case simpleVdArray, simpleVdArray + 1, simpleVdArray + 2, simpleVdArray + 3, simpleVdArray + 4:
|
||||||
|
d.bdType = valueTypeArray
|
||||||
|
case simpleVdMap, simpleVdMap + 1, simpleVdMap + 2, simpleVdMap + 3, simpleVdMap + 4:
|
||||||
|
d.bdType = valueTypeMap
|
||||||
|
default:
|
||||||
|
decErr("currentEncodedType: Unrecognized d.vd: 0x%x", d.bd)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return d.bdType
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *simpleDecDriver) tryDecodeAsNil() bool {
|
||||||
|
if d.bd == simpleVdNil {
|
||||||
|
d.bdRead = false
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *simpleDecDriver) isBuiltinType(rt uintptr) bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *simpleDecDriver) decodeBuiltin(rt uintptr, v interface{}) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *simpleDecDriver) decIntAny() (ui uint64, i int64, neg bool) {
|
||||||
|
switch d.bd {
|
||||||
|
case simpleVdPosInt:
|
||||||
|
ui = uint64(d.r.readn1())
|
||||||
|
i = int64(ui)
|
||||||
|
case simpleVdPosInt + 1:
|
||||||
|
ui = uint64(d.r.readUint16())
|
||||||
|
i = int64(ui)
|
||||||
|
case simpleVdPosInt + 2:
|
||||||
|
ui = uint64(d.r.readUint32())
|
||||||
|
i = int64(ui)
|
||||||
|
case simpleVdPosInt + 3:
|
||||||
|
ui = uint64(d.r.readUint64())
|
||||||
|
i = int64(ui)
|
||||||
|
case simpleVdNegInt:
|
||||||
|
ui = uint64(d.r.readn1())
|
||||||
|
i = -(int64(ui))
|
||||||
|
neg = true
|
||||||
|
case simpleVdNegInt + 1:
|
||||||
|
ui = uint64(d.r.readUint16())
|
||||||
|
i = -(int64(ui))
|
||||||
|
neg = true
|
||||||
|
case simpleVdNegInt + 2:
|
||||||
|
ui = uint64(d.r.readUint32())
|
||||||
|
i = -(int64(ui))
|
||||||
|
neg = true
|
||||||
|
case simpleVdNegInt + 3:
|
||||||
|
ui = uint64(d.r.readUint64())
|
||||||
|
i = -(int64(ui))
|
||||||
|
neg = true
|
||||||
|
default:
|
||||||
|
decErr("decIntAny: Integer only valid from pos/neg integer1..8. Invalid descriptor: %v", d.bd)
|
||||||
|
}
|
||||||
|
// don't do this check, because callers may only want the unsigned value.
|
||||||
|
// if ui > math.MaxInt64 {
|
||||||
|
// decErr("decIntAny: Integer out of range for signed int64: %v", ui)
|
||||||
|
// }
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *simpleDecDriver) decodeInt(bitsize uint8) (i int64) {
|
||||||
|
_, i, _ = d.decIntAny()
|
||||||
|
checkOverflow(0, i, bitsize)
|
||||||
|
d.bdRead = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *simpleDecDriver) decodeUint(bitsize uint8) (ui uint64) {
|
||||||
|
ui, i, neg := d.decIntAny()
|
||||||
|
if neg {
|
||||||
|
decErr("Assigning negative signed value: %v, to unsigned type", i)
|
||||||
|
}
|
||||||
|
checkOverflow(ui, 0, bitsize)
|
||||||
|
d.bdRead = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *simpleDecDriver) decodeFloat(chkOverflow32 bool) (f float64) {
|
||||||
|
switch d.bd {
|
||||||
|
case simpleVdFloat32:
|
||||||
|
f = float64(math.Float32frombits(d.r.readUint32()))
|
||||||
|
case simpleVdFloat64:
|
||||||
|
f = math.Float64frombits(d.r.readUint64())
|
||||||
|
default:
|
||||||
|
if d.bd >= simpleVdPosInt && d.bd <= simpleVdNegInt+3 {
|
||||||
|
_, i, _ := d.decIntAny()
|
||||||
|
f = float64(i)
|
||||||
|
} else {
|
||||||
|
decErr("Float only valid from float32/64: Invalid descriptor: %v", d.bd)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
checkOverflowFloat32(f, chkOverflow32)
|
||||||
|
d.bdRead = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// bool can be decoded from bool only (single byte).
|
||||||
|
func (d *simpleDecDriver) decodeBool() (b bool) {
|
||||||
|
switch d.bd {
|
||||||
|
case simpleVdTrue:
|
||||||
|
b = true
|
||||||
|
case simpleVdFalse:
|
||||||
|
default:
|
||||||
|
decErr("Invalid single-byte value for bool: %s: %x", msgBadDesc, d.bd)
|
||||||
|
}
|
||||||
|
d.bdRead = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *simpleDecDriver) readMapLen() (length int) {
|
||||||
|
d.bdRead = false
|
||||||
|
return d.decLen()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *simpleDecDriver) readArrayLen() (length int) {
|
||||||
|
d.bdRead = false
|
||||||
|
return d.decLen()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *simpleDecDriver) decLen() int {
|
||||||
|
switch d.bd % 8 {
|
||||||
|
case 0:
|
||||||
|
return 0
|
||||||
|
case 1:
|
||||||
|
return int(d.r.readn1())
|
||||||
|
case 2:
|
||||||
|
return int(d.r.readUint16())
|
||||||
|
case 3:
|
||||||
|
ui := uint64(d.r.readUint32())
|
||||||
|
checkOverflow(ui, 0, intBitsize)
|
||||||
|
return int(ui)
|
||||||
|
case 4:
|
||||||
|
ui := d.r.readUint64()
|
||||||
|
checkOverflow(ui, 0, intBitsize)
|
||||||
|
return int(ui)
|
||||||
|
}
|
||||||
|
decErr("decLen: Cannot read length: bd%8 must be in range 0..4. Got: %d", d.bd%8)
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *simpleDecDriver) decodeString() (s string) {
|
||||||
|
s = string(d.r.readn(d.decLen()))
|
||||||
|
d.bdRead = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *simpleDecDriver) decodeBytes(bs []byte) (bsOut []byte, changed bool) {
|
||||||
|
if clen := d.decLen(); clen > 0 {
|
||||||
|
// if no contents in stream, don't update the passed byteslice
|
||||||
|
if len(bs) != clen {
|
||||||
|
if len(bs) > clen {
|
||||||
|
bs = bs[:clen]
|
||||||
|
} else {
|
||||||
|
bs = make([]byte, clen)
|
||||||
|
}
|
||||||
|
bsOut = bs
|
||||||
|
changed = true
|
||||||
|
}
|
||||||
|
d.r.readb(bs)
|
||||||
|
}
|
||||||
|
d.bdRead = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *simpleDecDriver) decodeExt(verifyTag bool, tag byte) (xtag byte, xbs []byte) {
|
||||||
|
switch d.bd {
|
||||||
|
case simpleVdExt, simpleVdExt + 1, simpleVdExt + 2, simpleVdExt + 3, simpleVdExt + 4:
|
||||||
|
l := d.decLen()
|
||||||
|
xtag = d.r.readn1()
|
||||||
|
if verifyTag && xtag != tag {
|
||||||
|
decErr("Wrong extension tag. Got %b. Expecting: %v", xtag, tag)
|
||||||
|
}
|
||||||
|
xbs = d.r.readn(l)
|
||||||
|
case simpleVdByteArray, simpleVdByteArray + 1, simpleVdByteArray + 2, simpleVdByteArray + 3, simpleVdByteArray + 4:
|
||||||
|
xbs, _ = d.decodeBytes(nil)
|
||||||
|
default:
|
||||||
|
decErr("Invalid d.vd for extensions (Expecting extensions or byte array). Got: 0x%x", d.bd)
|
||||||
|
}
|
||||||
|
d.bdRead = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *simpleDecDriver) decodeNaked() (v interface{}, vt valueType, decodeFurther bool) {
|
||||||
|
d.initReadNext()
|
||||||
|
|
||||||
|
switch d.bd {
|
||||||
|
case simpleVdNil:
|
||||||
|
vt = valueTypeNil
|
||||||
|
case simpleVdFalse:
|
||||||
|
vt = valueTypeBool
|
||||||
|
v = false
|
||||||
|
case simpleVdTrue:
|
||||||
|
vt = valueTypeBool
|
||||||
|
v = true
|
||||||
|
case simpleVdPosInt, simpleVdPosInt + 1, simpleVdPosInt + 2, simpleVdPosInt + 3:
|
||||||
|
vt = valueTypeUint
|
||||||
|
ui, _, _ := d.decIntAny()
|
||||||
|
v = ui
|
||||||
|
case simpleVdNegInt, simpleVdNegInt + 1, simpleVdNegInt + 2, simpleVdNegInt + 3:
|
||||||
|
vt = valueTypeInt
|
||||||
|
_, i, _ := d.decIntAny()
|
||||||
|
v = i
|
||||||
|
case simpleVdFloat32:
|
||||||
|
vt = valueTypeFloat
|
||||||
|
v = d.decodeFloat(true)
|
||||||
|
case simpleVdFloat64:
|
||||||
|
vt = valueTypeFloat
|
||||||
|
v = d.decodeFloat(false)
|
||||||
|
case simpleVdString, simpleVdString + 1, simpleVdString + 2, simpleVdString + 3, simpleVdString + 4:
|
||||||
|
vt = valueTypeString
|
||||||
|
v = d.decodeString()
|
||||||
|
case simpleVdByteArray, simpleVdByteArray + 1, simpleVdByteArray + 2, simpleVdByteArray + 3, simpleVdByteArray + 4:
|
||||||
|
vt = valueTypeBytes
|
||||||
|
v, _ = d.decodeBytes(nil)
|
||||||
|
case simpleVdExt, simpleVdExt + 1, simpleVdExt + 2, simpleVdExt + 3, simpleVdExt + 4:
|
||||||
|
vt = valueTypeExt
|
||||||
|
l := d.decLen()
|
||||||
|
var re RawExt
|
||||||
|
re.Tag = d.r.readn1()
|
||||||
|
re.Data = d.r.readn(l)
|
||||||
|
v = &re
|
||||||
|
vt = valueTypeExt
|
||||||
|
case simpleVdArray, simpleVdArray + 1, simpleVdArray + 2, simpleVdArray + 3, simpleVdArray + 4:
|
||||||
|
vt = valueTypeArray
|
||||||
|
decodeFurther = true
|
||||||
|
case simpleVdMap, simpleVdMap + 1, simpleVdMap + 2, simpleVdMap + 3, simpleVdMap + 4:
|
||||||
|
vt = valueTypeMap
|
||||||
|
decodeFurther = true
|
||||||
|
default:
|
||||||
|
decErr("decodeNaked: Unrecognized d.vd: 0x%x", d.bd)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !decodeFurther {
|
||||||
|
d.bdRead = false
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------
|
||||||
|
|
||||||
|
// SimpleHandle is a Handle for a very simple encoding format.
|
||||||
|
//
|
||||||
|
// simple is a simplistic codec similar to binc, but not as compact.
|
||||||
|
// - Encoding of a value is always preceeded by the descriptor byte (bd)
|
||||||
|
// - True, false, nil are encoded fully in 1 byte (the descriptor)
|
||||||
|
// - Integers (intXXX, uintXXX) are encoded in 1, 2, 4 or 8 bytes (plus a descriptor byte).
|
||||||
|
// There are positive (uintXXX and intXXX >= 0) and negative (intXXX < 0) integers.
|
||||||
|
// - Floats are encoded in 4 or 8 bytes (plus a descriptor byte)
|
||||||
|
// - Lenght of containers (strings, bytes, array, map, extensions)
|
||||||
|
// are encoded in 0, 1, 2, 4 or 8 bytes.
|
||||||
|
// Zero-length containers have no length encoded.
|
||||||
|
// For others, the number of bytes is given by pow(2, bd%3)
|
||||||
|
// - maps are encoded as [bd] [length] [[key][value]]...
|
||||||
|
// - arrays are encoded as [bd] [length] [value]...
|
||||||
|
// - extensions are encoded as [bd] [length] [tag] [byte]...
|
||||||
|
// - strings/bytearrays are encoded as [bd] [length] [byte]...
|
||||||
|
//
|
||||||
|
// The full spec will be published soon.
|
||||||
|
type SimpleHandle struct {
|
||||||
|
BasicHandle
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *SimpleHandle) newEncDriver(w encWriter) encDriver {
|
||||||
|
return &simpleEncDriver{w: w, h: h}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *SimpleHandle) newDecDriver(r decReader) decDriver {
|
||||||
|
return &simpleDecDriver{r: r, h: h}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_ *SimpleHandle) writeExt() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *SimpleHandle) getBasicHandle() *BasicHandle {
|
||||||
|
return &h.BasicHandle
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ decDriver = (*simpleDecDriver)(nil)
|
||||||
|
var _ encDriver = (*simpleEncDriver)(nil)
|
||||||
193
vendor/github.com/hashicorp/go-msgpack/codec/time.go
generated
vendored
Normal file
193
vendor/github.com/hashicorp/go-msgpack/codec/time.go
generated
vendored
Normal file
@@ -0,0 +1,193 @@
|
|||||||
|
// Copyright (c) 2012, 2013 Ugorji Nwoke. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license found in the LICENSE file.
|
||||||
|
|
||||||
|
package codec
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
timeDigits = [...]byte{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}
|
||||||
|
)
|
||||||
|
|
||||||
|
// EncodeTime encodes a time.Time as a []byte, including
|
||||||
|
// information on the instant in time and UTC offset.
|
||||||
|
//
|
||||||
|
// Format Description
|
||||||
|
//
|
||||||
|
// A timestamp is composed of 3 components:
|
||||||
|
//
|
||||||
|
// - secs: signed integer representing seconds since unix epoch
|
||||||
|
// - nsces: unsigned integer representing fractional seconds as a
|
||||||
|
// nanosecond offset within secs, in the range 0 <= nsecs < 1e9
|
||||||
|
// - tz: signed integer representing timezone offset in minutes east of UTC,
|
||||||
|
// and a dst (daylight savings time) flag
|
||||||
|
//
|
||||||
|
// When encoding a timestamp, the first byte is the descriptor, which
|
||||||
|
// defines which components are encoded and how many bytes are used to
|
||||||
|
// encode secs and nsecs components. *If secs/nsecs is 0 or tz is UTC, it
|
||||||
|
// is not encoded in the byte array explicitly*.
|
||||||
|
//
|
||||||
|
// Descriptor 8 bits are of the form `A B C DDD EE`:
|
||||||
|
// A: Is secs component encoded? 1 = true
|
||||||
|
// B: Is nsecs component encoded? 1 = true
|
||||||
|
// C: Is tz component encoded? 1 = true
|
||||||
|
// DDD: Number of extra bytes for secs (range 0-7).
|
||||||
|
// If A = 1, secs encoded in DDD+1 bytes.
|
||||||
|
// If A = 0, secs is not encoded, and is assumed to be 0.
|
||||||
|
// If A = 1, then we need at least 1 byte to encode secs.
|
||||||
|
// DDD says the number of extra bytes beyond that 1.
|
||||||
|
// E.g. if DDD=0, then secs is represented in 1 byte.
|
||||||
|
// if DDD=2, then secs is represented in 3 bytes.
|
||||||
|
// EE: Number of extra bytes for nsecs (range 0-3).
|
||||||
|
// If B = 1, nsecs encoded in EE+1 bytes (similar to secs/DDD above)
|
||||||
|
//
|
||||||
|
// Following the descriptor bytes, subsequent bytes are:
|
||||||
|
//
|
||||||
|
// secs component encoded in `DDD + 1` bytes (if A == 1)
|
||||||
|
// nsecs component encoded in `EE + 1` bytes (if B == 1)
|
||||||
|
// tz component encoded in 2 bytes (if C == 1)
|
||||||
|
//
|
||||||
|
// secs and nsecs components are integers encoded in a BigEndian
|
||||||
|
// 2-complement encoding format.
|
||||||
|
//
|
||||||
|
// tz component is encoded as 2 bytes (16 bits). Most significant bit 15 to
|
||||||
|
// Least significant bit 0 are described below:
|
||||||
|
//
|
||||||
|
// Timezone offset has a range of -12:00 to +14:00 (ie -720 to +840 minutes).
|
||||||
|
// Bit 15 = have\_dst: set to 1 if we set the dst flag.
|
||||||
|
// Bit 14 = dst\_on: set to 1 if dst is in effect at the time, or 0 if not.
|
||||||
|
// Bits 13..0 = timezone offset in minutes. It is a signed integer in Big Endian format.
|
||||||
|
//
|
||||||
|
func encodeTime(t time.Time) []byte {
|
||||||
|
//t := rv.Interface().(time.Time)
|
||||||
|
tsecs, tnsecs := t.Unix(), t.Nanosecond()
|
||||||
|
var (
|
||||||
|
bd byte
|
||||||
|
btmp [8]byte
|
||||||
|
bs [16]byte
|
||||||
|
i int = 1
|
||||||
|
)
|
||||||
|
l := t.Location()
|
||||||
|
if l == time.UTC {
|
||||||
|
l = nil
|
||||||
|
}
|
||||||
|
if tsecs != 0 {
|
||||||
|
bd = bd | 0x80
|
||||||
|
bigen.PutUint64(btmp[:], uint64(tsecs))
|
||||||
|
f := pruneSignExt(btmp[:], tsecs >= 0)
|
||||||
|
bd = bd | (byte(7-f) << 2)
|
||||||
|
copy(bs[i:], btmp[f:])
|
||||||
|
i = i + (8 - f)
|
||||||
|
}
|
||||||
|
if tnsecs != 0 {
|
||||||
|
bd = bd | 0x40
|
||||||
|
bigen.PutUint32(btmp[:4], uint32(tnsecs))
|
||||||
|
f := pruneSignExt(btmp[:4], true)
|
||||||
|
bd = bd | byte(3-f)
|
||||||
|
copy(bs[i:], btmp[f:4])
|
||||||
|
i = i + (4 - f)
|
||||||
|
}
|
||||||
|
if l != nil {
|
||||||
|
bd = bd | 0x20
|
||||||
|
// Note that Go Libs do not give access to dst flag.
|
||||||
|
_, zoneOffset := t.Zone()
|
||||||
|
//zoneName, zoneOffset := t.Zone()
|
||||||
|
zoneOffset /= 60
|
||||||
|
z := uint16(zoneOffset)
|
||||||
|
bigen.PutUint16(btmp[:2], z)
|
||||||
|
// clear dst flags
|
||||||
|
bs[i] = btmp[0] & 0x3f
|
||||||
|
bs[i+1] = btmp[1]
|
||||||
|
i = i + 2
|
||||||
|
}
|
||||||
|
bs[0] = bd
|
||||||
|
return bs[0:i]
|
||||||
|
}
|
||||||
|
|
||||||
|
// DecodeTime decodes a []byte into a time.Time.
|
||||||
|
func decodeTime(bs []byte) (tt time.Time, err error) {
|
||||||
|
bd := bs[0]
|
||||||
|
var (
|
||||||
|
tsec int64
|
||||||
|
tnsec uint32
|
||||||
|
tz uint16
|
||||||
|
i byte = 1
|
||||||
|
i2 byte
|
||||||
|
n byte
|
||||||
|
)
|
||||||
|
if bd&(1<<7) != 0 {
|
||||||
|
var btmp [8]byte
|
||||||
|
n = ((bd >> 2) & 0x7) + 1
|
||||||
|
i2 = i + n
|
||||||
|
copy(btmp[8-n:], bs[i:i2])
|
||||||
|
//if first bit of bs[i] is set, then fill btmp[0..8-n] with 0xff (ie sign extend it)
|
||||||
|
if bs[i]&(1<<7) != 0 {
|
||||||
|
copy(btmp[0:8-n], bsAll0xff)
|
||||||
|
//for j,k := byte(0), 8-n; j < k; j++ { btmp[j] = 0xff }
|
||||||
|
}
|
||||||
|
i = i2
|
||||||
|
tsec = int64(bigen.Uint64(btmp[:]))
|
||||||
|
}
|
||||||
|
if bd&(1<<6) != 0 {
|
||||||
|
var btmp [4]byte
|
||||||
|
n = (bd & 0x3) + 1
|
||||||
|
i2 = i + n
|
||||||
|
copy(btmp[4-n:], bs[i:i2])
|
||||||
|
i = i2
|
||||||
|
tnsec = bigen.Uint32(btmp[:])
|
||||||
|
}
|
||||||
|
if bd&(1<<5) == 0 {
|
||||||
|
tt = time.Unix(tsec, int64(tnsec)).UTC()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// In stdlib time.Parse, when a date is parsed without a zone name, it uses "" as zone name.
|
||||||
|
// However, we need name here, so it can be shown when time is printed.
|
||||||
|
// Zone name is in form: UTC-08:00.
|
||||||
|
// Note that Go Libs do not give access to dst flag, so we ignore dst bits
|
||||||
|
|
||||||
|
i2 = i + 2
|
||||||
|
tz = bigen.Uint16(bs[i:i2])
|
||||||
|
i = i2
|
||||||
|
// sign extend sign bit into top 2 MSB (which were dst bits):
|
||||||
|
if tz&(1<<13) == 0 { // positive
|
||||||
|
tz = tz & 0x3fff //clear 2 MSBs: dst bits
|
||||||
|
} else { // negative
|
||||||
|
tz = tz | 0xc000 //set 2 MSBs: dst bits
|
||||||
|
//tzname[3] = '-' (TODO: verify. this works here)
|
||||||
|
}
|
||||||
|
tzint := int16(tz)
|
||||||
|
if tzint == 0 {
|
||||||
|
tt = time.Unix(tsec, int64(tnsec)).UTC()
|
||||||
|
} else {
|
||||||
|
// For Go Time, do not use a descriptive timezone.
|
||||||
|
// It's unnecessary, and makes it harder to do a reflect.DeepEqual.
|
||||||
|
// The Offset already tells what the offset should be, if not on UTC and unknown zone name.
|
||||||
|
// var zoneName = timeLocUTCName(tzint)
|
||||||
|
tt = time.Unix(tsec, int64(tnsec)).In(time.FixedZone("", int(tzint)*60))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func timeLocUTCName(tzint int16) string {
|
||||||
|
if tzint == 0 {
|
||||||
|
return "UTC"
|
||||||
|
}
|
||||||
|
var tzname = []byte("UTC+00:00")
|
||||||
|
//tzname := fmt.Sprintf("UTC%s%02d:%02d", tzsign, tz/60, tz%60) //perf issue using Sprintf. inline below.
|
||||||
|
//tzhr, tzmin := tz/60, tz%60 //faster if u convert to int first
|
||||||
|
var tzhr, tzmin int16
|
||||||
|
if tzint < 0 {
|
||||||
|
tzname[3] = '-' // (TODO: verify. this works here)
|
||||||
|
tzhr, tzmin = -tzint/60, (-tzint)%60
|
||||||
|
} else {
|
||||||
|
tzhr, tzmin = tzint/60, tzint%60
|
||||||
|
}
|
||||||
|
tzname[4] = timeDigits[tzhr/10]
|
||||||
|
tzname[5] = timeDigits[tzhr%10]
|
||||||
|
tzname[7] = timeDigits[tzmin/10]
|
||||||
|
tzname[8] = timeDigits[tzmin%10]
|
||||||
|
return string(tzname)
|
||||||
|
//return time.FixedZone(string(tzname), int(tzint)*60)
|
||||||
|
}
|
||||||
21
vendor/github.com/hashicorp/net-rpc-msgpackrpc/LICENSE.md
generated
vendored
Normal file
21
vendor/github.com/hashicorp/net-rpc-msgpackrpc/LICENSE.md
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2013 HashiCorp, Inc.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
9
vendor/github.com/hashicorp/net-rpc-msgpackrpc/README.md
generated
vendored
Normal file
9
vendor/github.com/hashicorp/net-rpc-msgpackrpc/README.md
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# net-rpc-msgpackrpc
|
||||||
|
|
||||||
|
This library provides the same functions as `net/rpc/jsonrpc` but for
|
||||||
|
communicating with [MessagePack](http://msgpack.org/) instead. The library
|
||||||
|
is modeled directly after the Go standard library so it should be easy to
|
||||||
|
use and obvious.
|
||||||
|
|
||||||
|
See the [GoDoc](http://godoc.org/github.com/hashicorp/net-rpc-msgpackrpc) for
|
||||||
|
API documentation.
|
||||||
43
vendor/github.com/hashicorp/net-rpc-msgpackrpc/client.go
generated
vendored
Normal file
43
vendor/github.com/hashicorp/net-rpc-msgpackrpc/client.go
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package msgpackrpc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"net/rpc"
|
||||||
|
"sync/atomic"
|
||||||
|
|
||||||
|
"github.com/hashicorp/go-multierror"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// nextCallSeq is used to assign a unique sequence number
|
||||||
|
// to each call made with CallWithCodec
|
||||||
|
nextCallSeq uint64
|
||||||
|
)
|
||||||
|
|
||||||
|
// CallWithCodec is used to perform the same actions as rpc.Client.Call but
|
||||||
|
// in a much cheaper way. It assumes the underlying connection is not being
|
||||||
|
// shared with multiple concurrent RPCs. The request/response must be syncronous.
|
||||||
|
func CallWithCodec(cc rpc.ClientCodec, method string, args interface{}, resp interface{}) error {
|
||||||
|
request := rpc.Request{
|
||||||
|
Seq: atomic.AddUint64(&nextCallSeq, 1),
|
||||||
|
ServiceMethod: method,
|
||||||
|
}
|
||||||
|
if err := cc.WriteRequest(&request, args); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var response rpc.Response
|
||||||
|
if err := cc.ReadResponseHeader(&response); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if response.Error != "" {
|
||||||
|
err := errors.New(response.Error)
|
||||||
|
if readErr := cc.ReadResponseBody(nil); readErr != nil {
|
||||||
|
err = multierror.Append(err, readErr)
|
||||||
|
}
|
||||||
|
return rpc.ServerError(err.Error())
|
||||||
|
}
|
||||||
|
if err := cc.ReadResponseBody(resp); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
122
vendor/github.com/hashicorp/net-rpc-msgpackrpc/codec.go
generated
vendored
Normal file
122
vendor/github.com/hashicorp/net-rpc-msgpackrpc/codec.go
generated
vendored
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
package msgpackrpc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"io"
|
||||||
|
"net/rpc"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/hashicorp/go-msgpack/codec"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// msgpackHandle is shared handle for decoding
|
||||||
|
msgpackHandle = &codec.MsgpackHandle{}
|
||||||
|
)
|
||||||
|
|
||||||
|
// MsgpackCodec implements the rpc.ClientCodec and rpc.ServerCodec
|
||||||
|
// using the msgpack encoding
|
||||||
|
type MsgpackCodec struct {
|
||||||
|
closed bool
|
||||||
|
conn io.ReadWriteCloser
|
||||||
|
bufR *bufio.Reader
|
||||||
|
bufW *bufio.Writer
|
||||||
|
enc *codec.Encoder
|
||||||
|
dec *codec.Decoder
|
||||||
|
writeLock sync.Mutex
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewCodec returns a MsgpackCodec that can be used as either a Client or Server
|
||||||
|
// rpc Codec using a default handle. It also provides controls for enabling and
|
||||||
|
// disabling buffering for both reads and writes.
|
||||||
|
func NewCodec(bufReads, bufWrites bool, conn io.ReadWriteCloser) *MsgpackCodec {
|
||||||
|
return NewCodecFromHandle(bufReads, bufWrites, conn, msgpackHandle)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewCodecFromHandle returns a MsgpackCodec that can be used as either a Client
|
||||||
|
// or Server rpc Codec using the passed handle. It also provides controls for
|
||||||
|
// enabling and disabling buffering for both reads and writes.
|
||||||
|
func NewCodecFromHandle(bufReads, bufWrites bool, conn io.ReadWriteCloser,
|
||||||
|
h *codec.MsgpackHandle) *MsgpackCodec {
|
||||||
|
cc := &MsgpackCodec{
|
||||||
|
conn: conn,
|
||||||
|
}
|
||||||
|
if bufReads {
|
||||||
|
cc.bufR = bufio.NewReader(conn)
|
||||||
|
cc.dec = codec.NewDecoder(cc.bufR, h)
|
||||||
|
} else {
|
||||||
|
cc.dec = codec.NewDecoder(cc.conn, h)
|
||||||
|
}
|
||||||
|
if bufWrites {
|
||||||
|
cc.bufW = bufio.NewWriter(conn)
|
||||||
|
cc.enc = codec.NewEncoder(cc.bufW, h)
|
||||||
|
} else {
|
||||||
|
cc.enc = codec.NewEncoder(cc.conn, h)
|
||||||
|
}
|
||||||
|
return cc
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cc *MsgpackCodec) ReadRequestHeader(r *rpc.Request) error {
|
||||||
|
return cc.read(r)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cc *MsgpackCodec) ReadRequestBody(out interface{}) error {
|
||||||
|
return cc.read(out)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cc *MsgpackCodec) WriteResponse(r *rpc.Response, body interface{}) error {
|
||||||
|
cc.writeLock.Lock()
|
||||||
|
defer cc.writeLock.Unlock()
|
||||||
|
return cc.write(r, body)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cc *MsgpackCodec) ReadResponseHeader(r *rpc.Response) error {
|
||||||
|
return cc.read(r)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cc *MsgpackCodec) ReadResponseBody(out interface{}) error {
|
||||||
|
return cc.read(out)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cc *MsgpackCodec) WriteRequest(r *rpc.Request, body interface{}) error {
|
||||||
|
cc.writeLock.Lock()
|
||||||
|
defer cc.writeLock.Unlock()
|
||||||
|
return cc.write(r, body)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cc *MsgpackCodec) Close() error {
|
||||||
|
if cc.closed {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
cc.closed = true
|
||||||
|
return cc.conn.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cc *MsgpackCodec) write(obj1, obj2 interface{}) (err error) {
|
||||||
|
if cc.closed {
|
||||||
|
return io.EOF
|
||||||
|
}
|
||||||
|
if err = cc.enc.Encode(obj1); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = cc.enc.Encode(obj2); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if cc.bufW != nil {
|
||||||
|
return cc.bufW.Flush()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cc *MsgpackCodec) read(obj interface{}) (err error) {
|
||||||
|
if cc.closed {
|
||||||
|
return io.EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
// If nil is passed in, we should still attempt to read content to nowhere.
|
||||||
|
if obj == nil {
|
||||||
|
var obj2 interface{}
|
||||||
|
return cc.dec.Decode(&obj2)
|
||||||
|
}
|
||||||
|
return cc.dec.Decode(obj)
|
||||||
|
}
|
||||||
42
vendor/github.com/hashicorp/net-rpc-msgpackrpc/msgpackrpc.go
generated
vendored
Normal file
42
vendor/github.com/hashicorp/net-rpc-msgpackrpc/msgpackrpc.go
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
// Package msgpackrpc implements a MessagePack-RPC ClientCodec and ServerCodec
|
||||||
|
// for the rpc package, using the same API as the Go standard library
|
||||||
|
// for jsonrpc.
|
||||||
|
package msgpackrpc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"net"
|
||||||
|
"net/rpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Dial connects to a MessagePack-RPC server at the specified network address.
|
||||||
|
func Dial(network, address string) (*rpc.Client, error) {
|
||||||
|
conn, err := net.Dial(network, address)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return NewClient(conn), err
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClient returns a new rpc.Client to handle requests to the set of
|
||||||
|
// services at the other end of the connection.
|
||||||
|
func NewClient(conn io.ReadWriteCloser) *rpc.Client {
|
||||||
|
return rpc.NewClientWithCodec(NewClientCodec(conn))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClientCodec returns a new rpc.ClientCodec using MessagePack-RPC on conn.
|
||||||
|
func NewClientCodec(conn io.ReadWriteCloser) rpc.ClientCodec {
|
||||||
|
return NewCodec(true, true, conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewServerCodec returns a new rpc.ServerCodec using MessagePack-RPC on conn.
|
||||||
|
func NewServerCodec(conn io.ReadWriteCloser) rpc.ServerCodec {
|
||||||
|
return NewCodec(true, true, conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ServeConn runs the MessagePack-RPC server on a single connection. ServeConn
|
||||||
|
// blocks, serving the connection until the client hangs up. The caller
|
||||||
|
// typically invokes ServeConn in a go statement.
|
||||||
|
func ServeConn(conn io.ReadWriteCloser) {
|
||||||
|
rpc.ServeCodec(NewServerCodec(conn))
|
||||||
|
}
|
||||||
363
vendor/github.com/hashicorp/scada-client/LICENSE
generated
vendored
Normal file
363
vendor/github.com/hashicorp/scada-client/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,363 @@
|
|||||||
|
Mozilla Public License, version 2.0
|
||||||
|
|
||||||
|
1. Definitions
|
||||||
|
|
||||||
|
1.1. "Contributor"
|
||||||
|
|
||||||
|
means each individual or legal entity that creates, contributes to the
|
||||||
|
creation of, or owns Covered Software.
|
||||||
|
|
||||||
|
1.2. "Contributor Version"
|
||||||
|
|
||||||
|
means the combination of the Contributions of others (if any) used by a
|
||||||
|
Contributor and that particular Contributor's Contribution.
|
||||||
|
|
||||||
|
1.3. "Contribution"
|
||||||
|
|
||||||
|
means Covered Software of a particular Contributor.
|
||||||
|
|
||||||
|
1.4. "Covered Software"
|
||||||
|
|
||||||
|
means Source Code Form to which the initial Contributor has attached the
|
||||||
|
notice in Exhibit A, the Executable Form of such Source Code Form, and
|
||||||
|
Modifications of such Source Code Form, in each case including portions
|
||||||
|
thereof.
|
||||||
|
|
||||||
|
1.5. "Incompatible With Secondary Licenses"
|
||||||
|
means
|
||||||
|
|
||||||
|
a. that the initial Contributor has attached the notice described in
|
||||||
|
Exhibit B to the Covered Software; or
|
||||||
|
|
||||||
|
b. that the Covered Software was made available under the terms of
|
||||||
|
version 1.1 or earlier of the License, but not also under the terms of
|
||||||
|
a Secondary License.
|
||||||
|
|
||||||
|
1.6. "Executable Form"
|
||||||
|
|
||||||
|
means any form of the work other than Source Code Form.
|
||||||
|
|
||||||
|
1.7. "Larger Work"
|
||||||
|
|
||||||
|
means a work that combines Covered Software with other material, in a
|
||||||
|
separate file or files, that is not Covered Software.
|
||||||
|
|
||||||
|
1.8. "License"
|
||||||
|
|
||||||
|
means this document.
|
||||||
|
|
||||||
|
1.9. "Licensable"
|
||||||
|
|
||||||
|
means having the right to grant, to the maximum extent possible, whether
|
||||||
|
at the time of the initial grant or subsequently, any and all of the
|
||||||
|
rights conveyed by this License.
|
||||||
|
|
||||||
|
1.10. "Modifications"
|
||||||
|
|
||||||
|
means any of the following:
|
||||||
|
|
||||||
|
a. any file in Source Code Form that results from an addition to,
|
||||||
|
deletion from, or modification of the contents of Covered Software; or
|
||||||
|
|
||||||
|
b. any new file in Source Code Form that contains any Covered Software.
|
||||||
|
|
||||||
|
1.11. "Patent Claims" of a Contributor
|
||||||
|
|
||||||
|
means any patent claim(s), including without limitation, method,
|
||||||
|
process, and apparatus claims, in any patent Licensable by such
|
||||||
|
Contributor that would be infringed, but for the grant of the License,
|
||||||
|
by the making, using, selling, offering for sale, having made, import,
|
||||||
|
or transfer of either its Contributions or its Contributor Version.
|
||||||
|
|
||||||
|
1.12. "Secondary License"
|
||||||
|
|
||||||
|
means either the GNU General Public License, Version 2.0, the GNU Lesser
|
||||||
|
General Public License, Version 2.1, the GNU Affero General Public
|
||||||
|
License, Version 3.0, or any later versions of those licenses.
|
||||||
|
|
||||||
|
1.13. "Source Code Form"
|
||||||
|
|
||||||
|
means the form of the work preferred for making modifications.
|
||||||
|
|
||||||
|
1.14. "You" (or "Your")
|
||||||
|
|
||||||
|
means an individual or a legal entity exercising rights under this
|
||||||
|
License. For legal entities, "You" includes any entity that controls, is
|
||||||
|
controlled by, or is under common control with You. For purposes of this
|
||||||
|
definition, "control" means (a) the power, direct or indirect, to cause
|
||||||
|
the direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (b) ownership of more than fifty percent (50%) of the
|
||||||
|
outstanding shares or beneficial ownership of such entity.
|
||||||
|
|
||||||
|
|
||||||
|
2. License Grants and Conditions
|
||||||
|
|
||||||
|
2.1. Grants
|
||||||
|
|
||||||
|
Each Contributor hereby grants You a world-wide, royalty-free,
|
||||||
|
non-exclusive license:
|
||||||
|
|
||||||
|
a. under intellectual property rights (other than patent or trademark)
|
||||||
|
Licensable by such Contributor to use, reproduce, make available,
|
||||||
|
modify, display, perform, distribute, and otherwise exploit its
|
||||||
|
Contributions, either on an unmodified basis, with Modifications, or
|
||||||
|
as part of a Larger Work; and
|
||||||
|
|
||||||
|
b. under Patent Claims of such Contributor to make, use, sell, offer for
|
||||||
|
sale, have made, import, and otherwise transfer either its
|
||||||
|
Contributions or its Contributor Version.
|
||||||
|
|
||||||
|
2.2. Effective Date
|
||||||
|
|
||||||
|
The licenses granted in Section 2.1 with respect to any Contribution
|
||||||
|
become effective for each Contribution on the date the Contributor first
|
||||||
|
distributes such Contribution.
|
||||||
|
|
||||||
|
2.3. Limitations on Grant Scope
|
||||||
|
|
||||||
|
The licenses granted in this Section 2 are the only rights granted under
|
||||||
|
this License. No additional rights or licenses will be implied from the
|
||||||
|
distribution or licensing of Covered Software under this License.
|
||||||
|
Notwithstanding Section 2.1(b) above, no patent license is granted by a
|
||||||
|
Contributor:
|
||||||
|
|
||||||
|
a. for any code that a Contributor has removed from Covered Software; or
|
||||||
|
|
||||||
|
b. for infringements caused by: (i) Your and any other third party's
|
||||||
|
modifications of Covered Software, or (ii) the combination of its
|
||||||
|
Contributions with other software (except as part of its Contributor
|
||||||
|
Version); or
|
||||||
|
|
||||||
|
c. under Patent Claims infringed by Covered Software in the absence of
|
||||||
|
its Contributions.
|
||||||
|
|
||||||
|
This License does not grant any rights in the trademarks, service marks,
|
||||||
|
or logos of any Contributor (except as may be necessary to comply with
|
||||||
|
the notice requirements in Section 3.4).
|
||||||
|
|
||||||
|
2.4. Subsequent Licenses
|
||||||
|
|
||||||
|
No Contributor makes additional grants as a result of Your choice to
|
||||||
|
distribute the Covered Software under a subsequent version of this
|
||||||
|
License (see Section 10.2) or under the terms of a Secondary License (if
|
||||||
|
permitted under the terms of Section 3.3).
|
||||||
|
|
||||||
|
2.5. Representation
|
||||||
|
|
||||||
|
Each Contributor represents that the Contributor believes its
|
||||||
|
Contributions are its original creation(s) or it has sufficient rights to
|
||||||
|
grant the rights to its Contributions conveyed by this License.
|
||||||
|
|
||||||
|
2.6. Fair Use
|
||||||
|
|
||||||
|
This License is not intended to limit any rights You have under
|
||||||
|
applicable copyright doctrines of fair use, fair dealing, or other
|
||||||
|
equivalents.
|
||||||
|
|
||||||
|
2.7. Conditions
|
||||||
|
|
||||||
|
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in
|
||||||
|
Section 2.1.
|
||||||
|
|
||||||
|
|
||||||
|
3. Responsibilities
|
||||||
|
|
||||||
|
3.1. Distribution of Source Form
|
||||||
|
|
||||||
|
All distribution of Covered Software in Source Code Form, including any
|
||||||
|
Modifications that You create or to which You contribute, must be under
|
||||||
|
the terms of this License. You must inform recipients that the Source
|
||||||
|
Code Form of the Covered Software is governed by the terms of this
|
||||||
|
License, and how they can obtain a copy of this License. You may not
|
||||||
|
attempt to alter or restrict the recipients' rights in the Source Code
|
||||||
|
Form.
|
||||||
|
|
||||||
|
3.2. Distribution of Executable Form
|
||||||
|
|
||||||
|
If You distribute Covered Software in Executable Form then:
|
||||||
|
|
||||||
|
a. such Covered Software must also be made available in Source Code Form,
|
||||||
|
as described in Section 3.1, and You must inform recipients of the
|
||||||
|
Executable Form how they can obtain a copy of such Source Code Form by
|
||||||
|
reasonable means in a timely manner, at a charge no more than the cost
|
||||||
|
of distribution to the recipient; and
|
||||||
|
|
||||||
|
b. You may distribute such Executable Form under the terms of this
|
||||||
|
License, or sublicense it under different terms, provided that the
|
||||||
|
license for the Executable Form does not attempt to limit or alter the
|
||||||
|
recipients' rights in the Source Code Form under this License.
|
||||||
|
|
||||||
|
3.3. Distribution of a Larger Work
|
||||||
|
|
||||||
|
You may create and distribute a Larger Work under terms of Your choice,
|
||||||
|
provided that You also comply with the requirements of this License for
|
||||||
|
the Covered Software. If the Larger Work is a combination of Covered
|
||||||
|
Software with a work governed by one or more Secondary Licenses, and the
|
||||||
|
Covered Software is not Incompatible With Secondary Licenses, this
|
||||||
|
License permits You to additionally distribute such Covered Software
|
||||||
|
under the terms of such Secondary License(s), so that the recipient of
|
||||||
|
the Larger Work may, at their option, further distribute the Covered
|
||||||
|
Software under the terms of either this License or such Secondary
|
||||||
|
License(s).
|
||||||
|
|
||||||
|
3.4. Notices
|
||||||
|
|
||||||
|
You may not remove or alter the substance of any license notices
|
||||||
|
(including copyright notices, patent notices, disclaimers of warranty, or
|
||||||
|
limitations of liability) contained within the Source Code Form of the
|
||||||
|
Covered Software, except that You may alter any license notices to the
|
||||||
|
extent required to remedy known factual inaccuracies.
|
||||||
|
|
||||||
|
3.5. Application of Additional Terms
|
||||||
|
|
||||||
|
You may choose to offer, and to charge a fee for, warranty, support,
|
||||||
|
indemnity or liability obligations to one or more recipients of Covered
|
||||||
|
Software. However, You may do so only on Your own behalf, and not on
|
||||||
|
behalf of any Contributor. You must make it absolutely clear that any
|
||||||
|
such warranty, support, indemnity, or liability obligation is offered by
|
||||||
|
You alone, and You hereby agree to indemnify every Contributor for any
|
||||||
|
liability incurred by such Contributor as a result of warranty, support,
|
||||||
|
indemnity or liability terms You offer. You may include additional
|
||||||
|
disclaimers of warranty and limitations of liability specific to any
|
||||||
|
jurisdiction.
|
||||||
|
|
||||||
|
4. Inability to Comply Due to Statute or Regulation
|
||||||
|
|
||||||
|
If it is impossible for You to comply with any of the terms of this License
|
||||||
|
with respect to some or all of the Covered Software due to statute,
|
||||||
|
judicial order, or regulation then You must: (a) comply with the terms of
|
||||||
|
this License to the maximum extent possible; and (b) describe the
|
||||||
|
limitations and the code they affect. Such description must be placed in a
|
||||||
|
text file included with all distributions of the Covered Software under
|
||||||
|
this License. Except to the extent prohibited by statute or regulation,
|
||||||
|
such description must be sufficiently detailed for a recipient of ordinary
|
||||||
|
skill to be able to understand it.
|
||||||
|
|
||||||
|
5. Termination
|
||||||
|
|
||||||
|
5.1. The rights granted under this License will terminate automatically if You
|
||||||
|
fail to comply with any of its terms. However, if You become compliant,
|
||||||
|
then the rights granted under this License from a particular Contributor
|
||||||
|
are reinstated (a) provisionally, unless and until such Contributor
|
||||||
|
explicitly and finally terminates Your grants, and (b) on an ongoing
|
||||||
|
basis, if such Contributor fails to notify You of the non-compliance by
|
||||||
|
some reasonable means prior to 60 days after You have come back into
|
||||||
|
compliance. Moreover, Your grants from a particular Contributor are
|
||||||
|
reinstated on an ongoing basis if such Contributor notifies You of the
|
||||||
|
non-compliance by some reasonable means, this is the first time You have
|
||||||
|
received notice of non-compliance with this License from such
|
||||||
|
Contributor, and You become compliant prior to 30 days after Your receipt
|
||||||
|
of the notice.
|
||||||
|
|
||||||
|
5.2. If You initiate litigation against any entity by asserting a patent
|
||||||
|
infringement claim (excluding declaratory judgment actions,
|
||||||
|
counter-claims, and cross-claims) alleging that a Contributor Version
|
||||||
|
directly or indirectly infringes any patent, then the rights granted to
|
||||||
|
You by any and all Contributors for the Covered Software under Section
|
||||||
|
2.1 of this License shall terminate.
|
||||||
|
|
||||||
|
5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user
|
||||||
|
license agreements (excluding distributors and resellers) which have been
|
||||||
|
validly granted by You or Your distributors under this License prior to
|
||||||
|
termination shall survive termination.
|
||||||
|
|
||||||
|
6. Disclaimer of Warranty
|
||||||
|
|
||||||
|
Covered Software is provided under this License on an "as is" basis,
|
||||||
|
without warranty of any kind, either expressed, implied, or statutory,
|
||||||
|
including, without limitation, warranties that the Covered Software is free
|
||||||
|
of defects, merchantable, fit for a particular purpose or non-infringing.
|
||||||
|
The entire risk as to the quality and performance of the Covered Software
|
||||||
|
is with You. Should any Covered Software prove defective in any respect,
|
||||||
|
You (not any Contributor) assume the cost of any necessary servicing,
|
||||||
|
repair, or correction. This disclaimer of warranty constitutes an essential
|
||||||
|
part of this License. No use of any Covered Software is authorized under
|
||||||
|
this License except under this disclaimer.
|
||||||
|
|
||||||
|
7. Limitation of Liability
|
||||||
|
|
||||||
|
Under no circumstances and under no legal theory, whether tort (including
|
||||||
|
negligence), contract, or otherwise, shall any Contributor, or anyone who
|
||||||
|
distributes Covered Software as permitted above, be liable to You for any
|
||||||
|
direct, indirect, special, incidental, or consequential damages of any
|
||||||
|
character including, without limitation, damages for lost profits, loss of
|
||||||
|
goodwill, work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses, even if such party shall have been
|
||||||
|
informed of the possibility of such damages. This limitation of liability
|
||||||
|
shall not apply to liability for death or personal injury resulting from
|
||||||
|
such party's negligence to the extent applicable law prohibits such
|
||||||
|
limitation. Some jurisdictions do not allow the exclusion or limitation of
|
||||||
|
incidental or consequential damages, so this exclusion and limitation may
|
||||||
|
not apply to You.
|
||||||
|
|
||||||
|
8. Litigation
|
||||||
|
|
||||||
|
Any litigation relating to this License may be brought only in the courts
|
||||||
|
of a jurisdiction where the defendant maintains its principal place of
|
||||||
|
business and such litigation shall be governed by laws of that
|
||||||
|
jurisdiction, without reference to its conflict-of-law provisions. Nothing
|
||||||
|
in this Section shall prevent a party's ability to bring cross-claims or
|
||||||
|
counter-claims.
|
||||||
|
|
||||||
|
9. Miscellaneous
|
||||||
|
|
||||||
|
This License represents the complete agreement concerning the subject
|
||||||
|
matter hereof. If any provision of this License is held to be
|
||||||
|
unenforceable, such provision shall be reformed only to the extent
|
||||||
|
necessary to make it enforceable. Any law or regulation which provides that
|
||||||
|
the language of a contract shall be construed against the drafter shall not
|
||||||
|
be used to construe this License against a Contributor.
|
||||||
|
|
||||||
|
|
||||||
|
10. Versions of the License
|
||||||
|
|
||||||
|
10.1. New Versions
|
||||||
|
|
||||||
|
Mozilla Foundation is the license steward. Except as provided in Section
|
||||||
|
10.3, no one other than the license steward has the right to modify or
|
||||||
|
publish new versions of this License. Each version will be given a
|
||||||
|
distinguishing version number.
|
||||||
|
|
||||||
|
10.2. Effect of New Versions
|
||||||
|
|
||||||
|
You may distribute the Covered Software under the terms of the version
|
||||||
|
of the License under which You originally received the Covered Software,
|
||||||
|
or under the terms of any subsequent version published by the license
|
||||||
|
steward.
|
||||||
|
|
||||||
|
10.3. Modified Versions
|
||||||
|
|
||||||
|
If you create software not governed by this License, and you want to
|
||||||
|
create a new license for such software, you may create and use a
|
||||||
|
modified version of this License if you rename the license and remove
|
||||||
|
any references to the name of the license steward (except to note that
|
||||||
|
such modified license differs from this License).
|
||||||
|
|
||||||
|
10.4. Distributing Source Code Form that is Incompatible With Secondary
|
||||||
|
Licenses If You choose to distribute Source Code Form that is
|
||||||
|
Incompatible With Secondary Licenses under the terms of this version of
|
||||||
|
the License, the notice described in Exhibit B of this License must be
|
||||||
|
attached.
|
||||||
|
|
||||||
|
Exhibit A - Source Code Form License Notice
|
||||||
|
|
||||||
|
This Source Code Form is subject to the
|
||||||
|
terms of the Mozilla Public License, v.
|
||||||
|
2.0. If a copy of the MPL was not
|
||||||
|
distributed with this file, You can
|
||||||
|
obtain one at
|
||||||
|
http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
If it is not possible or desirable to put the notice in a particular file,
|
||||||
|
then You may include the notice in a location (such as a LICENSE file in a
|
||||||
|
relevant directory) where a recipient would be likely to look for such a
|
||||||
|
notice.
|
||||||
|
|
||||||
|
You may add additional accurate notices of copyright ownership.
|
||||||
|
|
||||||
|
Exhibit B - "Incompatible With Secondary Licenses" Notice
|
||||||
|
|
||||||
|
This Source Code Form is "Incompatible
|
||||||
|
With Secondary Licenses", as defined by
|
||||||
|
the Mozilla Public License, v. 2.0.
|
||||||
|
|
||||||
23
vendor/github.com/hashicorp/scada-client/README.md
generated
vendored
Normal file
23
vendor/github.com/hashicorp/scada-client/README.md
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# SCADA Client
|
||||||
|
|
||||||
|
This library provides a Golang client for the [HashiCorp SCADA service](http://scada.hashicorp.com).
|
||||||
|
SCADA stands for Supervisory Control And Data Acquisition, and as the name implies it allows
|
||||||
|
[Atlas](https://atlas.hashicorp.com) to provide control functions and request data from the tools that integrate.
|
||||||
|
|
||||||
|
The technical details about how SCADA works are fairly simple. Clients first open a connection to
|
||||||
|
the SCADA service at scada.hashicorp.com on port 7223. This connection is secured by TLS, allowing
|
||||||
|
clients to verify the identity of the servers and to encrypt all communications. Once connected, a
|
||||||
|
handshake is performed where a client provides it's Atlas API credentials so that Atlas can verify
|
||||||
|
the client identity. Once complete, clients keep the connection open in an idle state waiting for
|
||||||
|
commands to be received. Commands map to APIs exposed by the product, and are subject to any ACLs,
|
||||||
|
authentication or authorization mechanisms of the client.
|
||||||
|
|
||||||
|
This library is used in various HashiCorp products to integrate with the SCADA system.
|
||||||
|
|
||||||
|
## Environmental Variables
|
||||||
|
|
||||||
|
This library respects the following environment variables:
|
||||||
|
|
||||||
|
* ATLAS_TOKEN: The Atlas token to use for authentication
|
||||||
|
* SCADA_ENDPOINT: Overrides the default SCADA endpoint
|
||||||
|
|
||||||
146
vendor/github.com/hashicorp/scada-client/client.go
generated
vendored
Normal file
146
vendor/github.com/hashicorp/scada-client/client.go
generated
vendored
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
package client
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/tls"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/hashicorp/net-rpc-msgpackrpc"
|
||||||
|
"github.com/hashicorp/yamux"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// clientPreamble is the preamble to send before upgrading
|
||||||
|
// the connection into a SCADA version 1 connection.
|
||||||
|
clientPreamble = "SCADA 1\n"
|
||||||
|
|
||||||
|
// rpcTimeout is how long of a read deadline we provide
|
||||||
|
rpcTimeout = 10 * time.Second
|
||||||
|
)
|
||||||
|
|
||||||
|
// Opts is used to parameterize a Dial
|
||||||
|
type Opts struct {
|
||||||
|
// Addr is the dial address
|
||||||
|
Addr string
|
||||||
|
|
||||||
|
// TLS controls if TLS is used
|
||||||
|
TLS bool
|
||||||
|
|
||||||
|
// TLSConfig or nil for default
|
||||||
|
TLSConfig *tls.Config
|
||||||
|
|
||||||
|
// Modifies the log output
|
||||||
|
LogOutput io.Writer
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client is a SCADA compatible client. This is a bare bones client that
|
||||||
|
// only handles the framing and RPC protocol. Higher-level clients should
|
||||||
|
// be prefered.
|
||||||
|
type Client struct {
|
||||||
|
conn net.Conn
|
||||||
|
client *yamux.Session
|
||||||
|
|
||||||
|
closed bool
|
||||||
|
closedLock sync.Mutex
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dial is used to establish a new connection over TCP
|
||||||
|
func Dial(addr string) (*Client, error) {
|
||||||
|
opts := Opts{Addr: addr, TLS: false}
|
||||||
|
return DialOpts(&opts)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DialTLS is used to establish a new connection using TLS/TCP
|
||||||
|
func DialTLS(addr string, tlsConf *tls.Config) (*Client, error) {
|
||||||
|
opts := Opts{Addr: addr, TLS: true, TLSConfig: tlsConf}
|
||||||
|
return DialOpts(&opts)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DialOpts is a parameterized Dial
|
||||||
|
func DialOpts(opts *Opts) (*Client, error) {
|
||||||
|
var conn net.Conn
|
||||||
|
var err error
|
||||||
|
if opts.TLS {
|
||||||
|
conn, err = tls.Dial("tcp", opts.Addr, opts.TLSConfig)
|
||||||
|
} else {
|
||||||
|
conn, err = net.DialTimeout("tcp", opts.Addr, 10*time.Second)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return initClient(conn, opts)
|
||||||
|
}
|
||||||
|
|
||||||
|
// initClient does the common initialization
|
||||||
|
func initClient(conn net.Conn, opts *Opts) (*Client, error) {
|
||||||
|
// Send the preamble
|
||||||
|
_, err := conn.Write([]byte(clientPreamble))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("preamble write failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wrap the connection in yamux for multiplexing
|
||||||
|
ymConf := yamux.DefaultConfig()
|
||||||
|
if opts.LogOutput != nil {
|
||||||
|
ymConf.LogOutput = opts.LogOutput
|
||||||
|
}
|
||||||
|
client, _ := yamux.Client(conn, ymConf)
|
||||||
|
|
||||||
|
// Create the client
|
||||||
|
c := &Client{
|
||||||
|
conn: conn,
|
||||||
|
client: client,
|
||||||
|
}
|
||||||
|
return c, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close is used to terminate the client connection
|
||||||
|
func (c *Client) Close() error {
|
||||||
|
c.closedLock.Lock()
|
||||||
|
defer c.closedLock.Unlock()
|
||||||
|
|
||||||
|
if c.closed {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
c.closed = true
|
||||||
|
c.client.GoAway() // Notify the other side of the close
|
||||||
|
return c.client.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
// RPC is used to perform an RPC
|
||||||
|
func (c *Client) RPC(method string, args interface{}, resp interface{}) error {
|
||||||
|
// Get a stream
|
||||||
|
stream, err := c.Open()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to open stream: %v", err)
|
||||||
|
}
|
||||||
|
defer stream.Close()
|
||||||
|
stream.SetDeadline(time.Now().Add(rpcTimeout))
|
||||||
|
|
||||||
|
// Create the RPC client
|
||||||
|
cc := msgpackrpc.NewCodec(true, true, stream)
|
||||||
|
return msgpackrpc.CallWithCodec(cc, method, args, resp)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Accept is used to accept an incoming connection
|
||||||
|
func (c *Client) Accept() (net.Conn, error) {
|
||||||
|
return c.client.Accept()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open is used to open an outgoing connection
|
||||||
|
func (c *Client) Open() (net.Conn, error) {
|
||||||
|
return c.client.Open()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Addr is so that client can act like a net.Listener
|
||||||
|
func (c *Client) Addr() net.Addr {
|
||||||
|
return c.client.LocalAddr()
|
||||||
|
}
|
||||||
|
|
||||||
|
// NumStreams returns the number of open streams on the client
|
||||||
|
func (c *Client) NumStreams() int {
|
||||||
|
return c.client.NumStreams()
|
||||||
|
}
|
||||||
473
vendor/github.com/hashicorp/scada-client/provider.go
generated
vendored
Normal file
473
vendor/github.com/hashicorp/scada-client/provider.go
generated
vendored
Normal file
@@ -0,0 +1,473 @@
|
|||||||
|
package client
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/tls"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"math/rand"
|
||||||
|
"net"
|
||||||
|
"net/rpc"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/armon/go-metrics"
|
||||||
|
"github.com/hashicorp/net-rpc-msgpackrpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// DefaultEndpoint is the endpoint used if none is provided
|
||||||
|
DefaultEndpoint = "scada.hashicorp.com:7223"
|
||||||
|
|
||||||
|
// DefaultBackoff is the amount of time we back off if we encounter
|
||||||
|
// and error, and no specific backoff is available.
|
||||||
|
DefaultBackoff = 120 * time.Second
|
||||||
|
|
||||||
|
// DisconnectDelay is how long we delay the disconnect to allow
|
||||||
|
// the RPC to complete.
|
||||||
|
DisconnectDelay = time.Second
|
||||||
|
)
|
||||||
|
|
||||||
|
// CapabilityProvider is used to provide a given capability
|
||||||
|
// when requested remotely. They must return a connection
|
||||||
|
// that is bridged or an error.
|
||||||
|
type CapabilityProvider func(capability string, meta map[string]string, conn io.ReadWriteCloser) error
|
||||||
|
|
||||||
|
// ProviderService is the service being exposed
|
||||||
|
type ProviderService struct {
|
||||||
|
Service string
|
||||||
|
ServiceVersion string
|
||||||
|
Capabilities map[string]int
|
||||||
|
Meta map[string]string
|
||||||
|
ResourceType string
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderConfig is used to parameterize a provider
|
||||||
|
type ProviderConfig struct {
|
||||||
|
// Endpoint is the SCADA endpoint, defaults to DefaultEndpoint
|
||||||
|
Endpoint string
|
||||||
|
|
||||||
|
// Service is the service to expose
|
||||||
|
Service *ProviderService
|
||||||
|
|
||||||
|
// Handlers are invoked to provide the named capability
|
||||||
|
Handlers map[string]CapabilityProvider
|
||||||
|
|
||||||
|
// ResourceGroup is the named group e.g. "hashicorp/prod"
|
||||||
|
ResourceGroup string
|
||||||
|
|
||||||
|
// Token is the Atlas authentication token
|
||||||
|
Token string
|
||||||
|
|
||||||
|
// Optional TLS configuration, defaults used otherwise
|
||||||
|
TLSConfig *tls.Config
|
||||||
|
|
||||||
|
// LogOutput is to control the log output
|
||||||
|
LogOutput io.Writer
|
||||||
|
}
|
||||||
|
|
||||||
|
// Provider is a high-level interface to SCADA by which
|
||||||
|
// clients declare themselves as a service providing capabilities.
|
||||||
|
// Provider manages the client/server interactions required,
|
||||||
|
// making it simpler to integrate.
|
||||||
|
type Provider struct {
|
||||||
|
config *ProviderConfig
|
||||||
|
logger *log.Logger
|
||||||
|
|
||||||
|
client *Client
|
||||||
|
clientLock sync.Mutex
|
||||||
|
|
||||||
|
noRetry bool // set when the server instructs us to not retry
|
||||||
|
backoff time.Duration // set when the server provides a longer backoff
|
||||||
|
backoffLock sync.Mutex
|
||||||
|
|
||||||
|
sessionID string
|
||||||
|
sessionAuth bool
|
||||||
|
sessionLock sync.RWMutex
|
||||||
|
|
||||||
|
shutdown bool
|
||||||
|
shutdownCh chan struct{}
|
||||||
|
shutdownLock sync.Mutex
|
||||||
|
}
|
||||||
|
|
||||||
|
// validateConfig is used to sanity check the configuration
|
||||||
|
func validateConfig(config *ProviderConfig) error {
|
||||||
|
// Validate the inputs
|
||||||
|
if config == nil {
|
||||||
|
return fmt.Errorf("missing config")
|
||||||
|
}
|
||||||
|
if config.Service == nil {
|
||||||
|
return fmt.Errorf("missing service")
|
||||||
|
}
|
||||||
|
if config.Service.Service == "" {
|
||||||
|
return fmt.Errorf("missing service name")
|
||||||
|
}
|
||||||
|
if config.Service.ServiceVersion == "" {
|
||||||
|
return fmt.Errorf("missing service version")
|
||||||
|
}
|
||||||
|
if config.Service.ResourceType == "" {
|
||||||
|
return fmt.Errorf("missing service resource type")
|
||||||
|
}
|
||||||
|
if config.Handlers == nil && len(config.Service.Capabilities) != 0 {
|
||||||
|
return fmt.Errorf("missing handlers")
|
||||||
|
}
|
||||||
|
for c := range config.Service.Capabilities {
|
||||||
|
if _, ok := config.Handlers[c]; !ok {
|
||||||
|
return fmt.Errorf("missing handler for '%s' capability", c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if config.ResourceGroup == "" {
|
||||||
|
return fmt.Errorf("missing resource group")
|
||||||
|
}
|
||||||
|
if config.Token == "" {
|
||||||
|
config.Token = os.Getenv("ATLAS_TOKEN")
|
||||||
|
}
|
||||||
|
if config.Token == "" {
|
||||||
|
return fmt.Errorf("missing token")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default the endpoint
|
||||||
|
if config.Endpoint == "" {
|
||||||
|
config.Endpoint = DefaultEndpoint
|
||||||
|
if end := os.Getenv("SCADA_ENDPOINT"); end != "" {
|
||||||
|
config.Endpoint = end
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewProvider is used to create a new provider
|
||||||
|
func NewProvider(config *ProviderConfig) (*Provider, error) {
|
||||||
|
if err := validateConfig(config); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create logger
|
||||||
|
if config.LogOutput == nil {
|
||||||
|
config.LogOutput = os.Stderr
|
||||||
|
}
|
||||||
|
logger := log.New(config.LogOutput, "", log.LstdFlags)
|
||||||
|
|
||||||
|
p := &Provider{
|
||||||
|
config: config,
|
||||||
|
logger: logger,
|
||||||
|
shutdownCh: make(chan struct{}),
|
||||||
|
}
|
||||||
|
go p.run()
|
||||||
|
return p, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Shutdown is used to close the provider
|
||||||
|
func (p *Provider) Shutdown() {
|
||||||
|
p.shutdownLock.Lock()
|
||||||
|
p.shutdownLock.Unlock()
|
||||||
|
if p.shutdown {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
p.shutdown = true
|
||||||
|
close(p.shutdownCh)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsShutdown checks if we have been shutdown
|
||||||
|
func (p *Provider) IsShutdown() bool {
|
||||||
|
select {
|
||||||
|
case <-p.shutdownCh:
|
||||||
|
return true
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// backoffDuration is used to compute the next backoff duration
|
||||||
|
func (p *Provider) backoffDuration() time.Duration {
|
||||||
|
// Use the default backoff
|
||||||
|
backoff := DefaultBackoff
|
||||||
|
|
||||||
|
// Check for a server specified backoff
|
||||||
|
p.backoffLock.Lock()
|
||||||
|
if p.backoff != 0 {
|
||||||
|
backoff = p.backoff
|
||||||
|
}
|
||||||
|
if p.noRetry {
|
||||||
|
backoff = 0
|
||||||
|
}
|
||||||
|
p.backoffLock.Unlock()
|
||||||
|
|
||||||
|
return backoff
|
||||||
|
}
|
||||||
|
|
||||||
|
// wait is used to delay dialing on an error
|
||||||
|
func (p *Provider) wait() {
|
||||||
|
// Compute the backoff time
|
||||||
|
backoff := p.backoffDuration()
|
||||||
|
|
||||||
|
// Setup a wait timer
|
||||||
|
var wait <-chan time.Time
|
||||||
|
if backoff > 0 {
|
||||||
|
jitter := time.Duration(rand.Uint32()) % backoff
|
||||||
|
wait = time.After(backoff + jitter)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait until timer or shutdown
|
||||||
|
select {
|
||||||
|
case <-wait:
|
||||||
|
case <-p.shutdownCh:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// run is a long running routine to manage the provider
|
||||||
|
func (p *Provider) run() {
|
||||||
|
for !p.IsShutdown() {
|
||||||
|
// Setup a new connection
|
||||||
|
client, err := p.clientSetup()
|
||||||
|
if err != nil {
|
||||||
|
p.wait()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle the session
|
||||||
|
doneCh := make(chan struct{})
|
||||||
|
go p.handleSession(client, doneCh)
|
||||||
|
|
||||||
|
// Wait for session termination or shutdown
|
||||||
|
select {
|
||||||
|
case <-doneCh:
|
||||||
|
p.wait()
|
||||||
|
case <-p.shutdownCh:
|
||||||
|
p.clientLock.Lock()
|
||||||
|
client.Close()
|
||||||
|
p.clientLock.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// handleSession is used to handle an established session
|
||||||
|
func (p *Provider) handleSession(list net.Listener, doneCh chan struct{}) {
|
||||||
|
defer close(doneCh)
|
||||||
|
defer list.Close()
|
||||||
|
// Accept new connections
|
||||||
|
for !p.IsShutdown() {
|
||||||
|
conn, err := list.Accept()
|
||||||
|
if err != nil {
|
||||||
|
p.logger.Printf("[ERR] scada-client: failed to accept connection: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
p.logger.Printf("[DEBUG] scada-client: accepted connection")
|
||||||
|
go p.handleConnection(conn)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// handleConnection handles an incoming connection
|
||||||
|
func (p *Provider) handleConnection(conn net.Conn) {
|
||||||
|
// Create an RPC server to handle inbound
|
||||||
|
pe := &providerEndpoint{p: p}
|
||||||
|
rpcServer := rpc.NewServer()
|
||||||
|
rpcServer.RegisterName("Client", pe)
|
||||||
|
rpcCodec := msgpackrpc.NewCodec(false, false, conn)
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if !pe.hijacked() {
|
||||||
|
conn.Close()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
for !p.IsShutdown() {
|
||||||
|
if err := rpcServer.ServeRequest(rpcCodec); err != nil {
|
||||||
|
if err != io.EOF && !strings.Contains(err.Error(), "closed") {
|
||||||
|
p.logger.Printf("[ERR] scada-client: RPC error: %v", err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle potential hijack in Client.Connect
|
||||||
|
if pe.hijacked() {
|
||||||
|
cb := pe.getHijack()
|
||||||
|
cb(conn)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// clientSetup is used to setup a new connection
|
||||||
|
func (p *Provider) clientSetup() (*Client, error) {
|
||||||
|
defer metrics.MeasureSince([]string{"scada", "setup"}, time.Now())
|
||||||
|
|
||||||
|
// Reset the previous backoff
|
||||||
|
p.backoffLock.Lock()
|
||||||
|
p.noRetry = false
|
||||||
|
p.backoff = 0
|
||||||
|
p.backoffLock.Unlock()
|
||||||
|
|
||||||
|
// Dial a new connection
|
||||||
|
opts := Opts{
|
||||||
|
Addr: p.config.Endpoint,
|
||||||
|
TLS: true,
|
||||||
|
TLSConfig: p.config.TLSConfig,
|
||||||
|
LogOutput: p.config.LogOutput,
|
||||||
|
}
|
||||||
|
client, err := DialOpts(&opts)
|
||||||
|
if err != nil {
|
||||||
|
p.logger.Printf("[ERR] scada-client: failed to dial: %v", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Perform a handshake
|
||||||
|
resp, err := p.handshake(client)
|
||||||
|
if err != nil {
|
||||||
|
p.logger.Printf("[ERR] scada-client: failed to handshake: %v", err)
|
||||||
|
client.Close()
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if resp != nil && resp.SessionID != "" {
|
||||||
|
p.logger.Printf("[DEBUG] scada-client: assigned session '%s'", resp.SessionID)
|
||||||
|
}
|
||||||
|
if resp != nil && !resp.Authenticated {
|
||||||
|
p.logger.Printf("[WARN] scada-client: authentication failed: %v", resp.Reason)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the new client
|
||||||
|
p.clientLock.Lock()
|
||||||
|
if p.client != nil {
|
||||||
|
p.client.Close()
|
||||||
|
}
|
||||||
|
p.client = client
|
||||||
|
p.clientLock.Unlock()
|
||||||
|
|
||||||
|
p.sessionLock.Lock()
|
||||||
|
p.sessionID = resp.SessionID
|
||||||
|
p.sessionAuth = resp.Authenticated
|
||||||
|
p.sessionLock.Unlock()
|
||||||
|
|
||||||
|
return client, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SessionID provides the current session ID
|
||||||
|
func (p *Provider) SessionID() string {
|
||||||
|
p.sessionLock.RLock()
|
||||||
|
defer p.sessionLock.RUnlock()
|
||||||
|
return p.sessionID
|
||||||
|
}
|
||||||
|
|
||||||
|
// SessionAuth checks if the current session is authenticated
|
||||||
|
func (p *Provider) SessionAuthenticated() bool {
|
||||||
|
p.sessionLock.RLock()
|
||||||
|
defer p.sessionLock.RUnlock()
|
||||||
|
return p.sessionAuth
|
||||||
|
}
|
||||||
|
|
||||||
|
// handshake does the initial handshake
|
||||||
|
func (p *Provider) handshake(client *Client) (*HandshakeResponse, error) {
|
||||||
|
defer metrics.MeasureSince([]string{"scada", "handshake"}, time.Now())
|
||||||
|
req := HandshakeRequest{
|
||||||
|
Service: p.config.Service.Service,
|
||||||
|
ServiceVersion: p.config.Service.ServiceVersion,
|
||||||
|
Capabilities: p.config.Service.Capabilities,
|
||||||
|
Meta: p.config.Service.Meta,
|
||||||
|
ResourceType: p.config.Service.ResourceType,
|
||||||
|
ResourceGroup: p.config.ResourceGroup,
|
||||||
|
Token: p.config.Token,
|
||||||
|
}
|
||||||
|
resp := new(HandshakeResponse)
|
||||||
|
if err := client.RPC("Session.Handshake", &req, resp); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type HijackFunc func(io.ReadWriteCloser)
|
||||||
|
|
||||||
|
// providerEndpoint is used to implement the Client.* RPC endpoints
|
||||||
|
// as part of the provider.
|
||||||
|
type providerEndpoint struct {
|
||||||
|
p *Provider
|
||||||
|
hijack HijackFunc
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hijacked is used to check if the connection has been hijacked
|
||||||
|
func (pe *providerEndpoint) hijacked() bool {
|
||||||
|
return pe.hijack != nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetHijack returns the hijack function
|
||||||
|
func (pe *providerEndpoint) getHijack() HijackFunc {
|
||||||
|
return pe.hijack
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hijack is used to take over the yamux stream for Client.Connect
|
||||||
|
func (pe *providerEndpoint) setHijack(cb HijackFunc) {
|
||||||
|
pe.hijack = cb
|
||||||
|
}
|
||||||
|
|
||||||
|
// Connect is invoked by the broker to connect to a capability
|
||||||
|
func (pe *providerEndpoint) Connect(args *ConnectRequest, resp *ConnectResponse) error {
|
||||||
|
defer metrics.IncrCounter([]string{"scada", "connect", args.Capability}, 1)
|
||||||
|
pe.p.logger.Printf("[INFO] scada-client: connect requested (capability: %s)",
|
||||||
|
args.Capability)
|
||||||
|
|
||||||
|
// Handle potential flash
|
||||||
|
if args.Severity != "" && args.Message != "" {
|
||||||
|
pe.p.logger.Printf("[%s] scada-client: %s", args.Severity, args.Message)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Look for the handler
|
||||||
|
handler := pe.p.config.Handlers[args.Capability]
|
||||||
|
if handler == nil {
|
||||||
|
pe.p.logger.Printf("[WARN] scada-client: requested capability '%s' not available",
|
||||||
|
args.Capability)
|
||||||
|
return fmt.Errorf("invalid capability")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hijack the connection
|
||||||
|
pe.setHijack(func(a io.ReadWriteCloser) {
|
||||||
|
if err := handler(args.Capability, args.Meta, a); err != nil {
|
||||||
|
pe.p.logger.Printf("[ERR] scada-client: '%s' handler error: %v",
|
||||||
|
args.Capability, err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
resp.Success = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disconnect is invoked by the broker to ask us to backoff
|
||||||
|
func (pe *providerEndpoint) Disconnect(args *DisconnectRequest, resp *DisconnectResponse) error {
|
||||||
|
defer metrics.IncrCounter([]string{"scada", "disconnect"}, 1)
|
||||||
|
if args.Reason == "" {
|
||||||
|
args.Reason = "<no reason provided>"
|
||||||
|
}
|
||||||
|
pe.p.logger.Printf("[INFO] scada-client: disconnect requested (retry: %v, backoff: %v): %v",
|
||||||
|
!args.NoRetry, args.Backoff, args.Reason)
|
||||||
|
|
||||||
|
// Use the backoff information
|
||||||
|
pe.p.backoffLock.Lock()
|
||||||
|
pe.p.noRetry = args.NoRetry
|
||||||
|
pe.p.backoff = args.Backoff
|
||||||
|
pe.p.backoffLock.Unlock()
|
||||||
|
|
||||||
|
// Clear the session information
|
||||||
|
pe.p.sessionLock.Lock()
|
||||||
|
pe.p.sessionID = ""
|
||||||
|
pe.p.sessionAuth = false
|
||||||
|
pe.p.sessionLock.Unlock()
|
||||||
|
|
||||||
|
// Force the disconnect
|
||||||
|
time.AfterFunc(DisconnectDelay, func() {
|
||||||
|
pe.p.clientLock.Lock()
|
||||||
|
if pe.p.client != nil {
|
||||||
|
pe.p.client.Close()
|
||||||
|
}
|
||||||
|
pe.p.clientLock.Unlock()
|
||||||
|
})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Flash is invoked by the broker log a message
|
||||||
|
func (pe *providerEndpoint) Flash(args *FlashRequest, resp *FlashResponse) error {
|
||||||
|
defer metrics.IncrCounter([]string{"scada", "flash"}, 1)
|
||||||
|
if args.Severity != "" && args.Message != "" {
|
||||||
|
pe.p.logger.Printf("[%s] scada-client: %s", args.Severity, args.Message)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
231
vendor/github.com/hashicorp/scada-client/scada/scada.go
generated
vendored
Normal file
231
vendor/github.com/hashicorp/scada-client/scada/scada.go
generated
vendored
Normal file
@@ -0,0 +1,231 @@
|
|||||||
|
package scada
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/tls"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net"
|
||||||
|
"os"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
sc "github.com/hashicorp/scada-client"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Provider wraps scada-client.Provider to allow most applications to only pull
|
||||||
|
// in this package
|
||||||
|
type Provider struct {
|
||||||
|
*sc.Provider
|
||||||
|
}
|
||||||
|
|
||||||
|
type AtlasConfig struct {
|
||||||
|
// Endpoint is the SCADA endpoint used for Atlas integration. If empty, the
|
||||||
|
// defaults from the provider are used.
|
||||||
|
Endpoint string `mapstructure:"endpoint"`
|
||||||
|
|
||||||
|
// The name of the infrastructure we belong to, e.g. "hashicorp/prod"
|
||||||
|
Infrastructure string `mapstructure:"infrastructure"`
|
||||||
|
|
||||||
|
// The Atlas authentication token
|
||||||
|
Token string `mapstructure:"token" json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Config holds the high-level information used to instantiate a SCADA provider
|
||||||
|
// and listener
|
||||||
|
type Config struct {
|
||||||
|
// The service name to use
|
||||||
|
Service string
|
||||||
|
|
||||||
|
// The version of the service
|
||||||
|
Version string
|
||||||
|
|
||||||
|
// The type of resource we represent
|
||||||
|
ResourceType string
|
||||||
|
|
||||||
|
// Metadata to send to along with the service information
|
||||||
|
Meta map[string]string
|
||||||
|
|
||||||
|
// If set, TLS certificate verification will be skipped. The value of the
|
||||||
|
// SCADA_INSECURE environment variable will be considered if this is false.
|
||||||
|
// If using SCADA_INSECURE, any non-empty value will trigger insecure mode.
|
||||||
|
Insecure bool
|
||||||
|
|
||||||
|
// Holds Atlas configuration
|
||||||
|
Atlas AtlasConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderService returns the service information for the provider
|
||||||
|
func providerService(c *Config) *sc.ProviderService {
|
||||||
|
ret := &sc.ProviderService{
|
||||||
|
Service: c.Service,
|
||||||
|
ServiceVersion: c.Version,
|
||||||
|
Capabilities: map[string]int{},
|
||||||
|
Meta: c.Meta,
|
||||||
|
ResourceType: c.ResourceType,
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
// providerConfig returns the configuration for the SCADA provider
|
||||||
|
func providerConfig(c *Config) *sc.ProviderConfig {
|
||||||
|
ret := &sc.ProviderConfig{
|
||||||
|
Service: providerService(c),
|
||||||
|
Handlers: map[string]sc.CapabilityProvider{},
|
||||||
|
Endpoint: c.Atlas.Endpoint,
|
||||||
|
ResourceGroup: c.Atlas.Infrastructure,
|
||||||
|
Token: c.Atlas.Token,
|
||||||
|
}
|
||||||
|
|
||||||
|
// SCADA_INSECURE env variable is used for testing to disable TLS
|
||||||
|
// certificate verification.
|
||||||
|
insecure := c.Insecure
|
||||||
|
if !insecure {
|
||||||
|
if os.Getenv("SCADA_INSECURE") != "" {
|
||||||
|
insecure = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if insecure {
|
||||||
|
ret.TLSConfig = &tls.Config{
|
||||||
|
InsecureSkipVerify: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewProvider creates a new SCADA provider using the given configuration.
|
||||||
|
// Requests for the HTTP capability are passed off to the listener that is
|
||||||
|
// returned.
|
||||||
|
func NewHTTPProvider(c *Config, logOutput io.Writer) (*Provider, net.Listener, error) {
|
||||||
|
// Get the configuration of the provider
|
||||||
|
config := providerConfig(c)
|
||||||
|
config.LogOutput = logOutput
|
||||||
|
|
||||||
|
// Set the HTTP capability
|
||||||
|
config.Service.Capabilities["http"] = 1
|
||||||
|
|
||||||
|
// Create an HTTP listener and handler
|
||||||
|
list := newScadaListener(c.Atlas.Infrastructure)
|
||||||
|
config.Handlers["http"] = func(capability string, meta map[string]string,
|
||||||
|
conn io.ReadWriteCloser) error {
|
||||||
|
return list.PushRWC(conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the provider
|
||||||
|
provider, err := sc.NewProvider(config)
|
||||||
|
if err != nil {
|
||||||
|
list.Close()
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Provider{provider}, list, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// scadaListener is used to return a net.Listener for
|
||||||
|
// incoming SCADA connections
|
||||||
|
type scadaListener struct {
|
||||||
|
addr *scadaAddr
|
||||||
|
pending chan net.Conn
|
||||||
|
|
||||||
|
closed bool
|
||||||
|
closedCh chan struct{}
|
||||||
|
l sync.Mutex
|
||||||
|
}
|
||||||
|
|
||||||
|
// newScadaListener returns a new listener
|
||||||
|
func newScadaListener(infra string) *scadaListener {
|
||||||
|
l := &scadaListener{
|
||||||
|
addr: &scadaAddr{infra},
|
||||||
|
pending: make(chan net.Conn),
|
||||||
|
closedCh: make(chan struct{}),
|
||||||
|
}
|
||||||
|
return l
|
||||||
|
}
|
||||||
|
|
||||||
|
// PushRWC is used to push a io.ReadWriteCloser as a net.Conn
|
||||||
|
func (s *scadaListener) PushRWC(conn io.ReadWriteCloser) error {
|
||||||
|
// Check if this already implements net.Conn
|
||||||
|
if nc, ok := conn.(net.Conn); ok {
|
||||||
|
return s.Push(nc)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wrap to implement the interface
|
||||||
|
wrapped := &scadaRWC{conn, s.addr}
|
||||||
|
return s.Push(wrapped)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Push is used to add a connection to the queu
|
||||||
|
func (s *scadaListener) Push(conn net.Conn) error {
|
||||||
|
select {
|
||||||
|
case s.pending <- conn:
|
||||||
|
return nil
|
||||||
|
case <-time.After(time.Second):
|
||||||
|
return fmt.Errorf("accept timed out")
|
||||||
|
case <-s.closedCh:
|
||||||
|
return fmt.Errorf("scada listener closed")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *scadaListener) Accept() (net.Conn, error) {
|
||||||
|
select {
|
||||||
|
case conn := <-s.pending:
|
||||||
|
return conn, nil
|
||||||
|
case <-s.closedCh:
|
||||||
|
return nil, fmt.Errorf("scada listener closed")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *scadaListener) Close() error {
|
||||||
|
s.l.Lock()
|
||||||
|
defer s.l.Unlock()
|
||||||
|
if s.closed {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
s.closed = true
|
||||||
|
close(s.closedCh)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *scadaListener) Addr() net.Addr {
|
||||||
|
return s.addr
|
||||||
|
}
|
||||||
|
|
||||||
|
// scadaAddr is used to return a net.Addr for SCADA
|
||||||
|
type scadaAddr struct {
|
||||||
|
infra string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *scadaAddr) Network() string {
|
||||||
|
return "SCADA"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *scadaAddr) String() string {
|
||||||
|
return fmt.Sprintf("SCADA::Atlas::%s", s.infra)
|
||||||
|
}
|
||||||
|
|
||||||
|
type scadaRWC struct {
|
||||||
|
io.ReadWriteCloser
|
||||||
|
addr *scadaAddr
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *scadaRWC) LocalAddr() net.Addr {
|
||||||
|
return s.addr
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *scadaRWC) RemoteAddr() net.Addr {
|
||||||
|
return s.addr
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *scadaRWC) SetDeadline(t time.Time) error {
|
||||||
|
return errors.New("SCADA.Conn does not support deadlines")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *scadaRWC) SetReadDeadline(t time.Time) error {
|
||||||
|
return errors.New("SCADA.Conn does not support deadlines")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *scadaRWC) SetWriteDeadline(t time.Time) error {
|
||||||
|
return errors.New("SCADA.Conn does not support deadlines")
|
||||||
|
}
|
||||||
49
vendor/github.com/hashicorp/scada-client/structs.go
generated
vendored
Normal file
49
vendor/github.com/hashicorp/scada-client/structs.go
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
package client
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
// HandshakeRequest is used to authenticate the session
|
||||||
|
type HandshakeRequest struct {
|
||||||
|
Service string
|
||||||
|
ServiceVersion string
|
||||||
|
Capabilities map[string]int
|
||||||
|
Meta map[string]string
|
||||||
|
ResourceType string
|
||||||
|
ResourceGroup string
|
||||||
|
Token string
|
||||||
|
}
|
||||||
|
|
||||||
|
type HandshakeResponse struct {
|
||||||
|
Authenticated bool
|
||||||
|
SessionID string
|
||||||
|
Reason string
|
||||||
|
}
|
||||||
|
|
||||||
|
type ConnectRequest struct {
|
||||||
|
Capability string
|
||||||
|
Meta map[string]string
|
||||||
|
|
||||||
|
Severity string
|
||||||
|
Message string
|
||||||
|
}
|
||||||
|
|
||||||
|
type ConnectResponse struct {
|
||||||
|
Success bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type DisconnectRequest struct {
|
||||||
|
NoRetry bool // Should the client retry
|
||||||
|
Backoff time.Duration // Minimum backoff
|
||||||
|
Reason string
|
||||||
|
}
|
||||||
|
|
||||||
|
type DisconnectResponse struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
type FlashRequest struct {
|
||||||
|
Severity string
|
||||||
|
Message string
|
||||||
|
}
|
||||||
|
|
||||||
|
type FlashResponse struct {
|
||||||
|
}
|
||||||
362
vendor/github.com/hashicorp/yamux/LICENSE
generated
vendored
Normal file
362
vendor/github.com/hashicorp/yamux/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,362 @@
|
|||||||
|
Mozilla Public License, version 2.0
|
||||||
|
|
||||||
|
1. Definitions
|
||||||
|
|
||||||
|
1.1. "Contributor"
|
||||||
|
|
||||||
|
means each individual or legal entity that creates, contributes to the
|
||||||
|
creation of, or owns Covered Software.
|
||||||
|
|
||||||
|
1.2. "Contributor Version"
|
||||||
|
|
||||||
|
means the combination of the Contributions of others (if any) used by a
|
||||||
|
Contributor and that particular Contributor's Contribution.
|
||||||
|
|
||||||
|
1.3. "Contribution"
|
||||||
|
|
||||||
|
means Covered Software of a particular Contributor.
|
||||||
|
|
||||||
|
1.4. "Covered Software"
|
||||||
|
|
||||||
|
means Source Code Form to which the initial Contributor has attached the
|
||||||
|
notice in Exhibit A, the Executable Form of such Source Code Form, and
|
||||||
|
Modifications of such Source Code Form, in each case including portions
|
||||||
|
thereof.
|
||||||
|
|
||||||
|
1.5. "Incompatible With Secondary Licenses"
|
||||||
|
means
|
||||||
|
|
||||||
|
a. that the initial Contributor has attached the notice described in
|
||||||
|
Exhibit B to the Covered Software; or
|
||||||
|
|
||||||
|
b. that the Covered Software was made available under the terms of
|
||||||
|
version 1.1 or earlier of the License, but not also under the terms of
|
||||||
|
a Secondary License.
|
||||||
|
|
||||||
|
1.6. "Executable Form"
|
||||||
|
|
||||||
|
means any form of the work other than Source Code Form.
|
||||||
|
|
||||||
|
1.7. "Larger Work"
|
||||||
|
|
||||||
|
means a work that combines Covered Software with other material, in a
|
||||||
|
separate file or files, that is not Covered Software.
|
||||||
|
|
||||||
|
1.8. "License"
|
||||||
|
|
||||||
|
means this document.
|
||||||
|
|
||||||
|
1.9. "Licensable"
|
||||||
|
|
||||||
|
means having the right to grant, to the maximum extent possible, whether
|
||||||
|
at the time of the initial grant or subsequently, any and all of the
|
||||||
|
rights conveyed by this License.
|
||||||
|
|
||||||
|
1.10. "Modifications"
|
||||||
|
|
||||||
|
means any of the following:
|
||||||
|
|
||||||
|
a. any file in Source Code Form that results from an addition to,
|
||||||
|
deletion from, or modification of the contents of Covered Software; or
|
||||||
|
|
||||||
|
b. any new file in Source Code Form that contains any Covered Software.
|
||||||
|
|
||||||
|
1.11. "Patent Claims" of a Contributor
|
||||||
|
|
||||||
|
means any patent claim(s), including without limitation, method,
|
||||||
|
process, and apparatus claims, in any patent Licensable by such
|
||||||
|
Contributor that would be infringed, but for the grant of the License,
|
||||||
|
by the making, using, selling, offering for sale, having made, import,
|
||||||
|
or transfer of either its Contributions or its Contributor Version.
|
||||||
|
|
||||||
|
1.12. "Secondary License"
|
||||||
|
|
||||||
|
means either the GNU General Public License, Version 2.0, the GNU Lesser
|
||||||
|
General Public License, Version 2.1, the GNU Affero General Public
|
||||||
|
License, Version 3.0, or any later versions of those licenses.
|
||||||
|
|
||||||
|
1.13. "Source Code Form"
|
||||||
|
|
||||||
|
means the form of the work preferred for making modifications.
|
||||||
|
|
||||||
|
1.14. "You" (or "Your")
|
||||||
|
|
||||||
|
means an individual or a legal entity exercising rights under this
|
||||||
|
License. For legal entities, "You" includes any entity that controls, is
|
||||||
|
controlled by, or is under common control with You. For purposes of this
|
||||||
|
definition, "control" means (a) the power, direct or indirect, to cause
|
||||||
|
the direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (b) ownership of more than fifty percent (50%) of the
|
||||||
|
outstanding shares or beneficial ownership of such entity.
|
||||||
|
|
||||||
|
|
||||||
|
2. License Grants and Conditions
|
||||||
|
|
||||||
|
2.1. Grants
|
||||||
|
|
||||||
|
Each Contributor hereby grants You a world-wide, royalty-free,
|
||||||
|
non-exclusive license:
|
||||||
|
|
||||||
|
a. under intellectual property rights (other than patent or trademark)
|
||||||
|
Licensable by such Contributor to use, reproduce, make available,
|
||||||
|
modify, display, perform, distribute, and otherwise exploit its
|
||||||
|
Contributions, either on an unmodified basis, with Modifications, or
|
||||||
|
as part of a Larger Work; and
|
||||||
|
|
||||||
|
b. under Patent Claims of such Contributor to make, use, sell, offer for
|
||||||
|
sale, have made, import, and otherwise transfer either its
|
||||||
|
Contributions or its Contributor Version.
|
||||||
|
|
||||||
|
2.2. Effective Date
|
||||||
|
|
||||||
|
The licenses granted in Section 2.1 with respect to any Contribution
|
||||||
|
become effective for each Contribution on the date the Contributor first
|
||||||
|
distributes such Contribution.
|
||||||
|
|
||||||
|
2.3. Limitations on Grant Scope
|
||||||
|
|
||||||
|
The licenses granted in this Section 2 are the only rights granted under
|
||||||
|
this License. No additional rights or licenses will be implied from the
|
||||||
|
distribution or licensing of Covered Software under this License.
|
||||||
|
Notwithstanding Section 2.1(b) above, no patent license is granted by a
|
||||||
|
Contributor:
|
||||||
|
|
||||||
|
a. for any code that a Contributor has removed from Covered Software; or
|
||||||
|
|
||||||
|
b. for infringements caused by: (i) Your and any other third party's
|
||||||
|
modifications of Covered Software, or (ii) the combination of its
|
||||||
|
Contributions with other software (except as part of its Contributor
|
||||||
|
Version); or
|
||||||
|
|
||||||
|
c. under Patent Claims infringed by Covered Software in the absence of
|
||||||
|
its Contributions.
|
||||||
|
|
||||||
|
This License does not grant any rights in the trademarks, service marks,
|
||||||
|
or logos of any Contributor (except as may be necessary to comply with
|
||||||
|
the notice requirements in Section 3.4).
|
||||||
|
|
||||||
|
2.4. Subsequent Licenses
|
||||||
|
|
||||||
|
No Contributor makes additional grants as a result of Your choice to
|
||||||
|
distribute the Covered Software under a subsequent version of this
|
||||||
|
License (see Section 10.2) or under the terms of a Secondary License (if
|
||||||
|
permitted under the terms of Section 3.3).
|
||||||
|
|
||||||
|
2.5. Representation
|
||||||
|
|
||||||
|
Each Contributor represents that the Contributor believes its
|
||||||
|
Contributions are its original creation(s) or it has sufficient rights to
|
||||||
|
grant the rights to its Contributions conveyed by this License.
|
||||||
|
|
||||||
|
2.6. Fair Use
|
||||||
|
|
||||||
|
This License is not intended to limit any rights You have under
|
||||||
|
applicable copyright doctrines of fair use, fair dealing, or other
|
||||||
|
equivalents.
|
||||||
|
|
||||||
|
2.7. Conditions
|
||||||
|
|
||||||
|
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in
|
||||||
|
Section 2.1.
|
||||||
|
|
||||||
|
|
||||||
|
3. Responsibilities
|
||||||
|
|
||||||
|
3.1. Distribution of Source Form
|
||||||
|
|
||||||
|
All distribution of Covered Software in Source Code Form, including any
|
||||||
|
Modifications that You create or to which You contribute, must be under
|
||||||
|
the terms of this License. You must inform recipients that the Source
|
||||||
|
Code Form of the Covered Software is governed by the terms of this
|
||||||
|
License, and how they can obtain a copy of this License. You may not
|
||||||
|
attempt to alter or restrict the recipients' rights in the Source Code
|
||||||
|
Form.
|
||||||
|
|
||||||
|
3.2. Distribution of Executable Form
|
||||||
|
|
||||||
|
If You distribute Covered Software in Executable Form then:
|
||||||
|
|
||||||
|
a. such Covered Software must also be made available in Source Code Form,
|
||||||
|
as described in Section 3.1, and You must inform recipients of the
|
||||||
|
Executable Form how they can obtain a copy of such Source Code Form by
|
||||||
|
reasonable means in a timely manner, at a charge no more than the cost
|
||||||
|
of distribution to the recipient; and
|
||||||
|
|
||||||
|
b. You may distribute such Executable Form under the terms of this
|
||||||
|
License, or sublicense it under different terms, provided that the
|
||||||
|
license for the Executable Form does not attempt to limit or alter the
|
||||||
|
recipients' rights in the Source Code Form under this License.
|
||||||
|
|
||||||
|
3.3. Distribution of a Larger Work
|
||||||
|
|
||||||
|
You may create and distribute a Larger Work under terms of Your choice,
|
||||||
|
provided that You also comply with the requirements of this License for
|
||||||
|
the Covered Software. If the Larger Work is a combination of Covered
|
||||||
|
Software with a work governed by one or more Secondary Licenses, and the
|
||||||
|
Covered Software is not Incompatible With Secondary Licenses, this
|
||||||
|
License permits You to additionally distribute such Covered Software
|
||||||
|
under the terms of such Secondary License(s), so that the recipient of
|
||||||
|
the Larger Work may, at their option, further distribute the Covered
|
||||||
|
Software under the terms of either this License or such Secondary
|
||||||
|
License(s).
|
||||||
|
|
||||||
|
3.4. Notices
|
||||||
|
|
||||||
|
You may not remove or alter the substance of any license notices
|
||||||
|
(including copyright notices, patent notices, disclaimers of warranty, or
|
||||||
|
limitations of liability) contained within the Source Code Form of the
|
||||||
|
Covered Software, except that You may alter any license notices to the
|
||||||
|
extent required to remedy known factual inaccuracies.
|
||||||
|
|
||||||
|
3.5. Application of Additional Terms
|
||||||
|
|
||||||
|
You may choose to offer, and to charge a fee for, warranty, support,
|
||||||
|
indemnity or liability obligations to one or more recipients of Covered
|
||||||
|
Software. However, You may do so only on Your own behalf, and not on
|
||||||
|
behalf of any Contributor. You must make it absolutely clear that any
|
||||||
|
such warranty, support, indemnity, or liability obligation is offered by
|
||||||
|
You alone, and You hereby agree to indemnify every Contributor for any
|
||||||
|
liability incurred by such Contributor as a result of warranty, support,
|
||||||
|
indemnity or liability terms You offer. You may include additional
|
||||||
|
disclaimers of warranty and limitations of liability specific to any
|
||||||
|
jurisdiction.
|
||||||
|
|
||||||
|
4. Inability to Comply Due to Statute or Regulation
|
||||||
|
|
||||||
|
If it is impossible for You to comply with any of the terms of this License
|
||||||
|
with respect to some or all of the Covered Software due to statute,
|
||||||
|
judicial order, or regulation then You must: (a) comply with the terms of
|
||||||
|
this License to the maximum extent possible; and (b) describe the
|
||||||
|
limitations and the code they affect. Such description must be placed in a
|
||||||
|
text file included with all distributions of the Covered Software under
|
||||||
|
this License. Except to the extent prohibited by statute or regulation,
|
||||||
|
such description must be sufficiently detailed for a recipient of ordinary
|
||||||
|
skill to be able to understand it.
|
||||||
|
|
||||||
|
5. Termination
|
||||||
|
|
||||||
|
5.1. The rights granted under this License will terminate automatically if You
|
||||||
|
fail to comply with any of its terms. However, if You become compliant,
|
||||||
|
then the rights granted under this License from a particular Contributor
|
||||||
|
are reinstated (a) provisionally, unless and until such Contributor
|
||||||
|
explicitly and finally terminates Your grants, and (b) on an ongoing
|
||||||
|
basis, if such Contributor fails to notify You of the non-compliance by
|
||||||
|
some reasonable means prior to 60 days after You have come back into
|
||||||
|
compliance. Moreover, Your grants from a particular Contributor are
|
||||||
|
reinstated on an ongoing basis if such Contributor notifies You of the
|
||||||
|
non-compliance by some reasonable means, this is the first time You have
|
||||||
|
received notice of non-compliance with this License from such
|
||||||
|
Contributor, and You become compliant prior to 30 days after Your receipt
|
||||||
|
of the notice.
|
||||||
|
|
||||||
|
5.2. If You initiate litigation against any entity by asserting a patent
|
||||||
|
infringement claim (excluding declaratory judgment actions,
|
||||||
|
counter-claims, and cross-claims) alleging that a Contributor Version
|
||||||
|
directly or indirectly infringes any patent, then the rights granted to
|
||||||
|
You by any and all Contributors for the Covered Software under Section
|
||||||
|
2.1 of this License shall terminate.
|
||||||
|
|
||||||
|
5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user
|
||||||
|
license agreements (excluding distributors and resellers) which have been
|
||||||
|
validly granted by You or Your distributors under this License prior to
|
||||||
|
termination shall survive termination.
|
||||||
|
|
||||||
|
6. Disclaimer of Warranty
|
||||||
|
|
||||||
|
Covered Software is provided under this License on an "as is" basis,
|
||||||
|
without warranty of any kind, either expressed, implied, or statutory,
|
||||||
|
including, without limitation, warranties that the Covered Software is free
|
||||||
|
of defects, merchantable, fit for a particular purpose or non-infringing.
|
||||||
|
The entire risk as to the quality and performance of the Covered Software
|
||||||
|
is with You. Should any Covered Software prove defective in any respect,
|
||||||
|
You (not any Contributor) assume the cost of any necessary servicing,
|
||||||
|
repair, or correction. This disclaimer of warranty constitutes an essential
|
||||||
|
part of this License. No use of any Covered Software is authorized under
|
||||||
|
this License except under this disclaimer.
|
||||||
|
|
||||||
|
7. Limitation of Liability
|
||||||
|
|
||||||
|
Under no circumstances and under no legal theory, whether tort (including
|
||||||
|
negligence), contract, or otherwise, shall any Contributor, or anyone who
|
||||||
|
distributes Covered Software as permitted above, be liable to You for any
|
||||||
|
direct, indirect, special, incidental, or consequential damages of any
|
||||||
|
character including, without limitation, damages for lost profits, loss of
|
||||||
|
goodwill, work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses, even if such party shall have been
|
||||||
|
informed of the possibility of such damages. This limitation of liability
|
||||||
|
shall not apply to liability for death or personal injury resulting from
|
||||||
|
such party's negligence to the extent applicable law prohibits such
|
||||||
|
limitation. Some jurisdictions do not allow the exclusion or limitation of
|
||||||
|
incidental or consequential damages, so this exclusion and limitation may
|
||||||
|
not apply to You.
|
||||||
|
|
||||||
|
8. Litigation
|
||||||
|
|
||||||
|
Any litigation relating to this License may be brought only in the courts
|
||||||
|
of a jurisdiction where the defendant maintains its principal place of
|
||||||
|
business and such litigation shall be governed by laws of that
|
||||||
|
jurisdiction, without reference to its conflict-of-law provisions. Nothing
|
||||||
|
in this Section shall prevent a party's ability to bring cross-claims or
|
||||||
|
counter-claims.
|
||||||
|
|
||||||
|
9. Miscellaneous
|
||||||
|
|
||||||
|
This License represents the complete agreement concerning the subject
|
||||||
|
matter hereof. If any provision of this License is held to be
|
||||||
|
unenforceable, such provision shall be reformed only to the extent
|
||||||
|
necessary to make it enforceable. Any law or regulation which provides that
|
||||||
|
the language of a contract shall be construed against the drafter shall not
|
||||||
|
be used to construe this License against a Contributor.
|
||||||
|
|
||||||
|
|
||||||
|
10. Versions of the License
|
||||||
|
|
||||||
|
10.1. New Versions
|
||||||
|
|
||||||
|
Mozilla Foundation is the license steward. Except as provided in Section
|
||||||
|
10.3, no one other than the license steward has the right to modify or
|
||||||
|
publish new versions of this License. Each version will be given a
|
||||||
|
distinguishing version number.
|
||||||
|
|
||||||
|
10.2. Effect of New Versions
|
||||||
|
|
||||||
|
You may distribute the Covered Software under the terms of the version
|
||||||
|
of the License under which You originally received the Covered Software,
|
||||||
|
or under the terms of any subsequent version published by the license
|
||||||
|
steward.
|
||||||
|
|
||||||
|
10.3. Modified Versions
|
||||||
|
|
||||||
|
If you create software not governed by this License, and you want to
|
||||||
|
create a new license for such software, you may create and use a
|
||||||
|
modified version of this License if you rename the license and remove
|
||||||
|
any references to the name of the license steward (except to note that
|
||||||
|
such modified license differs from this License).
|
||||||
|
|
||||||
|
10.4. Distributing Source Code Form that is Incompatible With Secondary
|
||||||
|
Licenses If You choose to distribute Source Code Form that is
|
||||||
|
Incompatible With Secondary Licenses under the terms of this version of
|
||||||
|
the License, the notice described in Exhibit B of this License must be
|
||||||
|
attached.
|
||||||
|
|
||||||
|
Exhibit A - Source Code Form License Notice
|
||||||
|
|
||||||
|
This Source Code Form is subject to the
|
||||||
|
terms of the Mozilla Public License, v.
|
||||||
|
2.0. If a copy of the MPL was not
|
||||||
|
distributed with this file, You can
|
||||||
|
obtain one at
|
||||||
|
http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
If it is not possible or desirable to put the notice in a particular file,
|
||||||
|
then You may include the notice in a location (such as a LICENSE file in a
|
||||||
|
relevant directory) where a recipient would be likely to look for such a
|
||||||
|
notice.
|
||||||
|
|
||||||
|
You may add additional accurate notices of copyright ownership.
|
||||||
|
|
||||||
|
Exhibit B - "Incompatible With Secondary Licenses" Notice
|
||||||
|
|
||||||
|
This Source Code Form is "Incompatible
|
||||||
|
With Secondary Licenses", as defined by
|
||||||
|
the Mozilla Public License, v. 2.0.
|
||||||
86
vendor/github.com/hashicorp/yamux/README.md
generated
vendored
Normal file
86
vendor/github.com/hashicorp/yamux/README.md
generated
vendored
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
# Yamux
|
||||||
|
|
||||||
|
Yamux (Yet another Multiplexer) is a multiplexing library for Golang.
|
||||||
|
It relies on an underlying connection to provide reliability
|
||||||
|
and ordering, such as TCP or Unix domain sockets, and provides
|
||||||
|
stream-oriented multiplexing. It is inspired by SPDY but is not
|
||||||
|
interoperable with it.
|
||||||
|
|
||||||
|
Yamux features include:
|
||||||
|
|
||||||
|
* Bi-directional streams
|
||||||
|
* Streams can be opened by either client or server
|
||||||
|
* Useful for NAT traversal
|
||||||
|
* Server-side push support
|
||||||
|
* Flow control
|
||||||
|
* Avoid starvation
|
||||||
|
* Back-pressure to prevent overwhelming a receiver
|
||||||
|
* Keep Alives
|
||||||
|
* Enables persistent connections over a load balancer
|
||||||
|
* Efficient
|
||||||
|
* Enables thousands of logical streams with low overhead
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
|
||||||
|
For complete documentation, see the associated [Godoc](http://godoc.org/github.com/hashicorp/yamux).
|
||||||
|
|
||||||
|
## Specification
|
||||||
|
|
||||||
|
The full specification for Yamux is provided in the `spec.md` file.
|
||||||
|
It can be used as a guide to implementors of interoperable libraries.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Using Yamux is remarkably simple:
|
||||||
|
|
||||||
|
```go
|
||||||
|
|
||||||
|
func client() {
|
||||||
|
// Get a TCP connection
|
||||||
|
conn, err := net.Dial(...)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup client side of yamux
|
||||||
|
session, err := yamux.Client(conn, nil)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open a new stream
|
||||||
|
stream, err := session.Open()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stream implements net.Conn
|
||||||
|
stream.Write([]byte("ping"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func server() {
|
||||||
|
// Accept a TCP connection
|
||||||
|
conn, err := listener.Accept()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup server side of yamux
|
||||||
|
session, err := yamux.Server(conn, nil)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Accept a stream
|
||||||
|
stream, err := session.Accept()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Listen for a message
|
||||||
|
buf := make([]byte, 4)
|
||||||
|
stream.Read(buf)
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
60
vendor/github.com/hashicorp/yamux/addr.go
generated
vendored
Normal file
60
vendor/github.com/hashicorp/yamux/addr.go
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
package yamux
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
|
)
|
||||||
|
|
||||||
|
// hasAddr is used to get the address from the underlying connection
|
||||||
|
type hasAddr interface {
|
||||||
|
LocalAddr() net.Addr
|
||||||
|
RemoteAddr() net.Addr
|
||||||
|
}
|
||||||
|
|
||||||
|
// yamuxAddr is used when we cannot get the underlying address
|
||||||
|
type yamuxAddr struct {
|
||||||
|
Addr string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*yamuxAddr) Network() string {
|
||||||
|
return "yamux"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (y *yamuxAddr) String() string {
|
||||||
|
return fmt.Sprintf("yamux:%s", y.Addr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Addr is used to get the address of the listener.
|
||||||
|
func (s *Session) Addr() net.Addr {
|
||||||
|
return s.LocalAddr()
|
||||||
|
}
|
||||||
|
|
||||||
|
// LocalAddr is used to get the local address of the
|
||||||
|
// underlying connection.
|
||||||
|
func (s *Session) LocalAddr() net.Addr {
|
||||||
|
addr, ok := s.conn.(hasAddr)
|
||||||
|
if !ok {
|
||||||
|
return &yamuxAddr{"local"}
|
||||||
|
}
|
||||||
|
return addr.LocalAddr()
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoteAddr is used to get the address of remote end
|
||||||
|
// of the underlying connection
|
||||||
|
func (s *Session) RemoteAddr() net.Addr {
|
||||||
|
addr, ok := s.conn.(hasAddr)
|
||||||
|
if !ok {
|
||||||
|
return &yamuxAddr{"remote"}
|
||||||
|
}
|
||||||
|
return addr.RemoteAddr()
|
||||||
|
}
|
||||||
|
|
||||||
|
// LocalAddr returns the local address
|
||||||
|
func (s *Stream) LocalAddr() net.Addr {
|
||||||
|
return s.session.LocalAddr()
|
||||||
|
}
|
||||||
|
|
||||||
|
// LocalAddr returns the remote address
|
||||||
|
func (s *Stream) RemoteAddr() net.Addr {
|
||||||
|
return s.session.RemoteAddr()
|
||||||
|
}
|
||||||
157
vendor/github.com/hashicorp/yamux/const.go
generated
vendored
Normal file
157
vendor/github.com/hashicorp/yamux/const.go
generated
vendored
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
package yamux
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/binary"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// ErrInvalidVersion means we received a frame with an
|
||||||
|
// invalid version
|
||||||
|
ErrInvalidVersion = fmt.Errorf("invalid protocol version")
|
||||||
|
|
||||||
|
// ErrInvalidMsgType means we received a frame with an
|
||||||
|
// invalid message type
|
||||||
|
ErrInvalidMsgType = fmt.Errorf("invalid msg type")
|
||||||
|
|
||||||
|
// ErrSessionShutdown is used if there is a shutdown during
|
||||||
|
// an operation
|
||||||
|
ErrSessionShutdown = fmt.Errorf("session shutdown")
|
||||||
|
|
||||||
|
// ErrStreamsExhausted is returned if we have no more
|
||||||
|
// stream ids to issue
|
||||||
|
ErrStreamsExhausted = fmt.Errorf("streams exhausted")
|
||||||
|
|
||||||
|
// ErrDuplicateStream is used if a duplicate stream is
|
||||||
|
// opened inbound
|
||||||
|
ErrDuplicateStream = fmt.Errorf("duplicate stream initiated")
|
||||||
|
|
||||||
|
// ErrReceiveWindowExceeded indicates the window was exceeded
|
||||||
|
ErrRecvWindowExceeded = fmt.Errorf("recv window exceeded")
|
||||||
|
|
||||||
|
// ErrTimeout is used when we reach an IO deadline
|
||||||
|
ErrTimeout = fmt.Errorf("i/o deadline reached")
|
||||||
|
|
||||||
|
// ErrStreamClosed is returned when using a closed stream
|
||||||
|
ErrStreamClosed = fmt.Errorf("stream closed")
|
||||||
|
|
||||||
|
// ErrUnexpectedFlag is set when we get an unexpected flag
|
||||||
|
ErrUnexpectedFlag = fmt.Errorf("unexpected flag")
|
||||||
|
|
||||||
|
// ErrRemoteGoAway is used when we get a go away from the other side
|
||||||
|
ErrRemoteGoAway = fmt.Errorf("remote end is not accepting connections")
|
||||||
|
|
||||||
|
// ErrConnectionReset is sent if a stream is reset. This can happen
|
||||||
|
// if the backlog is exceeded, or if there was a remote GoAway.
|
||||||
|
ErrConnectionReset = fmt.Errorf("connection reset")
|
||||||
|
|
||||||
|
// ErrConnectionWriteTimeout indicates that we hit the "safety valve"
|
||||||
|
// timeout writing to the underlying stream connection.
|
||||||
|
ErrConnectionWriteTimeout = fmt.Errorf("connection write timeout")
|
||||||
|
|
||||||
|
// ErrKeepAliveTimeout is sent if a missed keepalive caused the stream close
|
||||||
|
ErrKeepAliveTimeout = fmt.Errorf("keepalive timeout")
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// protoVersion is the only version we support
|
||||||
|
protoVersion uint8 = 0
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Data is used for data frames. They are followed
|
||||||
|
// by length bytes worth of payload.
|
||||||
|
typeData uint8 = iota
|
||||||
|
|
||||||
|
// WindowUpdate is used to change the window of
|
||||||
|
// a given stream. The length indicates the delta
|
||||||
|
// update to the window.
|
||||||
|
typeWindowUpdate
|
||||||
|
|
||||||
|
// Ping is sent as a keep-alive or to measure
|
||||||
|
// the RTT. The StreamID and Length value are echoed
|
||||||
|
// back in the response.
|
||||||
|
typePing
|
||||||
|
|
||||||
|
// GoAway is sent to terminate a session. The StreamID
|
||||||
|
// should be 0 and the length is an error code.
|
||||||
|
typeGoAway
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// SYN is sent to signal a new stream. May
|
||||||
|
// be sent with a data payload
|
||||||
|
flagSYN uint16 = 1 << iota
|
||||||
|
|
||||||
|
// ACK is sent to acknowledge a new stream. May
|
||||||
|
// be sent with a data payload
|
||||||
|
flagACK
|
||||||
|
|
||||||
|
// FIN is sent to half-close the given stream.
|
||||||
|
// May be sent with a data payload.
|
||||||
|
flagFIN
|
||||||
|
|
||||||
|
// RST is used to hard close a given stream.
|
||||||
|
flagRST
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// initialStreamWindow is the initial stream window size
|
||||||
|
initialStreamWindow uint32 = 256 * 1024
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// goAwayNormal is sent on a normal termination
|
||||||
|
goAwayNormal uint32 = iota
|
||||||
|
|
||||||
|
// goAwayProtoErr sent on a protocol error
|
||||||
|
goAwayProtoErr
|
||||||
|
|
||||||
|
// goAwayInternalErr sent on an internal error
|
||||||
|
goAwayInternalErr
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
sizeOfVersion = 1
|
||||||
|
sizeOfType = 1
|
||||||
|
sizeOfFlags = 2
|
||||||
|
sizeOfStreamID = 4
|
||||||
|
sizeOfLength = 4
|
||||||
|
headerSize = sizeOfVersion + sizeOfType + sizeOfFlags +
|
||||||
|
sizeOfStreamID + sizeOfLength
|
||||||
|
)
|
||||||
|
|
||||||
|
type header []byte
|
||||||
|
|
||||||
|
func (h header) Version() uint8 {
|
||||||
|
return h[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h header) MsgType() uint8 {
|
||||||
|
return h[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h header) Flags() uint16 {
|
||||||
|
return binary.BigEndian.Uint16(h[2:4])
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h header) StreamID() uint32 {
|
||||||
|
return binary.BigEndian.Uint32(h[4:8])
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h header) Length() uint32 {
|
||||||
|
return binary.BigEndian.Uint32(h[8:12])
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h header) String() string {
|
||||||
|
return fmt.Sprintf("Vsn:%d Type:%d Flags:%d StreamID:%d Length:%d",
|
||||||
|
h.Version(), h.MsgType(), h.Flags(), h.StreamID(), h.Length())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h header) encode(msgType uint8, flags uint16, streamID uint32, length uint32) {
|
||||||
|
h[0] = protoVersion
|
||||||
|
h[1] = msgType
|
||||||
|
binary.BigEndian.PutUint16(h[2:4], flags)
|
||||||
|
binary.BigEndian.PutUint32(h[4:8], streamID)
|
||||||
|
binary.BigEndian.PutUint32(h[8:12], length)
|
||||||
|
}
|
||||||
87
vendor/github.com/hashicorp/yamux/mux.go
generated
vendored
Normal file
87
vendor/github.com/hashicorp/yamux/mux.go
generated
vendored
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
package yamux
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Config is used to tune the Yamux session
|
||||||
|
type Config struct {
|
||||||
|
// AcceptBacklog is used to limit how many streams may be
|
||||||
|
// waiting an accept.
|
||||||
|
AcceptBacklog int
|
||||||
|
|
||||||
|
// EnableKeepalive is used to do a period keep alive
|
||||||
|
// messages using a ping.
|
||||||
|
EnableKeepAlive bool
|
||||||
|
|
||||||
|
// KeepAliveInterval is how often to perform the keep alive
|
||||||
|
KeepAliveInterval time.Duration
|
||||||
|
|
||||||
|
// ConnectionWriteTimeout is meant to be a "safety valve" timeout after
|
||||||
|
// we which will suspect a problem with the underlying connection and
|
||||||
|
// close it. This is only applied to writes, where's there's generally
|
||||||
|
// an expectation that things will move along quickly.
|
||||||
|
ConnectionWriteTimeout time.Duration
|
||||||
|
|
||||||
|
// MaxStreamWindowSize is used to control the maximum
|
||||||
|
// window size that we allow for a stream.
|
||||||
|
MaxStreamWindowSize uint32
|
||||||
|
|
||||||
|
// LogOutput is used to control the log destination
|
||||||
|
LogOutput io.Writer
|
||||||
|
}
|
||||||
|
|
||||||
|
// DefaultConfig is used to return a default configuration
|
||||||
|
func DefaultConfig() *Config {
|
||||||
|
return &Config{
|
||||||
|
AcceptBacklog: 256,
|
||||||
|
EnableKeepAlive: true,
|
||||||
|
KeepAliveInterval: 30 * time.Second,
|
||||||
|
ConnectionWriteTimeout: 10 * time.Second,
|
||||||
|
MaxStreamWindowSize: initialStreamWindow,
|
||||||
|
LogOutput: os.Stderr,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// VerifyConfig is used to verify the sanity of configuration
|
||||||
|
func VerifyConfig(config *Config) error {
|
||||||
|
if config.AcceptBacklog <= 0 {
|
||||||
|
return fmt.Errorf("backlog must be positive")
|
||||||
|
}
|
||||||
|
if config.KeepAliveInterval == 0 {
|
||||||
|
return fmt.Errorf("keep-alive interval must be positive")
|
||||||
|
}
|
||||||
|
if config.MaxStreamWindowSize < initialStreamWindow {
|
||||||
|
return fmt.Errorf("MaxStreamWindowSize must be larger than %d", initialStreamWindow)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server is used to initialize a new server-side connection.
|
||||||
|
// There must be at most one server-side connection. If a nil config is
|
||||||
|
// provided, the DefaultConfiguration will be used.
|
||||||
|
func Server(conn io.ReadWriteCloser, config *Config) (*Session, error) {
|
||||||
|
if config == nil {
|
||||||
|
config = DefaultConfig()
|
||||||
|
}
|
||||||
|
if err := VerifyConfig(config); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return newSession(config, conn, false), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client is used to initialize a new client-side connection.
|
||||||
|
// There must be at most one client-side connection.
|
||||||
|
func Client(conn io.ReadWriteCloser, config *Config) (*Session, error) {
|
||||||
|
if config == nil {
|
||||||
|
config = DefaultConfig()
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := VerifyConfig(config); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return newSession(config, conn, true), nil
|
||||||
|
}
|
||||||
623
vendor/github.com/hashicorp/yamux/session.go
generated
vendored
Normal file
623
vendor/github.com/hashicorp/yamux/session.go
generated
vendored
Normal file
@@ -0,0 +1,623 @@
|
|||||||
|
package yamux
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"math"
|
||||||
|
"net"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Session is used to wrap a reliable ordered connection and to
|
||||||
|
// multiplex it into multiple streams.
|
||||||
|
type Session struct {
|
||||||
|
// remoteGoAway indicates the remote side does
|
||||||
|
// not want futher connections. Must be first for alignment.
|
||||||
|
remoteGoAway int32
|
||||||
|
|
||||||
|
// localGoAway indicates that we should stop
|
||||||
|
// accepting futher connections. Must be first for alignment.
|
||||||
|
localGoAway int32
|
||||||
|
|
||||||
|
// nextStreamID is the next stream we should
|
||||||
|
// send. This depends if we are a client/server.
|
||||||
|
nextStreamID uint32
|
||||||
|
|
||||||
|
// config holds our configuration
|
||||||
|
config *Config
|
||||||
|
|
||||||
|
// logger is used for our logs
|
||||||
|
logger *log.Logger
|
||||||
|
|
||||||
|
// conn is the underlying connection
|
||||||
|
conn io.ReadWriteCloser
|
||||||
|
|
||||||
|
// bufRead is a buffered reader
|
||||||
|
bufRead *bufio.Reader
|
||||||
|
|
||||||
|
// pings is used to track inflight pings
|
||||||
|
pings map[uint32]chan struct{}
|
||||||
|
pingID uint32
|
||||||
|
pingLock sync.Mutex
|
||||||
|
|
||||||
|
// streams maps a stream id to a stream, and inflight has an entry
|
||||||
|
// for any outgoing stream that has not yet been established. Both are
|
||||||
|
// protected by streamLock.
|
||||||
|
streams map[uint32]*Stream
|
||||||
|
inflight map[uint32]struct{}
|
||||||
|
streamLock sync.Mutex
|
||||||
|
|
||||||
|
// synCh acts like a semaphore. It is sized to the AcceptBacklog which
|
||||||
|
// is assumed to be symmetric between the client and server. This allows
|
||||||
|
// the client to avoid exceeding the backlog and instead blocks the open.
|
||||||
|
synCh chan struct{}
|
||||||
|
|
||||||
|
// acceptCh is used to pass ready streams to the client
|
||||||
|
acceptCh chan *Stream
|
||||||
|
|
||||||
|
// sendCh is used to mark a stream as ready to send,
|
||||||
|
// or to send a header out directly.
|
||||||
|
sendCh chan sendReady
|
||||||
|
|
||||||
|
// recvDoneCh is closed when recv() exits to avoid a race
|
||||||
|
// between stream registration and stream shutdown
|
||||||
|
recvDoneCh chan struct{}
|
||||||
|
|
||||||
|
// shutdown is used to safely close a session
|
||||||
|
shutdown bool
|
||||||
|
shutdownErr error
|
||||||
|
shutdownCh chan struct{}
|
||||||
|
shutdownLock sync.Mutex
|
||||||
|
}
|
||||||
|
|
||||||
|
// sendReady is used to either mark a stream as ready
|
||||||
|
// or to directly send a header
|
||||||
|
type sendReady struct {
|
||||||
|
Hdr []byte
|
||||||
|
Body io.Reader
|
||||||
|
Err chan error
|
||||||
|
}
|
||||||
|
|
||||||
|
// newSession is used to construct a new session
|
||||||
|
func newSession(config *Config, conn io.ReadWriteCloser, client bool) *Session {
|
||||||
|
s := &Session{
|
||||||
|
config: config,
|
||||||
|
logger: log.New(config.LogOutput, "", log.LstdFlags),
|
||||||
|
conn: conn,
|
||||||
|
bufRead: bufio.NewReader(conn),
|
||||||
|
pings: make(map[uint32]chan struct{}),
|
||||||
|
streams: make(map[uint32]*Stream),
|
||||||
|
inflight: make(map[uint32]struct{}),
|
||||||
|
synCh: make(chan struct{}, config.AcceptBacklog),
|
||||||
|
acceptCh: make(chan *Stream, config.AcceptBacklog),
|
||||||
|
sendCh: make(chan sendReady, 64),
|
||||||
|
recvDoneCh: make(chan struct{}),
|
||||||
|
shutdownCh: make(chan struct{}),
|
||||||
|
}
|
||||||
|
if client {
|
||||||
|
s.nextStreamID = 1
|
||||||
|
} else {
|
||||||
|
s.nextStreamID = 2
|
||||||
|
}
|
||||||
|
go s.recv()
|
||||||
|
go s.send()
|
||||||
|
if config.EnableKeepAlive {
|
||||||
|
go s.keepalive()
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsClosed does a safe check to see if we have shutdown
|
||||||
|
func (s *Session) IsClosed() bool {
|
||||||
|
select {
|
||||||
|
case <-s.shutdownCh:
|
||||||
|
return true
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NumStreams returns the number of currently open streams
|
||||||
|
func (s *Session) NumStreams() int {
|
||||||
|
s.streamLock.Lock()
|
||||||
|
num := len(s.streams)
|
||||||
|
s.streamLock.Unlock()
|
||||||
|
return num
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open is used to create a new stream as a net.Conn
|
||||||
|
func (s *Session) Open() (net.Conn, error) {
|
||||||
|
conn, err := s.OpenStream()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return conn, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// OpenStream is used to create a new stream
|
||||||
|
func (s *Session) OpenStream() (*Stream, error) {
|
||||||
|
if s.IsClosed() {
|
||||||
|
return nil, ErrSessionShutdown
|
||||||
|
}
|
||||||
|
if atomic.LoadInt32(&s.remoteGoAway) == 1 {
|
||||||
|
return nil, ErrRemoteGoAway
|
||||||
|
}
|
||||||
|
|
||||||
|
// Block if we have too many inflight SYNs
|
||||||
|
select {
|
||||||
|
case s.synCh <- struct{}{}:
|
||||||
|
case <-s.shutdownCh:
|
||||||
|
return nil, ErrSessionShutdown
|
||||||
|
}
|
||||||
|
|
||||||
|
GET_ID:
|
||||||
|
// Get an ID, and check for stream exhaustion
|
||||||
|
id := atomic.LoadUint32(&s.nextStreamID)
|
||||||
|
if id >= math.MaxUint32-1 {
|
||||||
|
return nil, ErrStreamsExhausted
|
||||||
|
}
|
||||||
|
if !atomic.CompareAndSwapUint32(&s.nextStreamID, id, id+2) {
|
||||||
|
goto GET_ID
|
||||||
|
}
|
||||||
|
|
||||||
|
// Register the stream
|
||||||
|
stream := newStream(s, id, streamInit)
|
||||||
|
s.streamLock.Lock()
|
||||||
|
s.streams[id] = stream
|
||||||
|
s.inflight[id] = struct{}{}
|
||||||
|
s.streamLock.Unlock()
|
||||||
|
|
||||||
|
// Send the window update to create
|
||||||
|
if err := stream.sendWindowUpdate(); err != nil {
|
||||||
|
select {
|
||||||
|
case <-s.synCh:
|
||||||
|
default:
|
||||||
|
s.logger.Printf("[ERR] yamux: aborted stream open without inflight syn semaphore")
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return stream, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Accept is used to block until the next available stream
|
||||||
|
// is ready to be accepted.
|
||||||
|
func (s *Session) Accept() (net.Conn, error) {
|
||||||
|
conn, err := s.AcceptStream()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return conn, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// AcceptStream is used to block until the next available stream
|
||||||
|
// is ready to be accepted.
|
||||||
|
func (s *Session) AcceptStream() (*Stream, error) {
|
||||||
|
select {
|
||||||
|
case stream := <-s.acceptCh:
|
||||||
|
if err := stream.sendWindowUpdate(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return stream, nil
|
||||||
|
case <-s.shutdownCh:
|
||||||
|
return nil, s.shutdownErr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close is used to close the session and all streams.
|
||||||
|
// Attempts to send a GoAway before closing the connection.
|
||||||
|
func (s *Session) Close() error {
|
||||||
|
s.shutdownLock.Lock()
|
||||||
|
defer s.shutdownLock.Unlock()
|
||||||
|
|
||||||
|
if s.shutdown {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
s.shutdown = true
|
||||||
|
if s.shutdownErr == nil {
|
||||||
|
s.shutdownErr = ErrSessionShutdown
|
||||||
|
}
|
||||||
|
close(s.shutdownCh)
|
||||||
|
s.conn.Close()
|
||||||
|
<-s.recvDoneCh
|
||||||
|
|
||||||
|
s.streamLock.Lock()
|
||||||
|
defer s.streamLock.Unlock()
|
||||||
|
for _, stream := range s.streams {
|
||||||
|
stream.forceClose()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// exitErr is used to handle an error that is causing the
|
||||||
|
// session to terminate.
|
||||||
|
func (s *Session) exitErr(err error) {
|
||||||
|
s.shutdownLock.Lock()
|
||||||
|
if s.shutdownErr == nil {
|
||||||
|
s.shutdownErr = err
|
||||||
|
}
|
||||||
|
s.shutdownLock.Unlock()
|
||||||
|
s.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
// GoAway can be used to prevent accepting further
|
||||||
|
// connections. It does not close the underlying conn.
|
||||||
|
func (s *Session) GoAway() error {
|
||||||
|
return s.waitForSend(s.goAway(goAwayNormal), nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// goAway is used to send a goAway message
|
||||||
|
func (s *Session) goAway(reason uint32) header {
|
||||||
|
atomic.SwapInt32(&s.localGoAway, 1)
|
||||||
|
hdr := header(make([]byte, headerSize))
|
||||||
|
hdr.encode(typeGoAway, 0, 0, reason)
|
||||||
|
return hdr
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ping is used to measure the RTT response time
|
||||||
|
func (s *Session) Ping() (time.Duration, error) {
|
||||||
|
// Get a channel for the ping
|
||||||
|
ch := make(chan struct{})
|
||||||
|
|
||||||
|
// Get a new ping id, mark as pending
|
||||||
|
s.pingLock.Lock()
|
||||||
|
id := s.pingID
|
||||||
|
s.pingID++
|
||||||
|
s.pings[id] = ch
|
||||||
|
s.pingLock.Unlock()
|
||||||
|
|
||||||
|
// Send the ping request
|
||||||
|
hdr := header(make([]byte, headerSize))
|
||||||
|
hdr.encode(typePing, flagSYN, 0, id)
|
||||||
|
if err := s.waitForSend(hdr, nil); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for a response
|
||||||
|
start := time.Now()
|
||||||
|
select {
|
||||||
|
case <-ch:
|
||||||
|
case <-time.After(s.config.ConnectionWriteTimeout):
|
||||||
|
s.pingLock.Lock()
|
||||||
|
delete(s.pings, id) // Ignore it if a response comes later.
|
||||||
|
s.pingLock.Unlock()
|
||||||
|
return 0, ErrTimeout
|
||||||
|
case <-s.shutdownCh:
|
||||||
|
return 0, ErrSessionShutdown
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compute the RTT
|
||||||
|
return time.Now().Sub(start), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// keepalive is a long running goroutine that periodically does
|
||||||
|
// a ping to keep the connection alive.
|
||||||
|
func (s *Session) keepalive() {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-time.After(s.config.KeepAliveInterval):
|
||||||
|
_, err := s.Ping()
|
||||||
|
if err != nil {
|
||||||
|
s.logger.Printf("[ERR] yamux: keepalive failed: %v", err)
|
||||||
|
s.exitErr(ErrKeepAliveTimeout)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
case <-s.shutdownCh:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// waitForSendErr waits to send a header, checking for a potential shutdown
|
||||||
|
func (s *Session) waitForSend(hdr header, body io.Reader) error {
|
||||||
|
errCh := make(chan error, 1)
|
||||||
|
return s.waitForSendErr(hdr, body, errCh)
|
||||||
|
}
|
||||||
|
|
||||||
|
// waitForSendErr waits to send a header with optional data, checking for a
|
||||||
|
// potential shutdown. Since there's the expectation that sends can happen
|
||||||
|
// in a timely manner, we enforce the connection write timeout here.
|
||||||
|
func (s *Session) waitForSendErr(hdr header, body io.Reader, errCh chan error) error {
|
||||||
|
timer := time.NewTimer(s.config.ConnectionWriteTimeout)
|
||||||
|
defer timer.Stop()
|
||||||
|
|
||||||
|
ready := sendReady{Hdr: hdr, Body: body, Err: errCh}
|
||||||
|
select {
|
||||||
|
case s.sendCh <- ready:
|
||||||
|
case <-s.shutdownCh:
|
||||||
|
return ErrSessionShutdown
|
||||||
|
case <-timer.C:
|
||||||
|
return ErrConnectionWriteTimeout
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
case err := <-errCh:
|
||||||
|
return err
|
||||||
|
case <-s.shutdownCh:
|
||||||
|
return ErrSessionShutdown
|
||||||
|
case <-timer.C:
|
||||||
|
return ErrConnectionWriteTimeout
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sendNoWait does a send without waiting. Since there's the expectation that
|
||||||
|
// the send happens right here, we enforce the connection write timeout if we
|
||||||
|
// can't queue the header to be sent.
|
||||||
|
func (s *Session) sendNoWait(hdr header) error {
|
||||||
|
timer := time.NewTimer(s.config.ConnectionWriteTimeout)
|
||||||
|
defer timer.Stop()
|
||||||
|
|
||||||
|
select {
|
||||||
|
case s.sendCh <- sendReady{Hdr: hdr}:
|
||||||
|
return nil
|
||||||
|
case <-s.shutdownCh:
|
||||||
|
return ErrSessionShutdown
|
||||||
|
case <-timer.C:
|
||||||
|
return ErrConnectionWriteTimeout
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// send is a long running goroutine that sends data
|
||||||
|
func (s *Session) send() {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case ready := <-s.sendCh:
|
||||||
|
// Send a header if ready
|
||||||
|
if ready.Hdr != nil {
|
||||||
|
sent := 0
|
||||||
|
for sent < len(ready.Hdr) {
|
||||||
|
n, err := s.conn.Write(ready.Hdr[sent:])
|
||||||
|
if err != nil {
|
||||||
|
s.logger.Printf("[ERR] yamux: Failed to write header: %v", err)
|
||||||
|
asyncSendErr(ready.Err, err)
|
||||||
|
s.exitErr(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
sent += n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send data from a body if given
|
||||||
|
if ready.Body != nil {
|
||||||
|
_, err := io.Copy(s.conn, ready.Body)
|
||||||
|
if err != nil {
|
||||||
|
s.logger.Printf("[ERR] yamux: Failed to write body: %v", err)
|
||||||
|
asyncSendErr(ready.Err, err)
|
||||||
|
s.exitErr(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// No error, successful send
|
||||||
|
asyncSendErr(ready.Err, nil)
|
||||||
|
case <-s.shutdownCh:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// recv is a long running goroutine that accepts new data
|
||||||
|
func (s *Session) recv() {
|
||||||
|
if err := s.recvLoop(); err != nil {
|
||||||
|
s.exitErr(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// recvLoop continues to receive data until a fatal error is encountered
|
||||||
|
func (s *Session) recvLoop() error {
|
||||||
|
defer close(s.recvDoneCh)
|
||||||
|
hdr := header(make([]byte, headerSize))
|
||||||
|
var handler func(header) error
|
||||||
|
for {
|
||||||
|
// Read the header
|
||||||
|
if _, err := io.ReadFull(s.bufRead, hdr); err != nil {
|
||||||
|
if err != io.EOF && !strings.Contains(err.Error(), "closed") && !strings.Contains(err.Error(), "reset by peer") {
|
||||||
|
s.logger.Printf("[ERR] yamux: Failed to read header: %v", err)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify the version
|
||||||
|
if hdr.Version() != protoVersion {
|
||||||
|
s.logger.Printf("[ERR] yamux: Invalid protocol version: %d", hdr.Version())
|
||||||
|
return ErrInvalidVersion
|
||||||
|
}
|
||||||
|
|
||||||
|
// Switch on the type
|
||||||
|
switch hdr.MsgType() {
|
||||||
|
case typeData:
|
||||||
|
handler = s.handleStreamMessage
|
||||||
|
case typeWindowUpdate:
|
||||||
|
handler = s.handleStreamMessage
|
||||||
|
case typeGoAway:
|
||||||
|
handler = s.handleGoAway
|
||||||
|
case typePing:
|
||||||
|
handler = s.handlePing
|
||||||
|
default:
|
||||||
|
return ErrInvalidMsgType
|
||||||
|
}
|
||||||
|
|
||||||
|
// Invoke the handler
|
||||||
|
if err := handler(hdr); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// handleStreamMessage handles either a data or window update frame
|
||||||
|
func (s *Session) handleStreamMessage(hdr header) error {
|
||||||
|
// Check for a new stream creation
|
||||||
|
id := hdr.StreamID()
|
||||||
|
flags := hdr.Flags()
|
||||||
|
if flags&flagSYN == flagSYN {
|
||||||
|
if err := s.incomingStream(id); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the stream
|
||||||
|
s.streamLock.Lock()
|
||||||
|
stream := s.streams[id]
|
||||||
|
s.streamLock.Unlock()
|
||||||
|
|
||||||
|
// If we do not have a stream, likely we sent a RST
|
||||||
|
if stream == nil {
|
||||||
|
// Drain any data on the wire
|
||||||
|
if hdr.MsgType() == typeData && hdr.Length() > 0 {
|
||||||
|
s.logger.Printf("[WARN] yamux: Discarding data for stream: %d", id)
|
||||||
|
if _, err := io.CopyN(ioutil.Discard, s.bufRead, int64(hdr.Length())); err != nil {
|
||||||
|
s.logger.Printf("[ERR] yamux: Failed to discard data: %v", err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
s.logger.Printf("[WARN] yamux: frame for missing stream: %v", hdr)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if this is a window update
|
||||||
|
if hdr.MsgType() == typeWindowUpdate {
|
||||||
|
if err := stream.incrSendWindow(hdr, flags); err != nil {
|
||||||
|
if sendErr := s.sendNoWait(s.goAway(goAwayProtoErr)); sendErr != nil {
|
||||||
|
s.logger.Printf("[WARN] yamux: failed to send go away: %v", sendErr)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read the new data
|
||||||
|
if err := stream.readData(hdr, flags, s.bufRead); err != nil {
|
||||||
|
if sendErr := s.sendNoWait(s.goAway(goAwayProtoErr)); sendErr != nil {
|
||||||
|
s.logger.Printf("[WARN] yamux: failed to send go away: %v", sendErr)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// handlePing is invokde for a typePing frame
|
||||||
|
func (s *Session) handlePing(hdr header) error {
|
||||||
|
flags := hdr.Flags()
|
||||||
|
pingID := hdr.Length()
|
||||||
|
|
||||||
|
// Check if this is a query, respond back in a separate context so we
|
||||||
|
// don't interfere with the receiving thread blocking for the write.
|
||||||
|
if flags&flagSYN == flagSYN {
|
||||||
|
go func() {
|
||||||
|
hdr := header(make([]byte, headerSize))
|
||||||
|
hdr.encode(typePing, flagACK, 0, pingID)
|
||||||
|
if err := s.sendNoWait(hdr); err != nil {
|
||||||
|
s.logger.Printf("[WARN] yamux: failed to send ping reply: %v", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle a response
|
||||||
|
s.pingLock.Lock()
|
||||||
|
ch := s.pings[pingID]
|
||||||
|
if ch != nil {
|
||||||
|
delete(s.pings, pingID)
|
||||||
|
close(ch)
|
||||||
|
}
|
||||||
|
s.pingLock.Unlock()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// handleGoAway is invokde for a typeGoAway frame
|
||||||
|
func (s *Session) handleGoAway(hdr header) error {
|
||||||
|
code := hdr.Length()
|
||||||
|
switch code {
|
||||||
|
case goAwayNormal:
|
||||||
|
atomic.SwapInt32(&s.remoteGoAway, 1)
|
||||||
|
case goAwayProtoErr:
|
||||||
|
s.logger.Printf("[ERR] yamux: received protocol error go away")
|
||||||
|
return fmt.Errorf("yamux protocol error")
|
||||||
|
case goAwayInternalErr:
|
||||||
|
s.logger.Printf("[ERR] yamux: received internal error go away")
|
||||||
|
return fmt.Errorf("remote yamux internal error")
|
||||||
|
default:
|
||||||
|
s.logger.Printf("[ERR] yamux: received unexpected go away")
|
||||||
|
return fmt.Errorf("unexpected go away received")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// incomingStream is used to create a new incoming stream
|
||||||
|
func (s *Session) incomingStream(id uint32) error {
|
||||||
|
// Reject immediately if we are doing a go away
|
||||||
|
if atomic.LoadInt32(&s.localGoAway) == 1 {
|
||||||
|
hdr := header(make([]byte, headerSize))
|
||||||
|
hdr.encode(typeWindowUpdate, flagRST, id, 0)
|
||||||
|
return s.sendNoWait(hdr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allocate a new stream
|
||||||
|
stream := newStream(s, id, streamSYNReceived)
|
||||||
|
|
||||||
|
s.streamLock.Lock()
|
||||||
|
defer s.streamLock.Unlock()
|
||||||
|
|
||||||
|
// Check if stream already exists
|
||||||
|
if _, ok := s.streams[id]; ok {
|
||||||
|
s.logger.Printf("[ERR] yamux: duplicate stream declared")
|
||||||
|
if sendErr := s.sendNoWait(s.goAway(goAwayProtoErr)); sendErr != nil {
|
||||||
|
s.logger.Printf("[WARN] yamux: failed to send go away: %v", sendErr)
|
||||||
|
}
|
||||||
|
return ErrDuplicateStream
|
||||||
|
}
|
||||||
|
|
||||||
|
// Register the stream
|
||||||
|
s.streams[id] = stream
|
||||||
|
|
||||||
|
// Check if we've exceeded the backlog
|
||||||
|
select {
|
||||||
|
case s.acceptCh <- stream:
|
||||||
|
return nil
|
||||||
|
default:
|
||||||
|
// Backlog exceeded! RST the stream
|
||||||
|
s.logger.Printf("[WARN] yamux: backlog exceeded, forcing connection reset")
|
||||||
|
delete(s.streams, id)
|
||||||
|
stream.sendHdr.encode(typeWindowUpdate, flagRST, id, 0)
|
||||||
|
return s.sendNoWait(stream.sendHdr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// closeStream is used to close a stream once both sides have
|
||||||
|
// issued a close. If there was an in-flight SYN and the stream
|
||||||
|
// was not yet established, then this will give the credit back.
|
||||||
|
func (s *Session) closeStream(id uint32) {
|
||||||
|
s.streamLock.Lock()
|
||||||
|
if _, ok := s.inflight[id]; ok {
|
||||||
|
select {
|
||||||
|
case <-s.synCh:
|
||||||
|
default:
|
||||||
|
s.logger.Printf("[ERR] yamux: SYN tracking out of sync")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete(s.streams, id)
|
||||||
|
s.streamLock.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
// establishStream is used to mark a stream that was in the
|
||||||
|
// SYN Sent state as established.
|
||||||
|
func (s *Session) establishStream(id uint32) {
|
||||||
|
s.streamLock.Lock()
|
||||||
|
if _, ok := s.inflight[id]; ok {
|
||||||
|
delete(s.inflight, id)
|
||||||
|
} else {
|
||||||
|
s.logger.Printf("[ERR] yamux: established stream without inflight SYN (no tracking entry)")
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
case <-s.synCh:
|
||||||
|
default:
|
||||||
|
s.logger.Printf("[ERR] yamux: established stream without inflight SYN (didn't have semaphore)")
|
||||||
|
}
|
||||||
|
s.streamLock.Unlock()
|
||||||
|
}
|
||||||
141
vendor/github.com/hashicorp/yamux/spec.md
generated
vendored
Normal file
141
vendor/github.com/hashicorp/yamux/spec.md
generated
vendored
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
# Specification
|
||||||
|
|
||||||
|
We use this document to detail the internal specification of Yamux.
|
||||||
|
This is used both as a guide for implementing Yamux, but also for
|
||||||
|
alternative interoperable libraries to be built.
|
||||||
|
|
||||||
|
# Framing
|
||||||
|
|
||||||
|
Yamux uses a streaming connection underneath, but imposes a message
|
||||||
|
framing so that it can be shared between many logical streams. Each
|
||||||
|
frame contains a header like:
|
||||||
|
|
||||||
|
* Version (8 bits)
|
||||||
|
* Type (8 bits)
|
||||||
|
* Flags (16 bits)
|
||||||
|
* StreamID (32 bits)
|
||||||
|
* Length (32 bits)
|
||||||
|
|
||||||
|
This means that each header has a 12 byte overhead.
|
||||||
|
All fields are encoded in network order (big endian).
|
||||||
|
Each field is described below:
|
||||||
|
|
||||||
|
## Version Field
|
||||||
|
|
||||||
|
The version field is used for future backwards compatibily. At the
|
||||||
|
current time, the field is always set to 0, to indicate the initial
|
||||||
|
version.
|
||||||
|
|
||||||
|
## Type Field
|
||||||
|
|
||||||
|
The type field is used to switch the frame message type. The following
|
||||||
|
message types are supported:
|
||||||
|
|
||||||
|
* 0x0 Data - Used to transmit data. May transmit zero length payloads
|
||||||
|
depending on the flags.
|
||||||
|
|
||||||
|
* 0x1 Window Update - Used to updated the senders receive window size.
|
||||||
|
This is used to implement per-session flow control.
|
||||||
|
|
||||||
|
* 0x2 Ping - Used to measure RTT. It can also be used to heart-beat
|
||||||
|
and do keep-alives over TCP.
|
||||||
|
|
||||||
|
* 0x3 Go Away - Used to close a session.
|
||||||
|
|
||||||
|
## Flag Field
|
||||||
|
|
||||||
|
The flags field is used to provide additional information related
|
||||||
|
to the message type. The following flags are supported:
|
||||||
|
|
||||||
|
* 0x1 SYN - Signals the start of a new stream. May be sent with a data or
|
||||||
|
window update message. Also sent with a ping to indicate outbound.
|
||||||
|
|
||||||
|
* 0x2 ACK - Acknowledges the start of a new stream. May be sent with a data
|
||||||
|
or window update message. Also sent with a ping to indicate response.
|
||||||
|
|
||||||
|
* 0x4 FIN - Performs a half-close of a stream. May be sent with a data
|
||||||
|
message or window update.
|
||||||
|
|
||||||
|
* 0x8 RST - Reset a stream immediately. May be sent with a data or
|
||||||
|
window update message.
|
||||||
|
|
||||||
|
## StreamID Field
|
||||||
|
|
||||||
|
The StreamID field is used to identify the logical stream the frame
|
||||||
|
is addressing. The client side should use odd ID's, and the server even.
|
||||||
|
This prevents any collisions. Additionally, the 0 ID is reserved to represent
|
||||||
|
the session.
|
||||||
|
|
||||||
|
Both Ping and Go Away messages should always use the 0 StreamID.
|
||||||
|
|
||||||
|
## Length Field
|
||||||
|
|
||||||
|
The meaning of the length field depends on the message type:
|
||||||
|
|
||||||
|
* Data - provides the length of bytes following the header
|
||||||
|
* Window update - provides a delta update to the window size
|
||||||
|
* Ping - Contains an opaque value, echoed back
|
||||||
|
* Go Away - Contains an error code
|
||||||
|
|
||||||
|
# Message Flow
|
||||||
|
|
||||||
|
There is no explicit connection setup, as Yamux relies on an underlying
|
||||||
|
transport to be provided. However, there is a distinction between client
|
||||||
|
and server side of the connection.
|
||||||
|
|
||||||
|
## Opening a stream
|
||||||
|
|
||||||
|
To open a stream, an initial data or window update frame is sent
|
||||||
|
with a new StreamID. The SYN flag should be set to signal a new stream.
|
||||||
|
|
||||||
|
The receiver must then reply with either a data or window update frame
|
||||||
|
with the StreamID along with the ACK flag to accept the stream or with
|
||||||
|
the RST flag to reject the stream.
|
||||||
|
|
||||||
|
Because we are relying on the reliable stream underneath, a connection
|
||||||
|
can begin sending data once the SYN flag is sent. The corresponding
|
||||||
|
ACK does not need to be received. This is particularly well suited
|
||||||
|
for an RPC system where a client wants to open a stream and immediately
|
||||||
|
fire a request without waiting for the RTT of the ACK.
|
||||||
|
|
||||||
|
This does introduce the possibility of a connection being rejected
|
||||||
|
after data has been sent already. This is a slight semantic difference
|
||||||
|
from TCP, where the conection cannot be refused after it is opened.
|
||||||
|
Clients should be prepared to handle this by checking for an error
|
||||||
|
that indicates a RST was received.
|
||||||
|
|
||||||
|
## Closing a stream
|
||||||
|
|
||||||
|
To close a stream, either side sends a data or window update frame
|
||||||
|
along with the FIN flag. This does a half-close indicating the sender
|
||||||
|
will send no further data.
|
||||||
|
|
||||||
|
Once both sides have closed the connection, the stream is closed.
|
||||||
|
|
||||||
|
Alternatively, if an error occurs, the RST flag can be used to
|
||||||
|
hard close a stream immediately.
|
||||||
|
|
||||||
|
## Flow Control
|
||||||
|
|
||||||
|
When Yamux is initially starts each stream with a 256KB window size.
|
||||||
|
There is no window size for the session.
|
||||||
|
|
||||||
|
To prevent the streams from stalling, window update frames should be
|
||||||
|
sent regularly. Yamux can be configured to provide a larger limit for
|
||||||
|
windows sizes. Both sides assume the initial 256KB window, but can
|
||||||
|
immediately send a window update as part of the SYN/ACK indicating a
|
||||||
|
larger window.
|
||||||
|
|
||||||
|
Both sides should track the number of bytes sent in Data frames
|
||||||
|
only, as only they are tracked as part of the window size.
|
||||||
|
|
||||||
|
## Session termination
|
||||||
|
|
||||||
|
When a session is being terminated, the Go Away message should
|
||||||
|
be sent. The Length should be set to one of the following to
|
||||||
|
provide an error code:
|
||||||
|
|
||||||
|
* 0x0 Normal termination
|
||||||
|
* 0x1 Protocol error
|
||||||
|
* 0x2 Internal error
|
||||||
|
|
||||||
449
vendor/github.com/hashicorp/yamux/stream.go
generated
vendored
Normal file
449
vendor/github.com/hashicorp/yamux/stream.go
generated
vendored
Normal file
@@ -0,0 +1,449 @@
|
|||||||
|
package yamux
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"io"
|
||||||
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type streamState int
|
||||||
|
|
||||||
|
const (
|
||||||
|
streamInit streamState = iota
|
||||||
|
streamSYNSent
|
||||||
|
streamSYNReceived
|
||||||
|
streamEstablished
|
||||||
|
streamLocalClose
|
||||||
|
streamRemoteClose
|
||||||
|
streamClosed
|
||||||
|
streamReset
|
||||||
|
)
|
||||||
|
|
||||||
|
// Stream is used to represent a logical stream
|
||||||
|
// within a session.
|
||||||
|
type Stream struct {
|
||||||
|
recvWindow uint32
|
||||||
|
sendWindow uint32
|
||||||
|
|
||||||
|
id uint32
|
||||||
|
session *Session
|
||||||
|
|
||||||
|
state streamState
|
||||||
|
stateLock sync.Mutex
|
||||||
|
|
||||||
|
recvBuf *bytes.Buffer
|
||||||
|
recvLock sync.Mutex
|
||||||
|
|
||||||
|
controlHdr header
|
||||||
|
controlErr chan error
|
||||||
|
controlHdrLock sync.Mutex
|
||||||
|
|
||||||
|
sendHdr header
|
||||||
|
sendErr chan error
|
||||||
|
sendLock sync.Mutex
|
||||||
|
|
||||||
|
recvNotifyCh chan struct{}
|
||||||
|
sendNotifyCh chan struct{}
|
||||||
|
|
||||||
|
readDeadline time.Time
|
||||||
|
writeDeadline time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
// newStream is used to construct a new stream within
|
||||||
|
// a given session for an ID
|
||||||
|
func newStream(session *Session, id uint32, state streamState) *Stream {
|
||||||
|
s := &Stream{
|
||||||
|
id: id,
|
||||||
|
session: session,
|
||||||
|
state: state,
|
||||||
|
controlHdr: header(make([]byte, headerSize)),
|
||||||
|
controlErr: make(chan error, 1),
|
||||||
|
sendHdr: header(make([]byte, headerSize)),
|
||||||
|
sendErr: make(chan error, 1),
|
||||||
|
recvWindow: initialStreamWindow,
|
||||||
|
sendWindow: initialStreamWindow,
|
||||||
|
recvNotifyCh: make(chan struct{}, 1),
|
||||||
|
sendNotifyCh: make(chan struct{}, 1),
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
// Session returns the associated stream session
|
||||||
|
func (s *Stream) Session() *Session {
|
||||||
|
return s.session
|
||||||
|
}
|
||||||
|
|
||||||
|
// StreamID returns the ID of this stream
|
||||||
|
func (s *Stream) StreamID() uint32 {
|
||||||
|
return s.id
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read is used to read from the stream
|
||||||
|
func (s *Stream) Read(b []byte) (n int, err error) {
|
||||||
|
defer asyncNotify(s.recvNotifyCh)
|
||||||
|
START:
|
||||||
|
s.stateLock.Lock()
|
||||||
|
switch s.state {
|
||||||
|
case streamLocalClose:
|
||||||
|
fallthrough
|
||||||
|
case streamRemoteClose:
|
||||||
|
fallthrough
|
||||||
|
case streamClosed:
|
||||||
|
if s.recvBuf == nil || s.recvBuf.Len() == 0 {
|
||||||
|
s.stateLock.Unlock()
|
||||||
|
return 0, io.EOF
|
||||||
|
}
|
||||||
|
case streamReset:
|
||||||
|
s.stateLock.Unlock()
|
||||||
|
return 0, ErrConnectionReset
|
||||||
|
}
|
||||||
|
s.stateLock.Unlock()
|
||||||
|
|
||||||
|
// If there is no data available, block
|
||||||
|
s.recvLock.Lock()
|
||||||
|
if s.recvBuf == nil || s.recvBuf.Len() == 0 {
|
||||||
|
s.recvLock.Unlock()
|
||||||
|
goto WAIT
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read any bytes
|
||||||
|
n, _ = s.recvBuf.Read(b)
|
||||||
|
s.recvLock.Unlock()
|
||||||
|
|
||||||
|
// Send a window update potentially
|
||||||
|
err = s.sendWindowUpdate()
|
||||||
|
return n, err
|
||||||
|
|
||||||
|
WAIT:
|
||||||
|
var timeout <-chan time.Time
|
||||||
|
if !s.readDeadline.IsZero() {
|
||||||
|
delay := s.readDeadline.Sub(time.Now())
|
||||||
|
timeout = time.After(delay)
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
case <-s.recvNotifyCh:
|
||||||
|
goto START
|
||||||
|
case <-timeout:
|
||||||
|
return 0, ErrTimeout
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write is used to write to the stream
|
||||||
|
func (s *Stream) Write(b []byte) (n int, err error) {
|
||||||
|
s.sendLock.Lock()
|
||||||
|
defer s.sendLock.Unlock()
|
||||||
|
total := 0
|
||||||
|
for total < len(b) {
|
||||||
|
n, err := s.write(b[total:])
|
||||||
|
total += n
|
||||||
|
if err != nil {
|
||||||
|
return total, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return total, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// write is used to write to the stream, may return on
|
||||||
|
// a short write.
|
||||||
|
func (s *Stream) write(b []byte) (n int, err error) {
|
||||||
|
var flags uint16
|
||||||
|
var max uint32
|
||||||
|
var body io.Reader
|
||||||
|
START:
|
||||||
|
s.stateLock.Lock()
|
||||||
|
switch s.state {
|
||||||
|
case streamLocalClose:
|
||||||
|
fallthrough
|
||||||
|
case streamClosed:
|
||||||
|
s.stateLock.Unlock()
|
||||||
|
return 0, ErrStreamClosed
|
||||||
|
case streamReset:
|
||||||
|
s.stateLock.Unlock()
|
||||||
|
return 0, ErrConnectionReset
|
||||||
|
}
|
||||||
|
s.stateLock.Unlock()
|
||||||
|
|
||||||
|
// If there is no data available, block
|
||||||
|
window := atomic.LoadUint32(&s.sendWindow)
|
||||||
|
if window == 0 {
|
||||||
|
goto WAIT
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine the flags if any
|
||||||
|
flags = s.sendFlags()
|
||||||
|
|
||||||
|
// Send up to our send window
|
||||||
|
max = min(window, uint32(len(b)))
|
||||||
|
body = bytes.NewReader(b[:max])
|
||||||
|
|
||||||
|
// Send the header
|
||||||
|
s.sendHdr.encode(typeData, flags, s.id, max)
|
||||||
|
if err := s.session.waitForSendErr(s.sendHdr, body, s.sendErr); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reduce our send window
|
||||||
|
atomic.AddUint32(&s.sendWindow, ^uint32(max-1))
|
||||||
|
|
||||||
|
// Unlock
|
||||||
|
return int(max), err
|
||||||
|
|
||||||
|
WAIT:
|
||||||
|
var timeout <-chan time.Time
|
||||||
|
if !s.writeDeadline.IsZero() {
|
||||||
|
delay := s.writeDeadline.Sub(time.Now())
|
||||||
|
timeout = time.After(delay)
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
case <-s.sendNotifyCh:
|
||||||
|
goto START
|
||||||
|
case <-timeout:
|
||||||
|
return 0, ErrTimeout
|
||||||
|
}
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// sendFlags determines any flags that are appropriate
|
||||||
|
// based on the current stream state
|
||||||
|
func (s *Stream) sendFlags() uint16 {
|
||||||
|
s.stateLock.Lock()
|
||||||
|
defer s.stateLock.Unlock()
|
||||||
|
var flags uint16
|
||||||
|
switch s.state {
|
||||||
|
case streamInit:
|
||||||
|
flags |= flagSYN
|
||||||
|
s.state = streamSYNSent
|
||||||
|
case streamSYNReceived:
|
||||||
|
flags |= flagACK
|
||||||
|
s.state = streamEstablished
|
||||||
|
}
|
||||||
|
return flags
|
||||||
|
}
|
||||||
|
|
||||||
|
// sendWindowUpdate potentially sends a window update enabling
|
||||||
|
// further writes to take place. Must be invoked with the lock.
|
||||||
|
func (s *Stream) sendWindowUpdate() error {
|
||||||
|
s.controlHdrLock.Lock()
|
||||||
|
defer s.controlHdrLock.Unlock()
|
||||||
|
|
||||||
|
// Determine the delta update
|
||||||
|
max := s.session.config.MaxStreamWindowSize
|
||||||
|
delta := max - atomic.LoadUint32(&s.recvWindow)
|
||||||
|
|
||||||
|
// Determine the flags if any
|
||||||
|
flags := s.sendFlags()
|
||||||
|
|
||||||
|
// Check if we can omit the update
|
||||||
|
if delta < (max/2) && flags == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update our window
|
||||||
|
atomic.AddUint32(&s.recvWindow, delta)
|
||||||
|
|
||||||
|
// Send the header
|
||||||
|
s.controlHdr.encode(typeWindowUpdate, flags, s.id, delta)
|
||||||
|
if err := s.session.waitForSendErr(s.controlHdr, nil, s.controlErr); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// sendClose is used to send a FIN
|
||||||
|
func (s *Stream) sendClose() error {
|
||||||
|
s.controlHdrLock.Lock()
|
||||||
|
defer s.controlHdrLock.Unlock()
|
||||||
|
|
||||||
|
flags := s.sendFlags()
|
||||||
|
flags |= flagFIN
|
||||||
|
s.controlHdr.encode(typeWindowUpdate, flags, s.id, 0)
|
||||||
|
if err := s.session.waitForSendErr(s.controlHdr, nil, s.controlErr); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close is used to close the stream
|
||||||
|
func (s *Stream) Close() error {
|
||||||
|
closeStream := false
|
||||||
|
s.stateLock.Lock()
|
||||||
|
switch s.state {
|
||||||
|
// Opened means we need to signal a close
|
||||||
|
case streamSYNSent:
|
||||||
|
fallthrough
|
||||||
|
case streamSYNReceived:
|
||||||
|
fallthrough
|
||||||
|
case streamEstablished:
|
||||||
|
s.state = streamLocalClose
|
||||||
|
goto SEND_CLOSE
|
||||||
|
|
||||||
|
case streamLocalClose:
|
||||||
|
case streamRemoteClose:
|
||||||
|
s.state = streamClosed
|
||||||
|
closeStream = true
|
||||||
|
goto SEND_CLOSE
|
||||||
|
|
||||||
|
case streamClosed:
|
||||||
|
case streamReset:
|
||||||
|
default:
|
||||||
|
panic("unhandled state")
|
||||||
|
}
|
||||||
|
s.stateLock.Unlock()
|
||||||
|
return nil
|
||||||
|
SEND_CLOSE:
|
||||||
|
s.stateLock.Unlock()
|
||||||
|
s.sendClose()
|
||||||
|
s.notifyWaiting()
|
||||||
|
if closeStream {
|
||||||
|
s.session.closeStream(s.id)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// forceClose is used for when the session is exiting
|
||||||
|
func (s *Stream) forceClose() {
|
||||||
|
s.stateLock.Lock()
|
||||||
|
s.state = streamClosed
|
||||||
|
s.stateLock.Unlock()
|
||||||
|
s.notifyWaiting()
|
||||||
|
}
|
||||||
|
|
||||||
|
// processFlags is used to update the state of the stream
|
||||||
|
// based on set flags, if any. Lock must be held
|
||||||
|
func (s *Stream) processFlags(flags uint16) error {
|
||||||
|
// Close the stream without holding the state lock
|
||||||
|
closeStream := false
|
||||||
|
defer func() {
|
||||||
|
if closeStream {
|
||||||
|
s.session.closeStream(s.id)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
s.stateLock.Lock()
|
||||||
|
defer s.stateLock.Unlock()
|
||||||
|
if flags&flagACK == flagACK {
|
||||||
|
if s.state == streamSYNSent {
|
||||||
|
s.state = streamEstablished
|
||||||
|
}
|
||||||
|
s.session.establishStream(s.id)
|
||||||
|
}
|
||||||
|
if flags&flagFIN == flagFIN {
|
||||||
|
switch s.state {
|
||||||
|
case streamSYNSent:
|
||||||
|
fallthrough
|
||||||
|
case streamSYNReceived:
|
||||||
|
fallthrough
|
||||||
|
case streamEstablished:
|
||||||
|
s.state = streamRemoteClose
|
||||||
|
s.notifyWaiting()
|
||||||
|
case streamLocalClose:
|
||||||
|
s.state = streamClosed
|
||||||
|
closeStream = true
|
||||||
|
s.notifyWaiting()
|
||||||
|
default:
|
||||||
|
s.session.logger.Printf("[ERR] yamux: unexpected FIN flag in state %d", s.state)
|
||||||
|
return ErrUnexpectedFlag
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if flags&flagRST == flagRST {
|
||||||
|
s.state = streamReset
|
||||||
|
closeStream = true
|
||||||
|
s.notifyWaiting()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// notifyWaiting notifies all the waiting channels
|
||||||
|
func (s *Stream) notifyWaiting() {
|
||||||
|
asyncNotify(s.recvNotifyCh)
|
||||||
|
asyncNotify(s.sendNotifyCh)
|
||||||
|
}
|
||||||
|
|
||||||
|
// incrSendWindow updates the size of our send window
|
||||||
|
func (s *Stream) incrSendWindow(hdr header, flags uint16) error {
|
||||||
|
if err := s.processFlags(flags); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Increase window, unblock a sender
|
||||||
|
atomic.AddUint32(&s.sendWindow, hdr.Length())
|
||||||
|
asyncNotify(s.sendNotifyCh)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// readData is used to handle a data frame
|
||||||
|
func (s *Stream) readData(hdr header, flags uint16, conn io.Reader) error {
|
||||||
|
if err := s.processFlags(flags); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that our recv window is not exceeded
|
||||||
|
length := hdr.Length()
|
||||||
|
if length == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if remain := atomic.LoadUint32(&s.recvWindow); length > remain {
|
||||||
|
s.session.logger.Printf("[ERR] yamux: receive window exceeded (stream: %d, remain: %d, recv: %d)", s.id, remain, length)
|
||||||
|
return ErrRecvWindowExceeded
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wrap in a limited reader
|
||||||
|
conn = &io.LimitedReader{R: conn, N: int64(length)}
|
||||||
|
|
||||||
|
// Copy into buffer
|
||||||
|
s.recvLock.Lock()
|
||||||
|
if s.recvBuf == nil {
|
||||||
|
// Allocate the receive buffer just-in-time to fit the full data frame.
|
||||||
|
// This way we can read in the whole packet without further allocations.
|
||||||
|
s.recvBuf = bytes.NewBuffer(make([]byte, 0, length))
|
||||||
|
}
|
||||||
|
if _, err := io.Copy(s.recvBuf, conn); err != nil {
|
||||||
|
s.session.logger.Printf("[ERR] yamux: Failed to read stream data: %v", err)
|
||||||
|
s.recvLock.Unlock()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decrement the receive window
|
||||||
|
atomic.AddUint32(&s.recvWindow, ^uint32(length-1))
|
||||||
|
s.recvLock.Unlock()
|
||||||
|
|
||||||
|
// Unblock any readers
|
||||||
|
asyncNotify(s.recvNotifyCh)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDeadline sets the read and write deadlines
|
||||||
|
func (s *Stream) SetDeadline(t time.Time) error {
|
||||||
|
if err := s.SetReadDeadline(t); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := s.SetWriteDeadline(t); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetReadDeadline sets the deadline for future Read calls.
|
||||||
|
func (s *Stream) SetReadDeadline(t time.Time) error {
|
||||||
|
s.readDeadline = t
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetWriteDeadline sets the deadline for future Write calls
|
||||||
|
func (s *Stream) SetWriteDeadline(t time.Time) error {
|
||||||
|
s.writeDeadline = t
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Shrink is used to compact the amount of buffers utilized
|
||||||
|
// This is useful when using Yamux in a connection pool to reduce
|
||||||
|
// the idle memory utilization.
|
||||||
|
func (s *Stream) Shrink() {
|
||||||
|
s.recvLock.Lock()
|
||||||
|
if s.recvBuf != nil && s.recvBuf.Len() == 0 {
|
||||||
|
s.recvBuf = nil
|
||||||
|
}
|
||||||
|
s.recvLock.Unlock()
|
||||||
|
}
|
||||||
28
vendor/github.com/hashicorp/yamux/util.go
generated
vendored
Normal file
28
vendor/github.com/hashicorp/yamux/util.go
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package yamux
|
||||||
|
|
||||||
|
// asyncSendErr is used to try an async send of an error
|
||||||
|
func asyncSendErr(ch chan error, err error) {
|
||||||
|
if ch == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
case ch <- err:
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// asyncNotify is used to signal a waiting goroutine
|
||||||
|
func asyncNotify(ch chan struct{}) {
|
||||||
|
select {
|
||||||
|
case ch <- struct{}{}:
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// min computes the minimum of two values
|
||||||
|
func min(a, b uint32) uint32 {
|
||||||
|
if a < b {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
return b
|
||||||
|
}
|
||||||
194
vendor/vendor.json
vendored
194
vendor/vendor.json
vendored
@@ -27,184 +27,184 @@
|
|||||||
"revisionTime": "2016-05-19T10:40:38Z"
|
"revisionTime": "2016-05-19T10:40:38Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "YElK6wNjU5aZLUL4KP4Cxde/1MY=",
|
"checksumSHA1": "zKsZOyaTSC4MmdbKfiM6iUCjvGk=",
|
||||||
"path": "github.com/aws/aws-sdk-go/aws",
|
"path": "github.com/aws/aws-sdk-go/aws",
|
||||||
"revision": "665c623d7f3e0ee276596b006655ba4dbe0565b0",
|
"revision": "7878b9c08027abca987ff7e628e69f73d5a348b5",
|
||||||
"revisionTime": "2016-05-29T19:36:57Z"
|
"revisionTime": "2016-06-02T21:43:38Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "AWg3FBA1NTPdIVZipaQf/rGx38o=",
|
"checksumSHA1": "AWg3FBA1NTPdIVZipaQf/rGx38o=",
|
||||||
"path": "github.com/aws/aws-sdk-go/aws/awserr",
|
"path": "github.com/aws/aws-sdk-go/aws/awserr",
|
||||||
"revision": "665c623d7f3e0ee276596b006655ba4dbe0565b0",
|
"revision": "7878b9c08027abca987ff7e628e69f73d5a348b5",
|
||||||
"revisionTime": "2016-05-29T19:36:57Z"
|
"revisionTime": "2016-06-02T21:43:38Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "dkfyy7aRNZ6BmUZ4ZdLIcMMXiPA=",
|
"checksumSHA1": "dkfyy7aRNZ6BmUZ4ZdLIcMMXiPA=",
|
||||||
"path": "github.com/aws/aws-sdk-go/aws/awsutil",
|
"path": "github.com/aws/aws-sdk-go/aws/awsutil",
|
||||||
"revision": "665c623d7f3e0ee276596b006655ba4dbe0565b0",
|
"revision": "7878b9c08027abca987ff7e628e69f73d5a348b5",
|
||||||
"revisionTime": "2016-05-29T19:36:57Z"
|
"revisionTime": "2016-06-02T21:43:38Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "RsYlRfQceaAgqjIrExwNsb/RBEM=",
|
"checksumSHA1": "RsYlRfQceaAgqjIrExwNsb/RBEM=",
|
||||||
"path": "github.com/aws/aws-sdk-go/aws/client",
|
"path": "github.com/aws/aws-sdk-go/aws/client",
|
||||||
"revision": "665c623d7f3e0ee276596b006655ba4dbe0565b0",
|
"revision": "7878b9c08027abca987ff7e628e69f73d5a348b5",
|
||||||
"revisionTime": "2016-05-29T19:36:57Z"
|
"revisionTime": "2016-06-02T21:43:38Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "ieAJ+Cvp/PKv1LpUEnUXpc3OI6E=",
|
"checksumSHA1": "ieAJ+Cvp/PKv1LpUEnUXpc3OI6E=",
|
||||||
"path": "github.com/aws/aws-sdk-go/aws/client/metadata",
|
"path": "github.com/aws/aws-sdk-go/aws/client/metadata",
|
||||||
"revision": "665c623d7f3e0ee276596b006655ba4dbe0565b0",
|
"revision": "7878b9c08027abca987ff7e628e69f73d5a348b5",
|
||||||
"revisionTime": "2016-05-29T19:36:57Z"
|
"revisionTime": "2016-06-02T21:43:38Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "gNWirlrTfSLbOe421hISBAhTqa4=",
|
"checksumSHA1": "gNWirlrTfSLbOe421hISBAhTqa4=",
|
||||||
"path": "github.com/aws/aws-sdk-go/aws/corehandlers",
|
"path": "github.com/aws/aws-sdk-go/aws/corehandlers",
|
||||||
"revision": "665c623d7f3e0ee276596b006655ba4dbe0565b0",
|
"revision": "7878b9c08027abca987ff7e628e69f73d5a348b5",
|
||||||
"revisionTime": "2016-05-29T19:36:57Z"
|
"revisionTime": "2016-06-02T21:43:38Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "EiauD48zRlXIFvAENgZ+PXSEnT0=",
|
"checksumSHA1": "EiauD48zRlXIFvAENgZ+PXSEnT0=",
|
||||||
"path": "github.com/aws/aws-sdk-go/aws/credentials",
|
"path": "github.com/aws/aws-sdk-go/aws/credentials",
|
||||||
"revision": "665c623d7f3e0ee276596b006655ba4dbe0565b0",
|
"revision": "7878b9c08027abca987ff7e628e69f73d5a348b5",
|
||||||
"revisionTime": "2016-05-29T19:36:57Z"
|
"revisionTime": "2016-06-02T21:43:38Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "KQiUK/zr3mqnAXD7x/X55/iNme0=",
|
"checksumSHA1": "KQiUK/zr3mqnAXD7x/X55/iNme0=",
|
||||||
"path": "github.com/aws/aws-sdk-go/aws/credentials/ec2rolecreds",
|
"path": "github.com/aws/aws-sdk-go/aws/credentials/ec2rolecreds",
|
||||||
"revision": "665c623d7f3e0ee276596b006655ba4dbe0565b0",
|
"revision": "7878b9c08027abca987ff7e628e69f73d5a348b5",
|
||||||
"revisionTime": "2016-05-29T19:36:57Z"
|
"revisionTime": "2016-06-02T21:43:38Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "t9z4goehHyiGgU85snZcFogywwk=",
|
"checksumSHA1": "t9z4goehHyiGgU85snZcFogywwk=",
|
||||||
"path": "github.com/aws/aws-sdk-go/aws/defaults",
|
"path": "github.com/aws/aws-sdk-go/aws/defaults",
|
||||||
"revision": "665c623d7f3e0ee276596b006655ba4dbe0565b0",
|
"revision": "7878b9c08027abca987ff7e628e69f73d5a348b5",
|
||||||
"revisionTime": "2016-05-29T19:36:57Z"
|
"revisionTime": "2016-06-02T21:43:38Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "U0SthWum+t9ACanK7SDJOg3dO6M=",
|
"checksumSHA1": "U0SthWum+t9ACanK7SDJOg3dO6M=",
|
||||||
"path": "github.com/aws/aws-sdk-go/aws/ec2metadata",
|
"path": "github.com/aws/aws-sdk-go/aws/ec2metadata",
|
||||||
"revision": "665c623d7f3e0ee276596b006655ba4dbe0565b0",
|
"revision": "7878b9c08027abca987ff7e628e69f73d5a348b5",
|
||||||
"revisionTime": "2016-05-29T19:36:57Z"
|
"revisionTime": "2016-06-02T21:43:38Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "sPD1Ed00IPAslndR75MSwxVBlNg=",
|
"checksumSHA1": "sPD1Ed00IPAslndR75MSwxVBlNg=",
|
||||||
"path": "github.com/aws/aws-sdk-go/aws/request",
|
"path": "github.com/aws/aws-sdk-go/aws/request",
|
||||||
"revision": "665c623d7f3e0ee276596b006655ba4dbe0565b0",
|
"revision": "7878b9c08027abca987ff7e628e69f73d5a348b5",
|
||||||
"revisionTime": "2016-05-29T19:36:57Z"
|
"revisionTime": "2016-06-02T21:43:38Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "46SVikiXo5xuy/CS6mM1XVTUU7w=",
|
"checksumSHA1": "46SVikiXo5xuy/CS6mM1XVTUU7w=",
|
||||||
"path": "github.com/aws/aws-sdk-go/aws/session",
|
"path": "github.com/aws/aws-sdk-go/aws/session",
|
||||||
"revision": "665c623d7f3e0ee276596b006655ba4dbe0565b0",
|
"revision": "7878b9c08027abca987ff7e628e69f73d5a348b5",
|
||||||
"revisionTime": "2016-05-29T19:36:57Z"
|
"revisionTime": "2016-06-02T21:43:38Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "sgft7A0lRCVD7QBogydg46lr3NM=",
|
"checksumSHA1": "sgft7A0lRCVD7QBogydg46lr3NM=",
|
||||||
"path": "github.com/aws/aws-sdk-go/private/endpoints",
|
"path": "github.com/aws/aws-sdk-go/private/endpoints",
|
||||||
"revision": "665c623d7f3e0ee276596b006655ba4dbe0565b0",
|
"revision": "7878b9c08027abca987ff7e628e69f73d5a348b5",
|
||||||
"revisionTime": "2016-05-29T19:36:57Z"
|
"revisionTime": "2016-06-02T21:43:38Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "wk7EyvDaHwb5qqoOP/4d3cV0708=",
|
"checksumSHA1": "wk7EyvDaHwb5qqoOP/4d3cV0708=",
|
||||||
"path": "github.com/aws/aws-sdk-go/private/protocol",
|
"path": "github.com/aws/aws-sdk-go/private/protocol",
|
||||||
"revision": "665c623d7f3e0ee276596b006655ba4dbe0565b0",
|
"revision": "7878b9c08027abca987ff7e628e69f73d5a348b5",
|
||||||
"revisionTime": "2016-05-29T19:36:57Z"
|
"revisionTime": "2016-06-02T21:43:38Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "G1he3uSmd1h8ZRnKOIWuDrWp2zQ=",
|
"checksumSHA1": "G1he3uSmd1h8ZRnKOIWuDrWp2zQ=",
|
||||||
"path": "github.com/aws/aws-sdk-go/private/protocol/ec2query",
|
"path": "github.com/aws/aws-sdk-go/private/protocol/ec2query",
|
||||||
"revision": "665c623d7f3e0ee276596b006655ba4dbe0565b0",
|
"revision": "7878b9c08027abca987ff7e628e69f73d5a348b5",
|
||||||
"revisionTime": "2016-05-29T19:36:57Z"
|
"revisionTime": "2016-06-02T21:43:38Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "gHqZ41fSrCEUftkImHKGW+cKxFk=",
|
"checksumSHA1": "gHqZ41fSrCEUftkImHKGW+cKxFk=",
|
||||||
"path": "github.com/aws/aws-sdk-go/private/protocol/json/jsonutil",
|
"path": "github.com/aws/aws-sdk-go/private/protocol/json/jsonutil",
|
||||||
"revision": "665c623d7f3e0ee276596b006655ba4dbe0565b0",
|
"revision": "7878b9c08027abca987ff7e628e69f73d5a348b5",
|
||||||
"revisionTime": "2016-05-29T19:36:57Z"
|
"revisionTime": "2016-06-02T21:43:38Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "MPzz1x/qt6f2R/JW6aELbm/qT4k=",
|
"checksumSHA1": "MPzz1x/qt6f2R/JW6aELbm/qT4k=",
|
||||||
"path": "github.com/aws/aws-sdk-go/private/protocol/jsonrpc",
|
"path": "github.com/aws/aws-sdk-go/private/protocol/jsonrpc",
|
||||||
"revision": "665c623d7f3e0ee276596b006655ba4dbe0565b0",
|
"revision": "7878b9c08027abca987ff7e628e69f73d5a348b5",
|
||||||
"revisionTime": "2016-05-29T19:36:57Z"
|
"revisionTime": "2016-06-02T21:43:38Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "nHHyS4+VgZOV7F3Xu87crArmbds=",
|
"checksumSHA1": "nHHyS4+VgZOV7F3Xu87crArmbds=",
|
||||||
"path": "github.com/aws/aws-sdk-go/private/protocol/query",
|
"path": "github.com/aws/aws-sdk-go/private/protocol/query",
|
||||||
"revision": "665c623d7f3e0ee276596b006655ba4dbe0565b0",
|
"revision": "7878b9c08027abca987ff7e628e69f73d5a348b5",
|
||||||
"revisionTime": "2016-05-29T19:36:57Z"
|
"revisionTime": "2016-06-02T21:43:38Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "5xzix1R8prUyWxgLnzUQoxTsfik=",
|
"checksumSHA1": "5xzix1R8prUyWxgLnzUQoxTsfik=",
|
||||||
"path": "github.com/aws/aws-sdk-go/private/protocol/query/queryutil",
|
"path": "github.com/aws/aws-sdk-go/private/protocol/query/queryutil",
|
||||||
"revision": "665c623d7f3e0ee276596b006655ba4dbe0565b0",
|
"revision": "7878b9c08027abca987ff7e628e69f73d5a348b5",
|
||||||
"revisionTime": "2016-05-29T19:36:57Z"
|
"revisionTime": "2016-06-02T21:43:38Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "TW/7U+/8ormL7acf6z2rv2hDD+s=",
|
"checksumSHA1": "TW/7U+/8ormL7acf6z2rv2hDD+s=",
|
||||||
"path": "github.com/aws/aws-sdk-go/private/protocol/rest",
|
"path": "github.com/aws/aws-sdk-go/private/protocol/rest",
|
||||||
"revision": "665c623d7f3e0ee276596b006655ba4dbe0565b0",
|
"revision": "7878b9c08027abca987ff7e628e69f73d5a348b5",
|
||||||
"revisionTime": "2016-05-29T19:36:57Z"
|
"revisionTime": "2016-06-02T21:43:38Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "ttxyyPnlmMDqX+sY10BwbwwA+jo=",
|
"checksumSHA1": "ttxyyPnlmMDqX+sY10BwbwwA+jo=",
|
||||||
"path": "github.com/aws/aws-sdk-go/private/protocol/restxml",
|
"path": "github.com/aws/aws-sdk-go/private/protocol/restxml",
|
||||||
"revision": "665c623d7f3e0ee276596b006655ba4dbe0565b0",
|
"revision": "7878b9c08027abca987ff7e628e69f73d5a348b5",
|
||||||
"revisionTime": "2016-05-29T19:36:57Z"
|
"revisionTime": "2016-06-02T21:43:38Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "LsCIsjbzX2r3n/AhpNJvAC5ueNA=",
|
"checksumSHA1": "LsCIsjbzX2r3n/AhpNJvAC5ueNA=",
|
||||||
"path": "github.com/aws/aws-sdk-go/private/protocol/xml/xmlutil",
|
"path": "github.com/aws/aws-sdk-go/private/protocol/xml/xmlutil",
|
||||||
"revision": "665c623d7f3e0ee276596b006655ba4dbe0565b0",
|
"revision": "7878b9c08027abca987ff7e628e69f73d5a348b5",
|
||||||
"revisionTime": "2016-05-29T19:36:57Z"
|
"revisionTime": "2016-06-02T21:43:38Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "wZbHPxkyYsr5h6GW5OVh9qIMZR8=",
|
"checksumSHA1": "wZbHPxkyYsr5h6GW5OVh9qIMZR8=",
|
||||||
"path": "github.com/aws/aws-sdk-go/private/signer/v4",
|
"path": "github.com/aws/aws-sdk-go/private/signer/v4",
|
||||||
"revision": "665c623d7f3e0ee276596b006655ba4dbe0565b0",
|
"revision": "7878b9c08027abca987ff7e628e69f73d5a348b5",
|
||||||
"revisionTime": "2016-05-29T19:36:57Z"
|
"revisionTime": "2016-06-02T21:43:38Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "Eo9yODN5U99BK0pMzoqnBm7PCrY=",
|
"checksumSHA1": "Eo9yODN5U99BK0pMzoqnBm7PCrY=",
|
||||||
"path": "github.com/aws/aws-sdk-go/private/waiter",
|
"path": "github.com/aws/aws-sdk-go/private/waiter",
|
||||||
"revision": "665c623d7f3e0ee276596b006655ba4dbe0565b0",
|
"revision": "7878b9c08027abca987ff7e628e69f73d5a348b5",
|
||||||
"revisionTime": "2016-05-29T19:36:57Z"
|
"revisionTime": "2016-06-02T21:43:38Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "tDZIdoVN4ECk3PrhKev2IxpnXJA=",
|
"checksumSHA1": "tDZIdoVN4ECk3PrhKev2IxpnXJA=",
|
||||||
"path": "github.com/aws/aws-sdk-go/service/dynamodb",
|
"path": "github.com/aws/aws-sdk-go/service/dynamodb",
|
||||||
"revision": "665c623d7f3e0ee276596b006655ba4dbe0565b0",
|
"revision": "7878b9c08027abca987ff7e628e69f73d5a348b5",
|
||||||
"revisionTime": "2016-05-29T19:36:57Z"
|
"revisionTime": "2016-06-02T21:43:38Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "CT/wROCklrL1EkTmd43QRZCfuNw=",
|
"checksumSHA1": "CT/wROCklrL1EkTmd43QRZCfuNw=",
|
||||||
"path": "github.com/aws/aws-sdk-go/service/dynamodb/dynamodbattribute",
|
"path": "github.com/aws/aws-sdk-go/service/dynamodb/dynamodbattribute",
|
||||||
"revision": "665c623d7f3e0ee276596b006655ba4dbe0565b0",
|
"revision": "7878b9c08027abca987ff7e628e69f73d5a348b5",
|
||||||
"revisionTime": "2016-05-29T19:36:57Z"
|
"revisionTime": "2016-06-02T21:43:38Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "H3wPCfQrrQN2sxBwwahimRs7UIY=",
|
"checksumSHA1": "sf5+6DarxX5YbChCrJZUhsvSGMo=",
|
||||||
"path": "github.com/aws/aws-sdk-go/service/ec2",
|
"path": "github.com/aws/aws-sdk-go/service/ec2",
|
||||||
"revision": "665c623d7f3e0ee276596b006655ba4dbe0565b0",
|
"revision": "7878b9c08027abca987ff7e628e69f73d5a348b5",
|
||||||
"revisionTime": "2016-05-29T19:36:57Z"
|
"revisionTime": "2016-06-02T21:43:38Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "38ZhXbUh5DhfNvwIj98VWMT2i50=",
|
"checksumSHA1": "38ZhXbUh5DhfNvwIj98VWMT2i50=",
|
||||||
"path": "github.com/aws/aws-sdk-go/service/iam",
|
"path": "github.com/aws/aws-sdk-go/service/iam",
|
||||||
"revision": "665c623d7f3e0ee276596b006655ba4dbe0565b0",
|
"revision": "7878b9c08027abca987ff7e628e69f73d5a348b5",
|
||||||
"revisionTime": "2016-05-29T19:36:57Z"
|
"revisionTime": "2016-06-02T21:43:38Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "BA/gv0KordTClvOxXmhBZTnesqo=",
|
"checksumSHA1": "BA/gv0KordTClvOxXmhBZTnesqo=",
|
||||||
"path": "github.com/aws/aws-sdk-go/service/s3",
|
"path": "github.com/aws/aws-sdk-go/service/s3",
|
||||||
"revision": "665c623d7f3e0ee276596b006655ba4dbe0565b0",
|
"revision": "7878b9c08027abca987ff7e628e69f73d5a348b5",
|
||||||
"revisionTime": "2016-05-29T19:36:57Z"
|
"revisionTime": "2016-06-02T21:43:38Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "QOVvdzwlhH6tCVOPuRqUvFbxFMs=",
|
"checksumSHA1": "QOVvdzwlhH6tCVOPuRqUvFbxFMs=",
|
||||||
"path": "github.com/aws/aws-sdk-go/service/sts",
|
"path": "github.com/aws/aws-sdk-go/service/sts",
|
||||||
"revision": "665c623d7f3e0ee276596b006655ba4dbe0565b0",
|
"revision": "7878b9c08027abca987ff7e628e69f73d5a348b5",
|
||||||
"revisionTime": "2016-05-29T19:36:57Z"
|
"revisionTime": "2016-06-02T21:43:38Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "dvd7Su+WNmHRP1+w1HezrPUCDsc=",
|
"checksumSHA1": "dvd7Su+WNmHRP1+w1HezrPUCDsc=",
|
||||||
@@ -221,32 +221,32 @@
|
|||||||
{
|
{
|
||||||
"checksumSHA1": "Fa/Hw0ByZgcIDU5iG+Jt0MdeYYg=",
|
"checksumSHA1": "Fa/Hw0ByZgcIDU5iG+Jt0MdeYYg=",
|
||||||
"path": "github.com/coreos/etcd/client",
|
"path": "github.com/coreos/etcd/client",
|
||||||
"revision": "36fcc9e9d4ce993998a9170b2293c30b4e5a601a",
|
"revision": "b3fee0abffb42424c1f833fcdd92101736bb2ce9",
|
||||||
"revisionTime": "2016-06-01T14:04:36Z"
|
"revisionTime": "2016-06-03T04:48:45Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "mKIXx1kDwmVmdIpZ3pJtRBuUKso=",
|
"checksumSHA1": "mKIXx1kDwmVmdIpZ3pJtRBuUKso=",
|
||||||
"path": "github.com/coreos/etcd/pkg/pathutil",
|
"path": "github.com/coreos/etcd/pkg/pathutil",
|
||||||
"revision": "36fcc9e9d4ce993998a9170b2293c30b4e5a601a",
|
"revision": "b3fee0abffb42424c1f833fcdd92101736bb2ce9",
|
||||||
"revisionTime": "2016-06-01T14:04:36Z"
|
"revisionTime": "2016-06-03T04:48:45Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "rMyIh9PsSvPs6Yd+YgKITQzQJx8=",
|
"checksumSHA1": "rMyIh9PsSvPs6Yd+YgKITQzQJx8=",
|
||||||
"path": "github.com/coreos/etcd/pkg/tlsutil",
|
"path": "github.com/coreos/etcd/pkg/tlsutil",
|
||||||
"revision": "36fcc9e9d4ce993998a9170b2293c30b4e5a601a",
|
"revision": "b3fee0abffb42424c1f833fcdd92101736bb2ce9",
|
||||||
"revisionTime": "2016-06-01T14:04:36Z"
|
"revisionTime": "2016-06-03T04:48:45Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "sPw0rgNpFDQF2gvGitCpRj1WPXE=",
|
"checksumSHA1": "+rHx+d1sRhZGCJtp6DovJhQkHZw=",
|
||||||
"path": "github.com/coreos/etcd/pkg/transport",
|
"path": "github.com/coreos/etcd/pkg/transport",
|
||||||
"revision": "36fcc9e9d4ce993998a9170b2293c30b4e5a601a",
|
"revision": "b3fee0abffb42424c1f833fcdd92101736bb2ce9",
|
||||||
"revisionTime": "2016-06-01T14:04:36Z"
|
"revisionTime": "2016-06-03T04:48:45Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "kGLbveUJwLvoqg9yeWAnY0BQXtA=",
|
"checksumSHA1": "kGLbveUJwLvoqg9yeWAnY0BQXtA=",
|
||||||
"path": "github.com/coreos/etcd/pkg/types",
|
"path": "github.com/coreos/etcd/pkg/types",
|
||||||
"revision": "36fcc9e9d4ce993998a9170b2293c30b4e5a601a",
|
"revision": "b3fee0abffb42424c1f833fcdd92101736bb2ce9",
|
||||||
"revisionTime": "2016-06-01T14:04:36Z"
|
"revisionTime": "2016-06-03T04:48:45Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "4HOlPm1zZzFSCX7gZqQ4kxu0Gzc=",
|
"checksumSHA1": "4HOlPm1zZzFSCX7gZqQ4kxu0Gzc=",
|
||||||
@@ -285,10 +285,10 @@
|
|||||||
"revisionTime": "2016-05-03T19:07:39Z"
|
"revisionTime": "2016-05-03T19:07:39Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "BAsNRt/OaVkivs5nhA1v/ayOGag=",
|
"checksumSHA1": "FfdxnQ4CZVJJvG4BC1fWavgperI=",
|
||||||
"path": "github.com/go-ini/ini",
|
"path": "github.com/go-ini/ini",
|
||||||
"revision": "12f418cc7edc5a618a51407b7ac1f1f512139df3",
|
"revision": "72ba3e6b9e6b87e0c74c9a7a4dc86e8dd8ba4355",
|
||||||
"revisionTime": "2016-03-21T23:18:31Z"
|
"revisionTime": "2016-06-01T19:11:21Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "ka0nmgRfF36EbF2PztuMeYG7ysA=",
|
"checksumSHA1": "ka0nmgRfF36EbF2PztuMeYG7ysA=",
|
||||||
@@ -299,8 +299,8 @@
|
|||||||
{
|
{
|
||||||
"checksumSHA1": "E3ThDyBRCqfFAjY/jjzyGOyYS9w=",
|
"checksumSHA1": "E3ThDyBRCqfFAjY/jjzyGOyYS9w=",
|
||||||
"path": "github.com/go-sql-driver/mysql",
|
"path": "github.com/go-sql-driver/mysql",
|
||||||
"revision": "7ebe0a500653eeb1859664bed5e48dec1e164e73",
|
"revision": "3654d25ec346ee8ce71a68431025458d52a38ac0",
|
||||||
"revisionTime": "2016-04-11T07:50:31Z"
|
"revisionTime": "2016-06-02T00:10:21Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "Ob6CmVNdVsBvXJLDGIcowMz4WsA=",
|
"checksumSHA1": "Ob6CmVNdVsBvXJLDGIcowMz4WsA=",
|
||||||
@@ -353,14 +353,14 @@
|
|||||||
{
|
{
|
||||||
"checksumSHA1": "glOabn8rkJvz7tjz/xfX4lmt070=",
|
"checksumSHA1": "glOabn8rkJvz7tjz/xfX4lmt070=",
|
||||||
"path": "github.com/hashicorp/consul/api",
|
"path": "github.com/hashicorp/consul/api",
|
||||||
"revision": "b43f900766ad92eebbd5a8f931fe0fe244f9969d",
|
"revision": "ebf7ea1d759184c02a5bb5263a7c52d29838ffc3",
|
||||||
"revisionTime": "2016-05-29T18:34:41Z"
|
"revisionTime": "2016-06-01T20:35:34Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "0DPAA2cTBjrCGgXaxXil0vILcFs=",
|
"checksumSHA1": "0DPAA2cTBjrCGgXaxXil0vILcFs=",
|
||||||
"path": "github.com/hashicorp/consul/lib",
|
"path": "github.com/hashicorp/consul/lib",
|
||||||
"revision": "b43f900766ad92eebbd5a8f931fe0fe244f9969d",
|
"revision": "ebf7ea1d759184c02a5bb5263a7c52d29838ffc3",
|
||||||
"revisionTime": "2016-05-29T18:34:41Z"
|
"revisionTime": "2016-06-01T20:35:34Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "cdOCt0Yb+hdErz8NAQqayxPmRsY=",
|
"checksumSHA1": "cdOCt0Yb+hdErz8NAQqayxPmRsY=",
|
||||||
@@ -374,6 +374,12 @@
|
|||||||
"revision": "ad28ea4487f05916463e2423a55166280e8254b5",
|
"revision": "ad28ea4487f05916463e2423a55166280e8254b5",
|
||||||
"revisionTime": "2016-04-07T17:41:26Z"
|
"revisionTime": "2016-04-07T17:41:26Z"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"checksumSHA1": "TNlVzNR1OaajcNi3CbQ3bGbaLGU=",
|
||||||
|
"path": "github.com/hashicorp/go-msgpack/codec",
|
||||||
|
"revision": "fa3f63826f7c23912c15263591e65d54d080b458",
|
||||||
|
"revisionTime": "2015-05-18T23:42:57Z"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "lrSl49G23l6NhfilxPM0XFs5rZo=",
|
"checksumSHA1": "lrSl49G23l6NhfilxPM0XFs5rZo=",
|
||||||
"path": "github.com/hashicorp/go-multierror",
|
"path": "github.com/hashicorp/go-multierror",
|
||||||
@@ -470,12 +476,36 @@
|
|||||||
"revision": "0dc08b1671f34c4250ce212759ebd880f743d883",
|
"revision": "0dc08b1671f34c4250ce212759ebd880f743d883",
|
||||||
"revisionTime": "2015-06-09T07:04:31Z"
|
"revisionTime": "2015-06-09T07:04:31Z"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"checksumSHA1": "qnlqWJYV81ENr61SZk9c65R1mDo=",
|
||||||
|
"path": "github.com/hashicorp/net-rpc-msgpackrpc",
|
||||||
|
"revision": "a14192a58a694c123d8fe5481d4a4727d6ae82f3",
|
||||||
|
"revisionTime": "2015-11-16T02:03:38Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"checksumSHA1": "u9qHbpIgMZ7/fjO0gFfds2m/1ck=",
|
||||||
|
"path": "github.com/hashicorp/scada-client",
|
||||||
|
"revision": "6e896784f66f82cdc6f17e00052db91699dc277d",
|
||||||
|
"revisionTime": "2016-06-01T22:40:23Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"checksumSHA1": "fv3nX1vDZViW0tA7Aa5Va2lBUtM=",
|
||||||
|
"path": "github.com/hashicorp/scada-client/scada",
|
||||||
|
"revision": "6e896784f66f82cdc6f17e00052db91699dc277d",
|
||||||
|
"revisionTime": "2016-06-01T22:40:23Z"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "E3Xcanc9ouQwL+CZGOUyA/+giLg=",
|
"checksumSHA1": "E3Xcanc9ouQwL+CZGOUyA/+giLg=",
|
||||||
"path": "github.com/hashicorp/serf/coordinate",
|
"path": "github.com/hashicorp/serf/coordinate",
|
||||||
"revision": "b60a6d928fe726a588f79a1d500582507f9d79de",
|
"revision": "b60a6d928fe726a588f79a1d500582507f9d79de",
|
||||||
"revisionTime": "2016-05-25T23:17:25Z"
|
"revisionTime": "2016-05-25T23:17:25Z"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"checksumSHA1": "xvxetwF2G1XHScrmo8EM3yisjBc=",
|
||||||
|
"path": "github.com/hashicorp/yamux",
|
||||||
|
"revision": "172cde3b6ca5c154ff4e6e2ef96b7451332a9946",
|
||||||
|
"revisionTime": "2016-05-19T16:00:42Z"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "0ZrwvB6KoGPj2PoDNSEJwxQ6Mog=",
|
"checksumSHA1": "0ZrwvB6KoGPj2PoDNSEJwxQ6Mog=",
|
||||||
"path": "github.com/jmespath/go-jmespath",
|
"path": "github.com/jmespath/go-jmespath",
|
||||||
|
|||||||
Reference in New Issue
Block a user