diff --git a/deprecated.go b/deprecated.go new file mode 100644 index 0000000..ab7616e --- /dev/null +++ b/deprecated.go @@ -0,0 +1,42 @@ +// Deprecated: use github.com/libp2p/go-libp2p-core/routing instead. +package routing + +import ( + "context" + + ci "github.com/libp2p/go-libp2p-core/crypto" + "github.com/libp2p/go-libp2p-core/peer" + + core "github.com/libp2p/go-libp2p-core/routing" +) + +// Deprecated: use github.com/libp2p/go-libp2p-core/routing.ErrNotFound instead. +var ErrNotFound = core.ErrNotFound + +// Deprecated: use github.com/libp2p/go-libp2p-core/routing.ErrNotSupported instead. +var ErrNotSupported = core.ErrNotSupported + +// Deprecated: use github.com/libp2p/go-libp2p-core/routing.ContentRouting instead. +type ContentRouting = core.ContentRouting + +// Deprecated: use github.com/libp2p/go-libp2p-core/routing.PeerRouting instead. +type PeerRouting = core.PeerRouting + +// Deprecated: use github.com/libp2p/go-libp2p-core/routing.ValueStore instead. +type ValueStore = core.ValueStore + +// Deprecated: use github.com/libp2p/go-libp2p-core/routing.Routing instead. +type IpfsRouting = core.Routing + +// Deprecated: use github.com/libp2p/go-libp2p-core/routing.PubKeyFetcher instead. +type PubKeyFetcher = core.PubKeyFetcher + +// Deprecated: use github.com/libp2p/go-libp2p-core/routing.KeyForPublicKey instead. +func KeyForPublicKey(id peer.ID) string { + return core.KeyForPublicKey(id) +} + +// Deprecated: use github.com/libp2p/go-libp2p-core/routing.GetPublicKey instead. +func GetPublicKey(r core.ValueStore, ctx context.Context, p peer.ID) (ci.PubKey, error) { + return core.GetPublicKey(r, ctx, p) +} diff --git a/go.mod b/go.mod index e661bca..dcbc333 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,6 @@ module github.com/libp2p/go-libp2p-routing require ( - github.com/ipfs/go-cid v0.0.1 - github.com/libp2p/go-libp2p-crypto v0.0.1 - github.com/libp2p/go-libp2p-peer v0.0.1 - github.com/libp2p/go-libp2p-peerstore v0.0.1 + github.com/libp2p/go-libp2p-core v0.0.1 + golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 // indirect ) diff --git a/go.sum b/go.sum index 4105d68..4108f01 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,3 @@ -github.com/AndreasBriese/bbloom v0.0.0-20180913140656-343706a395b7/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= -github.com/Kubuxu/go-os-helper v0.0.1/go.mod h1:N8B+I7vPCT80IcP58r50u4+gEEcsZETFUpAzWW2ep1Y= github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32 h1:qkOC5Gd33k54tobS36cXdAzJbeHaduLtnLQQwNoIi78= github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32/go.mod h1:DrZx5ec/dmnfpw9KyYoQyYo7d0KEvTkk/5M/vbZjAr8= @@ -10,63 +8,41 @@ github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVa 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 h1:6IyqGr3fnd0tM3YxipK27TUskaOVUjU2nG45yzwcQKY= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dgraph-io/badger v1.5.5-0.20190226225317-8115aed38f8f/go.mod h1:VZxzAIRPHRVNRKRo6AXrX9BJegn6il06VMTZVJYCIjQ= -github.com/dgryski/go-farm v0.0.0-20190104051053-3adb47b1fb0f/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= -github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98= github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE= 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/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0= -github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gxed/hashland/keccakpg v0.0.1 h1:wrk3uMNaMxbXiHibbPO4S0ymqJMm41WiudyFSs7UnsU= github.com/gxed/hashland/keccakpg v0.0.1/go.mod h1:kRzw3HkwxFU1mpmPP8v1WyQzwdGfmKFJ6tItnhQ67kU= github.com/gxed/hashland/murmur3 v0.0.1 h1:SheiaIt0sda5K+8FLz952/1iWS9zrnKsEJaOJu4ZbSc= github.com/gxed/hashland/murmur3 v0.0.1/go.mod h1:KjXop02n4/ckmZSnY2+HKcLud/tcmvhST0bie/0lS48= -github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/ipfs/go-cid v0.0.1 h1:GBjWPktLnNyX0JiQCNFpUuUSoMw5KMyqrsejHYlILBE= github.com/ipfs/go-cid v0.0.1/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM= -github.com/ipfs/go-datastore v0.0.1/go.mod h1:d4KVXhMt913cLBEI/PXAy6ko+W7e9AhyAKBGh803qeE= -github.com/ipfs/go-ds-badger v0.0.2/go.mod h1:Y3QpeSFWQf6MopLTiZD+VT6IC1yZqaGmjvRcKeSGij8= -github.com/ipfs/go-ds-leveldb v0.0.1/go.mod h1:feO8V3kubwsEF22n0YRQCffeb79OOYIykR4L04tMOYc= -github.com/ipfs/go-ipfs-delay v0.0.0-20181109222059-70721b86a9a8/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw= -github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM= +github.com/jbenet/goprocess v0.0.0-20160826012719-b497e2f366b8 h1:bspPhN+oKYFk5fcGNuQzp6IGzYQSenLEgH3s6jkXrWw= 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/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/libp2p/go-buffer-pool v0.0.1/go.mod h1:xtyIz9PMobb13WaxR6Zo1Pd1zXJKYg0a8KiIvDp3TzQ= -github.com/libp2p/go-libp2p-crypto v0.0.1 h1:JNQd8CmoGTohO/akqrH16ewsqZpci2CbgYH/LmYl8gw= -github.com/libp2p/go-libp2p-crypto v0.0.1/go.mod h1:yJkNyDmO341d5wwXxDUGO0LykUVT72ImHNUqh5D/dBE= -github.com/libp2p/go-libp2p-peer v0.0.1 h1:0qwAOljzYewINrU+Kndoc+1jAL7vzY/oY2Go4DCGfyY= -github.com/libp2p/go-libp2p-peer v0.0.1/go.mod h1:nXQvOBbwVqoP+T5Y5nCjeH4sP9IX/J0AMzcDUVruVoo= -github.com/libp2p/go-libp2p-peerstore v0.0.1 h1:twKovq8YK5trLrd3nB7PD2Zu9JcyAIdm7Bz9yBWjhq8= -github.com/libp2p/go-libp2p-peerstore v0.0.1/go.mod h1:RabLyPVJLuNQ+GFyoEkfi8H4Ti6k/HtZJ7YKgtSq+20= -github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= -github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +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 h1:lYpkrQH5ajf0OXOcUbGjvZxxijuBwbbmlSxLiuofa+g= github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ= github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16 h1:5W7KhL8HVF3XCFOweFD3BNESdnO8ewyYTFT2R+/b8FQ= 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 h1:Y51FGVJ91WBqCEabAi5OPUz38eAx8DakuAm5svLcsfQ= github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= +github.com/mr-tron/base58 v1.1.1 h1:OJIdWOWYe2l5PQNgimGtuwHY8nDskvJ5vvs//YnzRLs= +github.com/mr-tron/base58 v1.1.1/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= github.com/multiformats/go-base32 v0.0.3 h1:tw5+NhuwaOjJCC5Pp82QuXbrmLzWg7uxlMFp8Nq/kkI= github.com/multiformats/go-base32 v0.0.3/go.mod h1:pLiuGC8y0QR3Ue4Zug5UzK9LjgbkL8NSQj0zQ5Nz/AA= -github.com/multiformats/go-multiaddr v0.0.1 h1:/QUV3VBMDI6pi6xfiw7lr6xhDWWvQKn9udPn68kLSdY= -github.com/multiformats/go-multiaddr v0.0.1/go.mod h1:xKVEak1K9cS1VdmPZW3LSIb6lgmoS58qz/pzqmAxV44= -github.com/multiformats/go-multiaddr-dns v0.0.1/go.mod h1:9kWcqw/Pj6FwxAwW38n/9403szc57zJPs45fmnznu3Q= -github.com/multiformats/go-multiaddr-net v0.0.1/go.mod h1:nw6HSxNmCIQH27XPGBuX+d1tnvM7ihcFwHMSstNAVUU= +github.com/multiformats/go-multiaddr v0.0.2 h1:RBysRCv5rv3FWlhKWKoXv8tnsCUpEpIZpCmqAGZos2s= +github.com/multiformats/go-multiaddr v0.0.2/go.mod h1:xKVEak1K9cS1VdmPZW3LSIb6lgmoS58qz/pzqmAxV44= github.com/multiformats/go-multibase v0.0.1 h1:PN9/v21eLywrFWdFNsFKaU04kLJzuYzmrJR+ubhT9qA= github.com/multiformats/go-multibase v0.0.1/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/gviWFaSteVbWT51qgs= github.com/multiformats/go-multihash v0.0.1 h1:HHwN1K12I+XllBCrqKnhX949Orn4oawPkegHMu2vDqQ= @@ -74,31 +50,24 @@ github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKT 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/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= -github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1/go.mod h1:8UvriyWtv5Q5EOgjHaSseUEdkQfvwFv1I/In/O2M9gc= -github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc/go.mod h1:bopw91TMyo8J3tvftk8xmU2kPmlrt4nScJQZU2hE5EM= -github.com/whyrusleeping/mafmt v1.2.8/go.mod h1:faQJFPbLSxzD9xpA02ttW/tS9vZykNvXwGvqIpk20FA= +github.com/spacemonkeygo/openssl v0.0.0-20181017203307-c2dcc5cca94a h1:/eS3yfGjQKG+9kayBkj0ip1BGhq6zJ3eaVksphxAaek= +github.com/spacemonkeygo/openssl v0.0.0-20181017203307-c2dcc5cca94a/go.mod h1:7AyxJNCJ7SBZ1MfVQCWD6Uqo2oubI2Eq2y2eqf+A5r0= +github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 h1:RC6RW7j+1+HkWaX/Yh71Ee5ZHaHYt7ZP4sQgUrm6cDU= +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 h1:+/WWzjwW6gidDJnMKWLKLX1gxn7irUTF1fLpQovfQ5M= 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/net v0.0.0-20190227160552-c95aed5357e7/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 h1:Z0Ahzd7HltpJtjAHHxX8QFP3j1yYgiuvjbjRzDj/KH0= golang.org/x/sys v0.0.0-20190219092855-153ac476189d/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/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= -google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/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/notifications/deprecated.go b/notifications/deprecated.go new file mode 100644 index 0000000..29e9e92 --- /dev/null +++ b/notifications/deprecated.go @@ -0,0 +1,48 @@ +// Deprecated: use github.com/libp2p/go-libp2p-core/routing instead. +package notifications + +import ( + "context" + + core "github.com/libp2p/go-libp2p-core/routing" +) + +// Deprecated: use github.com/libp2p/go-libp2p-core/routing/QueryEventType instead. +type QueryEventType = core.QueryEventType + +// Deprecated: use github.com/libp2p/go-libp2p-core/routing/QueryEventBufferSize instead. +// Warning: it's impossible to alias a var in go, so reads and writes to this variable may be inaccurate +// or not have the intended effect. +var QueryEventBufferSize = core.QueryEventBufferSize + +const ( + // Deprecated: use github.com/libp2p/go-libp2p-core/routing/SendingQuery instead. + SendingQuery = core.SendingQuery + // Deprecated: use github.com/libp2p/go-libp2p-core/routing/PeerResponse instead. + PeerResponse = core.PeerResponse + // Deprecated: use github.com/libp2p/go-libp2p-core/routing/FinalPeer instead. + FinalPeer = core.FinalPeer + // Deprecated: use github.com/libp2p/go-libp2p-core/routing/QueryError instead. + QueryError = core.QueryError + // Deprecated: use github.com/libp2p/go-libp2p-core/routing/Provider instead. + Provider = core.Provider + // Deprecated: use github.com/libp2p/go-libp2p-core/routing/Value instead. + Value = core.Value + // Deprecated: use github.com/libp2p/go-libp2p-core/routing/AddingPeer instead. + AddingPeer = core.AddingPeer + // Deprecated: use github.com/libp2p/go-libp2p-core/routing/DialingPeer instead. + DialingPeer = core.DialingPeer +) + +// Deprecated: use github.com/libp2p/go-libp2p-core/routing/QueryEvent instead. +type QueryEvent = core.QueryEvent + +// Deprecated: use github.com/libp2p/go-libp2p-core/routing/RegisterForQueryEvents instead. +func RegisterForQueryEvents(ctx context.Context) (context.Context, <-chan *core.QueryEvent) { + return core.RegisterForQueryEvents(ctx) +} + +// Deprecated: use github.com/libp2p/go-libp2p-core/routing/PublishQueryEvent instead. +func PublishQueryEvent(ctx context.Context, ev *core.QueryEvent) { + core.PublishQueryEvent(ctx, ev) +} diff --git a/notifications/query.go b/notifications/query.go deleted file mode 100644 index 84eba85..0000000 --- a/notifications/query.go +++ /dev/null @@ -1,121 +0,0 @@ -package notifications - -import ( - "context" - "encoding/json" - "sync" - - peer "github.com/libp2p/go-libp2p-peer" - pstore "github.com/libp2p/go-libp2p-peerstore" -) - -type QueryEventType int - -// Number of events to buffer. -var QueryEventBufferSize = 16 - -const ( - SendingQuery QueryEventType = iota - PeerResponse - FinalPeer - QueryError - Provider - Value - AddingPeer - DialingPeer -) - -type QueryEvent struct { - ID peer.ID - Type QueryEventType - Responses []*pstore.PeerInfo - Extra string -} - -type routingQueryKey struct{} -type eventChannel struct { - mu sync.Mutex - ctx context.Context - ch chan<- *QueryEvent -} - -// waitThenClose is spawned in a goroutine when the channel is registered. This -// safely cleans up the channel when the context has been canceled. -func (e *eventChannel) waitThenClose() { - <-e.ctx.Done() - e.mu.Lock() - close(e.ch) - // 1. Signals that we're done. - // 2. Frees memory (in case we end up hanging on to this for a while). - e.ch = nil - e.mu.Unlock() -} - -// send sends an event on the event channel, aborting if either the passed or -// the internal context expire. -func (e *eventChannel) send(ctx context.Context, ev *QueryEvent) { - e.mu.Lock() - // Closed. - if e.ch == nil { - e.mu.Unlock() - return - } - // in case the passed context is unrelated, wait on both. - select { - case e.ch <- ev: - case <-e.ctx.Done(): - case <-ctx.Done(): - } - e.mu.Unlock() -} - -func RegisterForQueryEvents(ctx context.Context) (context.Context, <-chan *QueryEvent) { - ch := make(chan *QueryEvent, QueryEventBufferSize) - ech := &eventChannel{ch: ch, ctx: ctx} - go ech.waitThenClose() - return context.WithValue(ctx, routingQueryKey{}, ech), ch -} - -func PublishQueryEvent(ctx context.Context, ev *QueryEvent) { - ich := ctx.Value(routingQueryKey{}) - if ich == nil { - return - } - - // We *want* to panic here. - ech := ich.(*eventChannel) - ech.send(ctx, ev) -} - -func (qe *QueryEvent) MarshalJSON() ([]byte, error) { - return json.Marshal(map[string]interface{}{ - "ID": peer.IDB58Encode(qe.ID), - "Type": int(qe.Type), - "Responses": qe.Responses, - "Extra": qe.Extra, - }) -} - -func (qe *QueryEvent) UnmarshalJSON(b []byte) error { - temp := struct { - ID string - Type int - Responses []*pstore.PeerInfo - Extra string - }{} - err := json.Unmarshal(b, &temp) - if err != nil { - return err - } - if len(temp.ID) > 0 { - pid, err := peer.IDB58Decode(temp.ID) - if err != nil { - return err - } - qe.ID = pid - } - qe.Type = QueryEventType(temp.Type) - qe.Responses = temp.Responses - qe.Extra = temp.Extra - return nil -} diff --git a/notifications/query_test.go b/notifications/query_test.go deleted file mode 100644 index 98c2c0e..0000000 --- a/notifications/query_test.go +++ /dev/null @@ -1,44 +0,0 @@ -package notifications - -import ( - "context" - "fmt" - "sync" - "testing" -) - -func TestEventsCancel(t *testing.T) { - ctx, cancel := context.WithCancel(context.Background()) - ctx, events := RegisterForQueryEvents(ctx) - goch := make(chan struct{}) - var wg sync.WaitGroup - wg.Add(2) - go func() { - defer wg.Done() - for i := 0; i < 100; i++ { - PublishQueryEvent(ctx, &QueryEvent{Extra: fmt.Sprint(i)}) - } - close(goch) - for i := 100; i < 1000; i++ { - PublishQueryEvent(ctx, &QueryEvent{Extra: fmt.Sprint(i)}) - } - }() - go func() { - defer wg.Done() - i := 0 - for e := range events { - if i < 100 { - if e.Extra != fmt.Sprint(i) { - t.Errorf("expected %d, got %s", i, e.Extra) - } - } - i++ - } - if i < 100 { - t.Errorf("expected at least 100 events, got %d", i) - } - }() - <-goch - cancel() - wg.Wait() -} diff --git a/options/deprecated.go b/options/deprecated.go new file mode 100644 index 0000000..46c36d7 --- /dev/null +++ b/options/deprecated.go @@ -0,0 +1,16 @@ +// Deprecated: use github.com/libp2p/go-libp2p-core/routing instead. +package ropts + +import core "github.com/libp2p/go-libp2p-core/routing" + +// Deprecated: use github.com/libp2p/go-libp2p-core/routing/Option instead. +type Option = core.Option + +// Deprecated: use github.com/libp2p/go-libp2p-core/routing/Options instead. +type Options = core.Options + +// Deprecated: use github.com/libp2p/go-libp2p-core/routing.Expired instead. +var Expired = core.Expired + +// Deprecated: use github.com/libp2p/go-libp2p-core/routing/Offline instead. +var Offline = core.Offline diff --git a/options/options.go b/options/options.go deleted file mode 100644 index e0c9a52..0000000 --- a/options/options.go +++ /dev/null @@ -1,50 +0,0 @@ -package ropts - -// Option is a single routing option. -type Option func(opts *Options) error - -// Options is a set of routing options -type Options struct { - // Allow expired values. - Expired bool - Offline bool - // Other (ValueStore implementation specific) options. - Other map[interface{}]interface{} -} - -// Apply applies the given options to this Options -func (opts *Options) Apply(options ...Option) error { - for _, o := range options { - if err := o(opts); err != nil { - return err - } - } - return nil -} - -// ToOption converts this Options to a single Option. -func (opts *Options) ToOption() Option { - return func(nopts *Options) error { - *nopts = *opts - if opts.Other != nil { - nopts.Other = make(map[interface{}]interface{}, len(opts.Other)) - for k, v := range opts.Other { - nopts.Other[k] = v - } - } - return nil - } -} - -// Expired is an option that tells the routing system to return expired records -// when no newer records are known. -var Expired Option = func(opts *Options) error { - opts.Expired = true - return nil -} - -// Offline is an option that tells the routing system to operate offline (i.e., rely on cached/local data only). -var Offline Option = func(opts *Options) error { - opts.Offline = true - return nil -} diff --git a/routing.go b/routing.go deleted file mode 100644 index 5fc1e9f..0000000 --- a/routing.go +++ /dev/null @@ -1,124 +0,0 @@ -// package routing defines the interface for a routing system used by ipfs. -package routing - -import ( - "context" - "errors" - - ropts "github.com/libp2p/go-libp2p-routing/options" - - cid "github.com/ipfs/go-cid" - ci "github.com/libp2p/go-libp2p-crypto" - peer "github.com/libp2p/go-libp2p-peer" - pstore "github.com/libp2p/go-libp2p-peerstore" -) - -// ErrNotFound is returned when the router fails to find the requested record. -var ErrNotFound = errors.New("routing: not found") - -// ErrNotSupported is returned when the router doesn't support the given record -// type/operation. -var ErrNotSupported = errors.New("routing: operation or key not supported") - -// ContentRouting is a value provider layer of indirection. It is used to find -// information about who has what content. -type ContentRouting interface { - // Provide adds the given cid to the content routing system. If 'true' is - // passed, it also announces it, otherwise it is just kept in the local - // accounting of which objects are being provided. - Provide(context.Context, cid.Cid, bool) error - - // Search for peers who are able to provide a given key - FindProvidersAsync(context.Context, cid.Cid, int) <-chan pstore.PeerInfo -} - -// PeerRouting is a way to find information about certain peers. -// This can be implemented by a simple lookup table, a tracking server, -// or even a DHT. -type PeerRouting interface { - // Find specific Peer - // FindPeer searches for a peer with given ID, returns a pstore.PeerInfo - // with relevant addresses. - FindPeer(context.Context, peer.ID) (pstore.PeerInfo, error) -} - -// ValueStore is a basic Put/Get interface. -type ValueStore interface { - - // PutValue adds value corresponding to given Key. - PutValue(context.Context, string, []byte, ...ropts.Option) error - - // GetValue searches for the value corresponding to given Key. - GetValue(context.Context, string, ...ropts.Option) ([]byte, error) - - // SearchValue searches for better and better values from this value - // store corresponding to the given Key. By default implementations must - // stop the search after a good value is found. A 'good' value is a value - // that would be returned from GetValue. - // - // Useful when you want a result *now* but still want to hear about - // better/newer results. - // - // Implementations of this methods won't return ErrNotFound. When a value - // couldn't be found, the channel will get closed without passing any results - SearchValue(context.Context, string, ...ropts.Option) (<-chan []byte, error) -} - -// IpfsRouting is the combination of different routing types that IPFS uses. -// It can be satisfied by a single item (such as a DHT) or multiple different -// pieces that are more optimized to each task. -type IpfsRouting interface { - ContentRouting - PeerRouting - ValueStore - - // Bootstrap allows callers to hint to the routing system to get into a - // Boostrapped state and remain there. It is not a synchronous call. - Bootstrap(context.Context) error - - // TODO expose io.Closer or plain-old Close error -} - -// PubKeyFetcher is an interfaces that should be implemented by value stores -// that can optimize retrieval of public keys. -// -// TODO(steb): Consider removing, see #22. -type PubKeyFetcher interface { - // GetPublicKey returns the public key for the given peer. - GetPublicKey(context.Context, peer.ID) (ci.PubKey, error) -} - -// KeyForPublicKey returns the key used to retrieve public keys -// from a value store. -func KeyForPublicKey(id peer.ID) string { - return "/pk/" + string(id) -} - -// GetPublicKey retrieves the public key associated with the given peer ID from -// the value store. -// -// If the ValueStore is also a PubKeyFetcher, this method will call GetPublicKey -// (which may be better optimized) instead of GetValue. -func GetPublicKey(r ValueStore, ctx context.Context, p peer.ID) (ci.PubKey, error) { - switch k, err := p.ExtractPublicKey(); err { - case peer.ErrNoPublicKey: - // check the datastore - case nil: - return k, nil - default: - return nil, err - } - - if dht, ok := r.(PubKeyFetcher); ok { - // If we have a DHT as our routing system, use optimized fetcher - return dht.GetPublicKey(ctx, p) - } - key := KeyForPublicKey(p) - pkval, err := r.GetValue(ctx, key) - if err != nil { - return nil, err - } - - // get PublicKey from node.Data - return ci.UnmarshalPublicKey(pkval) -}