move multiaddr-net for merge with multiaddr

This commit is contained in:
Steven Allen 2020-05-20 09:28:33 -07:00
parent f512d0e050
commit 0ae1c1ce2e
21 changed files with 2 additions and 397 deletions

2
.gitignore vendored
View File

@ -1,2 +0,0 @@
bin/gx*
*.swp

View File

@ -1 +0,0 @@
1.7.2: Qmc85NSvmSG4Frn9Vb2cBc1rMyULH6D3TNVEfCzSKoUpip

View File

@ -1,30 +0,0 @@
os:
- linux
language: go
go:
- 1.12.x
env:
global:
- GOTFLAGS="-race"
matrix:
- BUILD_DEPTYPE=gomod
# disable travis install
install:
- true
script:
- bash <(curl -s https://raw.githubusercontent.com/ipfs/ci-helpers/master/travis-ci/run-standard-tests.sh)
cache:
directories:
- $GOPATH/pkg/mod
- /home/travis/.cache/go-build
notifications:
email: false

21
LICENSE
View File

@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) 2014 Juan Batiz-Benet
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.

View File

@ -1,9 +0,0 @@
export IPFS_API ?= v04x.ipfs.io
gx:
go get -u github.com/whyrusleeping/gx
go get -u github.com/whyrusleeping/gx-go
deps: gx
gx --verbose install --global
gx-go rewrite

View File

@ -1,53 +0,0 @@
# go-multiaddr-net
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](https://protocol.ai)
[![](https://img.shields.io/badge/project-multiformats-blue.svg?style=flat-square)](https://github.com/multiformats/multiformats)
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](https://webchat.freenode.net/?channels=%23ipfs)
[![](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
[![GoDoc](https://godoc.org/github.com/multiformats/go-multiaddr-net?status.svg)](https://godoc.org/github.com/multiformats/go-multiaddr-net)
[![Travis CI](https://img.shields.io/travis/multiformats/go-multiaddr-net.svg?style=flat-square&branch=master)](https://travis-ci.org/multiformats/go-multiaddr-net)
<!---[![codecov.io](https://img.shields.io/codecov/c/github/multiformats/go-multiaddr-net.svg?style=flat-square&branch=master)](https://codecov.io/github/multiformats/go-multiaddr-net?branch=master)--->
> Multiaddress net tools
This package provides [Multiaddr](https://github.com/multiformats/go-multiaddr) specific versions of common functions in [stdlib](https://github.com/golang/go/tree/master/src)'s `net` package. This means wrappers of standard net symbols like `net.Dial` and `net.Listen`, as well
as conversion to and from `net.Addr`.
## Table of Contents
- [Install](#install)
- [Usage](#usage)
- [Maintainers](#maintainers)
- [Contribute](#contribute)
- [License](#license)
## Install
`go-multiaddr-net` is a standard Go module which can be installed with:
```sh
go get github.com/multiformats/go-multiaddr-net
```
Note that `go-multiaddr-net` is packaged with Gx, so it is recommended to use Gx to install and use it (see Usage section).
## Usage
See the docs:
- `multiaddr/net`: https://godoc.org/github.com/multiformats/go-multiaddr-net
- `multiaddr`: https://godoc.org/github.com/multiformats/go-multiaddr
## Contribute
Contributions welcome. Please check out [the issues](https://github.com/multiformats/go-multiaddr-net/issues).
Check out our [contributing document](https://github.com/multiformats/multiformats/blob/master/contributing.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to multiformats are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).
Small note: If editing the README, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.
## License
[MIT](LICENSE) © 2014 Juan Batiz-Benet

View File

@ -1,146 +0,0 @@
#!/bin/bash
die() {
echo "$@" >&2
exit 1
}
have_binary() {
type "$1" > /dev/null 2> /dev/null
}
check_writeable() {
printf "" > "$1" && rm "$1"
}
download() {
local url="$1"
local output="$2"
if [ -z "$url" ] || [ -z "$output" ]; then
die "download takes exactly two arguments. was given '$@'"
fi
if ! check_writeable "$output"; then
die "download error: cannot write to $output"
fi
if have_binary wget; then
printf 'Using wget to download "%s" to "%s"\n' "$url" "$output"
wget "$url" -O "$output"
elif have_binary curl; then
printf 'Using curl to download "%s" to "%s"\n' "$url" "$output"
curl --silent "$url" > "$output"
elif have_binary fetch; then
printf 'Using fetch to download "%s" to "%s"\n' "$url" "$output"
fetch "$url" -o "$output"
else
die "no binary found to download $url. exiting."
fi
}
unarchive() {
local archivetype="$1"
local infile="$2"
local outfile="$3"
local distname="$4"
if ! check_writeable "$outfile"; then
die "unarchive error: cannot write to $outfile"
fi
case $archivetype in
tar.gz)
if have_binary tar; then
echo "==> using 'tar' to extract binary from archive"
cat "$infile" | tar -O -z -x "$distname/$distname" > "$outfile"
else
die "no binary on system for extracting tar files"
fi
;;
zip)
if have_binary unzip; then
echo "==> using 'unzip' to extract binary from archive"
unzip -p "$infile" "$distname/$distname" > "$outfile"
else
die "no installed method for extracting .zip archives"
fi
;;
*)
die "unrecognized archive type '$archivetype'"
esac
chmod +x "$outfile"
}
get_go_vars() {
if [ ! -z "$GOOS" ] && [ ! -z "$GOARCH" ]; then
printf "%s-%s" "$GOOS" "$GOARCH"
fi
if have_binary go; then
printf "%s-%s" "$(go env GOOS)" "$(go env GOARCH)"
else
die "no way of determining system GOOS and GOARCH\nPlease manually set GOOS and GOARCH then retry."
fi
}
mkurl() {
local name="$1"
local vers="$2"
local archive="$3"
local govars=$(get_go_vars)
echo "http://dist.ipfs.io/$name/$vers/${name}_${vers}_$govars.$archive"
}
distname="$1"
outpath="$2"
version="$3"
if [ -z "$distname" ] || [ -z "$outpath" ] || [ -z "$version" ]; then
die "usage: dist_get <distname> <outpath> <version>"
fi
if [ ${version:0:1} != "v" ]; then
echo "invalid version '$version'" >&2
die "versions must begin with 'v', for example: v0.4.0"
fi
# TODO: don't depend on the go tool being installed to detect this
goenv=$(get_go_vars)
case $goenv in
linux-*)
archive="tar.gz"
;;
darwin-*)
archive="tar.gz"
;;
windows-*)
archive="zip"
;;
freebsd-*)
archive="tar.gz"
;;
*)
echo "unrecognized system environment: $goenv" >&2
die "currently only linux, darwin, windows and freebsd are supported by this script"
esac
mkdir -p bin/tmp
url=$(mkurl "$distname" "$version" "$archive")
tmpfi="bin/tmp/$distname.$archive"
download "$url" "$tmpfi"
if [ $? -ne 0 ]; then
die "failed to download $url to $tmpfi"
fi
unarchive "$archive" "$tmpfi" "$outpath" "$distname"
if [ $? -ne 0 ]; then
die "failed to exract archive $tmpfi"
fi

5
go.mod
View File

@ -1,5 +0,0 @@
module github.com/multiformats/go-multiaddr-net
require github.com/multiformats/go-multiaddr v0.2.1
go 1.12

31
go.sum
View File

@ -1,31 +0,0 @@
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 h1:lYpkrQH5ajf0OXOcUbGjvZxxijuBwbbmlSxLiuofa+g=
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ=
github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771 h1:MHkK1uRtFbVqvAgvWxafZe54+5uBxLluGylDiKgdhwo=
github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM=
github.com/mr-tron/base58 v1.1.2 h1:ZEw4I2EgPKDJ2iEw0cNmLB3ROrEmkOtXIkaG7wZg+78=
github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/mr-tron/base58 v1.1.3 h1:v+sk57XuaCKGXpWtVBX8YJzO7hMGx4Aajh4TQbdEFdc=
github.com/mr-tron/base58 v1.1.3/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/multiformats/go-multiaddr v0.2.0 h1:lR52sFwcTCuQb6bTfnXF6zA2XfyYvyd+5a9qECv/J90=
github.com/multiformats/go-multiaddr v0.2.0/go.mod h1:0nO36NvPpyV4QzvTLi/lafl2y95ncPj0vFwVF6k6wJ4=
github.com/multiformats/go-multiaddr v0.2.1 h1:SgG/cw5vqyB5QQe5FPe2TqggU9WtrA9X4nZw7LlVqOI=
github.com/multiformats/go-multiaddr v0.2.1/go.mod h1:s/Apk6IyxfvMjDafnhJgJ3/46z7tZ04iMk5wP4QMGGE=
github.com/multiformats/go-multihash v0.0.8 h1:wrYcW5yxSi3dU07n5jnuS5PrNwyHy0zRHGVoUugWvXg=
github.com/multiformats/go-multihash v0.0.8/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew=
github.com/multiformats/go-multihash v0.0.13 h1:06x+mk/zj1FoMsgNejLpy6QTvJqlSt/BhLEy87zidlc=
github.com/multiformats/go-multihash v0.0.13/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc=
github.com/multiformats/go-varint v0.0.1 h1:TR/0rdQtnNxuN2IhiB639xC3tWM4IUi7DkTBVTdGW/M=
github.com/multiformats/go-varint v0.0.1/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE=
github.com/multiformats/go-varint v0.0.2/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE=
github.com/multiformats/go-varint v0.0.5 h1:XVZwSo04Cs3j/jS0uAEPpT3JY6DzMcVLLoWOSnCxOjg=
github.com/multiformats/go-varint v0.0.5/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE=
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8 h1:1wopBVtVdWnn03fZelqdXTqk7U7zPQCb+T4rbU9ZEoU=
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

View File

@ -1 +0,0 @@
multiaddr

View File

@ -1,96 +0,0 @@
package main
import (
"encoding/hex"
"flag"
"fmt"
"os"
ma "github.com/multiformats/go-multiaddr"
manet "github.com/multiformats/go-multiaddr-net"
)
// flags
var formats = []string{"string", "bytes", "hex", "slice"}
var format string
var hideLoopback bool
func init() {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "usage: %s [<multiaddr>]\n\nFlags:\n", os.Args[0])
flag.PrintDefaults()
}
usage := fmt.Sprintf("output format, one of: %v", formats)
flag.StringVar(&format, "format", "string", usage)
flag.StringVar(&format, "f", "string", usage+" (shorthand)")
flag.BoolVar(&hideLoopback, "hide-loopback", false, "do not display loopback addresses")
}
func main() {
flag.Parse()
args := flag.Args()
if len(args) == 0 {
output(localAddresses()...)
} else {
output(address(args[0]))
}
}
func localAddresses() []ma.Multiaddr {
maddrs, err := manet.InterfaceMultiaddrs()
if err != nil {
die(err)
}
if !hideLoopback {
return maddrs
}
var maddrs2 []ma.Multiaddr
for _, a := range maddrs {
if !manet.IsIPLoopback(a) {
maddrs2 = append(maddrs2, a)
}
}
return maddrs2
}
func address(addr string) ma.Multiaddr {
m, err := ma.NewMultiaddr(addr)
if err != nil {
die(err)
}
return m
}
func output(ms ...ma.Multiaddr) {
for _, m := range ms {
fmt.Println(outfmt(m))
}
}
func outfmt(m ma.Multiaddr) string {
switch format {
case "string":
return m.String()
case "slice":
return fmt.Sprintf("%v", m.Bytes())
case "bytes":
return string(m.Bytes())
case "hex":
return "0x" + hex.EncodeToString(m.Bytes())
}
die("error: invalid format", format)
return ""
}
func die(v ...interface{}) {
fmt.Fprint(os.Stderr, v...)
fmt.Fprint(os.Stderr, "\n")
flag.Usage()
os.Exit(-1)
}

View File

View File

View File

@ -224,9 +224,9 @@ func (nla *netListenerAdapter) Accept() (net.Conn, error) {
// NetListener turns this Listener into a net.Listener.
//
// * Connections returned from Accept implement multiaddr-net Conn.
// * Connections returned from Accept implement multiaddr/net Conn.
// * Calling WrapNetListener on the net.Listener returned by this function will
// return the original (underlying) multiaddr-net Listener.
// return the original (underlying) multiaddr/net Listener.
func NetListener(l Listener) net.Listener {
return &netListenerAdapter{l}
}