From 1357b4bb4b863afcc688f7820c88564ad79818be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Kripalani?= Date: Fri, 24 May 2019 15:49:24 +0100 Subject: [PATCH] Consolidate abstractions and core types into go-libp2p-core (#12) --- deprecated.go | 31 ++++++++++++++++++++++++++++++ error.go | 29 ---------------------------- error_test.go | 20 ------------------- go.mod | 4 ++++ go.sum | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ interface.go | 38 ------------------------------------ 6 files changed, 88 insertions(+), 87 deletions(-) create mode 100644 deprecated.go delete mode 100644 error.go delete mode 100644 error_test.go create mode 100644 go.sum delete mode 100644 interface.go diff --git a/deprecated.go b/deprecated.go new file mode 100644 index 0000000..e068ae4 --- /dev/null +++ b/deprecated.go @@ -0,0 +1,31 @@ +// Deprecated: use github.com/libp2p/go-libp2p-core/pnet instead. +package ipnet + +import core "github.com/libp2p/go-libp2p-core/pnet" + +// Deprecated: use github.com/libp2p/go-libp2p-core/pnet.EnvKey instead. +const EnvKey = core.EnvKey + +// Deprecated: use github.com/libp2p/go-libp2p-core/pnet.ForcePrivateNetwork instead. +// Warning: it's impossible to alias a var in go. Writes to this var would have no longer +// have any effect, so it has been commented out to induce breakage for added safety. +// var ForcePrivateNetwork = core.ForcePrivateNetwork + +// Deprecated: use github.com/libp2p/go-libp2p-core/pnet.ErrNotInPrivateNetwork instead. +var ErrNotInPrivateNetwork = core.ErrNotInPrivateNetwork + +// Deprecated: use github.com/libp2p/go-libp2p-core/pnet.Protector instead. +type Protector = core.Protector + +// Deprecated: use github.com/libp2p/go-libp2p-core/pnet.Error instead. +type PNetError = core.Error + +// Deprecated: use github.com/libp2p/go-libp2p-core/pnet.NewError instead. +func NewError(err string) error { + return core.NewError(err) +} + +// Deprecated: use github.com/libp2p/go-libp2p-core/pnet.IsPNetError instead. +func IsPNetError(err error) bool { + return core.IsPNetError(err) +} diff --git a/error.go b/error.go deleted file mode 100644 index e4cb9f7..0000000 --- a/error.go +++ /dev/null @@ -1,29 +0,0 @@ -package ipnet - -// PNetError is error type for ease of detecting PNet errors -type PNetError interface { - IsPNetError() bool -} - -// NewError creates new PNetError -func NewError(err string) error { - return pnetErr("privnet: " + err) -} - -// IsPNetError checks if given error is PNet Error -func IsPNetError(err error) bool { - v, ok := err.(PNetError) - return ok && v.IsPNetError() -} - -type pnetErr string - -var _ PNetError = (PNetError)(pnetErr("")) - -func (p pnetErr) Error() string { - return string(p) -} - -func (pnetErr) IsPNetError() bool { - return true -} diff --git a/error_test.go b/error_test.go deleted file mode 100644 index c92b415..0000000 --- a/error_test.go +++ /dev/null @@ -1,20 +0,0 @@ -package ipnet - -import ( - "errors" - "testing" -) - -func TestIsPnetErr(t *testing.T) { - err := NewError("test") - - if err.Error() != "privnet: test" { - t.Fatalf("expected 'privnet: test' got '%s'", err.Error()) - } - if !IsPNetError(err) { - t.Fatal("expected the pnetErr to be detected by IsPnetError") - } - if IsPNetError(errors.New("not pnet error")) { - t.Fatal("expected generic error not to be pnetError") - } -} diff --git a/go.mod b/go.mod index d4ab6b5..69cab51 100644 --- a/go.mod +++ b/go.mod @@ -1 +1,5 @@ module github.com/libp2p/go-libp2p-interface-pnet + +go 1.12 + +require github.com/libp2p/go-libp2p-core v0.0.1 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..79cbe90 --- /dev/null +++ b/go.sum @@ -0,0 +1,53 @@ +github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= +github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32/go.mod h1:DrZx5ec/dmnfpw9KyYoQyYo7d0KEvTkk/5M/vbZjAr8= +github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= +github.com/btcsuite/btcutil v0.0.0-20190207003914-4c204d697803/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= +github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg= +github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY= +github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= +github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY= +github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= +github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/gxed/hashland/keccakpg v0.0.1/go.mod h1:kRzw3HkwxFU1mpmPP8v1WyQzwdGfmKFJ6tItnhQ67kU= +github.com/gxed/hashland/murmur3 v0.0.1/go.mod h1:KjXop02n4/ckmZSnY2+HKcLud/tcmvhST0bie/0lS48= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/ipfs/go-cid v0.0.1/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM= +github.com/jbenet/goprocess v0.0.0-20160826012719-b497e2f366b8/go.mod h1:Ly/wlsjFq/qrU3Rar62tu1gASgGw6chQbSh/XgIIXCY= +github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= +github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= +github.com/libp2p/go-flow-metrics v0.0.1/go.mod h1:Iv1GH0sG8DtYN3SVJ2eG221wMiNpZxBdp967ls1g+k8= +github.com/libp2p/go-libp2p-core v0.0.1 h1:HSTZtFIq/W5Ue43Zw+uWZyy2Vl5WtF0zDjKN8/DT/1I= +github.com/libp2p/go-libp2p-core v0.0.1/go.mod h1:g/VxnTZ/1ygHxH3dKok7Vno1VfpvGcGip57wjTU4fco= +github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ= +github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U= +github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= +github.com/mr-tron/base58 v1.1.1/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= +github.com/multiformats/go-base32 v0.0.3/go.mod h1:pLiuGC8y0QR3Ue4Zug5UzK9LjgbkL8NSQj0zQ5Nz/AA= +github.com/multiformats/go-multiaddr v0.0.2/go.mod h1:xKVEak1K9cS1VdmPZW3LSIb6lgmoS58qz/pzqmAxV44= +github.com/multiformats/go-multibase v0.0.1/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/gviWFaSteVbWT51qgs= +github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/spacemonkeygo/openssl v0.0.0-20181017203307-c2dcc5cca94a/go.mod h1:7AyxJNCJ7SBZ1MfVQCWD6Uqo2oubI2Eq2y2eqf+A5r0= +github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572/go.mod h1:w0SWMsp6j9O/dk4/ZpIhL+3CkG8ofA2vuv7k+ltqUMc= +golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190225124518-7f87c0fbb88b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190219092855-153ac476189d/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/interface.go b/interface.go deleted file mode 100644 index 85632b4..0000000 --- a/interface.go +++ /dev/null @@ -1,38 +0,0 @@ -package ipnet - -import ( - "net" - "os" -) - -// EnvKey defines environment variable name for forcing usage of PNet in libp2p -// When environment variable of this name is set to "1" the ForcePrivateNetwork -// variable will be set to true. -const EnvKey = "LIBP2P_FORCE_PNET" - -// ForcePrivateNetwork is boolean variable that forces usage of PNet in libp2p -// Setting this variable to true or setting LIBP2P_FORCE_PNET environment variable -// to true will make libp2p to require private network protector. -// If no network protector is provided and this variable is set to true libp2p will -// refuse to connect. -var ForcePrivateNetwork = false - -func init() { - ForcePrivateNetwork = os.Getenv(EnvKey) == "1" -} - -// ErrNotInPrivateNetwork is an error that should be returned by libp2p when it -// tries to dial with ForcePrivateNetwork set and no PNet Protector -var ErrNotInPrivateNetwork = NewError("private network was not configured but" + - " is enforced by the environment") - -// Protector interface is a way for private network implementation to be transparent in -// libp2p. It is created by implementation and use by libp2p-conn to secure connections -// so they can be only established with selected number of peers. -type Protector interface { - // Wraps passed connection to protect it - Protect(net.Conn) (net.Conn, error) - - // Returns key fingerprint that is safe to expose - Fingerprint() []byte -}