* go mod init; rm -rf vendor * tweak proto files and generation * go mod vendor * clean up build.go * protobuf literals in tests * downgrade gogo/protobuf
This commit is contained in:
6
vendor/github.com/AudriusButkevicius/cli/.travis.yml
generated
vendored
Normal file
6
vendor/github.com/AudriusButkevicius/cli/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
language: go
|
||||
go: 1.1
|
||||
|
||||
script:
|
||||
- go vet ./...
|
||||
- go test -v ./...
|
||||
280
vendor/github.com/AudriusButkevicius/cli/README.md
generated
vendored
Normal file
280
vendor/github.com/AudriusButkevicius/cli/README.md
generated
vendored
Normal file
@@ -0,0 +1,280 @@
|
||||
[](https://travis-ci.org/codegangsta/cli)
|
||||
|
||||
# cli.go
|
||||
cli.go is simple, fast, and fun package for building command line apps in Go. The goal is to enable developers to write fast and distributable command line applications in an expressive way.
|
||||
|
||||
You can view the API docs here:
|
||||
http://godoc.org/github.com/codegangsta/cli
|
||||
|
||||
## Overview
|
||||
Command line apps are usually so tiny that there is absolutely no reason why your code should *not* be self-documenting. Things like generating help text and parsing command flags/options should not hinder productivity when writing a command line app.
|
||||
|
||||
This is where cli.go comes into play. cli.go makes command line programming fun, organized, and expressive!
|
||||
|
||||
## Installation
|
||||
Make sure you have a working Go environment (go 1.1 is *required*). [See the install instructions](http://golang.org/doc/install.html).
|
||||
|
||||
To install cli.go, simply run:
|
||||
```
|
||||
$ go get github.com/codegangsta/cli
|
||||
```
|
||||
|
||||
Make sure your PATH includes to the `$GOPATH/bin` directory so your commands can be easily used:
|
||||
```
|
||||
export PATH=$PATH:$GOPATH/bin
|
||||
```
|
||||
|
||||
## Getting Started
|
||||
One of the philosophies behind cli.go is that an API should be playful and full of discovery. So a cli.go app can be as little as one line of code in `main()`.
|
||||
|
||||
``` go
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"github.com/codegangsta/cli"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cli.NewApp().Run(os.Args)
|
||||
}
|
||||
```
|
||||
|
||||
This app will run and show help text, but is not very useful. Let's give an action to execute and some help documentation:
|
||||
|
||||
``` go
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"github.com/codegangsta/cli"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := cli.NewApp()
|
||||
app.Name = "boom"
|
||||
app.Usage = "make an explosive entrance"
|
||||
app.Action = func(c *cli.Context) {
|
||||
println("boom! I say!")
|
||||
}
|
||||
|
||||
app.Run(os.Args)
|
||||
}
|
||||
```
|
||||
|
||||
Running this already gives you a ton of functionality, plus support for things like subcommands and flags, which are covered below.
|
||||
|
||||
## Example
|
||||
|
||||
Being a programmer can be a lonely job. Thankfully by the power of automation that is not the case! Let's create a greeter app to fend off our demons of loneliness!
|
||||
|
||||
``` go
|
||||
/* greet.go */
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"github.com/codegangsta/cli"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := cli.NewApp()
|
||||
app.Name = "greet"
|
||||
app.Usage = "fight the loneliness!"
|
||||
app.Action = func(c *cli.Context) {
|
||||
println("Hello friend!")
|
||||
}
|
||||
|
||||
app.Run(os.Args)
|
||||
}
|
||||
```
|
||||
|
||||
Install our command to the `$GOPATH/bin` directory:
|
||||
|
||||
```
|
||||
$ go install
|
||||
```
|
||||
|
||||
Finally run our new command:
|
||||
|
||||
```
|
||||
$ greet
|
||||
Hello friend!
|
||||
```
|
||||
|
||||
cli.go also generates some bitchass help text:
|
||||
```
|
||||
$ greet help
|
||||
NAME:
|
||||
greet - fight the loneliness!
|
||||
|
||||
USAGE:
|
||||
greet [global options] command [command options] [arguments...]
|
||||
|
||||
VERSION:
|
||||
0.0.0
|
||||
|
||||
COMMANDS:
|
||||
help, h Shows a list of commands or help for one command
|
||||
|
||||
GLOBAL OPTIONS
|
||||
--version Shows version information
|
||||
```
|
||||
|
||||
### Arguments
|
||||
You can lookup arguments by calling the `Args` function on cli.Context.
|
||||
|
||||
``` go
|
||||
...
|
||||
app.Action = func(c *cli.Context) {
|
||||
println("Hello", c.Args()[0])
|
||||
}
|
||||
...
|
||||
```
|
||||
|
||||
### Flags
|
||||
Setting and querying flags is simple.
|
||||
``` go
|
||||
...
|
||||
app.Flags = []cli.Flag {
|
||||
cli.StringFlag{
|
||||
Name: "lang",
|
||||
Value: "english",
|
||||
Usage: "language for the greeting",
|
||||
},
|
||||
}
|
||||
app.Action = func(c *cli.Context) {
|
||||
name := "someone"
|
||||
if len(c.Args()) > 0 {
|
||||
name = c.Args()[0]
|
||||
}
|
||||
if c.String("lang") == "spanish" {
|
||||
println("Hola", name)
|
||||
} else {
|
||||
println("Hello", name)
|
||||
}
|
||||
}
|
||||
...
|
||||
```
|
||||
|
||||
#### Alternate Names
|
||||
|
||||
You can set alternate (or short) names for flags by providing a comma-delimited list for the Name. e.g.
|
||||
|
||||
``` go
|
||||
app.Flags = []cli.Flag {
|
||||
cli.StringFlag{
|
||||
Name: "lang, l",
|
||||
Value: "english",
|
||||
Usage: "language for the greeting",
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
#### Values from the Environment
|
||||
|
||||
You can also have the default value set from the environment via EnvVar. e.g.
|
||||
|
||||
``` go
|
||||
app.Flags = []cli.Flag {
|
||||
cli.StringFlag{
|
||||
Name: "lang, l",
|
||||
Value: "english",
|
||||
Usage: "language for the greeting",
|
||||
EnvVar: "APP_LANG",
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
That flag can then be set with `--lang spanish` or `-l spanish`. Note that giving two different forms of the same flag in the same command invocation is an error.
|
||||
|
||||
### Subcommands
|
||||
|
||||
Subcommands can be defined for a more git-like command line app.
|
||||
```go
|
||||
...
|
||||
app.Commands = []cli.Command{
|
||||
{
|
||||
Name: "add",
|
||||
ShortName: "a",
|
||||
Usage: "add a task to the list",
|
||||
Action: func(c *cli.Context) {
|
||||
println("added task: ", c.Args().First())
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "complete",
|
||||
ShortName: "c",
|
||||
Usage: "complete a task on the list",
|
||||
Action: func(c *cli.Context) {
|
||||
println("completed task: ", c.Args().First())
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "template",
|
||||
ShortName: "r",
|
||||
Usage: "options for task templates",
|
||||
Subcommands: []cli.Command{
|
||||
{
|
||||
Name: "add",
|
||||
Usage: "add a new template",
|
||||
Action: func(c *cli.Context) {
|
||||
println("new task template: ", c.Args().First())
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "remove",
|
||||
Usage: "remove an existing template",
|
||||
Action: func(c *cli.Context) {
|
||||
println("removed task template: ", c.Args().First())
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
...
|
||||
```
|
||||
|
||||
### Bash Completion
|
||||
|
||||
You can enable completion commands by setting the EnableBashCompletion
|
||||
flag on the App object. By default, this setting will only auto-complete to
|
||||
show an app's subcommands, but you can write your own completion methods for
|
||||
the App or its subcommands.
|
||||
```go
|
||||
...
|
||||
var tasks = []string{"cook", "clean", "laundry", "eat", "sleep", "code"}
|
||||
app := cli.NewApp()
|
||||
app.EnableBashCompletion = true
|
||||
app.Commands = []cli.Command{
|
||||
{
|
||||
Name: "complete",
|
||||
ShortName: "c",
|
||||
Usage: "complete a task on the list",
|
||||
Action: func(c *cli.Context) {
|
||||
println("completed task: ", c.Args().First())
|
||||
},
|
||||
BashComplete: func(c *cli.Context) {
|
||||
// This will complete if no args are passed
|
||||
if len(c.Args()) > 0 {
|
||||
return
|
||||
}
|
||||
for _, t := range tasks {
|
||||
println(t)
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
...
|
||||
```
|
||||
|
||||
#### To Enable
|
||||
|
||||
Source the autocomplete/bash_autocomplete file in your .bashrc file while
|
||||
setting the PROG variable to the name of your program:
|
||||
|
||||
`PROG=myprogram source /.../cli/autocomplete/bash_autocomplete`
|
||||
|
||||
|
||||
## About
|
||||
cli.go is written by none other than the [Code Gangsta](http://codegangsta.io)
|
||||
48
vendor/github.com/AudriusButkevicius/go-nat-pmp/README.md
generated
vendored
Normal file
48
vendor/github.com/AudriusButkevicius/go-nat-pmp/README.md
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
go-nat-pmp
|
||||
==========
|
||||
|
||||
A Go language client for the NAT-PMP internet protocol for port mapping and discovering the external
|
||||
IP address of a firewall.
|
||||
|
||||
NAT-PMP is supported by Apple brand routers and open source routers like Tomato and DD-WRT.
|
||||
|
||||
See http://tools.ietf.org/html/draft-cheshire-nat-pmp-03
|
||||
|
||||
Get the package
|
||||
---------------
|
||||
|
||||
go get -u github.com/jackpal/go-nat-pmp
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
import natpmp "github.com/jackpal/go-nat-pmp"
|
||||
|
||||
client := natpmp.NewClient(gatewayIP)
|
||||
response, err := client.GetExternalAddress()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
print("External IP address:", response.ExternalIPAddress)
|
||||
|
||||
Notes
|
||||
-----
|
||||
|
||||
There doesn't seem to be an easy way to programmatically determine the address of the default gateway.
|
||||
(Linux and OSX have a "routes" kernel API that can be examined to get this information, but there is
|
||||
no Go package for getting this information.)
|
||||
|
||||
Clients
|
||||
-------
|
||||
|
||||
This library is used in the Taipei Torrent BitTorrent client http://github.com/jackpal/Taipei-Torrent
|
||||
|
||||
Complete documentation
|
||||
----------------------
|
||||
|
||||
http://godoc.org/github.com/jackpal/go-nat-pmp
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
This project is licensed under the Apache License 2.0.
|
||||
21
vendor/github.com/AudriusButkevicius/pfilter/LICENSE
generated
vendored
21
vendor/github.com/AudriusButkevicius/pfilter/LICENSE
generated
vendored
@@ -1,21 +0,0 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2016 Audrius Butkevicius
|
||||
|
||||
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.
|
||||
97
vendor/github.com/AudriusButkevicius/pfilter/conn.go
generated
vendored
97
vendor/github.com/AudriusButkevicius/pfilter/conn.go
generated
vendored
@@ -1,97 +0,0 @@
|
||||
package pfilter
|
||||
|
||||
import (
|
||||
"net"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
type FilteredConn struct {
|
||||
// Alignment
|
||||
deadline atomic.Value
|
||||
|
||||
source *PacketFilter
|
||||
priority int
|
||||
|
||||
recvBuffer chan packet
|
||||
|
||||
filter Filter
|
||||
|
||||
closed chan struct{}
|
||||
}
|
||||
|
||||
// LocalAddr returns the local address
|
||||
func (r *FilteredConn) LocalAddr() net.Addr {
|
||||
return r.source.LocalAddr()
|
||||
}
|
||||
|
||||
// SetReadDeadline sets a read deadline
|
||||
func (r *FilteredConn) SetReadDeadline(t time.Time) error {
|
||||
r.deadline.Store(t)
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetWriteDeadline sets a write deadline
|
||||
func (r *FilteredConn) SetWriteDeadline(t time.Time) error {
|
||||
return r.source.SetWriteDeadline(t)
|
||||
}
|
||||
|
||||
// SetDeadline sets a read and a write deadline
|
||||
func (r *FilteredConn) SetDeadline(t time.Time) error {
|
||||
r.SetReadDeadline(t)
|
||||
return r.SetWriteDeadline(t)
|
||||
}
|
||||
|
||||
// WriteTo writes bytes to the given address
|
||||
func (r *FilteredConn) WriteTo(b []byte, addr net.Addr) (n int, err error) {
|
||||
select {
|
||||
case <-r.closed:
|
||||
return 0, errClosed
|
||||
default:
|
||||
}
|
||||
|
||||
if r.filter != nil {
|
||||
r.filter.Outgoing(b, addr)
|
||||
}
|
||||
return r.source.WriteTo(b, addr)
|
||||
}
|
||||
|
||||
// ReadFrom reads from the filtered connection
|
||||
func (r *FilteredConn) ReadFrom(b []byte) (n int, addr net.Addr, err error) {
|
||||
select {
|
||||
case <-r.closed:
|
||||
return 0, nil, errClosed
|
||||
default:
|
||||
}
|
||||
|
||||
var timeout <-chan time.Time
|
||||
|
||||
if deadline, ok := r.deadline.Load().(time.Time); ok && !deadline.IsZero() {
|
||||
timer := time.NewTimer(deadline.Sub(time.Now()))
|
||||
timeout = timer.C
|
||||
defer timer.Stop()
|
||||
}
|
||||
|
||||
select {
|
||||
case <-timeout:
|
||||
return 0, nil, errTimeout
|
||||
case pkt := <-r.recvBuffer:
|
||||
copy(b[:pkt.n], pkt.buf)
|
||||
bufPool.Put(pkt.buf[:maxPacketSize])
|
||||
return pkt.n, pkt.addr, pkt.err
|
||||
case <-r.closed:
|
||||
return 0, nil, errClosed
|
||||
}
|
||||
}
|
||||
|
||||
// Close closes the filtered connection, removing it's filters
|
||||
func (r *FilteredConn) Close() error {
|
||||
select {
|
||||
case <-r.closed:
|
||||
return errClosed
|
||||
default:
|
||||
}
|
||||
close(r.closed)
|
||||
r.source.removeConn(r)
|
||||
return nil
|
||||
}
|
||||
135
vendor/github.com/AudriusButkevicius/pfilter/filter.go
generated
vendored
135
vendor/github.com/AudriusButkevicius/pfilter/filter.go
generated
vendored
@@ -1,135 +0,0 @@
|
||||
package pfilter
|
||||
|
||||
import (
|
||||
"net"
|
||||
"sort"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
// Filter object receives all data sent out on the Outgoing callback,
|
||||
// and is expected to decide if it wants to receive the packet or not via
|
||||
// the Receive callback
|
||||
type Filter interface {
|
||||
Outgoing([]byte, net.Addr)
|
||||
ClaimIncoming([]byte, net.Addr) bool
|
||||
}
|
||||
|
||||
// NewPacketFilter creates a packet filter object wrapping the given packet
|
||||
// connection.
|
||||
func NewPacketFilter(conn net.PacketConn) *PacketFilter {
|
||||
d := &PacketFilter{
|
||||
PacketConn: conn,
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
// PacketFilter embeds a net.PacketConn to perform the filtering.
|
||||
type PacketFilter struct {
|
||||
// Alignment
|
||||
dropped uint64
|
||||
overflow uint64
|
||||
|
||||
net.PacketConn
|
||||
|
||||
conns []*FilteredConn
|
||||
mut sync.Mutex
|
||||
}
|
||||
|
||||
// NewConn returns a new net.PacketConn object which filters packets based
|
||||
// on the provided filter. If filter is nil, the connection will receive all
|
||||
// packets. Priority decides which connection gets the ability to claim the packet.
|
||||
func (d *PacketFilter) NewConn(priority int, filter Filter) net.PacketConn {
|
||||
conn := &FilteredConn{
|
||||
priority: priority,
|
||||
source: d,
|
||||
recvBuffer: make(chan packet, 256),
|
||||
filter: filter,
|
||||
closed: make(chan struct{}),
|
||||
}
|
||||
d.mut.Lock()
|
||||
d.conns = append(d.conns, conn)
|
||||
sort.Sort(filteredConnList(d.conns))
|
||||
d.mut.Unlock()
|
||||
return conn
|
||||
}
|
||||
|
||||
func (d *PacketFilter) removeConn(r *FilteredConn) {
|
||||
d.mut.Lock()
|
||||
for i, conn := range d.conns {
|
||||
if conn == r {
|
||||
copy(d.conns[i:], d.conns[i+1:])
|
||||
d.conns[len(d.conns)-1] = nil
|
||||
d.conns = d.conns[:len(d.conns)-1]
|
||||
break
|
||||
}
|
||||
}
|
||||
d.mut.Unlock()
|
||||
}
|
||||
|
||||
// NumberOfConns returns the number of currently active virtual connections
|
||||
func (d *PacketFilter) NumberOfConns() int {
|
||||
d.mut.Lock()
|
||||
n := len(d.conns)
|
||||
d.mut.Unlock()
|
||||
return n
|
||||
}
|
||||
|
||||
// Dropped returns number of packets dropped due to nobody claiming them.
|
||||
func (d *PacketFilter) Dropped() uint64 {
|
||||
return atomic.LoadUint64(&d.dropped)
|
||||
}
|
||||
|
||||
// Overflow returns number of packets were dropped due to receive buffers being
|
||||
// full.
|
||||
func (d *PacketFilter) Overflow() uint64 {
|
||||
return atomic.LoadUint64(&d.overflow)
|
||||
}
|
||||
|
||||
// Start starts the packet filter.
|
||||
func (d *PacketFilter) Start() {
|
||||
go d.loop()
|
||||
}
|
||||
|
||||
func (d *PacketFilter) loop() {
|
||||
var buf []byte
|
||||
next:
|
||||
for {
|
||||
buf = bufPool.Get().([]byte)
|
||||
n, addr, err := d.ReadFrom(buf)
|
||||
pkt := packet{
|
||||
n: n,
|
||||
addr: addr,
|
||||
err: err,
|
||||
buf: buf[:n],
|
||||
}
|
||||
|
||||
d.mut.Lock()
|
||||
conns := d.conns
|
||||
d.mut.Unlock()
|
||||
|
||||
if err != nil {
|
||||
for _, conn := range conns {
|
||||
select {
|
||||
case conn.recvBuffer <- pkt:
|
||||
default:
|
||||
atomic.AddUint64(&d.overflow, 1)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
for _, conn := range conns {
|
||||
if conn.filter == nil || conn.filter.ClaimIncoming(pkt.buf, pkt.addr) {
|
||||
select {
|
||||
case conn.recvBuffer <- pkt:
|
||||
default:
|
||||
atomic.AddUint64(&d.overflow, 1)
|
||||
}
|
||||
goto next
|
||||
}
|
||||
}
|
||||
|
||||
atomic.AddUint64(&d.dropped, 1)
|
||||
}
|
||||
}
|
||||
51
vendor/github.com/AudriusButkevicius/pfilter/misc.go
generated
vendored
51
vendor/github.com/AudriusButkevicius/pfilter/misc.go
generated
vendored
@@ -1,51 +0,0 @@
|
||||
package pfilter
|
||||
|
||||
import (
|
||||
"net"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var (
|
||||
maxPacketSize = 1500
|
||||
bufPool = sync.Pool{
|
||||
New: func() interface{} {
|
||||
return make([]byte, maxPacketSize)
|
||||
},
|
||||
}
|
||||
errTimeout = &netError{
|
||||
msg: "i/o timeout",
|
||||
timeout: true,
|
||||
temporary: true,
|
||||
}
|
||||
errClosed = &netError{
|
||||
msg: "use of closed network connection",
|
||||
timeout: false,
|
||||
temporary: false,
|
||||
}
|
||||
|
||||
// Compile time interface assertion.
|
||||
_ net.Error = (*netError)(nil)
|
||||
)
|
||||
|
||||
type netError struct {
|
||||
msg string
|
||||
timeout bool
|
||||
temporary bool
|
||||
}
|
||||
|
||||
func (e *netError) Error() string { return e.msg }
|
||||
func (e *netError) Timeout() bool { return e.timeout }
|
||||
func (e *netError) Temporary() bool { return e.temporary }
|
||||
|
||||
type filteredConnList []*FilteredConn
|
||||
|
||||
func (r filteredConnList) Len() int { return len(r) }
|
||||
func (r filteredConnList) Swap(i, j int) { r[i], r[j] = r[j], r[i] }
|
||||
func (r filteredConnList) Less(i, j int) bool { return r[i].priority < r[j].priority }
|
||||
|
||||
type packet struct {
|
||||
n int
|
||||
addr net.Addr
|
||||
err error
|
||||
buf []byte
|
||||
}
|
||||
Reference in New Issue
Block a user