WIP
This commit is contained in:
parent
a40ef34357
commit
d91b419ecf
|
@ -9,9 +9,9 @@ package loggables
|
|||
import (
|
||||
"net"
|
||||
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
|
||||
logging "gx/QmfZZB1aVXWA4kaR5R4e9NifERT366TTCSagkfhmAbYLsu/go-log"
|
||||
logging "github.com/ipfs/go-log"
|
||||
|
||||
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
)
|
||||
|
|
|
@ -21,10 +21,10 @@ import (
|
|||
|
||||
pb "github.com/ipfs/go-libp2p/p2p/crypto/pb"
|
||||
|
||||
proto "gx/QmchriuyWMcqHha3dG86rQyxoswSUpmLUBjuJ2kotB65qR/gogo-protobuf/proto"
|
||||
proto "github.com/gogo/protobuf/proto"
|
||||
|
||||
u "gx/QmQA79FfVsUnGkH3TgKDqcDkupfjqLSJ6EYwDuDDZK8nhD/go-ipfs-util"
|
||||
logging "gx/QmfZZB1aVXWA4kaR5R4e9NifERT366TTCSagkfhmAbYLsu/go-log"
|
||||
u "github.com/ipfs/go-ipfs-util"
|
||||
logging "github.com/ipfs/go-log"
|
||||
)
|
||||
|
||||
var log = logging.Logger("crypto")
|
||||
|
|
|
@ -14,7 +14,7 @@ It has these top-level messages:
|
|||
*/
|
||||
package crypto_pb
|
||||
|
||||
import proto "gx/QmchriuyWMcqHha3dG86rQyxoswSUpmLUBjuJ2kotB65qR/gogo-protobuf/proto"
|
||||
import proto "github.com/gogo/protobuf/proto"
|
||||
import math "math"
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"crypto/x509"
|
||||
"errors"
|
||||
|
||||
proto "gx/QmchriuyWMcqHha3dG86rQyxoswSUpmLUBjuJ2kotB65qR/gogo-protobuf/proto"
|
||||
proto "github.com/gogo/protobuf/proto"
|
||||
|
||||
pb "github.com/ipfs/go-libp2p/p2p/crypto/pb"
|
||||
)
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
"hash"
|
||||
|
||||
ci "github.com/ipfs/go-libp2p/p2p/crypto"
|
||||
bfish "gx/QmYuvLUCBYFK656JmhuWc4wGpuCgE1wpt4E4wcL2y9ej6R/go-crypto/blowfish"
|
||||
bfish "golang.org/x/crypto/blowfish"
|
||||
)
|
||||
|
||||
// List of supported ECDH curves
|
||||
|
|
|
@ -7,8 +7,8 @@ import (
|
|||
ci "github.com/ipfs/go-libp2p/p2p/crypto"
|
||||
|
||||
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
msgio "gx/QmXMkWRYvXJ2NTzHMEz5794997kNPGsVX8EhFiXXpoKDZr/go-msgio"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
msgio "github.com/jbenet/go-msgio"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// SessionGenerator constructs secure communication sessions for a peer.
|
||||
|
|
|
@ -14,7 +14,7 @@ It has these top-level messages:
|
|||
*/
|
||||
package spipe_pb
|
||||
|
||||
import proto "gx/QmchriuyWMcqHha3dG86rQyxoswSUpmLUBjuJ2kotB65qR/gogo-protobuf/proto"
|
||||
import proto "github.com/gogo/protobuf/proto"
|
||||
import math "math"
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
|
|
|
@ -9,13 +9,13 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
u "github.com/ipfs/go-ipfs-util"
|
||||
ci "github.com/ipfs/go-libp2p/p2p/crypto"
|
||||
pb "github.com/ipfs/go-libp2p/p2p/crypto/secio/pb"
|
||||
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
u "gx/QmQA79FfVsUnGkH3TgKDqcDkupfjqLSJ6EYwDuDDZK8nhD/go-ipfs-util"
|
||||
msgio "gx/QmXMkWRYvXJ2NTzHMEz5794997kNPGsVX8EhFiXXpoKDZr/go-msgio"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
logging "gx/QmfZZB1aVXWA4kaR5R4e9NifERT366TTCSagkfhmAbYLsu/go-log"
|
||||
logging "github.com/ipfs/go-log"
|
||||
msgio "github.com/jbenet/go-msgio"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
var log = logging.Logger("secio")
|
||||
|
|
|
@ -9,10 +9,10 @@ import (
|
|||
|
||||
"crypto/hmac"
|
||||
|
||||
msgio "gx/QmXMkWRYvXJ2NTzHMEz5794997kNPGsVX8EhFiXXpoKDZr/go-msgio"
|
||||
mpool "gx/QmXMkWRYvXJ2NTzHMEz5794997kNPGsVX8EhFiXXpoKDZr/go-msgio/mpool"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
proto "gx/QmchriuyWMcqHha3dG86rQyxoswSUpmLUBjuJ2kotB65qR/gogo-protobuf/proto"
|
||||
proto "github.com/gogo/protobuf/proto"
|
||||
msgio "github.com/jbenet/go-msgio"
|
||||
mpool "github.com/jbenet/go-msgio/mpool"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
const MaxMsgSize = 8 * 1024 * 1024
|
||||
|
|
|
@ -9,13 +9,13 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
manet "gx/QmNT7d1e4Xcp3KcsvxyzUHVtqrR43uypoxLLzdKj6YZga2/go-multiaddr-net"
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
"gx/QmdkSkALqzKfXnuMTsbBVS26U4XGS9kCffRpSTWvVbkRSi/mdns"
|
||||
"github.com/cryptix/mdns"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
manet "github.com/jbenet/go-multiaddr-net"
|
||||
|
||||
"github.com/ipfs/go-libp2p/p2p/host"
|
||||
"github.com/ipfs/go-libp2p/p2p/peer"
|
||||
logging "gx/QmfZZB1aVXWA4kaR5R4e9NifERT366TTCSagkfhmAbYLsu/go-log"
|
||||
logging "github.com/ipfs/go-log"
|
||||
)
|
||||
|
||||
var log = logging.Logger("mdns")
|
||||
|
|
|
@ -5,10 +5,10 @@ import (
|
|||
|
||||
metrics "github.com/ipfs/go-libp2p/p2p/metrics"
|
||||
mstream "github.com/ipfs/go-libp2p/p2p/metrics/stream"
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
goprocess "gx/QmfDXyLfKNfja2XebomRZjZ2UZCa4BDyFoCymKtzNRVQ5b/goprocess"
|
||||
logging "gx/QmfZZB1aVXWA4kaR5R4e9NifERT366TTCSagkfhmAbYLsu/go-log"
|
||||
logging "github.com/ipfs/go-log"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
goprocess "github.com/jbenet/goprocess"
|
||||
context "golang.org/x/net/context"
|
||||
|
||||
inet "github.com/ipfs/go-libp2p/p2p/net"
|
||||
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
|
@ -16,7 +16,7 @@ import (
|
|||
identify "github.com/ipfs/go-libp2p/p2p/protocol/identify"
|
||||
relay "github.com/ipfs/go-libp2p/p2p/protocol/relay"
|
||||
|
||||
msmux "gx/QmdrbcnPVM2FnZQQM7p2GU91XhpuyYyd1tzPouEyh1phyD/go-multistream"
|
||||
msmux "github.com/whyrusleeping/go-multistream"
|
||||
)
|
||||
|
||||
var log = logging.Logger("github.com/ipfs/go-libp2p/p2p/host/basic")
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
protocol "github.com/ipfs/go-libp2p/p2p/protocol"
|
||||
testutil "github.com/ipfs/go-libp2p/p2p/test/util"
|
||||
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func TestHostSimple(t *testing.T) {
|
||||
|
|
|
@ -3,9 +3,9 @@ package basichost
|
|||
import (
|
||||
"sync"
|
||||
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
goprocess "gx/QmfDXyLfKNfja2XebomRZjZ2UZCa4BDyFoCymKtzNRVQ5b/goprocess"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
goprocess "github.com/jbenet/goprocess"
|
||||
context "golang.org/x/net/context"
|
||||
|
||||
lgbl "github.com/ipfs/go-libp2p/loggables"
|
||||
inat "github.com/ipfs/go-libp2p/p2p/nat"
|
||||
|
|
|
@ -5,11 +5,11 @@ import (
|
|||
inet "github.com/ipfs/go-libp2p/p2p/net"
|
||||
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
protocol "github.com/ipfs/go-libp2p/p2p/protocol"
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
logging "gx/QmfZZB1aVXWA4kaR5R4e9NifERT366TTCSagkfhmAbYLsu/go-log"
|
||||
logging "github.com/ipfs/go-log"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
context "golang.org/x/net/context"
|
||||
|
||||
msmux "gx/QmdrbcnPVM2FnZQQM7p2GU91XhpuyYyd1tzPouEyh1phyD/go-multistream"
|
||||
msmux "github.com/whyrusleeping/go-multistream"
|
||||
)
|
||||
|
||||
var log = logging.Logger("github.com/ipfs/go-libp2p/p2p/host")
|
||||
|
|
|
@ -5,9 +5,9 @@ import (
|
|||
"time"
|
||||
|
||||
lgbl "github.com/ipfs/go-libp2p/loggables"
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
logging "gx/QmfZZB1aVXWA4kaR5R4e9NifERT366TTCSagkfhmAbYLsu/go-log"
|
||||
logging "github.com/ipfs/go-log"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
context "golang.org/x/net/context"
|
||||
|
||||
host "github.com/ipfs/go-libp2p/p2p/host"
|
||||
metrics "github.com/ipfs/go-libp2p/p2p/metrics"
|
||||
|
@ -15,7 +15,7 @@ import (
|
|||
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
protocol "github.com/ipfs/go-libp2p/p2p/protocol"
|
||||
|
||||
msmux "gx/QmdrbcnPVM2FnZQQM7p2GU91XhpuyYyd1tzPouEyh1phyD/go-multistream"
|
||||
msmux "github.com/whyrusleeping/go-multistream"
|
||||
)
|
||||
|
||||
var log = logging.Logger("github.com/ipfs/go-libp2p/p2p/host/routed")
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
gm "gx/QmeYJHEk8UjVVZ4XCRTZe6dFQrb8pGWD81LYCgeLp8CvMB/go-metrics"
|
||||
gm "github.com/whyrusleeping/go-metrics"
|
||||
"sync"
|
||||
|
||||
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"io/ioutil"
|
||||
"testing"
|
||||
|
||||
randbo "gx/QmciEePSP8wpGYZp8fsPFi49Ya7xQMUFwFj2z5fDpfZnhC/randbo"
|
||||
randbo "github.com/dustin/randbo"
|
||||
inet "github.com/ipfs/go-libp2p/p2p/net"
|
||||
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
protocol "github.com/ipfs/go-libp2p/p2p/protocol"
|
||||
|
|
|
@ -8,14 +8,14 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
manet "gx/QmNT7d1e4Xcp3KcsvxyzUHVtqrR43uypoxLLzdKj6YZga2/go-multiaddr-net"
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
manet "github.com/jbenet/go-multiaddr-net"
|
||||
|
||||
notifier "gx/QmRV5aE4LZ4Kw9g2VAMpbEcaT7uz3Z3WxgdW8mzRPLL7g8/go-notifier"
|
||||
nat "gx/QmWjjKcvWKtkwzbqF6t3Kz3wXA3Uj8DRAbPaTtcgFnvTQt/go-nat"
|
||||
goprocess "gx/QmfDXyLfKNfja2XebomRZjZ2UZCa4BDyFoCymKtzNRVQ5b/goprocess"
|
||||
periodic "gx/QmfDXyLfKNfja2XebomRZjZ2UZCa4BDyFoCymKtzNRVQ5b/goprocess/periodic"
|
||||
logging "gx/QmfZZB1aVXWA4kaR5R4e9NifERT366TTCSagkfhmAbYLsu/go-log"
|
||||
nat "github.com/fd/go-nat"
|
||||
logging "github.com/ipfs/go-log"
|
||||
goprocess "github.com/jbenet/goprocess"
|
||||
periodic "github.com/jbenet/goprocess/periodic"
|
||||
notifier "github.com/whyrusleeping/go-notifier"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
|
@ -6,15 +6,15 @@ import (
|
|||
"net"
|
||||
"time"
|
||||
|
||||
u "github.com/ipfs/go-ipfs-util"
|
||||
lgbl "github.com/ipfs/go-libp2p/loggables"
|
||||
ic "github.com/ipfs/go-libp2p/p2p/crypto"
|
||||
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
manet "gx/QmNT7d1e4Xcp3KcsvxyzUHVtqrR43uypoxLLzdKj6YZga2/go-multiaddr-net"
|
||||
u "gx/QmQA79FfVsUnGkH3TgKDqcDkupfjqLSJ6EYwDuDDZK8nhD/go-ipfs-util"
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
mpool "gx/QmXMkWRYvXJ2NTzHMEz5794997kNPGsVX8EhFiXXpoKDZr/go-msgio/mpool"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
logging "gx/QmfZZB1aVXWA4kaR5R4e9NifERT366TTCSagkfhmAbYLsu/go-log"
|
||||
logging "github.com/ipfs/go-log"
|
||||
mpool "github.com/jbenet/go-msgio/mpool"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
manet "github.com/jbenet/go-multiaddr-net"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
var log = logging.Logger("conn")
|
||||
|
|
|
@ -9,8 +9,8 @@ import (
|
|||
"time"
|
||||
|
||||
travis "github.com/ipfs/go-libp2p/testutil/ci/travis"
|
||||
msgio "gx/QmXMkWRYvXJ2NTzHMEz5794997kNPGsVX8EhFiXXpoKDZr/go-msgio"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
msgio "github.com/jbenet/go-msgio"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func msgioWrap(c Conn) msgio.ReadWriter {
|
||||
|
|
|
@ -6,9 +6,9 @@ import (
|
|||
"strings"
|
||||
|
||||
lgbl "github.com/ipfs/go-libp2p/loggables"
|
||||
manet "gx/QmNT7d1e4Xcp3KcsvxyzUHVtqrR43uypoxLLzdKj6YZga2/go-multiaddr-net"
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
manet "github.com/jbenet/go-multiaddr-net"
|
||||
context "golang.org/x/net/context"
|
||||
|
||||
ci "github.com/ipfs/go-libp2p/p2p/crypto"
|
||||
addrutil "github.com/ipfs/go-libp2p/p2p/net/swarm/addr"
|
||||
|
|
|
@ -13,8 +13,8 @@ import (
|
|||
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
tu "github.com/ipfs/go-libp2p/testutil"
|
||||
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func echoListen(ctx context.Context, listener Listener) {
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
transport "github.com/ipfs/go-libp2p/p2p/net/transport"
|
||||
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
)
|
||||
|
||||
type PeerConn interface {
|
||||
|
|
|
@ -5,11 +5,11 @@ import (
|
|||
"io"
|
||||
"net"
|
||||
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
tec "gx/QmWtLNgjHvFnRHcHUheAMGx4sLYYYGSacNA3eG52ywy2UQ/go-temp-err-catcher"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
"gx/QmfDXyLfKNfja2XebomRZjZ2UZCa4BDyFoCymKtzNRVQ5b/goprocess"
|
||||
goprocessctx "gx/QmfDXyLfKNfja2XebomRZjZ2UZCa4BDyFoCymKtzNRVQ5b/goprocess/context"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
tec "github.com/jbenet/go-temp-err-catcher"
|
||||
"github.com/jbenet/goprocess"
|
||||
goprocessctx "github.com/jbenet/goprocess/context"
|
||||
context "golang.org/x/net/context"
|
||||
|
||||
ic "github.com/ipfs/go-libp2p/p2p/crypto"
|
||||
filter "github.com/ipfs/go-libp2p/p2p/net/filter"
|
||||
|
|
|
@ -5,8 +5,8 @@ import (
|
|||
"net"
|
||||
"time"
|
||||
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
context "golang.org/x/net/context"
|
||||
|
||||
ic "github.com/ipfs/go-libp2p/p2p/crypto"
|
||||
secio "github.com/ipfs/go-libp2p/p2p/crypto/secio"
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
ic "github.com/ipfs/go-libp2p/p2p/crypto"
|
||||
travis "github.com/ipfs/go-libp2p/testutil/ci/travis"
|
||||
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func upgradeToSecureConn(t *testing.T, ctx context.Context, sk ic.PrivKey, c Conn) (Conn, error) {
|
||||
|
|
|
@ -5,8 +5,8 @@ import (
|
|||
"strings"
|
||||
"sync"
|
||||
|
||||
manet "gx/QmNT7d1e4Xcp3KcsvxyzUHVtqrR43uypoxLLzdKj6YZga2/go-multiaddr-net"
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
manet "github.com/jbenet/go-multiaddr-net"
|
||||
)
|
||||
|
||||
type Filters struct {
|
||||
|
|
|
@ -6,9 +6,9 @@ import (
|
|||
conn "github.com/ipfs/go-libp2p/p2p/net/conn"
|
||||
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
"gx/QmfDXyLfKNfja2XebomRZjZ2UZCa4BDyFoCymKtzNRVQ5b/goprocess"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
"github.com/jbenet/goprocess"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// MessageSizeMax is a soft (recommended) maximum for network messages.
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
"io"
|
||||
"time"
|
||||
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
)
|
||||
|
||||
type Mocknet interface {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package mocknet
|
||||
|
||||
import (
|
||||
logging "gx/QmfZZB1aVXWA4kaR5R4e9NifERT366TTCSagkfhmAbYLsu/go-log"
|
||||
logging "github.com/ipfs/go-log"
|
||||
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
var log = logging.Logger("mocknet")
|
||||
|
|
|
@ -8,8 +8,8 @@ import (
|
|||
inet "github.com/ipfs/go-libp2p/p2p/net"
|
||||
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
process "gx/QmfDXyLfKNfja2XebomRZjZ2UZCa4BDyFoCymKtzNRVQ5b/goprocess"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
process "github.com/jbenet/goprocess"
|
||||
)
|
||||
|
||||
// conn represents one side's perspective of a
|
||||
|
|
|
@ -13,10 +13,10 @@ import (
|
|||
p2putil "github.com/ipfs/go-libp2p/p2p/test/util"
|
||||
testutil "github.com/ipfs/go-libp2p/testutil"
|
||||
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
"gx/QmfDXyLfKNfja2XebomRZjZ2UZCa4BDyFoCymKtzNRVQ5b/goprocess"
|
||||
goprocessctx "gx/QmfDXyLfKNfja2XebomRZjZ2UZCa4BDyFoCymKtzNRVQ5b/goprocess/context"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
"github.com/jbenet/goprocess"
|
||||
goprocessctx "github.com/jbenet/goprocess/context"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// mocknet implements mocknet.Mocknet
|
||||
|
|
|
@ -6,8 +6,8 @@ import (
|
|||
|
||||
inet "github.com/ipfs/go-libp2p/p2p/net"
|
||||
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func TestNotifications(t *testing.T) {
|
||||
|
|
|
@ -8,10 +8,10 @@ import (
|
|||
inet "github.com/ipfs/go-libp2p/p2p/net"
|
||||
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
"gx/QmfDXyLfKNfja2XebomRZjZ2UZCa4BDyFoCymKtzNRVQ5b/goprocess"
|
||||
goprocessctx "gx/QmfDXyLfKNfja2XebomRZjZ2UZCa4BDyFoCymKtzNRVQ5b/goprocess/context"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
"github.com/jbenet/goprocess"
|
||||
goprocessctx "github.com/jbenet/goprocess/context"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// peernet implements inet.Network
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"io"
|
||||
"time"
|
||||
|
||||
process "gx/QmfDXyLfKNfja2XebomRZjZ2UZCa4BDyFoCymKtzNRVQ5b/goprocess"
|
||||
process "github.com/jbenet/goprocess"
|
||||
|
||||
inet "github.com/ipfs/go-libp2p/p2p/net"
|
||||
)
|
||||
|
|
|
@ -14,8 +14,8 @@ import (
|
|||
protocol "github.com/ipfs/go-libp2p/p2p/protocol"
|
||||
testutil "github.com/ipfs/go-libp2p/testutil"
|
||||
|
||||
detectrace "gx/QmQHGMVmrsgmqUG8ih3puNXUJneSpi13dkcZpzLKkskUkH/go-detect-race"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
detectrace "github.com/jbenet/go-detect-race"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func randPeer(t *testing.T) peer.ID {
|
||||
|
|
|
@ -3,11 +3,11 @@ package addrutil
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
logging "gx/QmfZZB1aVXWA4kaR5R4e9NifERT366TTCSagkfhmAbYLsu/go-log"
|
||||
logging "github.com/ipfs/go-log"
|
||||
|
||||
manet "gx/QmNT7d1e4Xcp3KcsvxyzUHVtqrR43uypoxLLzdKj6YZga2/go-multiaddr-net"
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
manet "github.com/jbenet/go-multiaddr-net"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
var log = logging.Logger("github.com/ipfs/go-libp2p/p2p/net/swarm/addr")
|
||||
|
|
|
@ -3,8 +3,8 @@ package addrutil
|
|||
import (
|
||||
"testing"
|
||||
|
||||
manet "gx/QmNT7d1e4Xcp3KcsvxyzUHVtqrR43uypoxLLzdKj6YZga2/go-multiaddr-net"
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
manet "github.com/jbenet/go-multiaddr-net"
|
||||
)
|
||||
|
||||
func newMultiaddr(t *testing.T, s string) ma.Multiaddr {
|
||||
|
|
|
@ -13,9 +13,9 @@ import (
|
|||
testutil "github.com/ipfs/go-libp2p/testutil"
|
||||
ci "github.com/ipfs/go-libp2p/testutil/ci"
|
||||
|
||||
manet "gx/QmNT7d1e4Xcp3KcsvxyzUHVtqrR43uypoxLLzdKj6YZga2/go-multiaddr-net"
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
manet "github.com/jbenet/go-multiaddr-net"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func acceptAndHang(l net.Listener) {
|
||||
|
|
|
@ -5,8 +5,8 @@ import (
|
|||
|
||||
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func TestPeers(t *testing.T) {
|
||||
|
|
|
@ -9,8 +9,8 @@ import (
|
|||
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
ci "github.com/ipfs/go-libp2p/testutil/ci"
|
||||
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func TestSimultOpen(t *testing.T) {
|
||||
|
|
|
@ -16,16 +16,16 @@ import (
|
|||
transport "github.com/ipfs/go-libp2p/p2p/net/transport"
|
||||
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
|
||||
ps "gx/QmQMkNFMuh1UJbdaggASZpLtCroTnAYcWNenYL5hrzLJrT/go-peerstream"
|
||||
pst "gx/QmRmT6MSnfhRDW1PTUGSd3z4fqXK48GUequQAZzeT4c5iC/go-stream-muxer"
|
||||
psmss "gx/QmRmT6MSnfhRDW1PTUGSd3z4fqXK48GUequQAZzeT4c5iC/go-stream-muxer/multistream"
|
||||
mafilter "gx/QmVCmuhgDFer5MW5737Z8GtBEGpUyEkFnLUv4ASDWnLZdC/multiaddr-filter"
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
"gx/QmfDXyLfKNfja2XebomRZjZ2UZCa4BDyFoCymKtzNRVQ5b/goprocess"
|
||||
goprocessctx "gx/QmfDXyLfKNfja2XebomRZjZ2UZCa4BDyFoCymKtzNRVQ5b/goprocess/context"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
ps "github.com/jbenet/go-peerstream"
|
||||
pst "github.com/jbenet/go-stream-muxer"
|
||||
psmss "github.com/jbenet/go-stream-muxer/multistream"
|
||||
"github.com/jbenet/goprocess"
|
||||
goprocessctx "github.com/jbenet/goprocess/context"
|
||||
mafilter "github.com/whyrusleeping/multiaddr-filter"
|
||||
context "golang.org/x/net/context"
|
||||
|
||||
logging "gx/QmfZZB1aVXWA4kaR5R4e9NifERT366TTCSagkfhmAbYLsu/go-log"
|
||||
logging "github.com/ipfs/go-log"
|
||||
)
|
||||
|
||||
var log = logging.Logger("swarm2")
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
conn "github.com/ipfs/go-libp2p/p2p/net/conn"
|
||||
addrutil "github.com/ipfs/go-libp2p/p2p/net/swarm/addr"
|
||||
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
)
|
||||
|
||||
// ListenAddresses returns a list of addresses at which this swarm listens.
|
||||
|
|
|
@ -8,8 +8,8 @@ import (
|
|||
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
testutil "github.com/ipfs/go-libp2p/testutil"
|
||||
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func TestFilterAddrs(t *testing.T) {
|
||||
|
|
|
@ -8,9 +8,9 @@ import (
|
|||
conn "github.com/ipfs/go-libp2p/p2p/net/conn"
|
||||
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
|
||||
ps "gx/QmQMkNFMuh1UJbdaggASZpLtCroTnAYcWNenYL5hrzLJrT/go-peerstream"
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
ps "github.com/jbenet/go-peerstream"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// a Conn is a simple wrapper around a ps.Conn that also exposes
|
||||
|
|
|
@ -12,10 +12,10 @@ import (
|
|||
conn "github.com/ipfs/go-libp2p/p2p/net/conn"
|
||||
addrutil "github.com/ipfs/go-libp2p/p2p/net/swarm/addr"
|
||||
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
"gx/QmNT7d1e4Xcp3KcsvxyzUHVtqrR43uypoxLLzdKj6YZga2/go-multiaddr-net"
|
||||
"github.com/jbenet/go-multiaddr-net"
|
||||
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// Diagram of dial sync:
|
||||
|
|
|
@ -9,9 +9,9 @@ import (
|
|||
conn "github.com/ipfs/go-libp2p/p2p/net/conn"
|
||||
transport "github.com/ipfs/go-libp2p/p2p/net/transport"
|
||||
|
||||
ps "gx/QmQMkNFMuh1UJbdaggASZpLtCroTnAYcWNenYL5hrzLJrT/go-peerstream"
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
ps "github.com/jbenet/go-peerstream"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// Open listeners and reuse-dialers for the given addresses
|
||||
|
|
|
@ -8,9 +8,9 @@ import (
|
|||
metrics "github.com/ipfs/go-libp2p/p2p/metrics"
|
||||
inet "github.com/ipfs/go-libp2p/p2p/net"
|
||||
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
"gx/QmfDXyLfKNfja2XebomRZjZ2UZCa4BDyFoCymKtzNRVQ5b/goprocess"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
"github.com/jbenet/goprocess"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// Network implements the inet.Network interface.
|
||||
|
|
|
@ -5,9 +5,9 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
inet "github.com/ipfs/go-libp2p/p2p/net"
|
||||
testutil "github.com/ipfs/go-libp2p/p2p/test/util"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// TestConnectednessCorrect starts a few networks, connects a few
|
||||
|
|
|
@ -4,8 +4,8 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
context "golang.org/x/net/context"
|
||||
|
||||
inet "github.com/ipfs/go-libp2p/p2p/net"
|
||||
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
|
|
|
@ -3,7 +3,7 @@ package swarm
|
|||
import (
|
||||
inet "github.com/ipfs/go-libp2p/p2p/net"
|
||||
|
||||
ps "gx/QmQMkNFMuh1UJbdaggASZpLtCroTnAYcWNenYL5hrzLJrT/go-peerstream"
|
||||
ps "github.com/jbenet/go-peerstream"
|
||||
)
|
||||
|
||||
// a Stream is a wrapper around a ps.Stream that exposes a way to get
|
||||
|
|
|
@ -14,8 +14,8 @@ import (
|
|||
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
testutil "github.com/ipfs/go-libp2p/testutil"
|
||||
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func EchoStreamHandler(stream inet.Stream) {
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"strings"
|
||||
"syscall"
|
||||
|
||||
reuseport "gx/QmfDF93E1PjQUqFM4rKyFs85feJdMR9AaVm1axVZ4qdFU1/go-reuseport"
|
||||
reuseport "github.com/jbenet/go-reuseport"
|
||||
)
|
||||
|
||||
// envReuseport is the env variable name used to turn off reuse port.
|
||||
|
|
|
@ -7,10 +7,10 @@ import (
|
|||
"time"
|
||||
|
||||
lgbl "github.com/ipfs/go-libp2p/loggables"
|
||||
manet "gx/QmNT7d1e4Xcp3KcsvxyzUHVtqrR43uypoxLLzdKj6YZga2/go-multiaddr-net"
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
reuseport "gx/QmfDF93E1PjQUqFM4rKyFs85feJdMR9AaVm1axVZ4qdFU1/go-reuseport"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
manet "github.com/jbenet/go-multiaddr-net"
|
||||
reuseport "github.com/jbenet/go-reuseport"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
type TcpTransport struct {
|
||||
|
|
|
@ -4,9 +4,9 @@ import (
|
|||
"net"
|
||||
"time"
|
||||
|
||||
manet "gx/QmNT7d1e4Xcp3KcsvxyzUHVtqrR43uypoxLLzdKj6YZga2/go-multiaddr-net"
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
logging "gx/QmfZZB1aVXWA4kaR5R4e9NifERT366TTCSagkfhmAbYLsu/go-log"
|
||||
logging "github.com/ipfs/go-log"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
manet "github.com/jbenet/go-multiaddr-net"
|
||||
)
|
||||
|
||||
var log = logging.Logger("transport")
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
package addr
|
||||
|
||||
import (
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
)
|
||||
|
||||
// AddrSource is a source of addresses. It allows clients to retrieve
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"fmt"
|
||||
"testing"
|
||||
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
)
|
||||
|
||||
func newAddrOrFatal(t *testing.T, s string) ma.Multiaddr {
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
)
|
||||
|
||||
func IDS(t *testing.T, ids string) ID {
|
||||
|
|
|
@ -7,13 +7,13 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
|
||||
b58 "gx/QmNsoHoCVhgXcv1Yg45jtkMgimxorTAN36fV9AQMFXHHAQ/go-base58"
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
mh "gx/Qma7dqy7ZVH4tkNJdC9TRrA82Uz5fQfbbwuvmNVVc17r7a/go-multihash"
|
||||
b58 "github.com/jbenet/go-base58"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
mh "github.com/jbenet/go-multihash"
|
||||
|
||||
u "github.com/ipfs/go-ipfs-util"
|
||||
ic "github.com/ipfs/go-libp2p/p2p/crypto"
|
||||
u "gx/QmQA79FfVsUnGkH3TgKDqcDkupfjqLSJ6EYwDuDDZK8nhD/go-ipfs-util"
|
||||
logging "gx/QmfZZB1aVXWA4kaR5R4e9NifERT366TTCSagkfhmAbYLsu/go-log"
|
||||
logging "github.com/ipfs/go-log"
|
||||
)
|
||||
|
||||
var log = logging.Logger("peer")
|
||||
|
|
|
@ -6,12 +6,12 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
u "github.com/ipfs/go-ipfs-util"
|
||||
ic "github.com/ipfs/go-libp2p/p2p/crypto"
|
||||
. "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
tu "github.com/ipfs/go-libp2p/testutil"
|
||||
u "gx/QmQA79FfVsUnGkH3TgKDqcDkupfjqLSJ6EYwDuDDZK8nhD/go-ipfs-util"
|
||||
|
||||
b58 "gx/QmNsoHoCVhgXcv1Yg45jtkMgimxorTAN36fV9AQMFXHHAQ/go-base58"
|
||||
b58 "github.com/jbenet/go-base58"
|
||||
)
|
||||
|
||||
var gen1 keyset // generated
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
|
||||
//ds "github.com/jbenet/go-datastore"
|
||||
//dssync "github.com/jbenet/go-datastore/sync"
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"sync"
|
||||
|
||||
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
ks "gx/QmThbzo9oBE7FAVmgjp3xYv5Yra81uB7KXbrTei47gWT6o/go-keyspace"
|
||||
ks "github.com/whyrusleeping/go-keyspace"
|
||||
)
|
||||
|
||||
// peerMetric tracks a peer and its distance to something else.
|
||||
|
|
|
@ -6,10 +6,10 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
u "github.com/ipfs/go-ipfs-util"
|
||||
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
u "gx/QmQA79FfVsUnGkH3TgKDqcDkupfjqLSJ6EYwDuDDZK8nhD/go-ipfs-util"
|
||||
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func TestQueue(t *testing.T) {
|
||||
|
|
|
@ -2,8 +2,8 @@ package queue
|
|||
|
||||
import (
|
||||
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
logging "gx/QmfZZB1aVXWA4kaR5R4e9NifERT366TTCSagkfhmAbYLsu/go-log"
|
||||
logging "github.com/ipfs/go-log"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
var log = logging.Logger("peerqueue")
|
||||
|
|
|
@ -4,11 +4,11 @@ import (
|
|||
"strings"
|
||||
"sync"
|
||||
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
ggio "gx/QmchriuyWMcqHha3dG86rQyxoswSUpmLUBjuJ2kotB65qR/gogo-protobuf/io"
|
||||
semver "gx/QmcrrEpx3VMUbrbgVroH3YiYyUS5c4YAykzyPJWKspUYLa/go-semver/semver"
|
||||
msmux "gx/QmdrbcnPVM2FnZQQM7p2GU91XhpuyYyd1tzPouEyh1phyD/go-multistream"
|
||||
semver "github.com/coreos/go-semver/semver"
|
||||
ggio "github.com/gogo/protobuf/io"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
msmux "github.com/whyrusleeping/go-multistream"
|
||||
context "golang.org/x/net/context"
|
||||
|
||||
host "github.com/ipfs/go-libp2p/p2p/host"
|
||||
mstream "github.com/ipfs/go-libp2p/p2p/metrics/stream"
|
||||
|
@ -17,7 +17,7 @@ import (
|
|||
pb "github.com/ipfs/go-libp2p/p2p/protocol/identify/pb"
|
||||
|
||||
lgbl "github.com/ipfs/go-libp2p/loggables"
|
||||
logging "gx/QmfZZB1aVXWA4kaR5R4e9NifERT366TTCSagkfhmAbYLsu/go-log"
|
||||
logging "github.com/ipfs/go-log"
|
||||
)
|
||||
|
||||
var log = logging.Logger("net/identify")
|
||||
|
|
|
@ -9,8 +9,8 @@ import (
|
|||
identify "github.com/ipfs/go-libp2p/p2p/protocol/identify"
|
||||
testutil "github.com/ipfs/go-libp2p/p2p/test/util"
|
||||
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func subtestIDService(t *testing.T, postDialWait time.Duration) {
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
|
||||
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
)
|
||||
|
||||
// ObservedAddr is an entry for an address reported by our peers.
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
)
|
||||
|
||||
// TestObsAddrSet
|
||||
|
|
|
@ -13,7 +13,7 @@ It has these top-level messages:
|
|||
*/
|
||||
package identify_pb
|
||||
|
||||
import proto "gx/QmchriuyWMcqHha3dG86rQyxoswSUpmLUBjuJ2kotB65qR/gogo-protobuf/proto"
|
||||
import proto "github.com/gogo/protobuf/proto"
|
||||
import math "math"
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
|
|
|
@ -6,13 +6,13 @@ import (
|
|||
"io"
|
||||
"time"
|
||||
|
||||
u "gx/QmQA79FfVsUnGkH3TgKDqcDkupfjqLSJ6EYwDuDDZK8nhD/go-ipfs-util"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
u "github.com/ipfs/go-ipfs-util"
|
||||
context "golang.org/x/net/context"
|
||||
|
||||
host "github.com/ipfs/go-libp2p/p2p/host"
|
||||
inet "github.com/ipfs/go-libp2p/p2p/net"
|
||||
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
logging "gx/QmfZZB1aVXWA4kaR5R4e9NifERT366TTCSagkfhmAbYLsu/go-log"
|
||||
logging "github.com/ipfs/go-log"
|
||||
)
|
||||
|
||||
var log = logging.Logger("ping")
|
||||
|
|
|
@ -4,9 +4,9 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
netutil "github.com/ipfs/go-libp2p/p2p/test/util"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func TestPing(t *testing.T) {
|
||||
|
|
|
@ -5,14 +5,14 @@ import (
|
|||
"io"
|
||||
"time"
|
||||
|
||||
mh "gx/Qma7dqy7ZVH4tkNJdC9TRrA82Uz5fQfbbwuvmNVVc17r7a/go-multihash"
|
||||
mh "github.com/jbenet/go-multihash"
|
||||
|
||||
host "github.com/ipfs/go-libp2p/p2p/host"
|
||||
inet "github.com/ipfs/go-libp2p/p2p/net"
|
||||
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
protocol "github.com/ipfs/go-libp2p/p2p/protocol"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
logging "gx/QmfZZB1aVXWA4kaR5R4e9NifERT366TTCSagkfhmAbYLsu/go-log"
|
||||
logging "github.com/ipfs/go-log"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
var log = logging.Logger("github.com/ipfs/go-libp2p/p2p/protocol/relay")
|
||||
|
|
|
@ -8,10 +8,10 @@ import (
|
|||
protocol "github.com/ipfs/go-libp2p/p2p/protocol"
|
||||
relay "github.com/ipfs/go-libp2p/p2p/protocol/relay"
|
||||
testutil "github.com/ipfs/go-libp2p/p2p/test/util"
|
||||
logging "gx/QmfZZB1aVXWA4kaR5R4e9NifERT366TTCSagkfhmAbYLsu/go-log"
|
||||
logging "github.com/ipfs/go-log"
|
||||
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
msmux "gx/QmdrbcnPVM2FnZQQM7p2GU91XhpuyYyd1tzPouEyh1phyD/go-multistream"
|
||||
msmux "github.com/whyrusleeping/go-multistream"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
var log = logging.Logger("relay_test")
|
||||
|
|
|
@ -11,10 +11,10 @@ import (
|
|||
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
protocol "github.com/ipfs/go-libp2p/p2p/protocol"
|
||||
testutil "github.com/ipfs/go-libp2p/p2p/test/util"
|
||||
logging "gx/QmfZZB1aVXWA4kaR5R4e9NifERT366TTCSagkfhmAbYLsu/go-log"
|
||||
logging "github.com/ipfs/go-log"
|
||||
|
||||
u "gx/QmQA79FfVsUnGkH3TgKDqcDkupfjqLSJ6EYwDuDDZK8nhD/go-ipfs-util"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
u "github.com/ipfs/go-ipfs-util"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
var log = logging.Logger("backpressure")
|
||||
|
|
|
@ -7,16 +7,16 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
u "github.com/ipfs/go-ipfs-util"
|
||||
host "github.com/ipfs/go-libp2p/p2p/host"
|
||||
inet "github.com/ipfs/go-libp2p/p2p/net"
|
||||
swarm "github.com/ipfs/go-libp2p/p2p/net/swarm"
|
||||
protocol "github.com/ipfs/go-libp2p/p2p/protocol"
|
||||
testutil "github.com/ipfs/go-libp2p/p2p/test/util"
|
||||
u "gx/QmQA79FfVsUnGkH3TgKDqcDkupfjqLSJ6EYwDuDDZK8nhD/go-ipfs-util"
|
||||
logging "gx/QmfZZB1aVXWA4kaR5R4e9NifERT366TTCSagkfhmAbYLsu/go-log"
|
||||
logging "github.com/ipfs/go-log"
|
||||
|
||||
ps "gx/QmQMkNFMuh1UJbdaggASZpLtCroTnAYcWNenYL5hrzLJrT/go-peerstream"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
ps "github.com/jbenet/go-peerstream"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
|
|
@ -5,14 +5,14 @@ import (
|
|||
"io"
|
||||
"testing"
|
||||
|
||||
u "github.com/ipfs/go-ipfs-util"
|
||||
testutil "github.com/ipfs/go-libp2p/testutil"
|
||||
u "gx/QmQA79FfVsUnGkH3TgKDqcDkupfjqLSJ6EYwDuDDZK8nhD/go-ipfs-util"
|
||||
logging "gx/QmfZZB1aVXWA4kaR5R4e9NifERT366TTCSagkfhmAbYLsu/go-log"
|
||||
logging "github.com/ipfs/go-log"
|
||||
|
||||
ic "github.com/ipfs/go-libp2p/p2p/crypto"
|
||||
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
)
|
||||
|
||||
var log = logging.Logger("boguskey")
|
||||
|
|
|
@ -10,8 +10,8 @@ import (
|
|||
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
tu "github.com/ipfs/go-libp2p/testutil"
|
||||
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
context "gx/QmacZi9WygGK7Me8mH53pypyscHzU386aUZXpr28GZgUct/context"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func GenSwarmNetwork(t *testing.T, ctx context.Context) *swarm.Network {
|
||||
|
|
84
package.json
84
package.json
|
@ -2,91 +2,9 @@
|
|||
"name": "go-libp2p",
|
||||
"author": "whyrusleeping",
|
||||
"version": "1.0.0",
|
||||
"gxDependencies": [
|
||||
{
|
||||
"name": "go-log",
|
||||
"hash": "QmfZZB1aVXWA4kaR5R4e9NifERT366TTCSagkfhmAbYLsu",
|
||||
"version": "1.0.0"
|
||||
},
|
||||
{
|
||||
"name": "go-keyspace",
|
||||
"hash": "QmThbzo9oBE7FAVmgjp3xYv5Yra81uB7KXbrTei47gWT6o",
|
||||
"version": "1.0.0"
|
||||
},
|
||||
{
|
||||
"name": "go-multiaddr-net",
|
||||
"hash": "QmNT7d1e4Xcp3KcsvxyzUHVtqrR43uypoxLLzdKj6YZga2",
|
||||
"version": "1.0.0"
|
||||
},
|
||||
{
|
||||
"name": "multiaddr-filter",
|
||||
"hash": "QmVCmuhgDFer5MW5737Z8GtBEGpUyEkFnLUv4ASDWnLZdC",
|
||||
"version": "1.0.0"
|
||||
},
|
||||
{
|
||||
"name": "go-notifier",
|
||||
"hash": "QmRV5aE4LZ4Kw9g2VAMpbEcaT7uz3Z3WxgdW8mzRPLL7g8",
|
||||
"version": "1.0.0"
|
||||
},
|
||||
{
|
||||
"name": "go-ipfs-util",
|
||||
"hash": "QmQA79FfVsUnGkH3TgKDqcDkupfjqLSJ6EYwDuDDZK8nhD",
|
||||
"version": "1.0.0"
|
||||
},
|
||||
{
|
||||
"name": "go-peerstream",
|
||||
"hash": "QmQMkNFMuh1UJbdaggASZpLtCroTnAYcWNenYL5hrzLJrT",
|
||||
"version": "1.0.0"
|
||||
},
|
||||
{
|
||||
"name": "go-msgio",
|
||||
"hash": "QmXMkWRYvXJ2NTzHMEz5794997kNPGsVX8EhFiXXpoKDZr",
|
||||
"version": "0.0.0"
|
||||
},
|
||||
{
|
||||
"name": "randbo",
|
||||
"hash": "QmciEePSP8wpGYZp8fsPFi49Ya7xQMUFwFj2z5fDpfZnhC",
|
||||
"version": "1.0.0"
|
||||
},
|
||||
{
|
||||
"name": "mdns",
|
||||
"hash": "QmdkSkALqzKfXnuMTsbBVS26U4XGS9kCffRpSTWvVbkRSi",
|
||||
"version": "0.0.0"
|
||||
},
|
||||
{
|
||||
"name": "go-reuseport",
|
||||
"hash": "QmfDF93E1PjQUqFM4rKyFs85feJdMR9AaVm1axVZ4qdFU1",
|
||||
"version": "0.0.0"
|
||||
},
|
||||
{
|
||||
"name": "go-semver",
|
||||
"hash": "QmcrrEpx3VMUbrbgVroH3YiYyUS5c4YAykzyPJWKspUYLa",
|
||||
"version": "0.0.0"
|
||||
},
|
||||
{
|
||||
"name": "go-nat",
|
||||
"hash": "QmWjjKcvWKtkwzbqF6t3Kz3wXA3Uj8DRAbPaTtcgFnvTQt",
|
||||
"version": "0.0.0"
|
||||
},
|
||||
{
|
||||
"name": "go-metrics",
|
||||
"hash": "QmeYJHEk8UjVVZ4XCRTZe6dFQrb8pGWD81LYCgeLp8CvMB",
|
||||
"version": "0.0.0"
|
||||
},
|
||||
{
|
||||
"name": "go-detect-race",
|
||||
"hash": "QmQHGMVmrsgmqUG8ih3puNXUJneSpi13dkcZpzLKkskUkH",
|
||||
"version": "0.0.0"
|
||||
},
|
||||
{
|
||||
"name": "gogo-protobuf",
|
||||
"hash": "QmchriuyWMcqHha3dG86rQyxoswSUpmLUBjuJ2kotB65qR",
|
||||
"version": "0.0.0"
|
||||
}
|
||||
],
|
||||
"language": "go",
|
||||
"issues_url": "",
|
||||
"gx": {
|
||||
"dvcsimport": "github.com/ipfs/go-libp2p"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,11 +8,11 @@ import (
|
|||
"sync"
|
||||
"testing"
|
||||
|
||||
u "github.com/ipfs/go-ipfs-util"
|
||||
ci "github.com/ipfs/go-libp2p/p2p/crypto"
|
||||
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
u "gx/QmQA79FfVsUnGkH3TgKDqcDkupfjqLSJ6EYwDuDDZK8nhD/go-ipfs-util"
|
||||
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
)
|
||||
|
||||
// ZeroLocalTCPAddress is the "zero" tcp local multiaddr. This means:
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
|
||||
ci "github.com/ipfs/go-libp2p/p2p/crypto"
|
||||
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
ma "github.com/jbenet/go-multiaddr"
|
||||
)
|
||||
|
||||
type Identity interface {
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
Godeps/*
|
|
@ -1,11 +0,0 @@
|
|||
language: go
|
||||
|
||||
go:
|
||||
- 1.3
|
||||
- release
|
||||
- tip
|
||||
|
||||
script:
|
||||
- make test
|
||||
|
||||
env: TEST_VERBOSE=1
|
|
@ -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.
|
|
@ -1,19 +0,0 @@
|
|||
all: install
|
||||
|
||||
godep:
|
||||
go get github.com/tools/godep
|
||||
|
||||
# saves/vendors third-party dependencies to Godeps/_workspace
|
||||
# -r flag rewrites import paths to use the vendored path
|
||||
# ./... performs operation on all packages in tree
|
||||
vendor: godep
|
||||
godep save -r ./...
|
||||
|
||||
install: dep
|
||||
cd multiaddr && go install
|
||||
|
||||
test:
|
||||
go test -race -cpu=5 -v ./...
|
||||
|
||||
dep:
|
||||
cd multiaddr && go get ./...
|
|
@ -1,11 +0,0 @@
|
|||
# multiaddr/net - Multiaddr friendly net
|
||||
|
||||
Package multiaddr/net provides [Multiaddr](http://github.com/jbenet/go-multiaddr) specific versions of common
|
||||
functions in stdlib's net package. This means wrappers of
|
||||
standard net symbols like net.Dial and net.Listen, as well
|
||||
as conversion to/from net.Addr.
|
||||
|
||||
Docs:
|
||||
|
||||
- `multiaddr/net`: https://godoc.org/github.com/jbenet/go-multiaddr-net
|
||||
- `multiaddr`: https://godoc.org/github.com/jbenet/go-multiaddr
|
|
@ -1,172 +0,0 @@
|
|||
package manet
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
utp "gx/QmNT7d1e4Xcp3KcsvxyzUHVtqrR43uypoxLLzdKj6YZga2/go-multiaddr-net/utp"
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
)
|
||||
|
||||
var errIncorrectNetAddr = fmt.Errorf("incorrect network addr conversion")
|
||||
|
||||
// FromNetAddr converts a net.Addr type to a Multiaddr.
|
||||
func FromNetAddr(a net.Addr) (ma.Multiaddr, error) {
|
||||
if a == nil {
|
||||
return nil, fmt.Errorf("nil multiaddr")
|
||||
}
|
||||
|
||||
switch a.Network() {
|
||||
case "tcp", "tcp4", "tcp6":
|
||||
ac, ok := a.(*net.TCPAddr)
|
||||
if !ok {
|
||||
return nil, errIncorrectNetAddr
|
||||
}
|
||||
|
||||
// Get IP Addr
|
||||
ipm, err := FromIP(ac.IP)
|
||||
if err != nil {
|
||||
return nil, errIncorrectNetAddr
|
||||
}
|
||||
|
||||
// Get TCP Addr
|
||||
tcpm, err := ma.NewMultiaddr(fmt.Sprintf("/tcp/%d", ac.Port))
|
||||
if err != nil {
|
||||
return nil, errIncorrectNetAddr
|
||||
}
|
||||
|
||||
// Encapsulate
|
||||
return ipm.Encapsulate(tcpm), nil
|
||||
|
||||
case "udp", "upd4", "udp6":
|
||||
ac, ok := a.(*net.UDPAddr)
|
||||
if !ok {
|
||||
return nil, errIncorrectNetAddr
|
||||
}
|
||||
|
||||
// Get IP Addr
|
||||
ipm, err := FromIP(ac.IP)
|
||||
if err != nil {
|
||||
return nil, errIncorrectNetAddr
|
||||
}
|
||||
|
||||
// Get UDP Addr
|
||||
udpm, err := ma.NewMultiaddr(fmt.Sprintf("/udp/%d", ac.Port))
|
||||
if err != nil {
|
||||
return nil, errIncorrectNetAddr
|
||||
}
|
||||
|
||||
// Encapsulate
|
||||
return ipm.Encapsulate(udpm), nil
|
||||
|
||||
case "utp", "utp4", "utp6":
|
||||
acc, ok := a.(*utp.Addr)
|
||||
if !ok {
|
||||
return nil, errIncorrectNetAddr
|
||||
}
|
||||
|
||||
// Get UDP Addr
|
||||
ac, ok := acc.Child().(*net.UDPAddr)
|
||||
if !ok {
|
||||
return nil, errIncorrectNetAddr
|
||||
}
|
||||
|
||||
// Get IP Addr
|
||||
ipm, err := FromIP(ac.IP)
|
||||
if err != nil {
|
||||
return nil, errIncorrectNetAddr
|
||||
}
|
||||
|
||||
// Get UDP Addr
|
||||
utpm, err := ma.NewMultiaddr(fmt.Sprintf("/udp/%d/utp", ac.Port))
|
||||
if err != nil {
|
||||
return nil, errIncorrectNetAddr
|
||||
}
|
||||
|
||||
// Encapsulate
|
||||
return ipm.Encapsulate(utpm), nil
|
||||
|
||||
case "ip", "ip4", "ip6":
|
||||
ac, ok := a.(*net.IPAddr)
|
||||
if !ok {
|
||||
return nil, errIncorrectNetAddr
|
||||
}
|
||||
return FromIP(ac.IP)
|
||||
|
||||
case "ip+net":
|
||||
ac, ok := a.(*net.IPNet)
|
||||
if !ok {
|
||||
return nil, errIncorrectNetAddr
|
||||
}
|
||||
return FromIP(ac.IP)
|
||||
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown network %v", a.Network())
|
||||
}
|
||||
}
|
||||
|
||||
// ToNetAddr converts a Multiaddr to a net.Addr
|
||||
// Must be ThinWaist. acceptable protocol stacks are:
|
||||
// /ip{4,6}/{tcp, udp}
|
||||
func ToNetAddr(maddr ma.Multiaddr) (net.Addr, error) {
|
||||
network, host, err := DialArgs(maddr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
switch network {
|
||||
case "tcp", "tcp4", "tcp6":
|
||||
return net.ResolveTCPAddr(network, host)
|
||||
case "udp", "udp4", "udp6":
|
||||
return net.ResolveUDPAddr(network, host)
|
||||
case "utp", "utp4", "utp6":
|
||||
return utp.ResolveAddr(network, host)
|
||||
case "ip", "ip4", "ip6":
|
||||
return net.ResolveIPAddr(network, host)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("network not supported: %s", network)
|
||||
}
|
||||
|
||||
// FromIP converts a net.IP type to a Multiaddr.
|
||||
func FromIP(ip net.IP) (ma.Multiaddr, error) {
|
||||
switch {
|
||||
case ip.To4() != nil:
|
||||
return ma.NewMultiaddr("/ip4/" + ip.String())
|
||||
case ip.To16() != nil:
|
||||
return ma.NewMultiaddr("/ip6/" + ip.String())
|
||||
default:
|
||||
return nil, errIncorrectNetAddr
|
||||
}
|
||||
}
|
||||
|
||||
// DialArgs is a convenience function returning arguments for use in net.Dial
|
||||
func DialArgs(m ma.Multiaddr) (string, string, error) {
|
||||
if !IsThinWaist(m) {
|
||||
return "", "", fmt.Errorf("%s is not a 'thin waist' address", m)
|
||||
}
|
||||
|
||||
str := m.String()
|
||||
parts := strings.Split(str, "/")[1:]
|
||||
|
||||
if len(parts) == 2 { // only IP
|
||||
return parts[0], parts[1], nil
|
||||
}
|
||||
|
||||
network := parts[2]
|
||||
if parts[2] == "udp" && len(parts) > 4 && parts[4] == "utp" {
|
||||
network = parts[4]
|
||||
}
|
||||
|
||||
var host string
|
||||
switch parts[0] {
|
||||
case "ip4":
|
||||
network = network + "4"
|
||||
host = strings.Join([]string{parts[1], parts[3]}, ":")
|
||||
case "ip6":
|
||||
network = network + "6"
|
||||
host = fmt.Sprintf("[%s]:%s", parts[1], parts[3])
|
||||
}
|
||||
return network, host, nil
|
||||
}
|
|
@ -1,157 +0,0 @@
|
|||
package manet
|
||||
|
||||
import (
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
mautp "gx/QmNT7d1e4Xcp3KcsvxyzUHVtqrR43uypoxLLzdKj6YZga2/go-multiaddr-net/utp"
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
)
|
||||
|
||||
type GenFunc func() (ma.Multiaddr, error)
|
||||
|
||||
func testConvert(t *testing.T, s string, gen GenFunc) {
|
||||
m, err := gen()
|
||||
if err != nil {
|
||||
t.Fatal("failed to generate.")
|
||||
}
|
||||
|
||||
if s2 := m.String(); err != nil || s2 != s {
|
||||
t.Fatal("failed to convert: " + s + " != " + s2)
|
||||
}
|
||||
}
|
||||
|
||||
func testToNetAddr(t *testing.T, maddr, ntwk, addr string) {
|
||||
m, err := ma.NewMultiaddr(maddr)
|
||||
if err != nil {
|
||||
t.Fatal("failed to generate.")
|
||||
}
|
||||
|
||||
naddr, err := ToNetAddr(m)
|
||||
if addr == "" { // should fail
|
||||
if err == nil {
|
||||
t.Fatalf("failed to error: %s", m)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// shouldn't fail
|
||||
if err != nil {
|
||||
t.Fatalf("failed to convert to net addr: %s", m)
|
||||
}
|
||||
|
||||
if naddr.String() != addr {
|
||||
t.Fatalf("naddr.Address() == %s != %s", naddr, addr)
|
||||
}
|
||||
|
||||
if naddr.Network() != ntwk {
|
||||
t.Fatalf("naddr.Network() == %s != %s", naddr.Network(), ntwk)
|
||||
}
|
||||
|
||||
// should convert properly
|
||||
switch ntwk {
|
||||
case "tcp":
|
||||
_ = naddr.(*net.TCPAddr)
|
||||
case "udp":
|
||||
_ = naddr.(*net.UDPAddr)
|
||||
case "ip":
|
||||
_ = naddr.(*net.IPAddr)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFromIP4(t *testing.T) {
|
||||
testConvert(t, "/ip4/10.20.30.40", func() (ma.Multiaddr, error) {
|
||||
return FromIP(net.ParseIP("10.20.30.40"))
|
||||
})
|
||||
}
|
||||
|
||||
func TestFromIP6(t *testing.T) {
|
||||
testConvert(t, "/ip6/2001:4860:0:2001::68", func() (ma.Multiaddr, error) {
|
||||
return FromIP(net.ParseIP("2001:4860:0:2001::68"))
|
||||
})
|
||||
}
|
||||
|
||||
func TestFromTCP(t *testing.T) {
|
||||
testConvert(t, "/ip4/10.20.30.40/tcp/1234", func() (ma.Multiaddr, error) {
|
||||
return FromNetAddr(&net.TCPAddr{
|
||||
IP: net.ParseIP("10.20.30.40"),
|
||||
Port: 1234,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestFromUDP(t *testing.T) {
|
||||
testConvert(t, "/ip4/10.20.30.40/udp/1234", func() (ma.Multiaddr, error) {
|
||||
return FromNetAddr(&net.UDPAddr{
|
||||
IP: net.ParseIP("10.20.30.40"),
|
||||
Port: 1234,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestFromUTP(t *testing.T) {
|
||||
a := &net.UDPAddr{IP: net.ParseIP("10.20.30.40"), Port: 1234}
|
||||
testConvert(t, "/ip4/10.20.30.40/udp/1234/utp", func() (ma.Multiaddr, error) {
|
||||
return FromNetAddr(mautp.MakeAddr(a))
|
||||
})
|
||||
}
|
||||
|
||||
func TestThinWaist(t *testing.T) {
|
||||
addrs := map[string]bool{
|
||||
"/ip4/127.0.0.1/udp/1234": true,
|
||||
"/ip4/127.0.0.1/tcp/1234": true,
|
||||
"/ip4/127.0.0.1/udp/1234/utp": true,
|
||||
"/ip4/127.0.0.1/udp/1234/tcp/1234": true,
|
||||
"/ip4/127.0.0.1/tcp/12345/ip4/1.2.3.4": true,
|
||||
"/ip6/::1/tcp/80": true,
|
||||
"/ip6/::1/udp/80": true,
|
||||
"/ip6/::1": true,
|
||||
"/ip6/::1/utp": false,
|
||||
"/tcp/1234/ip4/1.2.3.4": false,
|
||||
"/tcp/1234": false,
|
||||
"/tcp/1234/utp": false,
|
||||
"/tcp/1234/udp/1234": false,
|
||||
"/ip4/1.2.3.4/ip4/2.3.4.5": true,
|
||||
"/ip6/::1/ip4/2.3.4.5": true,
|
||||
}
|
||||
|
||||
for a, res := range addrs {
|
||||
m, err := ma.NewMultiaddr(a)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to construct Multiaddr: %s", a)
|
||||
}
|
||||
|
||||
if IsThinWaist(m) != res {
|
||||
t.Fatalf("IsThinWaist(%s) != %v", a, res)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDialArgs(t *testing.T) {
|
||||
test := func(e_maddr, e_nw, e_host string) {
|
||||
m, err := ma.NewMultiaddr(e_maddr)
|
||||
if err != nil {
|
||||
t.Fatal("failed to construct", "/ip4/127.0.0.1/udp/1234", e_maddr)
|
||||
}
|
||||
|
||||
nw, host, err := DialArgs(m)
|
||||
if err != nil {
|
||||
t.Fatal("failed to get dial args", e_maddr, m, err)
|
||||
}
|
||||
|
||||
if nw != e_nw {
|
||||
t.Error("failed to get udp network Dial Arg", e_nw, nw)
|
||||
}
|
||||
|
||||
if host != e_host {
|
||||
t.Error("failed to get host:port Dial Arg", e_host, host)
|
||||
}
|
||||
}
|
||||
|
||||
test("/ip4/127.0.0.1/udp/1234", "udp4", "127.0.0.1:1234")
|
||||
test("/ip4/127.0.0.1/tcp/4321", "tcp4", "127.0.0.1:4321")
|
||||
test("/ip4/127.0.0.1/udp/1234/utp", "utp4", "127.0.0.1:1234")
|
||||
test("/ip6/::1/udp/1234", "udp6", "[::1]:1234")
|
||||
test("/ip6/::1/tcp/4321", "tcp6", "[::1]:4321")
|
||||
test("/ip6/::1/udp/1234/utp", "utp6", "[::1]:1234")
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
// Package manet provides Multiaddr specific versions of common
|
||||
// functions in stdlib's net package. This means wrappers of
|
||||
// standard net symbols like net.Dial and net.Listen, as well
|
||||
// as conversion to/from net.Addr.
|
||||
package manet
|
|
@ -1,85 +0,0 @@
|
|||
package manet
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
)
|
||||
|
||||
// Loopback Addresses
|
||||
var (
|
||||
// IP4Loopback is the ip4 loopback multiaddr
|
||||
IP4Loopback = ma.StringCast("/ip4/127.0.0.1")
|
||||
|
||||
// IP6Loopback is the ip6 loopback multiaddr
|
||||
IP6Loopback = ma.StringCast("/ip6/::1")
|
||||
|
||||
// IP6LinkLocalLoopback is the ip6 link-local loopback multiaddr
|
||||
IP6LinkLocalLoopback = ma.StringCast("/ip6/fe80::1")
|
||||
)
|
||||
|
||||
// Unspecified Addresses (used for )
|
||||
var (
|
||||
IP4Unspecified = ma.StringCast("/ip4/0.0.0.0")
|
||||
IP6Unspecified = ma.StringCast("/ip6/::")
|
||||
)
|
||||
|
||||
// IsThinWaist returns whether a Multiaddr starts with "Thin Waist" Protocols.
|
||||
// This means: /{IP4, IP6}[/{TCP, UDP}]
|
||||
func IsThinWaist(m ma.Multiaddr) bool {
|
||||
p := m.Protocols()
|
||||
|
||||
// nothing? not even a waist.
|
||||
if len(p) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
if p[0].Code != ma.P_IP4 && p[0].Code != ma.P_IP6 {
|
||||
return false
|
||||
}
|
||||
|
||||
// only IP? still counts.
|
||||
if len(p) == 1 {
|
||||
return true
|
||||
}
|
||||
|
||||
switch p[1].Code {
|
||||
case ma.P_TCP, ma.P_UDP, ma.P_IP4, ma.P_IP6:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// IsIPLoopback returns whether a Multiaddr is a "Loopback" IP address
|
||||
// This means either /ip4/127.0.0.1 or /ip6/::1
|
||||
// TODO: differentiate IsIPLoopback and OverIPLoopback
|
||||
func IsIPLoopback(m ma.Multiaddr) bool {
|
||||
b := m.Bytes()
|
||||
|
||||
// /ip4/127 prefix (_entire_ /8 is loopback...)
|
||||
if bytes.HasPrefix(b, []byte{ma.P_IP4, 127}) {
|
||||
return true
|
||||
}
|
||||
|
||||
// /ip6/::1
|
||||
if IP6Loopback.Equal(m) || IP6LinkLocalLoopback.Equal(m) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// IP6 Link Local addresses are non routable. The prefix is technically
|
||||
// fe80::/10, but we test fe80::/16 for simplicity (no need to mask).
|
||||
// So far, no hardware interfaces exist long enough to use those 2 bits.
|
||||
// Send a PR if there is.
|
||||
func IsIP6LinkLocal(m ma.Multiaddr) bool {
|
||||
return bytes.HasPrefix(m.Bytes(), []byte{ma.P_IP6, 0xfe, 0x80})
|
||||
}
|
||||
|
||||
// IsIPUnspecified returns whether a Multiaddr is am Unspecified IP address
|
||||
// This means either /ip4/0.0.0.0 or /ip6/::
|
||||
func IsIPUnspecified(m ma.Multiaddr) bool {
|
||||
return IP4Unspecified.Equal(m) || IP6Unspecified.Equal(m)
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
multiaddr
|
|
@ -1,96 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
manet "gx/QmNT7d1e4Xcp3KcsvxyzUHVtqrR43uypoxLLzdKj6YZga2/go-multiaddr-net"
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
)
|
||||
|
||||
// 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)
|
||||
}
|
|
@ -1,298 +0,0 @@
|
|||
package manet
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
mautp "gx/QmNT7d1e4Xcp3KcsvxyzUHVtqrR43uypoxLLzdKj6YZga2/go-multiaddr-net/utp"
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
)
|
||||
|
||||
// Conn is the equivalent of a net.Conn object. It is the
|
||||
// result of calling the Dial or Listen functions in this
|
||||
// package, with associated local and remote Multiaddrs.
|
||||
type Conn interface {
|
||||
net.Conn
|
||||
|
||||
// LocalMultiaddr returns the local Multiaddr associated
|
||||
// with this connection
|
||||
LocalMultiaddr() ma.Multiaddr
|
||||
|
||||
// RemoteMultiaddr returns the remote Multiaddr associated
|
||||
// with this connection
|
||||
RemoteMultiaddr() ma.Multiaddr
|
||||
}
|
||||
|
||||
// WrapNetConn wraps a net.Conn object with a Multiaddr
|
||||
// friendly Conn.
|
||||
func WrapNetConn(nconn net.Conn) (Conn, error) {
|
||||
if nconn == nil {
|
||||
return nil, fmt.Errorf("failed to convert nconn.LocalAddr: nil")
|
||||
}
|
||||
|
||||
laddr, err := FromNetAddr(nconn.LocalAddr())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to convert nconn.LocalAddr: %s", err)
|
||||
}
|
||||
|
||||
raddr, err := FromNetAddr(nconn.RemoteAddr())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to convert nconn.RemoteAddr: %s", err)
|
||||
}
|
||||
|
||||
return &maConn{
|
||||
Conn: nconn,
|
||||
laddr: laddr,
|
||||
raddr: raddr,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// maConn implements the Conn interface. It's a thin wrapper
|
||||
// around a net.Conn
|
||||
type maConn struct {
|
||||
net.Conn
|
||||
laddr ma.Multiaddr
|
||||
raddr ma.Multiaddr
|
||||
}
|
||||
|
||||
// LocalMultiaddr returns the local address associated with
|
||||
// this connection
|
||||
func (c *maConn) LocalMultiaddr() ma.Multiaddr {
|
||||
return c.laddr
|
||||
}
|
||||
|
||||
// RemoteMultiaddr returns the remote address associated with
|
||||
// this connection
|
||||
func (c *maConn) RemoteMultiaddr() ma.Multiaddr {
|
||||
return c.raddr
|
||||
}
|
||||
|
||||
// Dialer contains options for connecting to an address. It
|
||||
// is effectively the same as net.Dialer, but its LocalAddr
|
||||
// and RemoteAddr options are Multiaddrs, instead of net.Addrs.
|
||||
type Dialer struct {
|
||||
|
||||
// Dialer is just an embedded net.Dialer, with all its options.
|
||||
net.Dialer
|
||||
|
||||
// LocalAddr is the local address to use when dialing an
|
||||
// address. The address must be of a compatible type for the
|
||||
// network being dialed.
|
||||
// If nil, a local address is automatically chosen.
|
||||
LocalAddr ma.Multiaddr
|
||||
}
|
||||
|
||||
// Dial connects to a remote address, using the options of the
|
||||
// Dialer. Dialer uses an underlying net.Dialer to Dial a
|
||||
// net.Conn, then wraps that in a Conn object (with local and
|
||||
// remote Multiaddrs).
|
||||
func (d *Dialer) Dial(remote ma.Multiaddr) (Conn, error) {
|
||||
|
||||
// if a LocalAddr is specified, use it on the embedded dialer.
|
||||
if d.LocalAddr != nil {
|
||||
// convert our multiaddr to net.Addr friendly
|
||||
naddr, err := ToNetAddr(d.LocalAddr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// set the dialer's LocalAddr as naddr
|
||||
d.Dialer.LocalAddr = naddr
|
||||
}
|
||||
|
||||
// get the net.Dial friendly arguments from the remote addr
|
||||
rnet, rnaddr, err := DialArgs(remote)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// ok, Dial!
|
||||
var nconn net.Conn
|
||||
switch rnet {
|
||||
case "tcp", "tcp4", "tcp6", "udp", "udp4", "udp6":
|
||||
nconn, err = d.Dialer.Dial(rnet, rnaddr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case "utp", "utp4", "utp6":
|
||||
utpd := mautp.Dialer{
|
||||
Timeout: d.Timeout,
|
||||
LocalAddr: d.Dialer.LocalAddr,
|
||||
}
|
||||
// construct utp dialer, with options on our net.Dialer
|
||||
nconn, err = utpd.Dial(rnet, rnaddr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// get local address (pre-specified or assigned within net.Conn)
|
||||
local := d.LocalAddr
|
||||
if local == nil {
|
||||
local, err = FromNetAddr(nconn.LocalAddr())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return &maConn{
|
||||
Conn: nconn,
|
||||
laddr: local,
|
||||
raddr: remote,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Dial connects to a remote address. It uses an underlying net.Conn,
|
||||
// then wraps it in a Conn object (with local and remote Multiaddrs).
|
||||
func Dial(remote ma.Multiaddr) (Conn, error) {
|
||||
return (&Dialer{}).Dial(remote)
|
||||
}
|
||||
|
||||
// A Listener is a generic network listener for stream-oriented protocols.
|
||||
// it uses an embedded net.Listener, overriding net.Listener.Accept to
|
||||
// return a Conn and providing Multiaddr.
|
||||
type Listener interface {
|
||||
|
||||
// NetListener returns the embedded net.Listener. Use with caution.
|
||||
NetListener() net.Listener
|
||||
|
||||
// Accept waits for and returns the next connection to the listener.
|
||||
// Returns a Multiaddr friendly Conn
|
||||
Accept() (Conn, error)
|
||||
|
||||
// Close closes the listener.
|
||||
// Any blocked Accept operations will be unblocked and return errors.
|
||||
Close() error
|
||||
|
||||
// Multiaddr returns the listener's (local) Multiaddr.
|
||||
Multiaddr() ma.Multiaddr
|
||||
|
||||
// Addr returns the net.Listener's network address.
|
||||
Addr() net.Addr
|
||||
}
|
||||
|
||||
// maListener implements Listener
|
||||
type maListener struct {
|
||||
net.Listener
|
||||
laddr ma.Multiaddr
|
||||
}
|
||||
|
||||
// NetListener returns the embedded net.Listener. Use with caution.
|
||||
func (l *maListener) NetListener() net.Listener {
|
||||
return l.Listener
|
||||
}
|
||||
|
||||
// Accept waits for and returns the next connection to the listener.
|
||||
// Returns a Multiaddr friendly Conn
|
||||
func (l *maListener) Accept() (Conn, error) {
|
||||
nconn, err := l.Listener.Accept()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
raddr, err := FromNetAddr(nconn.RemoteAddr())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to convert connn.RemoteAddr: %s", err)
|
||||
}
|
||||
|
||||
return &maConn{
|
||||
Conn: nconn,
|
||||
laddr: l.laddr,
|
||||
raddr: raddr,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Multiaddr returns the listener's (local) Multiaddr.
|
||||
func (l *maListener) Multiaddr() ma.Multiaddr {
|
||||
return l.laddr
|
||||
}
|
||||
|
||||
// Addr returns the listener's network address.
|
||||
func (l *maListener) Addr() net.Addr {
|
||||
return l.Listener.Addr()
|
||||
}
|
||||
|
||||
// Listen announces on the local network address laddr.
|
||||
// The Multiaddr must be a "ThinWaist" stream-oriented network:
|
||||
// ip4/tcp, ip6/tcp, (TODO: unix, unixpacket)
|
||||
// See Dial for the syntax of laddr.
|
||||
func Listen(laddr ma.Multiaddr) (Listener, error) {
|
||||
|
||||
// get the net.Listen friendly arguments from the remote addr
|
||||
lnet, lnaddr, err := DialArgs(laddr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var nl net.Listener
|
||||
switch lnet {
|
||||
case "utp", "utp4", "utp6":
|
||||
nl, err = mautp.Listen(lnet, lnaddr)
|
||||
default:
|
||||
nl, err = net.Listen(lnet, lnaddr)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// we want to fetch the new multiaddr from the listener, as it may
|
||||
// have resolved to some other value. WrapNetListener does it for us.
|
||||
return WrapNetListener(nl)
|
||||
}
|
||||
|
||||
// WrapNetListener wraps a net.Listener with a manet.Listener.
|
||||
func WrapNetListener(nl net.Listener) (Listener, error) {
|
||||
laddr, err := FromNetAddr(nl.Addr())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &maListener{
|
||||
Listener: nl,
|
||||
laddr: laddr,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// InterfaceMultiaddrs will return the addresses matching net.InterfaceAddrs
|
||||
func InterfaceMultiaddrs() ([]ma.Multiaddr, error) {
|
||||
addrs, err := net.InterfaceAddrs()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
maddrs := make([]ma.Multiaddr, len(addrs))
|
||||
for i, a := range addrs {
|
||||
maddrs[i], err = FromNetAddr(a)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return maddrs, nil
|
||||
}
|
||||
|
||||
// AddrMatch returns the Multiaddrs that match the protocol stack on addr
|
||||
func AddrMatch(match ma.Multiaddr, addrs []ma.Multiaddr) []ma.Multiaddr {
|
||||
|
||||
// we should match transports entirely.
|
||||
p1s := match.Protocols()
|
||||
|
||||
out := make([]ma.Multiaddr, 0, len(addrs))
|
||||
for _, a := range addrs {
|
||||
p2s := a.Protocols()
|
||||
if len(p1s) != len(p2s) {
|
||||
continue
|
||||
}
|
||||
|
||||
match := true
|
||||
for i, p2 := range p2s {
|
||||
if p1s[i].Code != p2.Code {
|
||||
match = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if match {
|
||||
out = append(out, a)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
|
@ -1,507 +0,0 @@
|
|||
package manet
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
ma "gx/QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj/go-multiaddr"
|
||||
)
|
||||
|
||||
func newMultiaddr(t *testing.T, m string) ma.Multiaddr {
|
||||
maddr, err := ma.NewMultiaddr(m)
|
||||
if err != nil {
|
||||
t.Fatal("failed to construct multiaddr:", m, err)
|
||||
}
|
||||
return maddr
|
||||
}
|
||||
|
||||
func TestDial(t *testing.T) {
|
||||
|
||||
listener, err := net.Listen("tcp", "127.0.0.1:4321")
|
||||
if err != nil {
|
||||
t.Fatal("failed to listen")
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
|
||||
cB, err := listener.Accept()
|
||||
if err != nil {
|
||||
t.Fatal("failed to accept")
|
||||
}
|
||||
|
||||
// echo out
|
||||
buf := make([]byte, 1024)
|
||||
for {
|
||||
_, err := cB.Read(buf)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
cB.Write(buf)
|
||||
}
|
||||
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
maddr := newMultiaddr(t, "/ip4/127.0.0.1/tcp/4321")
|
||||
cA, err := Dial(maddr)
|
||||
if err != nil {
|
||||
t.Fatal("failed to dial")
|
||||
}
|
||||
|
||||
buf := make([]byte, 1024)
|
||||
if _, err := cA.Write([]byte("beep boop")); err != nil {
|
||||
t.Fatal("failed to write:", err)
|
||||
}
|
||||
|
||||
if _, err := cA.Read(buf); err != nil {
|
||||
t.Fatal("failed to read:", buf, err)
|
||||
}
|
||||
|
||||
if !bytes.Equal(buf[:9], []byte("beep boop")) {
|
||||
t.Fatal("failed to echo:", buf)
|
||||
}
|
||||
|
||||
maddr2 := cA.RemoteMultiaddr()
|
||||
if !maddr2.Equal(maddr) {
|
||||
t.Fatal("remote multiaddr not equal:", maddr, maddr2)
|
||||
}
|
||||
|
||||
cA.Close()
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func TestListen(t *testing.T) {
|
||||
|
||||
maddr := newMultiaddr(t, "/ip4/127.0.0.1/tcp/4322")
|
||||
listener, err := Listen(maddr)
|
||||
if err != nil {
|
||||
t.Fatal("failed to listen")
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
|
||||
cB, err := listener.Accept()
|
||||
if err != nil {
|
||||
t.Fatal("failed to accept")
|
||||
}
|
||||
|
||||
if !cB.LocalMultiaddr().Equal(maddr) {
|
||||
t.Fatal("local multiaddr not equal:", maddr, cB.LocalMultiaddr())
|
||||
}
|
||||
|
||||
// echo out
|
||||
buf := make([]byte, 1024)
|
||||
for {
|
||||
_, err := cB.Read(buf)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
cB.Write(buf)
|
||||
}
|
||||
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
cA, err := net.Dial("tcp", "127.0.0.1:4322")
|
||||
if err != nil {
|
||||
t.Fatal("failed to dial")
|
||||
}
|
||||
|
||||
buf := make([]byte, 1024)
|
||||
if _, err := cA.Write([]byte("beep boop")); err != nil {
|
||||
t.Fatal("failed to write:", err)
|
||||
}
|
||||
|
||||
if _, err := cA.Read(buf); err != nil {
|
||||
t.Fatal("failed to read:", buf, err)
|
||||
}
|
||||
|
||||
if !bytes.Equal(buf[:9], []byte("beep boop")) {
|
||||
t.Fatal("failed to echo:", buf)
|
||||
}
|
||||
|
||||
maddr2, err := FromNetAddr(cA.RemoteAddr())
|
||||
if err != nil {
|
||||
t.Fatal("failed to convert", err)
|
||||
}
|
||||
if !maddr2.Equal(maddr) {
|
||||
t.Fatal("remote multiaddr not equal:", maddr, maddr2)
|
||||
}
|
||||
|
||||
cA.Close()
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func TestListenAddrs(t *testing.T) {
|
||||
|
||||
test := func(addr, resaddr string, succeed bool) {
|
||||
if resaddr == "" {
|
||||
resaddr = addr
|
||||
}
|
||||
|
||||
maddr := newMultiaddr(t, addr)
|
||||
l, err := Listen(maddr)
|
||||
if !succeed {
|
||||
if err == nil {
|
||||
t.Fatal("succeeded in listening", addr)
|
||||
}
|
||||
return
|
||||
}
|
||||
if succeed && err != nil {
|
||||
t.Error("failed to listen", addr, err)
|
||||
}
|
||||
if l == nil {
|
||||
t.Error("failed to listen", addr, succeed, err)
|
||||
}
|
||||
if l.Multiaddr().String() != resaddr {
|
||||
t.Error("listen addr did not resolve properly", l.Multiaddr().String(), resaddr, succeed, err)
|
||||
}
|
||||
|
||||
if err = l.Close(); err != nil {
|
||||
t.Fatal("failed to close listener", addr, err)
|
||||
}
|
||||
}
|
||||
|
||||
test("/ip4/127.0.0.1/tcp/4324", "", true)
|
||||
test("/ip4/127.0.0.1/udp/4325", "", false)
|
||||
test("/ip4/127.0.0.1/udp/4326/udt", "", false)
|
||||
test("/ip4/0.0.0.0/tcp/4324", "", true)
|
||||
test("/ip4/0.0.0.0/udp/4325", "", false)
|
||||
test("/ip4/0.0.0.0/udp/4326/udt", "", false)
|
||||
test("/ip6/::1/tcp/4324", "", true)
|
||||
test("/ip6/::1/udp/4325", "", false)
|
||||
test("/ip6/::1/udp/4326/udt", "", false)
|
||||
test("/ip6/::/tcp/4324", "", true)
|
||||
test("/ip6/::/udp/4325", "", false)
|
||||
test("/ip6/::/udp/4326/udt", "", false)
|
||||
// test("/ip4/127.0.0.1/udp/4326/utp", true)
|
||||
}
|
||||
|
||||
func TestListenAndDial(t *testing.T) {
|
||||
|
||||
maddr := newMultiaddr(t, "/ip4/127.0.0.1/tcp/4323")
|
||||
listener, err := Listen(maddr)
|
||||
if err != nil {
|
||||
t.Fatal("failed to listen")
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
|
||||
cB, err := listener.Accept()
|
||||
if err != nil {
|
||||
t.Fatal("failed to accept")
|
||||
}
|
||||
|
||||
if !cB.LocalMultiaddr().Equal(maddr) {
|
||||
t.Fatal("local multiaddr not equal:", maddr, cB.LocalMultiaddr())
|
||||
}
|
||||
|
||||
// echo out
|
||||
buf := make([]byte, 1024)
|
||||
for {
|
||||
_, err := cB.Read(buf)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
cB.Write(buf)
|
||||
}
|
||||
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
cA, err := Dial(newMultiaddr(t, "/ip4/127.0.0.1/tcp/4323"))
|
||||
if err != nil {
|
||||
t.Fatal("failed to dial")
|
||||
}
|
||||
|
||||
buf := make([]byte, 1024)
|
||||
if _, err := cA.Write([]byte("beep boop")); err != nil {
|
||||
t.Fatal("failed to write:", err)
|
||||
}
|
||||
|
||||
if _, err := cA.Read(buf); err != nil {
|
||||
t.Fatal("failed to read:", buf, err)
|
||||
}
|
||||
|
||||
if !bytes.Equal(buf[:9], []byte("beep boop")) {
|
||||
t.Fatal("failed to echo:", buf)
|
||||
}
|
||||
|
||||
maddr2 := cA.RemoteMultiaddr()
|
||||
if !maddr2.Equal(maddr) {
|
||||
t.Fatal("remote multiaddr not equal:", maddr, maddr2)
|
||||
}
|
||||
|
||||
cA.Close()
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func TestListenAndDialUTP(t *testing.T) {
|
||||
maddr := newMultiaddr(t, "/ip4/127.0.0.1/udp/4323/utp")
|
||||
listener, err := Listen(maddr)
|
||||
if err != nil {
|
||||
t.Fatal("failed to listen: ", err)
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
|
||||
cB, err := listener.Accept()
|
||||
if err != nil {
|
||||
t.Fatal("failed to accept")
|
||||
}
|
||||
|
||||
if !cB.LocalMultiaddr().Equal(maddr) {
|
||||
t.Fatal("local multiaddr not equal:", maddr, cB.LocalMultiaddr())
|
||||
}
|
||||
|
||||
defer cB.Close()
|
||||
|
||||
// echo out
|
||||
buf := make([]byte, 1024)
|
||||
for {
|
||||
_, err := cB.Read(buf)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
cB.Write(buf)
|
||||
}
|
||||
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
cA, err := Dial(newMultiaddr(t, "/ip4/127.0.0.1/udp/4323/utp"))
|
||||
if err != nil {
|
||||
t.Fatal("failed to dial", err)
|
||||
}
|
||||
|
||||
buf := make([]byte, 1024)
|
||||
if _, err := cA.Write([]byte("beep boop")); err != nil {
|
||||
t.Fatal("failed to write:", err)
|
||||
}
|
||||
|
||||
if _, err := cA.Read(buf); err != nil {
|
||||
t.Fatal("failed to read:", buf, err)
|
||||
}
|
||||
|
||||
if !bytes.Equal(buf[:9], []byte("beep boop")) {
|
||||
t.Fatal("failed to echo:", buf)
|
||||
}
|
||||
|
||||
maddr2 := cA.RemoteMultiaddr()
|
||||
if !maddr2.Equal(maddr) {
|
||||
t.Fatal("remote multiaddr not equal:", maddr, maddr2)
|
||||
}
|
||||
|
||||
cA.Close()
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func TestIPLoopback(t *testing.T) {
|
||||
if IP4Loopback.String() != "/ip4/127.0.0.1" {
|
||||
t.Error("IP4Loopback incorrect:", IP4Loopback)
|
||||
}
|
||||
|
||||
if IP6Loopback.String() != "/ip6/::1" {
|
||||
t.Error("IP6Loopback incorrect:", IP6Loopback)
|
||||
}
|
||||
|
||||
if IP6LinkLocalLoopback.String() != "/ip6/fe80::1" {
|
||||
t.Error("IP6LinkLocalLoopback incorrect:", IP6Loopback)
|
||||
}
|
||||
|
||||
if !IsIPLoopback(IP4Loopback) {
|
||||
t.Error("IsIPLoopback failed (IP4Loopback)")
|
||||
}
|
||||
|
||||
if !IsIPLoopback(IP6Loopback) {
|
||||
t.Error("IsIPLoopback failed (IP6Loopback)")
|
||||
}
|
||||
|
||||
if !IsIPLoopback(IP6LinkLocalLoopback) {
|
||||
t.Error("IsIPLoopback failed (IP6LinkLocalLoopback)")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIPUnspecified(t *testing.T) {
|
||||
if IP4Unspecified.String() != "/ip4/0.0.0.0" {
|
||||
t.Error("IP4Unspecified incorrect:", IP4Unspecified)
|
||||
}
|
||||
|
||||
if IP6Unspecified.String() != "/ip6/::" {
|
||||
t.Error("IP6Unspecified incorrect:", IP6Unspecified)
|
||||
}
|
||||
|
||||
if !IsIPUnspecified(IP4Unspecified) {
|
||||
t.Error("IsIPUnspecified failed (IP4Unspecified)")
|
||||
}
|
||||
|
||||
if !IsIPUnspecified(IP6Unspecified) {
|
||||
t.Error("IsIPUnspecified failed (IP6Unspecified)")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIP6LinkLocal(t *testing.T) {
|
||||
if !IsIP6LinkLocal(IP6LinkLocalLoopback) {
|
||||
t.Error("IsIP6LinkLocal failed (IP6LinkLocalLoopback)")
|
||||
}
|
||||
|
||||
for a := 0; a < 65536; a++ {
|
||||
isLinkLocal := (a == 0xfe80)
|
||||
m := newMultiaddr(t, fmt.Sprintf("/ip6/%x::1", a))
|
||||
if IsIP6LinkLocal(m) != isLinkLocal {
|
||||
t.Error("IsIP6LinkLocal failed (%s != %v)", m, isLinkLocal)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertNetAddr(t *testing.T) {
|
||||
m1 := newMultiaddr(t, "/ip4/1.2.3.4/tcp/4001")
|
||||
|
||||
n1, err := ToNetAddr(m1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
m2, err := FromNetAddr(n1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if m1.String() != m2.String() {
|
||||
t.Fatal("ToNetAddr + FromNetAddr did not work")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWrapNetConn(t *testing.T) {
|
||||
// test WrapNetConn nil
|
||||
if _, err := WrapNetConn(nil); err == nil {
|
||||
t.Error("WrapNetConn(nil) should return an error")
|
||||
}
|
||||
|
||||
checkErr := func(err error, s string) {
|
||||
if err != nil {
|
||||
t.Fatal(s, err)
|
||||
}
|
||||
}
|
||||
|
||||
listener, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
checkErr(err, "failed to listen")
|
||||
|
||||
var wg sync.WaitGroup
|
||||
defer wg.Wait()
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
cB, err := listener.Accept()
|
||||
checkErr(err, "failed to accept")
|
||||
cB.Close()
|
||||
}()
|
||||
|
||||
cA, err := net.Dial("tcp", listener.Addr().String())
|
||||
checkErr(err, "failed to dial")
|
||||
defer cA.Close()
|
||||
|
||||
lmaddr, err := FromNetAddr(cA.LocalAddr())
|
||||
checkErr(err, "failed to get local addr")
|
||||
rmaddr, err := FromNetAddr(cA.RemoteAddr())
|
||||
checkErr(err, "failed to get remote addr")
|
||||
|
||||
mcA, err := WrapNetConn(cA)
|
||||
checkErr(err, "failed to wrap conn")
|
||||
|
||||
if mcA.LocalAddr().String() != cA.LocalAddr().String() {
|
||||
t.Error("wrapped conn local addr differs")
|
||||
}
|
||||
if mcA.RemoteAddr().String() != cA.RemoteAddr().String() {
|
||||
t.Error("wrapped conn remote addr differs")
|
||||
}
|
||||
if mcA.LocalMultiaddr().String() != lmaddr.String() {
|
||||
t.Error("wrapped conn local maddr differs")
|
||||
}
|
||||
if mcA.RemoteMultiaddr().String() != rmaddr.String() {
|
||||
t.Error("wrapped conn remote maddr differs")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddrMatch(t *testing.T) {
|
||||
|
||||
test := func(m ma.Multiaddr, input, expect []ma.Multiaddr) {
|
||||
actual := AddrMatch(m, input)
|
||||
testSliceEqual(t, expect, actual)
|
||||
}
|
||||
|
||||
a := []ma.Multiaddr{
|
||||
newMultiaddr(t, "/ip4/1.2.3.4/tcp/1234"),
|
||||
newMultiaddr(t, "/ip4/1.2.3.4/tcp/2345"),
|
||||
newMultiaddr(t, "/ip4/1.2.3.4/tcp/1234/tcp/2345"),
|
||||
newMultiaddr(t, "/ip4/1.2.3.4/tcp/1234/tcp/2345"),
|
||||
newMultiaddr(t, "/ip4/1.2.3.4/tcp/1234/udp/1234"),
|
||||
newMultiaddr(t, "/ip4/1.2.3.4/tcp/1234/udp/1234"),
|
||||
newMultiaddr(t, "/ip4/1.2.3.4/tcp/1234/ip6/::1"),
|
||||
newMultiaddr(t, "/ip4/1.2.3.4/tcp/1234/ip6/::1"),
|
||||
newMultiaddr(t, "/ip6/::1/tcp/1234"),
|
||||
newMultiaddr(t, "/ip6/::1/tcp/2345"),
|
||||
newMultiaddr(t, "/ip6/::1/tcp/1234/tcp/2345"),
|
||||
newMultiaddr(t, "/ip6/::1/tcp/1234/tcp/2345"),
|
||||
newMultiaddr(t, "/ip6/::1/tcp/1234/udp/1234"),
|
||||
newMultiaddr(t, "/ip6/::1/tcp/1234/udp/1234"),
|
||||
newMultiaddr(t, "/ip6/::1/tcp/1234/ip6/::1"),
|
||||
newMultiaddr(t, "/ip6/::1/tcp/1234/ip6/::1"),
|
||||
}
|
||||
|
||||
test(a[0], a, []ma.Multiaddr{
|
||||
newMultiaddr(t, "/ip4/1.2.3.4/tcp/1234"),
|
||||
newMultiaddr(t, "/ip4/1.2.3.4/tcp/2345"),
|
||||
})
|
||||
test(a[2], a, []ma.Multiaddr{
|
||||
newMultiaddr(t, "/ip4/1.2.3.4/tcp/1234/tcp/2345"),
|
||||
newMultiaddr(t, "/ip4/1.2.3.4/tcp/1234/tcp/2345"),
|
||||
})
|
||||
test(a[4], a, []ma.Multiaddr{
|
||||
newMultiaddr(t, "/ip4/1.2.3.4/tcp/1234/udp/1234"),
|
||||
newMultiaddr(t, "/ip4/1.2.3.4/tcp/1234/udp/1234"),
|
||||
})
|
||||
test(a[6], a, []ma.Multiaddr{
|
||||
newMultiaddr(t, "/ip4/1.2.3.4/tcp/1234/ip6/::1"),
|
||||
newMultiaddr(t, "/ip4/1.2.3.4/tcp/1234/ip6/::1"),
|
||||
})
|
||||
test(a[8], a, []ma.Multiaddr{
|
||||
newMultiaddr(t, "/ip6/::1/tcp/1234"),
|
||||
newMultiaddr(t, "/ip6/::1/tcp/2345"),
|
||||
})
|
||||
test(a[10], a, []ma.Multiaddr{
|
||||
newMultiaddr(t, "/ip6/::1/tcp/1234/tcp/2345"),
|
||||
newMultiaddr(t, "/ip6/::1/tcp/1234/tcp/2345"),
|
||||
})
|
||||
test(a[12], a, []ma.Multiaddr{
|
||||
newMultiaddr(t, "/ip6/::1/tcp/1234/udp/1234"),
|
||||
newMultiaddr(t, "/ip6/::1/tcp/1234/udp/1234"),
|
||||
})
|
||||
test(a[14], a, []ma.Multiaddr{
|
||||
newMultiaddr(t, "/ip6/::1/tcp/1234/ip6/::1"),
|
||||
newMultiaddr(t, "/ip6/::1/tcp/1234/ip6/::1"),
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func testSliceEqual(t *testing.T, a, b []ma.Multiaddr) {
|
||||
if len(a) != len(b) {
|
||||
t.Error("differ", a, b)
|
||||
}
|
||||
for i, addrA := range a {
|
||||
if !addrA.Equal(b[i]) {
|
||||
t.Error("differ", a, b)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
{
|
||||
"name": "go-multiaddr-net",
|
||||
"author": "whyrusleeping",
|
||||
"version": "0.0.0",
|
||||
"gxDependencies": [
|
||||
{
|
||||
"name": "go-multiaddr",
|
||||
"hash": "QmVUi2ncqnU48zsPgR1rQosDGwY3SSZ1Ndp33j33YjXdsj",
|
||||
"version": "0.0.0"
|
||||
},
|
||||
{
|
||||
"name": "go-utp",
|
||||
"hash": "QmRTXGMiKMNuptgBt6vRhAsYEP8J982NN4cmNi23xwQ69m",
|
||||
"version": "0.0.0"
|
||||
}
|
||||
],
|
||||
"language": "go",
|
||||
"issues_url": "",
|
||||
"gx": {
|
||||
"dvcsimport": "github.com/jbenet/go-multiaddr-net"
|
||||
}
|
||||
}
|
|
@ -1,105 +0,0 @@
|
|||
package utp
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
utp "gx/QmRTXGMiKMNuptgBt6vRhAsYEP8J982NN4cmNi23xwQ69m/go-utp"
|
||||
)
|
||||
|
||||
type Listener struct {
|
||||
*utp.Socket
|
||||
}
|
||||
|
||||
type Conn struct {
|
||||
net.Conn
|
||||
}
|
||||
|
||||
type Addr struct {
|
||||
net string
|
||||
child net.Addr
|
||||
}
|
||||
|
||||
func (ca *Addr) Network() string {
|
||||
return ca.net
|
||||
}
|
||||
|
||||
func (ca *Addr) String() string {
|
||||
return ca.child.String()
|
||||
}
|
||||
|
||||
func (ca *Addr) Child() net.Addr {
|
||||
return ca.child
|
||||
}
|
||||
|
||||
func MakeAddr(a net.Addr) net.Addr {
|
||||
return &Addr{
|
||||
net: "utp",
|
||||
child: a,
|
||||
}
|
||||
}
|
||||
|
||||
func ResolveAddr(network string, host string) (net.Addr, error) {
|
||||
a, err := net.ResolveUDPAddr("udp"+network[3:], host)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return MakeAddr(a), nil
|
||||
}
|
||||
|
||||
func (u *Conn) LocalAddr() net.Addr {
|
||||
return MakeAddr(u.Conn.LocalAddr())
|
||||
}
|
||||
|
||||
func (u *Conn) RemoteAddr() net.Addr {
|
||||
return MakeAddr(u.Conn.RemoteAddr())
|
||||
}
|
||||
|
||||
func Listen(network string, laddr string) (net.Listener, error) {
|
||||
switch network {
|
||||
case "utp", "utp4", "utp6":
|
||||
s, err := utp.NewSocket("udp"+network[3:], laddr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Listener{s}, nil
|
||||
|
||||
default:
|
||||
return nil, errors.New("unrecognized network: " + network)
|
||||
}
|
||||
}
|
||||
|
||||
func (u *Listener) Accept() (net.Conn, error) {
|
||||
c, err := u.Socket.Accept()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Conn{c}, nil
|
||||
}
|
||||
|
||||
func (u *Listener) Addr() net.Addr {
|
||||
return MakeAddr(u.Socket.Addr())
|
||||
}
|
||||
|
||||
type Dialer struct {
|
||||
Timeout time.Duration
|
||||
LocalAddr net.Addr
|
||||
}
|
||||
|
||||
func (d *Dialer) Dial(rnet string, raddr string) (net.Conn, error) {
|
||||
if d.LocalAddr != nil {
|
||||
s, err := utp.NewSocket(d.LocalAddr.Network(), d.LocalAddr.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// zero timeout is the same as calling s.Dial()
|
||||
return s.DialTimeout(raddr, d.Timeout)
|
||||
}
|
||||
|
||||
return utp.DialTimeout(raddr, d.Timeout)
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
Copyright (c) 2013 Conformal Systems LLC.
|
||||
|
||||
Permission to use, copy, modify, and distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
@ -1,66 +0,0 @@
|
|||
# go-base58
|
||||
|
||||
I extracted this package from https://github.com/conformal/btcutil to provide a simple base58 package that
|
||||
- defaults to base58-check (btc)
|
||||
- and allows using different alphabets.
|
||||
|
||||
## Usage
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
b58 "github.com/jbenet/go-base58"
|
||||
)
|
||||
|
||||
func main() {
|
||||
buf := []byte{255, 254, 253, 252}
|
||||
fmt.Printf("buffer: %v\n", buf)
|
||||
|
||||
str := b58.Encode(buf)
|
||||
fmt.Printf("encoded: %s\n", str)
|
||||
|
||||
buf2 := b58.Decode(str)
|
||||
fmt.Printf("decoded: %v\n", buf2)
|
||||
}
|
||||
```
|
||||
|
||||
### Another alphabet
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
b58 "github.com/jbenet/go-base58"
|
||||
)
|
||||
|
||||
const BogusAlphabet = "ZYXWVUTSRQPNMLKJHGFEDCBAzyxwvutsrqponmkjihgfedcba987654321"
|
||||
|
||||
|
||||
func encdec(alphabet string) {
|
||||
fmt.Printf("using: %s\n", alphabet)
|
||||
|
||||
buf := []byte{255, 254, 253, 252}
|
||||
fmt.Printf("buffer: %v\n", buf)
|
||||
|
||||
str := b58.EncodeAlphabet(buf, alphabet)
|
||||
fmt.Printf("encoded: %s\n", str)
|
||||
|
||||
buf2 := b58.DecodeAlphabet(str, alphabet)
|
||||
fmt.Printf("decoded: %v\n\n", buf2)
|
||||
}
|
||||
|
||||
|
||||
func main() {
|
||||
encdec(b58.BTCAlphabet)
|
||||
encdec(b58.FlickrAlphabet)
|
||||
encdec(BogusAlphabet)
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## License
|
||||
|
||||
Package base58 (and the original btcutil) are licensed under the ISC License.
|
|
@ -1,90 +0,0 @@
|
|||
// Copyright (c) 2013-2014 Conformal Systems LLC.
|
||||
// Use of this source code is governed by an ISC
|
||||
// license that can be found in the LICENSE file.
|
||||
// Modified by Juan Benet (juan@benet.ai)
|
||||
|
||||
package base58
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// alphabet is the modified base58 alphabet used by Bitcoin.
|
||||
const BTCAlphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
||||
const FlickrAlphabet = "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
|
||||
|
||||
var bigRadix = big.NewInt(58)
|
||||
var bigZero = big.NewInt(0)
|
||||
|
||||
// Decode decodes a modified base58 string to a byte slice, using BTCAlphabet
|
||||
func Decode(b string) []byte {
|
||||
return DecodeAlphabet(b, BTCAlphabet)
|
||||
}
|
||||
|
||||
// Encode encodes a byte slice to a modified base58 string, using BTCAlphabet
|
||||
func Encode(b []byte) string {
|
||||
return EncodeAlphabet(b, BTCAlphabet)
|
||||
}
|
||||
|
||||
// DecodeAlphabet decodes a modified base58 string to a byte slice, using alphabet.
|
||||
func DecodeAlphabet(b, alphabet string) []byte {
|
||||
answer := big.NewInt(0)
|
||||
j := big.NewInt(1)
|
||||
|
||||
for i := len(b) - 1; i >= 0; i-- {
|
||||
tmp := strings.IndexAny(alphabet, string(b[i]))
|
||||
if tmp == -1 {
|
||||
return []byte("")
|
||||
}
|
||||
idx := big.NewInt(int64(tmp))
|
||||
tmp1 := big.NewInt(0)
|
||||
tmp1.Mul(j, idx)
|
||||
|
||||
answer.Add(answer, tmp1)
|
||||
j.Mul(j, bigRadix)
|
||||
}
|
||||
|
||||
tmpval := answer.Bytes()
|
||||
|
||||
var numZeros int
|
||||
for numZeros = 0; numZeros < len(b); numZeros++ {
|
||||
if b[numZeros] != alphabet[0] {
|
||||
break
|
||||
}
|
||||
}
|
||||
flen := numZeros + len(tmpval)
|
||||
val := make([]byte, flen, flen)
|
||||
copy(val[numZeros:], tmpval)
|
||||
|
||||
return val
|
||||
}
|
||||
|
||||
// Encode encodes a byte slice to a modified base58 string, using alphabet
|
||||
func EncodeAlphabet(b []byte, alphabet string) string {
|
||||
x := new(big.Int)
|
||||
x.SetBytes(b)
|
||||
|
||||
answer := make([]byte, 0, len(b)*136/100)
|
||||
for x.Cmp(bigZero) > 0 {
|
||||
mod := new(big.Int)
|
||||
x.DivMod(x, bigRadix, mod)
|
||||
answer = append(answer, alphabet[mod.Int64()])
|
||||
}
|
||||
|
||||
// leading zero bytes
|
||||
for _, i := range b {
|
||||
if i != 0 {
|
||||
break
|
||||
}
|
||||
answer = append(answer, alphabet[0])
|
||||
}
|
||||
|
||||
// reverse
|
||||
alen := len(answer)
|
||||
for i := 0; i < alen/2; i++ {
|
||||
answer[i], answer[alen-1-i] = answer[alen-1-i], answer[i]
|
||||
}
|
||||
|
||||
return string(answer)
|
||||
}
|
|
@ -1,130 +0,0 @@
|
|||
// Copyright (c) 2013-2014 Conformal Systems LLC.
|
||||
// Use of this source code is governed by an ISC
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package base58
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var stringTests = []struct {
|
||||
in string
|
||||
out string
|
||||
}{
|
||||
{"", ""},
|
||||
{" ", "Z"},
|
||||
{"-", "n"},
|
||||
{"0", "q"},
|
||||
{"1", "r"},
|
||||
{"-1", "4SU"},
|
||||
{"11", "4k8"},
|
||||
{"abc", "ZiCa"},
|
||||
{"1234598760", "3mJr7AoUXx2Wqd"},
|
||||
{"abcdefghijklmnopqrstuvwxyz", "3yxU3u1igY8WkgtjK92fbJQCd4BZiiT1v25f"},
|
||||
{"00000000000000000000000000000000000000000000000000000000000000", "3sN2THZeE9Eh9eYrwkvZqNstbHGvrxSAM7gXUXvyFQP8XvQLUqNCS27icwUeDT7ckHm4FUHM2mTVh1vbLmk7y"},
|
||||
}
|
||||
|
||||
var invalidStringTests = []struct {
|
||||
in string
|
||||
out string
|
||||
}{
|
||||
{"0", ""},
|
||||
{"O", ""},
|
||||
{"I", ""},
|
||||
{"l", ""},
|
||||
{"3mJr0", ""},
|
||||
{"O3yxU", ""},
|
||||
{"3sNI", ""},
|
||||
{"4kl8", ""},
|
||||
{"0OIl", ""},
|
||||
{"!@#$%^&*()-_=+~`", ""},
|
||||
}
|
||||
|
||||
var hexTests = []struct {
|
||||
in string
|
||||
out string
|
||||
}{
|
||||
{"61", "2g"},
|
||||
{"626262", "a3gV"},
|
||||
{"636363", "aPEr"},
|
||||
{"73696d706c792061206c6f6e6720737472696e67", "2cFupjhnEsSn59qHXstmK2ffpLv2"},
|
||||
{"00eb15231dfceb60925886b67d065299925915aeb172c06647", "1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L"},
|
||||
{"516b6fcd0f", "ABnLTmg"},
|
||||
{"bf4f89001e670274dd", "3SEo3LWLoPntC"},
|
||||
{"572e4794", "3EFU7m"},
|
||||
{"ecac89cad93923c02321", "EJDM8drfXA6uyA"},
|
||||
{"10c8511e", "Rt5zm"},
|
||||
{"00000000000000000000", "1111111111"},
|
||||
}
|
||||
|
||||
func TestBase58(t *testing.T) {
|
||||
// Base58Encode tests
|
||||
for x, test := range stringTests {
|
||||
tmp := []byte(test.in)
|
||||
if res := Encode(tmp); res != test.out {
|
||||
t.Errorf("Base58Encode test #%d failed: got: %s want: %s",
|
||||
x, res, test.out)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// Base58Decode tests
|
||||
for x, test := range hexTests {
|
||||
b, err := hex.DecodeString(test.in)
|
||||
if err != nil {
|
||||
t.Errorf("hex.DecodeString failed failed #%d: got: %s", x, test.in)
|
||||
continue
|
||||
}
|
||||
if res := Decode(test.out); bytes.Equal(res, b) != true {
|
||||
t.Errorf("Base58Decode test #%d failed: got: %q want: %q",
|
||||
x, res, test.in)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// Base58Decode with invalid input
|
||||
for x, test := range invalidStringTests {
|
||||
if res := Decode(test.in); string(res) != test.out {
|
||||
t.Errorf("Base58Decode invalidString test #%d failed: got: %q want: %q",
|
||||
x, res, test.out)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkDecodeShort(b *testing.B) {
|
||||
const in = "1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L"
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = Decode(in)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkEncodeShort(b *testing.B) {
|
||||
var in = []byte("00eb15231dfceb60925886b67d065299925915aeb172c06647")
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = Encode(in)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkDecodeOneKilo(b *testing.B) {
|
||||
const in = "3GimCffBLAHhXMCeNxX2nST6dBem9pbUi3KVKykW73LmewcFtMk9oh9eNPdNR2eSzNqp7Z3E21vrWUkGHzJ7w2yqDUDJ4LKo1w5D6aafZ4SUoNQyrSVxyVG3pwgoZkKXMZVixRyiPZVUpekrsTvZuUoW7mB6BQgDTXbDuMMSRoNR7yiUTKpgwTD61DLmhNZopNxfFjn4avpYPgzsTB94iWueq1yU3EoruWCUMvp6fc1CEbDrZY3pkx9oUbUaSMC37rruBKSSGHh1ZE3XK3kQXBCFraMmUQf8dagofMEg5aTnDiLAZjLyWJMdnQwW1FqKKztP8KAQS2JX8GCCfc68KB4VGf2CfEGXtaapnsNWFrHuWi7Wo5vqyuHd21zGm1u5rsiR6tKNCsFC4nzf3WUNxJNoZrDSdF9KERqhTWWmmcM4qdKRCtBWKTrs1DJD2oiK6BK9BgwoW2dfQdKuxojFyFvmxqPKDDAEZPPpJ51wHoFzBFMM1tUBBkN15cT2GpNwKzDcjHPKJAQ6FNRgppfQytzqpq76sSeZaWAB8hhULMJCQGU57ZUjvP7xYAQwtACBnYrjdxA91XwXFbq5AsQJwAmLw6euKVWNyv11BuHrejVmnNViWg5kuZBrtgL6NtzRWHtdxngHDMtuyky3brqGXaGQhUyXrkSpeknkkHL6NLThHH5NPnfFMVPwn2xf5UM5R51X2nTBzADSVcpi4cT7i44dT7o3yRKWtKfUzZiuNyTcSSrfH8KVdLap5ZKLmdPuXM65M2Z5wJVh3Uc4iv6iZKk44RKikM7zs1hqC4sBxRwLZjxhKvvMXDjDcYFkzyUkues4y7fjdCnVTxc4vTYUqcbY2k2WMssyj9SDseVc7dVrEvWCLQtYy79mJFoz1Hmsfk5ynE28ipznzQ3yTBugLHA6j6qW3S74eY4pJ6iynFEuXT4RqqkLGFcMh3goqS7CkphUMzP4wuJyGnzqa5tCno4U3dJ2jUL7Povg8voRqYAfiHyXC8zuhn225EdmRcSnu2pAuutQVV9hN3bkjfzAFUhUWKki8SwXtFSjy6NJyrYUiaze4p7ApsjHQBCgg2zAoBaGCwVN8991Jny31B5vPyYHy1oRSE4xTVZ7tTw9FyQ7w9p1NSEF4sziCxZHh5rFWZKAajc5c7KaMNDvHPNV6S62MTFGTyuKPQNbv9yHRGN4eH6SnZGW6snvEVdYCspWZ1U3Nbxo6vCmBK95UyYpcxHgg1CCGdU4s3edju2NDQkMifyPkJdkabzzHVDhJJbChAJc1ACQfNW74VXXwrBZmeZyA2R28MBctDyXuSuffiwueys2LVowLu9wiTHUox7KQjtHK2c9howk9czzx2mpnYzkVYH42CYsWa5514EM4CJEXPJSSbXSgJJ"
|
||||
b.SetBytes(int64(len(in))) // 1024
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = Decode(in)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkEncodeOneKilo(b *testing.B) {
|
||||
var in = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\x00\x00\x04\xff\xfb\x63\xc9\x7e\x5f\x97\x68\xe5\x10\x08\xe5\xa5\x9a\x7c\x24\x75\x35\xbe\xaf\x37\x0b\xc3\xf4\x18\x62\x4a\xb7\x18\xd0\x10\x0b\x6b\x62\xe1\x36\x0f\x62\xa6\xeb\x78\xa5\xf3\x33\x52\xbc\xdf\x04\xcb\x37\xcf\x3d\x97\x5c\xb8\x75\x09\x1f\x18\x9f\xfc\xa9\xda\x1e\x59\x77\x09\x9c\x5d\xb6\xf2\x9e\x45\xb7\x5e\x5d\x11\xf1\x20\x14\x85\xf8\x54\x87\x8c\x1e\x2c\x2e\x15\x57\x89\xe7\x5d\x49\xb6\xae\x24\x3a\x20\x50\x0e\xa7\x5b\x10\xbf\x0a\xb4\x01\x42\xed\xce\x2d\x45\x21\xb6\xe8\x64\x73\x4e\x7e\x0a\x36\x1d\x57\x0a\x5e\x1c\x21\xc2\xb8\xe7\x89\x82\xe4\x04\x7e\x50\xff\xda\x4f\xfe\x11\x95\xfb\x35\xf9\x6d\x32\xce\xef\x8f\x3d\x1b\xdb\x38\xfa\xcd\x26\x36\x12\x93\xa0\x96\xea\x42\xbe\xd6\x85\x86\xc1\xc1\xe2\x55\x41\xd1\x7f\x8d\x0e\x00\x81\x58\xb4\x10\xbb\x64\x92\x05\x07\xa9\xd5\xd9\x40\x28\x8b\x9b\x4c\x8d\x8e\x4e\x69\xf9\xc9\x35\xea\xda\x2f\x61\x87\x35\x2d\x6b\x25\x32\xf0\x7e\x89\x1a\xcb\xc0\xea\x66\x88\x99\x39\xe0\x3b\x24\x3b\x05\x74\xd3\x72\xf6\x48\x15\xdc\x02\x0a\xbf\xc8\x49\x42\x10\x22\xeb\xe9\x44\x71\x55\xaf\x67\x67\xe6\x2a\x40\x31\x81\xb9\x6f\x65\x86\x0f\x0f\x9d\x58\x4c\x51\xc1\x2e\x4e\x60\x7e\xe8\x93\x39\x90\xda\xe5\xbe\xec\xe4\xdd\xbc\x1d\xba\x40\xa6\x85\xd9\xb2\xec\xb4\x26\x74\xee\xc1\xec\xe3\x40\xb9\x49\xa3\xe1\x26\x76\x8a\xeb\x95\xc8\x72\xb0\x85\x36\x19\x3f\x55\x06\x7b\xcd\x3e\xd0\xdf\x7e\x8d\x2a\xea\xa6\x24\xc6\xf6\xfb\xda\xe0\x45\xcf\x32\x0e\xbc\xf4\x41\x7d\x71\x3d\x86\xf9\xb4\xaf\x07\xa0\xd1\x34\x8a\x02\x28\x56\xd4\xcc\x36\x44\x98\x44\xcb\x9d\xc5\xfc\x45\x2d\xc4\x5c\xfe\xce\xaa\x44\xda\x66\x52\x2d\x32\x6e\x13\x32\xac\xaf\x13\x72\x87\x79\xd2\x92\x54\x9f\xc7\xb9\xf3\x21\xae\xdd\x69\x44\xe9\x46\x94\x1c\x62\x84\x03\xe0\xbf\x66\xfb\xe0\x79\xf9\x57\x9e\x22\x9e\x23\x2d\x2a\x73\xeb\x74\x38\xf0\xea\x5d\xb3\x8f\x87\x26\x3e\x3c\x54\x11\xb7\x98\xbd\x7f\x78\x64\xa3\xf1\x8f\xa9\x5e\x4f\x18\x3f\xa7\x1f\x3a\x29\x27\x27\xb7\x49\x40\x16\x18\x1f\xd3\xed\x86\x61\xbd\xc3\x4e\x4a\x53\x37\x78\x5c\x00\xd3\x50\x45\x1c\x55\xc0\x9b\xd7\x62\x29\x88\x2e\xa4\x0d\x6a\x15\x6c\x33\x3c\xe7\x31\xfa\xc1\xaf\xdf\x7a\x3e\x37\x3e\xe5\xbc\xfd\xfb\x9b\x72\x10\x35\x90\x25\x6e\x87\x0d\x74\x1c\xfd\xe3\x0b\xee\xf5\x92\x28\x8d\x22\x8a\x49\x7b\xcd\xbb\xd8\x24\x6b\x5e\x58\x40\xec\x1b\x6c\xed\x8e\xcb\x56\x62\xa6\xb4\x42\x3d\x7d\xa2\xef\x27\x27\x46\x50\xbc\x5e\x37\x9b\x27\x72\xf0\xea\xa7\xe7\x4d\xf4\xae\x7e\x95\x8f\x91\x2e\x58\xc4\x6a\x06\xda\x7a\x06\x5c\x8d\xfe\xef\xf5\xb3\x0f\xb4\x0a\x20\x53\xd8\x35\x80\x02\xca\x97\x81\xb6\x1c\x4b\x8f\xb7\xee\xd0\xc3\x88\x6c\x76\x3e\xb0\x28\xce\xa1\x9f\x76\x5f\xaa\xc3\x53\x44\x09\x70\xa3\x95\xd9\x8c\x54\xba\x8a\x9a\x6b\xce\xc3\x07\xdf\x13\x6d\xea\x0f\x51\x9c\xe2\x81\x87\xf6\x82\x7a\x70\xd8\xfa\xe2\xa8\x32\xc1\x5e\x53\xc2\x85\xe9\x61\x8a\x17\x82\x12\xab\x92\x79\x2b\xed\x07\xca\x1e\x93\x23\x9c\x4b\xd2\x89\x86\xac\x55\xf9\x50\x23\x8f\x9e\xd3\xab\x22\x57\x91\x5a\x0b\x48\xd7\xa2\xb8\x06\xbb\x74\xae\xe9\xca\x06\x41\x8d\x6a\x00\x42\xc4\x40\xa9\xfe\xae\x88\x42\xc2\x83\xe0\x8a\xd8\x5c\xbb\x5a\xb5\x9c\x1d\xa5\xbe\x67\x50\xb1\x4e\xec\x96\x65\xaa\x87\x5b\xb0\x76\x88\xe3\x1b\xcb\x38\x21\x02\x8e\xc9\xe7\xf5\xc7\xe1\x1d\xe8\xeb\x54\x0e\x0b\xea\xd1\x2e\xad\xbb\xec\x22\x21\xb3\x64\x36\x29\x34\x5e\x3a\x22\xe8\x03\x4b\x86\xb1\x67\x7d\x4f\x48\x6d\xfb\x4b\xde\xe6\x4c\xb0\xaf\x40\x66\xab\xe9\x1a\x4e\xae\x1a\x7e\x05\xc5\x67\x2a\x95\x6d\xc2\x61\x35\x20\xfe\x33\xc3\x2c\x7f\x9b\xbe\x9f\x9a\xd5\xf0\x63\x28\xa1\x94\xb1\x5c\xc1\x18\x6b\x5b\x33\xb4\x4d\xcf\xbe\xf7\xb2\x94\x58\xaa\xcf\xad\xc8\x75\x93\x1a\x08\xf4\xd2\xd9\xf6\x95\x03\x3b\xf3\x4e\xfb\x15\xe4\x28\xed\xd5\x79\xd9\xbf\xb7\x8f\xb2\x70\x16\x4c\x2d\x65\xf6\xec\x33\x1e\xaf\xea\x46\x69\xc6\x9a\x6b\xdd\xf3\x57\xe0\x1d\x28\xcd\xf8\x83\x3d\x94\x4c\x2f\x6e\xfd\x51\x3d\xa8\xff\xcb\x33\xad\x32\x42\x0e\xd3\x00\x0a\xe5\x71\x76\x3b\x83\xc9\x2a\x67\x50\xc3\xa5\xeb\x4d\x8d\x67\xd6\xd9\x1b\x9a\x5a\xbe\xdd\xc5\x15\x00\xcf\x97\x0f\x47\x44\x34\x1d\x4e\xb6\x6f\x91\x31\xf3\x45\x0f\x59\x48\x10\x23\x53\x40\x49\x83\xe6\xc8\xdf\x51\x6c\xa8\x9f\x3a\x43\x3d\xb9\xd4\xea\x30\x4d\xe0\xd2\xb8\x44\xf3\x91\x20\x79\xdb\x7b\xe6\x50\xf9\x0f\xfb\x4c\xac\x79\x93\xf6\xf8\x96\x0d\x55\x7c\x41\x9b\x1a\x86\xad\x4b\xd1\xf9\x5d\xed\x3a\x4f\xc9\x64\x72\xd4\x22\x53\x59\x2f\x01\x00\x00\xff\xff\xc6\xfd\xa0\x37\x00\x04\x00\x00")
|
||||
b.SetBytes(int64(len(in))) // 1024
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = Encode(in)
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue