From 0ae1c1ce2ed16a6b3e818b575da01954b4fe02df Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 20 May 2020 09:28:33 -0700 Subject: [PATCH] move multiaddr-net for merge with multiaddr --- .gitignore | 2 - .gx/lastpubver | 1 - .travis.yml | 30 ----- LICENSE | 21 ---- Makefile | 9 -- README.md | 53 -------- bin/dist_get | 146 ----------------------- go.mod | 5 - go.sum | 31 ----- multiaddr/.gitignore | 1 - multiaddr/multiaddr.go | 96 --------------- convert.go => net/convert.go | 0 convert_test.go => net/convert_test.go | 0 doc.go => net/doc.go | 0 ip.go => net/ip.go | 0 net.go => net/net.go | 4 +- net_test.go => net/net_test.go | 0 private.go => net/private.go | 0 private_test.go => net/private_test.go | 0 registry.go => net/registry.go | 0 registry_test.go => net/registry_test.go | 0 21 files changed, 2 insertions(+), 397 deletions(-) delete mode 100644 .gitignore delete mode 100644 .gx/lastpubver delete mode 100644 .travis.yml delete mode 100644 LICENSE delete mode 100644 Makefile delete mode 100644 README.md delete mode 100755 bin/dist_get delete mode 100644 go.mod delete mode 100644 go.sum delete mode 100644 multiaddr/.gitignore delete mode 100644 multiaddr/multiaddr.go rename convert.go => net/convert.go (100%) rename convert_test.go => net/convert_test.go (100%) rename doc.go => net/doc.go (100%) rename ip.go => net/ip.go (100%) rename net.go => net/net.go (98%) rename net_test.go => net/net_test.go (100%) rename private.go => net/private.go (100%) rename private_test.go => net/private_test.go (100%) rename registry.go => net/registry.go (100%) rename registry_test.go => net/registry_test.go (100%) diff --git a/.gitignore b/.gitignore deleted file mode 100644 index a186a0e..0000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -bin/gx* -*.swp diff --git a/.gx/lastpubver b/.gx/lastpubver deleted file mode 100644 index 807d8a2..0000000 --- a/.gx/lastpubver +++ /dev/null @@ -1 +0,0 @@ -1.7.2: Qmc85NSvmSG4Frn9Vb2cBc1rMyULH6D3TNVEfCzSKoUpip diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 336deb4..0000000 --- a/.travis.yml +++ /dev/null @@ -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 diff --git a/LICENSE b/LICENSE deleted file mode 100644 index c7386b3..0000000 --- a/LICENSE +++ /dev/null @@ -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. diff --git a/Makefile b/Makefile deleted file mode 100644 index 5415256..0000000 --- a/Makefile +++ /dev/null @@ -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 diff --git a/README.md b/README.md deleted file mode 100644 index e9ad25f..0000000 --- a/README.md +++ /dev/null @@ -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) - - - -> 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 diff --git a/bin/dist_get b/bin/dist_get deleted file mode 100755 index d6bdd12..0000000 --- a/bin/dist_get +++ /dev/null @@ -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 " -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 diff --git a/go.mod b/go.mod deleted file mode 100644 index 97d2481..0000000 --- a/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -module github.com/multiformats/go-multiaddr-net - -require github.com/multiformats/go-multiaddr v0.2.1 - -go 1.12 diff --git a/go.sum b/go.sum deleted file mode 100644 index 5d87b25..0000000 --- a/go.sum +++ /dev/null @@ -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= diff --git a/multiaddr/.gitignore b/multiaddr/.gitignore deleted file mode 100644 index e4dcb09..0000000 --- a/multiaddr/.gitignore +++ /dev/null @@ -1 +0,0 @@ -multiaddr diff --git a/multiaddr/multiaddr.go b/multiaddr/multiaddr.go deleted file mode 100644 index 5faf35f..0000000 --- a/multiaddr/multiaddr.go +++ /dev/null @@ -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 []\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) -} diff --git a/convert.go b/net/convert.go similarity index 100% rename from convert.go rename to net/convert.go diff --git a/convert_test.go b/net/convert_test.go similarity index 100% rename from convert_test.go rename to net/convert_test.go diff --git a/doc.go b/net/doc.go similarity index 100% rename from doc.go rename to net/doc.go diff --git a/ip.go b/net/ip.go similarity index 100% rename from ip.go rename to net/ip.go diff --git a/net.go b/net/net.go similarity index 98% rename from net.go rename to net/net.go index 79ad96e..95439af 100644 --- a/net.go +++ b/net/net.go @@ -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} } diff --git a/net_test.go b/net/net_test.go similarity index 100% rename from net_test.go rename to net/net_test.go diff --git a/private.go b/net/private.go similarity index 100% rename from private.go rename to net/private.go diff --git a/private_test.go b/net/private_test.go similarity index 100% rename from private_test.go rename to net/private_test.go diff --git a/registry.go b/net/registry.go similarity index 100% rename from registry.go rename to net/registry.go diff --git a/registry_test.go b/net/registry_test.go similarity index 100% rename from registry_test.go rename to net/registry_test.go