diff --git a/assets/assets.go b/assets/assets.go index 4965b0f5afe..df24f7f483b 100644 --- a/assets/assets.go +++ b/assets/assets.go @@ -8,10 +8,10 @@ import ( "fmt" "path/filepath" - "github.com/ipfs/go-ipfs/blocks/key" "github.com/ipfs/go-ipfs/core" "github.com/ipfs/go-ipfs/core/coreunix" uio "github.com/ipfs/go-ipfs/unixfs/io" + "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) // initDocPaths lists the paths for the docs we want to seed during --init diff --git a/blocks/blocks.go b/blocks/blocks.go index c41e1323a11..ed8a388403c 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -6,9 +6,9 @@ import ( "errors" "fmt" - key "github.com/ipfs/go-ipfs/blocks/key" mh "gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash" u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) var ErrWrongHash = errors.New("data did not match given hash!") diff --git a/blocks/blockstore/arc_cache.go b/blocks/blockstore/arc_cache.go index c0ec192312c..51c4048e873 100644 --- a/blocks/blockstore/arc_cache.go +++ b/blocks/blockstore/arc_cache.go @@ -2,10 +2,10 @@ package blockstore import ( "github.com/ipfs/go-ipfs/blocks" - key "github.com/ipfs/go-ipfs/blocks/key" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" lru "gx/ipfs/QmVYxfoJQiZijTgPNHCHgHELvQpbsJNTg6Crmc3dQkj3yy/golang-lru" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) type arccache struct { diff --git a/blocks/blockstore/arc_cache_test.go b/blocks/blockstore/arc_cache_test.go index 17570123273..1d0012991ea 100644 --- a/blocks/blockstore/arc_cache_test.go +++ b/blocks/blockstore/arc_cache_test.go @@ -4,11 +4,11 @@ import ( "testing" "github.com/ipfs/go-ipfs/blocks" - "github.com/ipfs/go-ipfs/blocks/key" + "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - syncds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/sync" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + syncds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/sync" ) var exampleBlock = blocks.NewBlock([]byte("foo")) diff --git a/blocks/blockstore/blockstore.go b/blocks/blockstore/blockstore.go index f96178b4433..29055fa808e 100644 --- a/blocks/blockstore/blockstore.go +++ b/blocks/blockstore/blockstore.go @@ -8,13 +8,13 @@ import ( "sync/atomic" blocks "github.com/ipfs/go-ipfs/blocks" - key "github.com/ipfs/go-ipfs/blocks/key" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - dsns "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/namespace" - dsq "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/query" logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" mh "gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + dsns "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/namespace" + dsq "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/query" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) var log = logging.Logger("blockstore") diff --git a/blocks/blockstore/blockstore_test.go b/blocks/blockstore/blockstore_test.go index fc78ca6e9b1..e39b43d5038 100644 --- a/blocks/blockstore/blockstore_test.go +++ b/blocks/blockstore/blockstore_test.go @@ -5,14 +5,14 @@ import ( "fmt" "testing" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - dsq "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/query" - ds_sync "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/sync" u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + dsq "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/query" + ds_sync "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/sync" blocks "github.com/ipfs/go-ipfs/blocks" - key "github.com/ipfs/go-ipfs/blocks/key" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) func TestGetWhenKeyNotPresent(t *testing.T) { diff --git a/blocks/blockstore/bloom_cache.go b/blocks/blockstore/bloom_cache.go index e10dacfaf1b..30c068471d3 100644 --- a/blocks/blockstore/bloom_cache.go +++ b/blocks/blockstore/bloom_cache.go @@ -2,9 +2,9 @@ package blockstore import ( "github.com/ipfs/go-ipfs/blocks" - key "github.com/ipfs/go-ipfs/blocks/key" bloom "gx/ipfs/QmWQ2SJisXwcCLsUXLwYCKSfyExXjFRW2WbBH5sqCUnwX5/bbloom" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" "sync/atomic" ) diff --git a/blocks/blockstore/bloom_cache_test.go b/blocks/blockstore/bloom_cache_test.go index 607bf8d2413..457efb7d808 100644 --- a/blocks/blockstore/bloom_cache_test.go +++ b/blocks/blockstore/bloom_cache_test.go @@ -8,10 +8,10 @@ import ( "github.com/ipfs/go-ipfs/blocks" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - dsq "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/query" - syncds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/sync" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + dsq "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/query" + syncds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/sync" ) func testBloomCached(bs GCBlockstore, ctx context.Context) (*bloomcache, error) { diff --git a/blocks/key/key.go b/blocks/key/key.go deleted file mode 100644 index 15c2be86b10..00000000000 --- a/blocks/key/key.go +++ /dev/null @@ -1,86 +0,0 @@ -package key - -import ( - "encoding/json" - "fmt" - - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - b58 "gx/ipfs/QmT8rehPR3F6bmwL6zjUN8XpiDBFFpMP2myPdC6ApsWfJf/go-base58" - mh "gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash" - base32 "gx/ipfs/Qmb1DA2A9LS2wR4FFweB4uEDomFsdmnw1VLawLE1yQzudj/base32" -) - -// Key is a string representation of multihash for use with maps. -type Key string - -// String is utililty function for printing out keys as strings (Pretty). -func (k Key) String() string { - return k.B58String() -} - -func (k Key) ToMultihash() mh.Multihash { - return mh.Multihash(k) -} - -// B58String returns Key in a b58 encoded string -func (k Key) B58String() string { - return B58KeyEncode(k) -} - -// B58KeyDecode returns Key from a b58 encoded string -func B58KeyDecode(s string) Key { - return Key(string(b58.Decode(s))) -} - -// B58KeyEncode returns Key in a b58 encoded string -func B58KeyEncode(k Key) string { - return b58.Encode([]byte(k)) -} - -// DsKey returns a Datastore key -func (k Key) DsKey() ds.Key { - return ds.NewKey(base32.RawStdEncoding.EncodeToString([]byte(k))) -} - -// UnmarshalJSON returns a JSON-encoded Key (string) -func (k *Key) UnmarshalJSON(mk []byte) error { - var s string - err := json.Unmarshal(mk, &s) - if err != nil { - return err - } - - *k = Key(string(b58.Decode(s))) - if len(*k) == 0 && len(s) > 2 { // if b58.Decode fails, k == "" - return fmt.Errorf("Key.UnmarshalJSON: invalid b58 string: %v", mk) - } - return nil -} - -// MarshalJSON returns a JSON-encoded Key (string) -func (k *Key) MarshalJSON() ([]byte, error) { - return json.Marshal(b58.Encode([]byte(*k))) -} - -func (k *Key) Loggable() map[string]interface{} { - return map[string]interface{}{ - "key": k.String(), - } -} - -// KeyFromDsKey returns a Datastore key -func KeyFromDsKey(dsk ds.Key) (Key, error) { - dec, err := base32.RawStdEncoding.DecodeString(dsk.String()[1:]) - if err != nil { - return "", err - } - - return Key(dec), nil -} - -// KeySlice is used for sorting Keys -type KeySlice []Key - -func (es KeySlice) Len() int { return len(es) } -func (es KeySlice) Swap(i, j int) { es[i], es[j] = es[j], es[i] } -func (es KeySlice) Less(i, j int) bool { return es[i] < es[j] } diff --git a/blocks/key/key_set.go b/blocks/key/key_set.go deleted file mode 100644 index f880ec33edd..00000000000 --- a/blocks/key/key_set.go +++ /dev/null @@ -1,39 +0,0 @@ -package key - -type KeySet interface { - Add(Key) - Has(Key) bool - Remove(Key) - Keys() []Key -} - -type keySet struct { - keys map[Key]struct{} -} - -func NewKeySet() KeySet { - return &keySet{make(map[Key]struct{})} -} - -func (gcs *keySet) Add(k Key) { - gcs.keys[k] = struct{}{} -} - -func (gcs *keySet) Has(k Key) bool { - _, has := gcs.keys[k] - return has -} - -func (ks *keySet) Keys() []Key { - var out []Key - for k, _ := range ks.keys { - out = append(out, k) - } - return out -} - -func (ks *keySet) Remove(k Key) { - delete(ks.keys, k) -} - -// TODO: implement disk-backed keyset for working with massive DAGs diff --git a/blocks/key/key_test.go b/blocks/key/key_test.go deleted file mode 100644 index bdb1a06750d..00000000000 --- a/blocks/key/key_test.go +++ /dev/null @@ -1,28 +0,0 @@ -package key - -import ( - "bytes" - "testing" - - mh "gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash" -) - -func TestKey(t *testing.T) { - - h1, err := mh.Sum([]byte("beep boop"), mh.SHA2_256, -1) - if err != nil { - t.Error(err) - } - - k1 := Key(h1) - h2 := mh.Multihash(k1) - k2 := Key(h2) - - if !bytes.Equal(h1, h2) { - t.Error("Multihashes not equal.") - } - - if k1 != k2 { - t.Error("Keys not equal.") - } -} diff --git a/blocks/set/set.go b/blocks/set/set.go index 10fea92dc02..24304209205 100644 --- a/blocks/set/set.go +++ b/blocks/set/set.go @@ -3,8 +3,8 @@ package set import ( "github.com/ipfs/go-ipfs/blocks/bloom" - key "github.com/ipfs/go-ipfs/blocks/key" logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) var log = logging.Logger("blockset") diff --git a/blocks/set/set_test.go b/blocks/set/set_test.go index 74465b92714..3dcb33d505d 100644 --- a/blocks/set/set_test.go +++ b/blocks/set/set_test.go @@ -4,7 +4,7 @@ import ( "testing" bu "github.com/ipfs/go-ipfs/blocks/blocksutil" - k "github.com/ipfs/go-ipfs/blocks/key" + k "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) const ( diff --git a/blockservice/blockservice.go b/blockservice/blockservice.go index 25282a44145..b99e1db48b8 100644 --- a/blockservice/blockservice.go +++ b/blockservice/blockservice.go @@ -8,10 +8,10 @@ import ( blocks "github.com/ipfs/go-ipfs/blocks" "github.com/ipfs/go-ipfs/blocks/blockstore" - key "github.com/ipfs/go-ipfs/blocks/key" exchange "github.com/ipfs/go-ipfs/exchange" logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) var log = logging.Logger("blockservice") diff --git a/blockservice/test/blocks_test.go b/blockservice/test/blocks_test.go index 81d61818b34..ea7cc8b08f5 100644 --- a/blockservice/test/blocks_test.go +++ b/blockservice/test/blocks_test.go @@ -8,13 +8,13 @@ import ( blocks "github.com/ipfs/go-ipfs/blocks" blockstore "github.com/ipfs/go-ipfs/blocks/blockstore" blocksutil "github.com/ipfs/go-ipfs/blocks/blocksutil" - key "github.com/ipfs/go-ipfs/blocks/key" . "github.com/ipfs/go-ipfs/blockservice" offline "github.com/ipfs/go-ipfs/exchange/offline" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - dssync "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/sync" u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + dssync "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/sync" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) func TestBlocks(t *testing.T) { diff --git a/cmd/ipfs/daemon.go b/cmd/ipfs/daemon.go index 2131fcc3d62..91c820caf2a 100644 --- a/cmd/ipfs/daemon.go +++ b/cmd/ipfs/daemon.go @@ -25,10 +25,10 @@ import ( nodeMount "github.com/ipfs/go-ipfs/fuse/node" fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo" migrate "github.com/ipfs/go-ipfs/repo/fsrepo/migrations" - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" + conn "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/net/conn" + pstore "gx/ipfs/QmXhhVSpXMUjpf9XgQDyePxug2iHm8ZvZD99aA9N6kuqMN/go-libp2p-peerstore" util "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" prometheus "gx/ipfs/QmdhsRK1EK2fvAz2i2SH5DEfkL6seDuyMYEsxKa9Braim3/client_golang/prometheus" - conn "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/net/conn" ) const ( diff --git a/cmd/ipfs/main.go b/cmd/ipfs/main.go index 0a16c36d719..3f6b0d75501 100644 --- a/cmd/ipfs/main.go +++ b/cmd/ipfs/main.go @@ -32,7 +32,7 @@ import ( repo "github.com/ipfs/go-ipfs/repo" config "github.com/ipfs/go-ipfs/repo/config" fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo" - loggables "github.com/ipfs/go-ipfs/thirdparty/loggables" + loggables "gx/ipfs/QmYrv4LgCC8FhG2Ab4bwuq5DqBdwMtx3hMb3KKJDZcr2d7/go-libp2p-loggables" ) // log is the command logger diff --git a/cmd/ipfswatch/main.go b/cmd/ipfswatch/main.go index 4c69a35b823..4b50590cf5b 100644 --- a/cmd/ipfswatch/main.go +++ b/cmd/ipfswatch/main.go @@ -14,7 +14,7 @@ import ( coreunix "github.com/ipfs/go-ipfs/core/coreunix" config "github.com/ipfs/go-ipfs/repo/config" fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo" - process "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess" + process "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" fsnotify "gx/ipfs/QmczzCMvJ3HV57WBKDy8b4ucp7quT325JjDbixYRS5Pwvv/fsnotify.v1" ) diff --git a/cmd/seccat/seccat.go b/cmd/seccat/seccat.go index 85462b07eca..e3578632e94 100644 --- a/cmd/seccat/seccat.go +++ b/cmd/seccat/seccat.go @@ -18,12 +18,12 @@ import ( "os/signal" "syscall" - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" ci "gx/ipfs/QmVoi5es8D5fNHZDqoW6DgDAEPEV5hQp8GBz161vZXiwpQ/go-libp2p-crypto" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" + pstore "gx/ipfs/QmXhhVSpXMUjpf9XgQDyePxug2iHm8ZvZD99aA9N6kuqMN/go-libp2p-peerstore" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" - secio "gx/ipfs/QmbP93111oShRbdjoWvP3NZCUApTLkaPXgaNDaXZPfHQHR/go-libp2p-secio" + secio "gx/ipfs/QmbnPJidHfeekkdLkoboBooA56KB92cT8csDmJwCc2bQJ1/go-libp2p-secio" ) var verbose = false diff --git a/core/bootstrap.go b/core/bootstrap.go index 5f495323d49..68337f22ea5 100644 --- a/core/bootstrap.go +++ b/core/bootstrap.go @@ -9,17 +9,17 @@ import ( "time" config "github.com/ipfs/go-ipfs/repo/config" - lgbl "github.com/ipfs/go-ipfs/thirdparty/loggables" math2 "github.com/ipfs/go-ipfs/thirdparty/math2" - - goprocess "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess" - procctx "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess/context" - periodicproc "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess/periodic" - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + lgbl "gx/ipfs/QmYrv4LgCC8FhG2Ab4bwuq5DqBdwMtx3hMb3KKJDZcr2d7/go-libp2p-loggables" + + goprocess "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess" + procctx "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess/context" + periodicproc "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess/periodic" + host "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/host" + inet "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/net" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" + pstore "gx/ipfs/QmXhhVSpXMUjpf9XgQDyePxug2iHm8ZvZD99aA9N6kuqMN/go-libp2p-peerstore" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" - host "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/host" - inet "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/net" ) // ErrNotEnoughBootstrapPeers signals that we do not have enough bootstrap diff --git a/core/bootstrap_test.go b/core/bootstrap_test.go index 2aa60227be6..17a2435e9a5 100644 --- a/core/bootstrap_test.go +++ b/core/bootstrap_test.go @@ -5,8 +5,8 @@ import ( "testing" config "github.com/ipfs/go-ipfs/repo/config" - testutil "github.com/ipfs/go-ipfs/thirdparty/testutil" - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" + pstore "gx/ipfs/QmXhhVSpXMUjpf9XgQDyePxug2iHm8ZvZD99aA9N6kuqMN/go-libp2p-peerstore" + testutil "gx/ipfs/QmYpVUnnedgGrp6cX2pBii5HRQgcSr778FiKVe7o7nF5Z3/go-testutil" ) func TestSubsetWhenMaxIsGreaterThanLengthOfSlice(t *testing.T) { diff --git a/core/builder.go b/core/builder.go index cbe6f54156c..dcecac6bb6d 100644 --- a/core/builder.go +++ b/core/builder.go @@ -9,7 +9,6 @@ import ( "time" bstore "github.com/ipfs/go-ipfs/blocks/blockstore" - key "github.com/ipfs/go-ipfs/blocks/key" bserv "github.com/ipfs/go-ipfs/blockservice" offline "github.com/ipfs/go-ipfs/exchange/offline" dag "github.com/ipfs/go-ipfs/merkledag" @@ -17,14 +16,15 @@ import ( pin "github.com/ipfs/go-ipfs/pin" repo "github.com/ipfs/go-ipfs/repo" cfg "github.com/ipfs/go-ipfs/repo/config" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - dsync "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/sync" - goprocessctx "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess/context" - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" - retry "gx/ipfs/QmV71dCdjYivZwta22a7YvNmeS86r1EpnBjq9XAD21rBV9/retry-datastore" + retry "gx/ipfs/QmPF5kxTYFkzhaY5LmkExood7aTTZBHWQC6cjdDQBuGrjp/retry-datastore" + goprocessctx "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess/context" ci "gx/ipfs/QmVoi5es8D5fNHZDqoW6DgDAEPEV5hQp8GBz161vZXiwpQ/go-libp2p-crypto" + pstore "gx/ipfs/QmXhhVSpXMUjpf9XgQDyePxug2iHm8ZvZD99aA9N6kuqMN/go-libp2p-peerstore" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + dsync "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/sync" ) type BuildCfg struct { diff --git a/core/commands/bitswap.go b/core/commands/bitswap.go index f06d1e78d0d..02a48aa2774 100644 --- a/core/commands/bitswap.go +++ b/core/commands/bitswap.go @@ -5,13 +5,13 @@ import ( "fmt" "io" - key "github.com/ipfs/go-ipfs/blocks/key" cmds "github.com/ipfs/go-ipfs/commands" bitswap "github.com/ipfs/go-ipfs/exchange/bitswap" decision "github.com/ipfs/go-ipfs/exchange/bitswap/decision" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" "gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" ) diff --git a/core/commands/block.go b/core/commands/block.go index 48fa90e8818..10731dc119c 100644 --- a/core/commands/block.go +++ b/core/commands/block.go @@ -10,12 +10,12 @@ import ( "github.com/ipfs/go-ipfs/blocks" bs "github.com/ipfs/go-ipfs/blocks/blockstore" - key "github.com/ipfs/go-ipfs/blocks/key" cmds "github.com/ipfs/go-ipfs/commands" "github.com/ipfs/go-ipfs/pin" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" mh "gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash" u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" + ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) type BlockStat struct { diff --git a/core/commands/dht.go b/core/commands/dht.go index 638163b66c6..312a0d1862b 100644 --- a/core/commands/dht.go +++ b/core/commands/dht.go @@ -7,17 +7,17 @@ import ( "io" "time" - key "github.com/ipfs/go-ipfs/blocks/key" cmds "github.com/ipfs/go-ipfs/commands" dag "github.com/ipfs/go-ipfs/merkledag" - notif "github.com/ipfs/go-ipfs/notifications" path "github.com/ipfs/go-ipfs/path" - routing "github.com/ipfs/go-ipfs/routing" - ipdht "github.com/ipfs/go-ipfs/routing/dht" - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + ipdht "gx/ipfs/QmSXEMQ9yXxVm84YNXXyyDzu5gyHa3K8FYSfwzPjNXSfHq/go-libp2p-kad-dht" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" + pstore "gx/ipfs/QmXhhVSpXMUjpf9XgQDyePxug2iHm8ZvZD99aA9N6kuqMN/go-libp2p-peerstore" + routing "gx/ipfs/QmYQadj3iegqmRPWjaWMRc8DG52hZa2HMkmyPkto5chDvs/go-libp2p-routing" + notif "gx/ipfs/QmYQadj3iegqmRPWjaWMRc8DG52hZa2HMkmyPkto5chDvs/go-libp2p-routing/notifications" u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) var ErrNotDHT = errors.New("routing service is not a DHT") diff --git a/core/commands/dht_test.go b/core/commands/dht_test.go index bf75aff98ff..035589c559f 100644 --- a/core/commands/dht_test.go +++ b/core/commands/dht_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/ipfs/go-ipfs/namesys" - tu "github.com/ipfs/go-ipfs/thirdparty/testutil" + tu "gx/ipfs/QmYpVUnnedgGrp6cX2pBii5HRQgcSr778FiKVe7o7nF5Z3/go-testutil" ) func TestKeyTranslation(t *testing.T) { diff --git a/core/commands/id.go b/core/commands/id.go index b9b3b7549ec..8e883db3120 100644 --- a/core/commands/id.go +++ b/core/commands/id.go @@ -12,13 +12,13 @@ import ( cmds "github.com/ipfs/go-ipfs/commands" core "github.com/ipfs/go-ipfs/core" - kb "github.com/ipfs/go-ipfs/routing/kbucket" + kb "gx/ipfs/Qmc5r13R4j3V75ucMkGzHimsQDgkg4aUanX5upcUWns7XM/go-libp2p-kbucket" - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" + identify "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/protocol/identify" ic "gx/ipfs/QmVoi5es8D5fNHZDqoW6DgDAEPEV5hQp8GBz161vZXiwpQ/go-libp2p-crypto" - "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" + pstore "gx/ipfs/QmXhhVSpXMUjpf9XgQDyePxug2iHm8ZvZD99aA9N6kuqMN/go-libp2p-peerstore" u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" - identify "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/protocol/identify" ) const offlineIdErrorMessage = `'ipfs id' currently cannot query information on remote diff --git a/core/commands/ls.go b/core/commands/ls.go index b0de779ef0e..d836cfc638a 100644 --- a/core/commands/ls.go +++ b/core/commands/ls.go @@ -6,13 +6,13 @@ import ( "io" "text/tabwriter" - key "github.com/ipfs/go-ipfs/blocks/key" cmds "github.com/ipfs/go-ipfs/commands" core "github.com/ipfs/go-ipfs/core" merkledag "github.com/ipfs/go-ipfs/merkledag" path "github.com/ipfs/go-ipfs/path" unixfs "github.com/ipfs/go-ipfs/unixfs" unixfspb "github.com/ipfs/go-ipfs/unixfs/pb" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) type LsLink struct { diff --git a/core/commands/pin.go b/core/commands/pin.go index efa6fa1bb3e..b30cdfe2f81 100644 --- a/core/commands/pin.go +++ b/core/commands/pin.go @@ -5,7 +5,6 @@ import ( "fmt" "io" - key "github.com/ipfs/go-ipfs/blocks/key" cmds "github.com/ipfs/go-ipfs/commands" core "github.com/ipfs/go-ipfs/core" corerepo "github.com/ipfs/go-ipfs/core/corerepo" @@ -14,6 +13,7 @@ import ( pin "github.com/ipfs/go-ipfs/pin" u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) var PinCmd = &cmds.Command{ diff --git a/core/commands/ping.go b/core/commands/ping.go index c028912c6a9..332b130ca30 100644 --- a/core/commands/ping.go +++ b/core/commands/ping.go @@ -10,8 +10,8 @@ import ( cmds "github.com/ipfs/go-ipfs/commands" core "github.com/ipfs/go-ipfs/core" - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" + pstore "gx/ipfs/QmXhhVSpXMUjpf9XgQDyePxug2iHm8ZvZD99aA9N6kuqMN/go-libp2p-peerstore" u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" ma "gx/ipfs/QmYzDkkgAEmrcNzFCiYo6L1dTX4EAG1gZkbtdbd9trL4vd/go-multiaddr" diff --git a/core/commands/publish.go b/core/commands/publish.go index 499d7cb3057..4da4b10b17d 100644 --- a/core/commands/publish.go +++ b/core/commands/publish.go @@ -9,11 +9,11 @@ import ( context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" - key "github.com/ipfs/go-ipfs/blocks/key" cmds "github.com/ipfs/go-ipfs/commands" core "github.com/ipfs/go-ipfs/core" path "github.com/ipfs/go-ipfs/path" crypto "gx/ipfs/QmVoi5es8D5fNHZDqoW6DgDAEPEV5hQp8GBz161vZXiwpQ/go-libp2p-crypto" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) var errNotOnline = errors.New("This command must be run in online mode. Try running 'ipfs daemon' first.") diff --git a/core/commands/refs.go b/core/commands/refs.go index 0fd4b7735dd..ce920cd9145 100644 --- a/core/commands/refs.go +++ b/core/commands/refs.go @@ -6,13 +6,13 @@ import ( "io" "strings" - key "github.com/ipfs/go-ipfs/blocks/key" cmds "github.com/ipfs/go-ipfs/commands" "github.com/ipfs/go-ipfs/core" dag "github.com/ipfs/go-ipfs/merkledag" path "github.com/ipfs/go-ipfs/path" u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) // KeyList is a general type for outputting lists of keys diff --git a/core/commands/stat.go b/core/commands/stat.go index 0e87734d02d..fc457e0fcae 100644 --- a/core/commands/stat.go +++ b/core/commands/stat.go @@ -10,10 +10,10 @@ import ( humanize "gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize" cmds "github.com/ipfs/go-ipfs/commands" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + metrics "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/metrics" + protocol "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/protocol" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" - metrics "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/metrics" - protocol "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/protocol" ) var StatsCmd = &cmds.Command{ diff --git a/core/commands/swarm.go b/core/commands/swarm.go index 61fa01faa3c..ecb4b7476d7 100644 --- a/core/commands/swarm.go +++ b/core/commands/swarm.go @@ -13,8 +13,8 @@ import ( config "github.com/ipfs/go-ipfs/repo/config" "github.com/ipfs/go-ipfs/repo/fsrepo" iaddr "github.com/ipfs/go-ipfs/thirdparty/ipfsaddr" - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" - swarm "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/net/swarm" + swarm "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/net/swarm" + pstore "gx/ipfs/QmXhhVSpXMUjpf9XgQDyePxug2iHm8ZvZD99aA9N6kuqMN/go-libp2p-peerstore" mafilter "gx/ipfs/QmSMZwvs3n4GBikZ7hKzT17c3bk65FmyZo2JqtJ16swqCv/multiaddr-filter" ma "gx/ipfs/QmYzDkkgAEmrcNzFCiYo6L1dTX4EAG1gZkbtdbd9trL4vd/go-multiaddr" diff --git a/core/core.go b/core/core.go index 2d3b3281034..3788159de43 100644 --- a/core/core.go +++ b/core/core.go @@ -17,38 +17,38 @@ import ( "time" diag "github.com/ipfs/go-ipfs/diagnostics" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - goprocess "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess" + goprocess "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess" mamask "gx/ipfs/QmSMZwvs3n4GBikZ7hKzT17c3bk65FmyZo2JqtJ16swqCv/multiaddr-filter" - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" b58 "gx/ipfs/QmT8rehPR3F6bmwL6zjUN8XpiDBFFpMP2myPdC6ApsWfJf/go-base58" + discovery "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/discovery" + p2phost "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/host" + p2pbhost "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/host/basic" + rhost "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/host/routed" + metrics "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/metrics" + swarm "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/net/swarm" + addrutil "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/net/swarm/addr" + ping "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/protocol/ping" ic "gx/ipfs/QmVoi5es8D5fNHZDqoW6DgDAEPEV5hQp8GBz161vZXiwpQ/go-libp2p-crypto" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" + pstore "gx/ipfs/QmXhhVSpXMUjpf9XgQDyePxug2iHm8ZvZD99aA9N6kuqMN/go-libp2p-peerstore" ma "gx/ipfs/QmYzDkkgAEmrcNzFCiYo6L1dTX4EAG1gZkbtdbd9trL4vd/go-multiaddr" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" - discovery "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/discovery" - p2phost "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/host" - p2pbhost "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/host/basic" - rhost "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/host/routed" - metrics "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/metrics" - swarm "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/net/swarm" - addrutil "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/net/swarm/addr" - ping "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/protocol/ping" - - routing "github.com/ipfs/go-ipfs/routing" - dht "github.com/ipfs/go-ipfs/routing/dht" + ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + nilrouting "github.com/ipfs/go-ipfs/routing/none" offroute "github.com/ipfs/go-ipfs/routing/offline" + dht "gx/ipfs/QmSXEMQ9yXxVm84YNXXyyDzu5gyHa3K8FYSfwzPjNXSfHq/go-libp2p-kad-dht" + routing "gx/ipfs/QmYQadj3iegqmRPWjaWMRc8DG52hZa2HMkmyPkto5chDvs/go-libp2p-routing" bstore "github.com/ipfs/go-ipfs/blocks/blockstore" - key "github.com/ipfs/go-ipfs/blocks/key" bserv "github.com/ipfs/go-ipfs/blockservice" exchange "github.com/ipfs/go-ipfs/exchange" bitswap "github.com/ipfs/go-ipfs/exchange/bitswap" bsnet "github.com/ipfs/go-ipfs/exchange/bitswap/network" rp "github.com/ipfs/go-ipfs/exchange/reprovide" mfs "github.com/ipfs/go-ipfs/mfs" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" mount "github.com/ipfs/go-ipfs/fuse/mount" merkledag "github.com/ipfs/go-ipfs/merkledag" diff --git a/core/core_test.go b/core/core_test.go index 862956b4bc6..7ffbd4d5098 100644 --- a/core/core_test.go +++ b/core/core_test.go @@ -5,7 +5,7 @@ import ( "github.com/ipfs/go-ipfs/repo" config "github.com/ipfs/go-ipfs/repo/config" - "github.com/ipfs/go-ipfs/thirdparty/testutil" + "github.com/ipfs/go-ipfs/thirdparty/datastore2" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" ) @@ -38,7 +38,7 @@ func TestInitialization(t *testing.T) { for i, c := range good { r := &repo.Mock{ C: *c, - D: testutil.ThreadSafeCloserMapDatastore(), + D: datastore2.ThreadSafeCloserMapDatastore(), } n, err := NewNode(ctx, &BuildCfg{Repo: r}) if n == nil || err != nil { @@ -49,7 +49,7 @@ func TestInitialization(t *testing.T) { for i, c := range bad { r := &repo.Mock{ C: *c, - D: testutil.ThreadSafeCloserMapDatastore(), + D: datastore2.ThreadSafeCloserMapDatastore(), } n, err := NewNode(ctx, &BuildCfg{Repo: r}) if n != nil || err == nil { diff --git a/core/corehttp/corehttp.go b/core/corehttp/corehttp.go index 51deda011f0..e4f9529190c 100644 --- a/core/corehttp/corehttp.go +++ b/core/corehttp/corehttp.go @@ -12,7 +12,7 @@ import ( core "github.com/ipfs/go-ipfs/core" manet "gx/ipfs/QmPpRcbNUXauP3zWZ1NJMLWpe4QnmEHrd2ba2D3yqWznw7/go-multiaddr-net" - "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess" + "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess" logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" ma "gx/ipfs/QmYzDkkgAEmrcNzFCiYo6L1dTX4EAG1gZkbtdbd9trL4vd/go-multiaddr" ) diff --git a/core/corehttp/gateway.go b/core/corehttp/gateway.go index 54bd8e4075f..85eddd2f570 100644 --- a/core/corehttp/gateway.go +++ b/core/corehttp/gateway.go @@ -7,7 +7,7 @@ import ( core "github.com/ipfs/go-ipfs/core" config "github.com/ipfs/go-ipfs/repo/config" - id "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/protocol/identify" + id "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/protocol/identify" ) type GatewayConfig struct { diff --git a/core/corehttp/gateway_handler.go b/core/corehttp/gateway_handler.go index 88b7a85877d..7fee7b201fe 100644 --- a/core/corehttp/gateway_handler.go +++ b/core/corehttp/gateway_handler.go @@ -13,15 +13,15 @@ import ( humanize "gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize" "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" - key "github.com/ipfs/go-ipfs/blocks/key" core "github.com/ipfs/go-ipfs/core" "github.com/ipfs/go-ipfs/importer" chunk "github.com/ipfs/go-ipfs/importer/chunk" dag "github.com/ipfs/go-ipfs/merkledag" dagutils "github.com/ipfs/go-ipfs/merkledag/utils" path "github.com/ipfs/go-ipfs/path" - "github.com/ipfs/go-ipfs/routing" uio "github.com/ipfs/go-ipfs/unixfs/io" + "gx/ipfs/QmYQadj3iegqmRPWjaWMRc8DG52hZa2HMkmyPkto5chDvs/go-libp2p-routing" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) const ( diff --git a/core/corehttp/gateway_test.go b/core/corehttp/gateway_test.go index b532913fd92..6fbc4f901ae 100644 --- a/core/corehttp/gateway_test.go +++ b/core/corehttp/gateway_test.go @@ -15,10 +15,10 @@ import ( path "github.com/ipfs/go-ipfs/path" repo "github.com/ipfs/go-ipfs/repo" config "github.com/ipfs/go-ipfs/repo/config" - testutil "github.com/ipfs/go-ipfs/thirdparty/testutil" + datastore2 "github.com/ipfs/go-ipfs/thirdparty/datastore2" + id "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/protocol/identify" ci "gx/ipfs/QmVoi5es8D5fNHZDqoW6DgDAEPEV5hQp8GBz161vZXiwpQ/go-libp2p-crypto" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" - id "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/protocol/identify" ) type mockNamesys map[string]path.Path @@ -51,7 +51,7 @@ func newNodeWithMockNamesys(ns mockNamesys) (*core.IpfsNode, error) { } r := &repo.Mock{ C: c, - D: testutil.ThreadSafeCloserMapDatastore(), + D: datastore2.ThreadSafeCloserMapDatastore(), } n, err := core.NewNode(context.Background(), &core.BuildCfg{Repo: r}) if err != nil { diff --git a/core/corehttp/metrics_test.go b/core/corehttp/metrics_test.go index 5d3a72e22c1..6b23eebea29 100644 --- a/core/corehttp/metrics_test.go +++ b/core/corehttp/metrics_test.go @@ -5,10 +5,10 @@ import ( "time" core "github.com/ipfs/go-ipfs/core" + bhost "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/host/basic" + inet "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/net" + testutil "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/test/util" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" - bhost "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/host/basic" - inet "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/net" - testutil "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/test/util" ) // This test is based on go-libp2p/p2p/net/swarm.TestConnectednessCorrect diff --git a/core/corenet/net.go b/core/corenet/net.go index 544a77f3892..ae9f185e26c 100644 --- a/core/corenet/net.go +++ b/core/corenet/net.go @@ -4,11 +4,11 @@ import ( "time" core "github.com/ipfs/go-ipfs/core" - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + net "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/net" + pro "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/protocol" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" + pstore "gx/ipfs/QmXhhVSpXMUjpf9XgQDyePxug2iHm8ZvZD99aA9N6kuqMN/go-libp2p-peerstore" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" - net "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/net" - pro "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/protocol" ) type ipfsListener struct { diff --git a/core/corerepo/gc.go b/core/corerepo/gc.go index 223ab87d73b..5d723d5f28c 100644 --- a/core/corerepo/gc.go +++ b/core/corerepo/gc.go @@ -4,7 +4,6 @@ import ( "errors" "time" - key "github.com/ipfs/go-ipfs/blocks/key" "github.com/ipfs/go-ipfs/core" mfs "github.com/ipfs/go-ipfs/mfs" gc "github.com/ipfs/go-ipfs/pin/gc" @@ -12,6 +11,7 @@ import ( humanize "gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize" logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) var log = logging.Logger("corerepo") diff --git a/core/corerepo/pinning.go b/core/corerepo/pinning.go index 675ba834945..63f6abfb95a 100644 --- a/core/corerepo/pinning.go +++ b/core/corerepo/pinning.go @@ -18,10 +18,10 @@ import ( context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" - key "github.com/ipfs/go-ipfs/blocks/key" "github.com/ipfs/go-ipfs/core" "github.com/ipfs/go-ipfs/merkledag" path "github.com/ipfs/go-ipfs/path" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) func Pin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool) ([]key.Key, error) { diff --git a/core/corerouting/core.go b/core/corerouting/core.go index d02b00b375e..2e70cccf9f4 100644 --- a/core/corerouting/core.go +++ b/core/corerouting/core.go @@ -5,13 +5,13 @@ import ( core "github.com/ipfs/go-ipfs/core" repo "github.com/ipfs/go-ipfs/repo" - routing "github.com/ipfs/go-ipfs/routing" supernode "github.com/ipfs/go-ipfs/routing/supernode" gcproxy "github.com/ipfs/go-ipfs/routing/supernode/proxy" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" + "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/host" + pstore "gx/ipfs/QmXhhVSpXMUjpf9XgQDyePxug2iHm8ZvZD99aA9N6kuqMN/go-libp2p-peerstore" + routing "gx/ipfs/QmYQadj3iegqmRPWjaWMRc8DG52hZa2HMkmyPkto5chDvs/go-libp2p-routing" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" - "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/host" + ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" ) // NB: DHT option is included in the core to avoid 1) because it's a sane diff --git a/core/coreunix/add.go b/core/coreunix/add.go index bd3929ea7b3..7a99b22318a 100644 --- a/core/coreunix/add.go +++ b/core/coreunix/add.go @@ -8,16 +8,16 @@ import ( gopath "path" bstore "github.com/ipfs/go-ipfs/blocks/blockstore" - key "github.com/ipfs/go-ipfs/blocks/key" bserv "github.com/ipfs/go-ipfs/blockservice" "github.com/ipfs/go-ipfs/exchange/offline" importer "github.com/ipfs/go-ipfs/importer" "github.com/ipfs/go-ipfs/importer/chunk" mfs "github.com/ipfs/go-ipfs/mfs" "github.com/ipfs/go-ipfs/pin" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - syncds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/sync" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + syncds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/sync" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" bs "github.com/ipfs/go-ipfs/blocks/blockstore" "github.com/ipfs/go-ipfs/commands/files" diff --git a/core/coreunix/add_test.go b/core/coreunix/add_test.go index 7a43b634903..11104990162 100644 --- a/core/coreunix/add_test.go +++ b/core/coreunix/add_test.go @@ -7,15 +7,15 @@ import ( "testing" "time" - "github.com/ipfs/go-ipfs/blocks/key" "github.com/ipfs/go-ipfs/commands/files" "github.com/ipfs/go-ipfs/core" dag "github.com/ipfs/go-ipfs/merkledag" "github.com/ipfs/go-ipfs/pin/gc" "github.com/ipfs/go-ipfs/repo" "github.com/ipfs/go-ipfs/repo/config" - "github.com/ipfs/go-ipfs/thirdparty/testutil" + "github.com/ipfs/go-ipfs/thirdparty/datastore2" "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) func TestAddRecursive(t *testing.T) { @@ -25,7 +25,7 @@ func TestAddRecursive(t *testing.T) { PeerID: "Qmfoo", // required by offline node }, }, - D: testutil.ThreadSafeCloserMapDatastore(), + D: datastore2.ThreadSafeCloserMapDatastore(), } node, err := core.NewNode(context.Background(), &core.BuildCfg{Repo: r}) if err != nil { @@ -45,7 +45,7 @@ func TestAddGCLive(t *testing.T) { PeerID: "Qmfoo", // required by offline node }, }, - D: testutil.ThreadSafeCloserMapDatastore(), + D: datastore2.ThreadSafeCloserMapDatastore(), } node, err := core.NewNode(context.Background(), &core.BuildCfg{Repo: r}) if err != nil { diff --git a/core/coreunix/metadata.go b/core/coreunix/metadata.go index eb318e1a2eb..86987b6b6dd 100644 --- a/core/coreunix/metadata.go +++ b/core/coreunix/metadata.go @@ -1,10 +1,10 @@ package coreunix import ( - key "github.com/ipfs/go-ipfs/blocks/key" core "github.com/ipfs/go-ipfs/core" dag "github.com/ipfs/go-ipfs/merkledag" ft "github.com/ipfs/go-ipfs/unixfs" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) func AddMetadataTo(n *core.IpfsNode, skey string, m *ft.Metadata) (string, error) { diff --git a/core/coreunix/metadata_test.go b/core/coreunix/metadata_test.go index 47d516d1cd1..fe074086a85 100644 --- a/core/coreunix/metadata_test.go +++ b/core/coreunix/metadata_test.go @@ -5,12 +5,11 @@ import ( "io/ioutil" "testing" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - dssync "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/sync" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + dssync "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/sync" bstore "github.com/ipfs/go-ipfs/blocks/blockstore" - key "github.com/ipfs/go-ipfs/blocks/key" bserv "github.com/ipfs/go-ipfs/blockservice" core "github.com/ipfs/go-ipfs/core" offline "github.com/ipfs/go-ipfs/exchange/offline" @@ -20,6 +19,7 @@ import ( ft "github.com/ipfs/go-ipfs/unixfs" uio "github.com/ipfs/go-ipfs/unixfs/io" u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) func getDagserv(t *testing.T) merkledag.DAGService { diff --git a/core/mock/mock.go b/core/mock/mock.go index d3cdedbcfe6..133cdf4a7b5 100644 --- a/core/mock/mock.go +++ b/core/mock/mock.go @@ -3,21 +3,21 @@ package coremock import ( "net" - "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - syncds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/sync" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + syncds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/sync" commands "github.com/ipfs/go-ipfs/commands" core "github.com/ipfs/go-ipfs/core" "github.com/ipfs/go-ipfs/repo" config "github.com/ipfs/go-ipfs/repo/config" ds2 "github.com/ipfs/go-ipfs/thirdparty/datastore2" - testutil "github.com/ipfs/go-ipfs/thirdparty/testutil" - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" - host "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/host" - metrics "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/metrics" - mocknet "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/net/mock" + host "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/host" + metrics "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/metrics" + mocknet "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/net/mock" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" + pstore "gx/ipfs/QmXhhVSpXMUjpf9XgQDyePxug2iHm8ZvZD99aA9N6kuqMN/go-libp2p-peerstore" + testutil "gx/ipfs/QmYpVUnnedgGrp6cX2pBii5HRQgcSr778FiKVe7o7nF5Z3/go-testutil" ) // NewMockNode constructs an IpfsNode for use in tests. diff --git a/core/pathresolver.go b/core/pathresolver.go index 555cc3dfadc..d0b84713e77 100644 --- a/core/pathresolver.go +++ b/core/pathresolver.go @@ -6,9 +6,9 @@ import ( context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" - key "github.com/ipfs/go-ipfs/blocks/key" merkledag "github.com/ipfs/go-ipfs/merkledag" path "github.com/ipfs/go-ipfs/path" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) // ErrNoNamesys is an explicit error for when an IPFS node doesn't diff --git a/diagnostics/diag.go b/diagnostics/diag.go index c31cbab2ffc..98ad041dd74 100644 --- a/diagnostics/diag.go +++ b/diagnostics/diag.go @@ -13,14 +13,14 @@ import ( pb "github.com/ipfs/go-ipfs/diagnostics/pb" logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + host "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/host" + inet "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/net" + protocol "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/protocol" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" ctxio "gx/ipfs/QmX6DhWrpBB5NtadXmPSXYNdVvuLfJXoFNMvUMoVvP5UJa/go-context/io" ggio "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/io" proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" - host "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/host" - inet "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/net" - protocol "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/protocol" ) var log = logging.Logger("diagnostics") diff --git a/diagnostics/vis.go b/diagnostics/vis.go index c3fcc892bcf..def3ed8b384 100644 --- a/diagnostics/vis.go +++ b/diagnostics/vis.go @@ -5,8 +5,8 @@ import ( "fmt" "io" - rtable "github.com/ipfs/go-ipfs/routing/kbucket" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" + rtable "gx/ipfs/Qmc5r13R4j3V75ucMkGzHimsQDgkg4aUanX5upcUWns7XM/go-libp2p-kbucket" ) type node struct { diff --git a/exchange/bitswap/bitswap.go b/exchange/bitswap/bitswap.go index c98a98db733..4d4824df0a6 100644 --- a/exchange/bitswap/bitswap.go +++ b/exchange/bitswap/bitswap.go @@ -8,15 +8,14 @@ import ( "sync" "time" - process "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess" - procctx "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess/context" + process "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess" + procctx "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess/context" logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" blocks "github.com/ipfs/go-ipfs/blocks" blockstore "github.com/ipfs/go-ipfs/blocks/blockstore" - key "github.com/ipfs/go-ipfs/blocks/key" exchange "github.com/ipfs/go-ipfs/exchange" decision "github.com/ipfs/go-ipfs/exchange/bitswap/decision" bsmsg "github.com/ipfs/go-ipfs/exchange/bitswap/message" @@ -25,7 +24,8 @@ import ( wantlist "github.com/ipfs/go-ipfs/exchange/bitswap/wantlist" flags "github.com/ipfs/go-ipfs/flags" "github.com/ipfs/go-ipfs/thirdparty/delay" - loggables "github.com/ipfs/go-ipfs/thirdparty/loggables" + loggables "gx/ipfs/QmYrv4LgCC8FhG2Ab4bwuq5DqBdwMtx3hMb3KKJDZcr2d7/go-libp2p-loggables" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) var log = logging.Logger("bitswap") diff --git a/exchange/bitswap/bitswap_test.go b/exchange/bitswap/bitswap_test.go index df2bf9e279b..17d866256d3 100644 --- a/exchange/bitswap/bitswap_test.go +++ b/exchange/bitswap/bitswap_test.go @@ -7,17 +7,17 @@ import ( "time" detectrace "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-detect-race" - travis "github.com/ipfs/go-ipfs/thirdparty/testutil/ci/travis" + travis "gx/ipfs/QmYpVUnnedgGrp6cX2pBii5HRQgcSr778FiKVe7o7nF5Z3/go-testutil/ci/travis" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" blocks "github.com/ipfs/go-ipfs/blocks" blockstore "github.com/ipfs/go-ipfs/blocks/blockstore" blocksutil "github.com/ipfs/go-ipfs/blocks/blocksutil" - key "github.com/ipfs/go-ipfs/blocks/key" tn "github.com/ipfs/go-ipfs/exchange/bitswap/testnet" mockrouting "github.com/ipfs/go-ipfs/routing/mock" delay "github.com/ipfs/go-ipfs/thirdparty/delay" - p2ptestutil "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/test/util" + p2ptestutil "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/test/util" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) // FIXME the tests are really sensitive to the network delay. fix them to work diff --git a/exchange/bitswap/decision/bench_test.go b/exchange/bitswap/decision/bench_test.go index 22d533ea29b..17dc021316b 100644 --- a/exchange/bitswap/decision/bench_test.go +++ b/exchange/bitswap/decision/bench_test.go @@ -4,10 +4,10 @@ import ( "math" "testing" - key "github.com/ipfs/go-ipfs/blocks/key" "github.com/ipfs/go-ipfs/exchange/bitswap/wantlist" - "github.com/ipfs/go-ipfs/thirdparty/testutil" - "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" + "gx/ipfs/QmYpVUnnedgGrp6cX2pBii5HRQgcSr778FiKVe7o7nF5Z3/go-testutil" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) // FWIW: At the time of this commit, including a timestamp in task increases diff --git a/exchange/bitswap/decision/engine.go b/exchange/bitswap/decision/engine.go index 51a0f052487..5f2561ee812 100644 --- a/exchange/bitswap/decision/engine.go +++ b/exchange/bitswap/decision/engine.go @@ -10,7 +10,7 @@ import ( bsmsg "github.com/ipfs/go-ipfs/exchange/bitswap/message" wl "github.com/ipfs/go-ipfs/exchange/bitswap/wantlist" logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" ) diff --git a/exchange/bitswap/decision/engine_test.go b/exchange/bitswap/decision/engine_test.go index f9cb8aae34a..47d46edd919 100644 --- a/exchange/bitswap/decision/engine_test.go +++ b/exchange/bitswap/decision/engine_test.go @@ -11,11 +11,11 @@ import ( blocks "github.com/ipfs/go-ipfs/blocks" blockstore "github.com/ipfs/go-ipfs/blocks/blockstore" message "github.com/ipfs/go-ipfs/exchange/bitswap/message" - testutil "github.com/ipfs/go-ipfs/thirdparty/testutil" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - dssync "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/sync" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" + testutil "gx/ipfs/QmYpVUnnedgGrp6cX2pBii5HRQgcSr778FiKVe7o7nF5Z3/go-testutil" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + dssync "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/sync" ) type peerAndEngine struct { diff --git a/exchange/bitswap/decision/ledger.go b/exchange/bitswap/decision/ledger.go index 225e00f156f..dedbbb8e38d 100644 --- a/exchange/bitswap/decision/ledger.go +++ b/exchange/bitswap/decision/ledger.go @@ -4,9 +4,9 @@ import ( "sync" "time" - key "github.com/ipfs/go-ipfs/blocks/key" wl "github.com/ipfs/go-ipfs/exchange/bitswap/wantlist" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) // keySet is just a convenient alias for maps of keys, where we only care diff --git a/exchange/bitswap/decision/peer_request_queue.go b/exchange/bitswap/decision/peer_request_queue.go index 7265ea9e65d..c6eb045c145 100644 --- a/exchange/bitswap/decision/peer_request_queue.go +++ b/exchange/bitswap/decision/peer_request_queue.go @@ -4,10 +4,10 @@ import ( "sync" "time" - key "github.com/ipfs/go-ipfs/blocks/key" wantlist "github.com/ipfs/go-ipfs/exchange/bitswap/wantlist" pq "github.com/ipfs/go-ipfs/thirdparty/pq" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) type peerRequestQueue interface { diff --git a/exchange/bitswap/decision/peer_request_queue_test.go b/exchange/bitswap/decision/peer_request_queue_test.go index b1091c03c33..249dc82883c 100644 --- a/exchange/bitswap/decision/peer_request_queue_test.go +++ b/exchange/bitswap/decision/peer_request_queue_test.go @@ -7,9 +7,9 @@ import ( "strings" "testing" - key "github.com/ipfs/go-ipfs/blocks/key" "github.com/ipfs/go-ipfs/exchange/bitswap/wantlist" - "github.com/ipfs/go-ipfs/thirdparty/testutil" + "gx/ipfs/QmYpVUnnedgGrp6cX2pBii5HRQgcSr778FiKVe7o7nF5Z3/go-testutil" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) func TestPushPop(t *testing.T) { diff --git a/exchange/bitswap/message/message.go b/exchange/bitswap/message/message.go index f3b45e0545f..29c15159e15 100644 --- a/exchange/bitswap/message/message.go +++ b/exchange/bitswap/message/message.go @@ -4,10 +4,10 @@ import ( "io" blocks "github.com/ipfs/go-ipfs/blocks" - key "github.com/ipfs/go-ipfs/blocks/key" pb "github.com/ipfs/go-ipfs/exchange/bitswap/message/pb" wantlist "github.com/ipfs/go-ipfs/exchange/bitswap/wantlist" - inet "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/net" + inet "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/net" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ggio "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/io" proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto" diff --git a/exchange/bitswap/message/message_test.go b/exchange/bitswap/message/message_test.go index db79208d245..500b3f6e31d 100644 --- a/exchange/bitswap/message/message_test.go +++ b/exchange/bitswap/message/message_test.go @@ -7,8 +7,8 @@ import ( proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto" blocks "github.com/ipfs/go-ipfs/blocks" - key "github.com/ipfs/go-ipfs/blocks/key" pb "github.com/ipfs/go-ipfs/exchange/bitswap/message/pb" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) func TestAppendWanted(t *testing.T) { diff --git a/exchange/bitswap/network/interface.go b/exchange/bitswap/network/interface.go index 16f0dfed2e3..0f9f24ae0db 100644 --- a/exchange/bitswap/network/interface.go +++ b/exchange/bitswap/network/interface.go @@ -1,11 +1,11 @@ package network import ( - key "github.com/ipfs/go-ipfs/blocks/key" bsmsg "github.com/ipfs/go-ipfs/exchange/bitswap/message" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + protocol "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/protocol" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" - protocol "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/protocol" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) var ProtocolBitswap protocol.ID = "/ipfs/bitswap" diff --git a/exchange/bitswap/network/ipfs_impl.go b/exchange/bitswap/network/ipfs_impl.go index fe764641d9b..7732db178ff 100644 --- a/exchange/bitswap/network/ipfs_impl.go +++ b/exchange/bitswap/network/ipfs_impl.go @@ -3,18 +3,18 @@ package network import ( "io" - key "github.com/ipfs/go-ipfs/blocks/key" bsmsg "github.com/ipfs/go-ipfs/exchange/bitswap/message" - routing "github.com/ipfs/go-ipfs/routing" + routing "gx/ipfs/QmYQadj3iegqmRPWjaWMRc8DG52hZa2HMkmyPkto5chDvs/go-libp2p-routing" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + host "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/host" + inet "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/net" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" + pstore "gx/ipfs/QmXhhVSpXMUjpf9XgQDyePxug2iHm8ZvZD99aA9N6kuqMN/go-libp2p-peerstore" ma "gx/ipfs/QmYzDkkgAEmrcNzFCiYo6L1dTX4EAG1gZkbtdbd9trL4vd/go-multiaddr" ggio "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/io" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" - host "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/host" - inet "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/net" ) var log = logging.Logger("bitswap_network") diff --git a/exchange/bitswap/notifications/notifications.go b/exchange/bitswap/notifications/notifications.go index 0b7f4f33a78..4e440b490b3 100644 --- a/exchange/bitswap/notifications/notifications.go +++ b/exchange/bitswap/notifications/notifications.go @@ -3,8 +3,8 @@ package notifications import ( pubsub "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/briantigerchow/pubsub" blocks "github.com/ipfs/go-ipfs/blocks" - key "github.com/ipfs/go-ipfs/blocks/key" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) const bufferSize = 16 diff --git a/exchange/bitswap/notifications/notifications_test.go b/exchange/bitswap/notifications/notifications_test.go index 3e923b84ef7..84319f81f71 100644 --- a/exchange/bitswap/notifications/notifications_test.go +++ b/exchange/bitswap/notifications/notifications_test.go @@ -7,8 +7,8 @@ import ( blocks "github.com/ipfs/go-ipfs/blocks" blocksutil "github.com/ipfs/go-ipfs/blocks/blocksutil" - key "github.com/ipfs/go-ipfs/blocks/key" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) func TestDuplicates(t *testing.T) { diff --git a/exchange/bitswap/stat.go b/exchange/bitswap/stat.go index 956a4c5b71e..ff201c3aefa 100644 --- a/exchange/bitswap/stat.go +++ b/exchange/bitswap/stat.go @@ -1,7 +1,7 @@ package bitswap import ( - key "github.com/ipfs/go-ipfs/blocks/key" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" "sort" ) diff --git a/exchange/bitswap/testnet/interface.go b/exchange/bitswap/testnet/interface.go index 0378cc9949b..d2c7a5b49cb 100644 --- a/exchange/bitswap/testnet/interface.go +++ b/exchange/bitswap/testnet/interface.go @@ -2,8 +2,8 @@ package bitswap import ( bsnet "github.com/ipfs/go-ipfs/exchange/bitswap/network" - "github.com/ipfs/go-ipfs/thirdparty/testutil" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" + "gx/ipfs/QmYpVUnnedgGrp6cX2pBii5HRQgcSr778FiKVe7o7nF5Z3/go-testutil" ) type Network interface { diff --git a/exchange/bitswap/testnet/network_test.go b/exchange/bitswap/testnet/network_test.go index 077c220e05b..7d5fccafe09 100644 --- a/exchange/bitswap/testnet/network_test.go +++ b/exchange/bitswap/testnet/network_test.go @@ -9,8 +9,8 @@ import ( bsnet "github.com/ipfs/go-ipfs/exchange/bitswap/network" mockrouting "github.com/ipfs/go-ipfs/routing/mock" delay "github.com/ipfs/go-ipfs/thirdparty/delay" - testutil "github.com/ipfs/go-ipfs/thirdparty/testutil" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" + testutil "gx/ipfs/QmYpVUnnedgGrp6cX2pBii5HRQgcSr778FiKVe7o7nF5Z3/go-testutil" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" ) diff --git a/exchange/bitswap/testnet/peernet.go b/exchange/bitswap/testnet/peernet.go index eb692fe7a8a..cbb157b6b45 100644 --- a/exchange/bitswap/testnet/peernet.go +++ b/exchange/bitswap/testnet/peernet.go @@ -3,11 +3,11 @@ package bitswap import ( bsnet "github.com/ipfs/go-ipfs/exchange/bitswap/network" mockrouting "github.com/ipfs/go-ipfs/routing/mock" - testutil "github.com/ipfs/go-ipfs/thirdparty/testutil" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + mockpeernet "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/net/mock" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" + testutil "gx/ipfs/QmYpVUnnedgGrp6cX2pBii5HRQgcSr778FiKVe7o7nF5Z3/go-testutil" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" - mockpeernet "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/net/mock" + ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" ) type peernet struct { diff --git a/exchange/bitswap/testnet/virtual.go b/exchange/bitswap/testnet/virtual.go index e442903137b..230eae2b65a 100644 --- a/exchange/bitswap/testnet/virtual.go +++ b/exchange/bitswap/testnet/virtual.go @@ -3,15 +3,15 @@ package bitswap import ( "errors" - key "github.com/ipfs/go-ipfs/blocks/key" bsmsg "github.com/ipfs/go-ipfs/exchange/bitswap/message" bsnet "github.com/ipfs/go-ipfs/exchange/bitswap/network" - routing "github.com/ipfs/go-ipfs/routing" mockrouting "github.com/ipfs/go-ipfs/routing/mock" delay "github.com/ipfs/go-ipfs/thirdparty/delay" - testutil "github.com/ipfs/go-ipfs/thirdparty/testutil" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" + routing "gx/ipfs/QmYQadj3iegqmRPWjaWMRc8DG52hZa2HMkmyPkto5chDvs/go-libp2p-routing" + testutil "gx/ipfs/QmYpVUnnedgGrp6cX2pBii5HRQgcSr778FiKVe7o7nF5Z3/go-testutil" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) func VirtualNetwork(rs mockrouting.Server, d delay.D) Network { diff --git a/exchange/bitswap/testutils.go b/exchange/bitswap/testutils.go index 16b9d4d2054..abdc23b8022 100644 --- a/exchange/bitswap/testutils.go +++ b/exchange/bitswap/testutils.go @@ -7,12 +7,12 @@ import ( tn "github.com/ipfs/go-ipfs/exchange/bitswap/testnet" datastore2 "github.com/ipfs/go-ipfs/thirdparty/datastore2" delay "github.com/ipfs/go-ipfs/thirdparty/delay" - testutil "github.com/ipfs/go-ipfs/thirdparty/testutil" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - ds_sync "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/sync" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + p2ptestutil "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/test/util" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" + testutil "gx/ipfs/QmYpVUnnedgGrp6cX2pBii5HRQgcSr778FiKVe7o7nF5Z3/go-testutil" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" - p2ptestutil "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/test/util" + ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + ds_sync "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/sync" ) // WARNING: this uses RandTestBogusIdentity DO NOT USE for NON TESTS! diff --git a/exchange/bitswap/wantlist/wantlist.go b/exchange/bitswap/wantlist/wantlist.go index 77b959a65e2..2fcaf0c2909 100644 --- a/exchange/bitswap/wantlist/wantlist.go +++ b/exchange/bitswap/wantlist/wantlist.go @@ -6,7 +6,7 @@ import ( "sort" "sync" - key "github.com/ipfs/go-ipfs/blocks/key" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" ) diff --git a/exchange/bitswap/wantmanager.go b/exchange/bitswap/wantmanager.go index 47ea7ba35ea..189c2e38e32 100644 --- a/exchange/bitswap/wantmanager.go +++ b/exchange/bitswap/wantmanager.go @@ -4,13 +4,13 @@ import ( "sync" "time" - key "github.com/ipfs/go-ipfs/blocks/key" engine "github.com/ipfs/go-ipfs/exchange/bitswap/decision" bsmsg "github.com/ipfs/go-ipfs/exchange/bitswap/message" bsnet "github.com/ipfs/go-ipfs/exchange/bitswap/network" wantlist "github.com/ipfs/go-ipfs/exchange/bitswap/wantlist" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) type WantManager struct { diff --git a/exchange/bitswap/workers.go b/exchange/bitswap/workers.go index f6d2b912d97..f2c84aa7575 100644 --- a/exchange/bitswap/workers.go +++ b/exchange/bitswap/workers.go @@ -4,14 +4,14 @@ import ( "sync" "time" - process "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess" - procctx "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess/context" + process "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess" + procctx "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess/context" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" - key "github.com/ipfs/go-ipfs/blocks/key" wantlist "github.com/ipfs/go-ipfs/exchange/bitswap/wantlist" logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) var TaskWorkerCount = 8 diff --git a/exchange/interface.go b/exchange/interface.go index 6db476d9ec2..bd482cabb3e 100644 --- a/exchange/interface.go +++ b/exchange/interface.go @@ -5,8 +5,8 @@ import ( "io" blocks "github.com/ipfs/go-ipfs/blocks" - key "github.com/ipfs/go-ipfs/blocks/key" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) // Any type that implements exchange.Interface may be used as an IPFS block diff --git a/exchange/offline/offline.go b/exchange/offline/offline.go index d2ee4fbaa64..198677c93d4 100644 --- a/exchange/offline/offline.go +++ b/exchange/offline/offline.go @@ -5,9 +5,9 @@ package offline import ( blocks "github.com/ipfs/go-ipfs/blocks" "github.com/ipfs/go-ipfs/blocks/blockstore" - key "github.com/ipfs/go-ipfs/blocks/key" exchange "github.com/ipfs/go-ipfs/exchange" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) func Exchange(bs blockstore.Blockstore) exchange.Interface { diff --git a/exchange/offline/offline_test.go b/exchange/offline/offline_test.go index 6f1687586b3..8eaf751441c 100644 --- a/exchange/offline/offline_test.go +++ b/exchange/offline/offline_test.go @@ -6,10 +6,10 @@ import ( blocks "github.com/ipfs/go-ipfs/blocks" "github.com/ipfs/go-ipfs/blocks/blockstore" "github.com/ipfs/go-ipfs/blocks/blocksutil" - key "github.com/ipfs/go-ipfs/blocks/key" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - ds_sync "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/sync" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + ds_sync "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/sync" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) func TestBlockReturnsErr(t *testing.T) { diff --git a/exchange/reprovide/reprovide.go b/exchange/reprovide/reprovide.go index 93125d0adff..d2bdc2f4633 100644 --- a/exchange/reprovide/reprovide.go +++ b/exchange/reprovide/reprovide.go @@ -5,9 +5,9 @@ import ( "time" blocks "github.com/ipfs/go-ipfs/blocks/blockstore" - routing "github.com/ipfs/go-ipfs/routing" backoff "gx/ipfs/QmPJUtEJsm5YLUWhF6imvyCH8KZXRJa9Wup7FDMwTy5Ufz/backoff" logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" + routing "gx/ipfs/QmYQadj3iegqmRPWjaWMRc8DG52hZa2HMkmyPkto5chDvs/go-libp2p-routing" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" ) diff --git a/exchange/reprovide/reprovide_test.go b/exchange/reprovide/reprovide_test.go index 03440d38f96..aec5c69734b 100644 --- a/exchange/reprovide/reprovide_test.go +++ b/exchange/reprovide/reprovide_test.go @@ -6,10 +6,10 @@ import ( blocks "github.com/ipfs/go-ipfs/blocks" blockstore "github.com/ipfs/go-ipfs/blocks/blockstore" mock "github.com/ipfs/go-ipfs/routing/mock" - testutil "github.com/ipfs/go-ipfs/thirdparty/testutil" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - dssync "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/sync" + testutil "gx/ipfs/QmYpVUnnedgGrp6cX2pBii5HRQgcSr778FiKVe7o7nF5Z3/go-testutil" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + dssync "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/sync" . "github.com/ipfs/go-ipfs/exchange/reprovide" ) diff --git a/fuse/ipns/ipns_test.go b/fuse/ipns/ipns_test.go index 9f1b8080830..ad90d7fbd95 100644 --- a/fuse/ipns/ipns_test.go +++ b/fuse/ipns/ipns_test.go @@ -17,7 +17,7 @@ import ( core "github.com/ipfs/go-ipfs/core" namesys "github.com/ipfs/go-ipfs/namesys" offroute "github.com/ipfs/go-ipfs/routing/offline" - ci "github.com/ipfs/go-ipfs/thirdparty/testutil/ci" + ci "gx/ipfs/QmYpVUnnedgGrp6cX2pBii5HRQgcSr778FiKVe7o7nF5Z3/go-testutil/ci" u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" ) diff --git a/fuse/ipns/ipns_unix.go b/fuse/ipns/ipns_unix.go index 4e2e302f24f..6fb47ef656a 100644 --- a/fuse/ipns/ipns_unix.go +++ b/fuse/ipns/ipns_unix.go @@ -14,13 +14,13 @@ import ( logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" - key "github.com/ipfs/go-ipfs/blocks/key" core "github.com/ipfs/go-ipfs/core" dag "github.com/ipfs/go-ipfs/merkledag" mfs "github.com/ipfs/go-ipfs/mfs" path "github.com/ipfs/go-ipfs/path" ft "github.com/ipfs/go-ipfs/unixfs" ci "gx/ipfs/QmVoi5es8D5fNHZDqoW6DgDAEPEV5hQp8GBz161vZXiwpQ/go-libp2p-crypto" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) func init() { diff --git a/fuse/mount/fuse.go b/fuse/mount/fuse.go index a09ec8b6512..5308878ea83 100644 --- a/fuse/mount/fuse.go +++ b/fuse/mount/fuse.go @@ -12,7 +12,7 @@ import ( "github.com/ipfs/go-ipfs/Godeps/_workspace/src/bazil.org/fuse" "github.com/ipfs/go-ipfs/Godeps/_workspace/src/bazil.org/fuse/fs" - goprocess "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess" + goprocess "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess" ) var ErrNotMounted = errors.New("not mounted") diff --git a/fuse/mount/mount.go b/fuse/mount/mount.go index 758aa30f95c..82ccde319b2 100644 --- a/fuse/mount/mount.go +++ b/fuse/mount/mount.go @@ -8,7 +8,7 @@ import ( "runtime" "time" - goprocess "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess" + goprocess "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess" logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" ) diff --git a/fuse/node/mount_test.go b/fuse/node/mount_test.go index b6fdee4446a..2a32a47604b 100644 --- a/fuse/node/mount_test.go +++ b/fuse/node/mount_test.go @@ -14,7 +14,7 @@ import ( mount "github.com/ipfs/go-ipfs/fuse/mount" namesys "github.com/ipfs/go-ipfs/namesys" offroute "github.com/ipfs/go-ipfs/routing/offline" - ci "github.com/ipfs/go-ipfs/thirdparty/testutil/ci" + ci "gx/ipfs/QmYpVUnnedgGrp6cX2pBii5HRQgcSr778FiKVe7o7nF5Z3/go-testutil/ci" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" ) diff --git a/fuse/readonly/ipfs_test.go b/fuse/readonly/ipfs_test.go index 3a778752177..1f85c4fc04d 100644 --- a/fuse/readonly/ipfs_test.go +++ b/fuse/readonly/ipfs_test.go @@ -15,16 +15,16 @@ import ( fstest "github.com/ipfs/go-ipfs/Godeps/_workspace/src/bazil.org/fuse/fs/fstestutil" - key "github.com/ipfs/go-ipfs/blocks/key" core "github.com/ipfs/go-ipfs/core" coreunix "github.com/ipfs/go-ipfs/core/coreunix" coremock "github.com/ipfs/go-ipfs/core/mock" importer "github.com/ipfs/go-ipfs/importer" chunk "github.com/ipfs/go-ipfs/importer/chunk" dag "github.com/ipfs/go-ipfs/merkledag" - ci "github.com/ipfs/go-ipfs/thirdparty/testutil/ci" uio "github.com/ipfs/go-ipfs/unixfs/io" + ci "gx/ipfs/QmYpVUnnedgGrp6cX2pBii5HRQgcSr778FiKVe7o7nF5Z3/go-testutil/ci" u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) func maybeSkipFuseTests(t *testing.T) { diff --git a/fuse/readonly/readonly_unix.go b/fuse/readonly/readonly_unix.go index 3333a41d447..356d3822efb 100644 --- a/fuse/readonly/readonly_unix.go +++ b/fuse/readonly/readonly_unix.go @@ -14,10 +14,10 @@ import ( core "github.com/ipfs/go-ipfs/core" mdag "github.com/ipfs/go-ipfs/merkledag" path "github.com/ipfs/go-ipfs/path" - lgbl "github.com/ipfs/go-ipfs/thirdparty/loggables" uio "github.com/ipfs/go-ipfs/unixfs/io" ftpb "github.com/ipfs/go-ipfs/unixfs/pb" logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" + lgbl "gx/ipfs/QmYrv4LgCC8FhG2Ab4bwuq5DqBdwMtx3hMb3KKJDZcr2d7/go-libp2p-loggables" proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto" "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" ) diff --git a/importer/chunk/rabin_test.go b/importer/chunk/rabin_test.go index 9b9cfce8fd9..99b1bad5887 100644 --- a/importer/chunk/rabin_test.go +++ b/importer/chunk/rabin_test.go @@ -4,8 +4,8 @@ import ( "bytes" "fmt" "github.com/ipfs/go-ipfs/blocks" - "github.com/ipfs/go-ipfs/blocks/key" "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" + "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" "io" "testing" ) diff --git a/merkledag/merkledag.go b/merkledag/merkledag.go index 7d601d86d38..6593cc60a86 100644 --- a/merkledag/merkledag.go +++ b/merkledag/merkledag.go @@ -7,10 +7,10 @@ import ( "sync" blocks "github.com/ipfs/go-ipfs/blocks" - key "github.com/ipfs/go-ipfs/blocks/key" bserv "github.com/ipfs/go-ipfs/blockservice" logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) var log = logging.Logger("merkledag") diff --git a/merkledag/merkledag_test.go b/merkledag/merkledag_test.go index 38545ac126f..8866bce8504 100644 --- a/merkledag/merkledag_test.go +++ b/merkledag/merkledag_test.go @@ -10,7 +10,6 @@ import ( "sync" "testing" - key "github.com/ipfs/go-ipfs/blocks/key" bserv "github.com/ipfs/go-ipfs/blockservice" bstest "github.com/ipfs/go-ipfs/blockservice/test" offline "github.com/ipfs/go-ipfs/exchange/offline" @@ -22,6 +21,7 @@ import ( uio "github.com/ipfs/go-ipfs/unixfs/io" u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) func TestNode(t *testing.T) { diff --git a/merkledag/node.go b/merkledag/node.go index 7be5c4d0a83..81d6e7e3b55 100644 --- a/merkledag/node.go +++ b/merkledag/node.go @@ -5,8 +5,8 @@ import ( "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" - key "github.com/ipfs/go-ipfs/blocks/key" mh "gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) var ErrLinkNotFound = fmt.Errorf("no link by that name") diff --git a/merkledag/test/utils.go b/merkledag/test/utils.go index 59bbd497951..1475a6f8438 100644 --- a/merkledag/test/utils.go +++ b/merkledag/test/utils.go @@ -5,8 +5,8 @@ import ( bsrv "github.com/ipfs/go-ipfs/blockservice" "github.com/ipfs/go-ipfs/exchange/offline" dag "github.com/ipfs/go-ipfs/merkledag" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - dssync "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/sync" + ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + dssync "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/sync" ) func Mock() dag.DAGService { diff --git a/merkledag/utils/diff.go b/merkledag/utils/diff.go index 493394437be..153615dae27 100644 --- a/merkledag/utils/diff.go +++ b/merkledag/utils/diff.go @@ -5,9 +5,9 @@ import ( "fmt" "path" - key "github.com/ipfs/go-ipfs/blocks/key" dag "github.com/ipfs/go-ipfs/merkledag" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) const ( diff --git a/merkledag/utils/utils.go b/merkledag/utils/utils.go index a1e4125f7e1..5f795006ba4 100644 --- a/merkledag/utils/utils.go +++ b/merkledag/utils/utils.go @@ -3,9 +3,9 @@ package dagutils import ( "errors" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - syncds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/sync" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + syncds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/sync" bstore "github.com/ipfs/go-ipfs/blocks/blockstore" bserv "github.com/ipfs/go-ipfs/blockservice" diff --git a/merkledag/utils/utils_test.go b/merkledag/utils/utils_test.go index 1ec444b0ba1..e2128292570 100644 --- a/merkledag/utils/utils_test.go +++ b/merkledag/utils/utils_test.go @@ -3,10 +3,10 @@ package dagutils import ( "testing" - key "github.com/ipfs/go-ipfs/blocks/key" dag "github.com/ipfs/go-ipfs/merkledag" mdtest "github.com/ipfs/go-ipfs/merkledag/test" path "github.com/ipfs/go-ipfs/path" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" ) diff --git a/mfs/mfs_test.go b/mfs/mfs_test.go index f4aba72cbe8..5bdca0cf75c 100644 --- a/mfs/mfs_test.go +++ b/mfs/mfs_test.go @@ -14,7 +14,6 @@ import ( "time" bstore "github.com/ipfs/go-ipfs/blocks/blockstore" - key "github.com/ipfs/go-ipfs/blocks/key" bserv "github.com/ipfs/go-ipfs/blockservice" offline "github.com/ipfs/go-ipfs/exchange/offline" importer "github.com/ipfs/go-ipfs/importer" @@ -23,11 +22,12 @@ import ( "github.com/ipfs/go-ipfs/path" ft "github.com/ipfs/go-ipfs/unixfs" uio "github.com/ipfs/go-ipfs/unixfs/io" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - dssync "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/sync" u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + dssync "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/sync" ) func emptyDirNode() *dag.Node { diff --git a/mfs/repub_test.go b/mfs/repub_test.go index 32e0b2b27be..2cf5d117d2b 100644 --- a/mfs/repub_test.go +++ b/mfs/repub_test.go @@ -4,8 +4,8 @@ import ( "testing" "time" - key "github.com/ipfs/go-ipfs/blocks/key" - ci "github.com/ipfs/go-ipfs/thirdparty/testutil/ci" + ci "gx/ipfs/QmYpVUnnedgGrp6cX2pBii5HRQgcSr778FiKVe7o7nF5Z3/go-testutil/ci" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" ) diff --git a/mfs/system.go b/mfs/system.go index 56891cc215b..c9780323bdb 100644 --- a/mfs/system.go +++ b/mfs/system.go @@ -14,9 +14,9 @@ import ( "sync" "time" - key "github.com/ipfs/go-ipfs/blocks/key" dag "github.com/ipfs/go-ipfs/merkledag" ft "github.com/ipfs/go-ipfs/unixfs" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" diff --git a/namesys/namesys.go b/namesys/namesys.go index 699cc5327ad..6f5105aa524 100644 --- a/namesys/namesys.go +++ b/namesys/namesys.go @@ -5,10 +5,10 @@ import ( "time" path "github.com/ipfs/go-ipfs/path" - routing "github.com/ipfs/go-ipfs/routing" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" ci "gx/ipfs/QmVoi5es8D5fNHZDqoW6DgDAEPEV5hQp8GBz161vZXiwpQ/go-libp2p-crypto" + routing "gx/ipfs/QmYQadj3iegqmRPWjaWMRc8DG52hZa2HMkmyPkto5chDvs/go-libp2p-routing" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" ) // mpns (a multi-protocol NameSystem) implements generic IPFS naming. diff --git a/namesys/publisher.go b/namesys/publisher.go index 77604ae9558..cba844b9e88 100644 --- a/namesys/publisher.go +++ b/namesys/publisher.go @@ -6,22 +6,22 @@ import ( "fmt" "time" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" - key "github.com/ipfs/go-ipfs/blocks/key" dag "github.com/ipfs/go-ipfs/merkledag" pb "github.com/ipfs/go-ipfs/namesys/pb" path "github.com/ipfs/go-ipfs/path" pin "github.com/ipfs/go-ipfs/pin" - routing "github.com/ipfs/go-ipfs/routing" - dhtpb "github.com/ipfs/go-ipfs/routing/dht/pb" - record "github.com/ipfs/go-ipfs/routing/record" ft "github.com/ipfs/go-ipfs/unixfs" ci "gx/ipfs/QmVoi5es8D5fNHZDqoW6DgDAEPEV5hQp8GBz161vZXiwpQ/go-libp2p-crypto" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" + routing "gx/ipfs/QmYQadj3iegqmRPWjaWMRc8DG52hZa2HMkmyPkto5chDvs/go-libp2p-routing" u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" + record "gx/ipfs/Qme7D9iKHYxwq28p6PzCymywsYSRBx9uyGzW7qNB3s9VbC/go-libp2p-record" + recpb "gx/ipfs/Qme7D9iKHYxwq28p6PzCymywsYSRBx9uyGzW7qNB3s9VbC/go-libp2p-record/pb" ) // ErrExpiredRecord should be returned when an ipns record is @@ -91,7 +91,7 @@ func (p *ipnsPublisher) getPreviousSeqNo(ctx context.Context, ipnskey key.Key) ( if !ok { return 0, fmt.Errorf("unexpected type returned from datastore: %#v", prevrec) } - dhtrec := new(dhtpb.Record) + dhtrec := new(recpb.Record) err := proto.Unmarshal(prbytes, dhtrec) if err != nil { return 0, err diff --git a/namesys/republisher/repub.go b/namesys/republisher/repub.go index 91228ea5231..c89d95084fd 100644 --- a/namesys/republisher/repub.go +++ b/namesys/republisher/repub.go @@ -5,21 +5,21 @@ import ( "sync" "time" - key "github.com/ipfs/go-ipfs/blocks/key" namesys "github.com/ipfs/go-ipfs/namesys" pb "github.com/ipfs/go-ipfs/namesys/pb" path "github.com/ipfs/go-ipfs/path" - "github.com/ipfs/go-ipfs/routing" - dhtpb "github.com/ipfs/go-ipfs/routing/dht/pb" + "gx/ipfs/QmYQadj3iegqmRPWjaWMRc8DG52hZa2HMkmyPkto5chDvs/go-libp2p-routing" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" + recpb "gx/ipfs/Qme7D9iKHYxwq28p6PzCymywsYSRBx9uyGzW7qNB3s9VbC/go-libp2p-record/pb" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - goprocess "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess" - gpctx "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess/context" - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" + goprocess "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess" + gpctx "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess/context" logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" + pstore "gx/ipfs/QmXhhVSpXMUjpf9XgQDyePxug2iHm8ZvZD99aA9N6kuqMN/go-libp2p-peerstore" proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" ) var errNoEntry = errors.New("no previous entry") @@ -115,7 +115,7 @@ func (rp *Republisher) getLastVal(k key.Key) (path.Path, uint64, error) { } val := ival.([]byte) - dhtrec := new(dhtpb.Record) + dhtrec := new(recpb.Record) err = proto.Unmarshal(val, dhtrec) if err != nil { return "", 0, err diff --git a/namesys/republisher/repub_test.go b/namesys/republisher/repub_test.go index be54999eb32..68aa0b403ab 100644 --- a/namesys/republisher/repub_test.go +++ b/namesys/republisher/repub_test.go @@ -5,7 +5,7 @@ import ( "testing" "time" - goprocess "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess" + goprocess "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" "github.com/ipfs/go-ipfs/core" @@ -13,8 +13,8 @@ import ( namesys "github.com/ipfs/go-ipfs/namesys" . "github.com/ipfs/go-ipfs/namesys/republisher" path "github.com/ipfs/go-ipfs/path" - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" - mocknet "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/net/mock" + mocknet "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/net/mock" + pstore "gx/ipfs/QmXhhVSpXMUjpf9XgQDyePxug2iHm8ZvZD99aA9N6kuqMN/go-libp2p-peerstore" ) func TestRepublish(t *testing.T) { diff --git a/namesys/resolve_test.go b/namesys/resolve_test.go index 57e08ccdbcb..1d4f8bc4aee 100644 --- a/namesys/resolve_test.go +++ b/namesys/resolve_test.go @@ -5,15 +5,15 @@ import ( "testing" "time" - key "github.com/ipfs/go-ipfs/blocks/key" path "github.com/ipfs/go-ipfs/path" mockrouting "github.com/ipfs/go-ipfs/routing/mock" - testutil "github.com/ipfs/go-ipfs/thirdparty/testutil" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - dssync "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/sync" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" + testutil "gx/ipfs/QmYpVUnnedgGrp6cX2pBii5HRQgcSr778FiKVe7o7nF5Z3/go-testutil" u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + dssync "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/sync" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) func TestRoutingResolve(t *testing.T) { diff --git a/namesys/routing.go b/namesys/routing.go index d2c4fda1101..4ac3379ed18 100644 --- a/namesys/routing.go +++ b/namesys/routing.go @@ -10,13 +10,13 @@ import ( proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto" "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" - key "github.com/ipfs/go-ipfs/blocks/key" pb "github.com/ipfs/go-ipfs/namesys/pb" path "github.com/ipfs/go-ipfs/path" - routing "github.com/ipfs/go-ipfs/routing" logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" ci "gx/ipfs/QmVoi5es8D5fNHZDqoW6DgDAEPEV5hQp8GBz161vZXiwpQ/go-libp2p-crypto" + routing "gx/ipfs/QmYQadj3iegqmRPWjaWMRc8DG52hZa2HMkmyPkto5chDvs/go-libp2p-routing" u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) var log = logging.Logger("namesys") diff --git a/notifications/query.go b/notifications/query.go deleted file mode 100644 index 0fd35ccb771..00000000000 --- a/notifications/query.go +++ /dev/null @@ -1,85 +0,0 @@ -package notifications - -import ( - "encoding/json" - - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" - context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" -) - -const RoutingQueryKey = "RoutingQueryEvent" - -type QueryEventType int - -const ( - SendingQuery QueryEventType = iota - PeerResponse - FinalPeer - QueryError - Provider - Value - AddingPeer - DialingPeer -) - -type QueryEvent struct { - ID peer.ID - Type QueryEventType - Responses []*pstore.PeerInfo - Extra string -} - -func RegisterForQueryEvents(ctx context.Context, ch chan<- *QueryEvent) context.Context { - return context.WithValue(ctx, RoutingQueryKey, ch) -} - -func PublishQueryEvent(ctx context.Context, ev *QueryEvent) { - ich := ctx.Value(RoutingQueryKey) - if ich == nil { - return - } - - ch, ok := ich.(chan<- *QueryEvent) - if !ok { - return - } - - select { - case ch <- ev: - case <-ctx.Done(): - } -} - -func (qe *QueryEvent) MarshalJSON() ([]byte, error) { - out := make(map[string]interface{}) - out["ID"] = peer.IDB58Encode(qe.ID) - out["Type"] = int(qe.Type) - out["Responses"] = qe.Responses - out["Extra"] = qe.Extra - return json.Marshal(out) -} - -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/package.json b/package.json index 7a9bee150c6..46cc6503777 100644 --- a/package.json +++ b/package.json @@ -14,9 +14,9 @@ }, { "author": "whyrusleeping", - "hash": "QmbP93111oShRbdjoWvP3NZCUApTLkaPXgaNDaXZPfHQHR", + "hash": "QmbnPJidHfeekkdLkoboBooA56KB92cT8csDmJwCc2bQJ1", "name": "go-libp2p-secio", - "version": "1.0.11" + "version": "1.0.12" }, { "author": "whyrusleeping", @@ -24,21 +24,15 @@ "name": "go-libp2p-crypto", "version": "1.0.4" }, - { - "author": "whyrusleeping", - "hash": "QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8", - "name": "go-libp2p-peer", - "version": "2.0.3" - }, { "hash": "QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt", "name": "go-net", "version": "0.0.0" }, { - "hash": "QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn", + "hash": "QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP", "name": "goprocess", - "version": "0.0.0" + "version": "1.0.0" }, { "hash": "QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV", @@ -134,9 +128,9 @@ }, { "author": "jbenet", - "hash": "QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp", + "hash": "QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU", "name": "go-datastore", - "version": "0.2.1" + "version": "1.0.0" }, { "author": "codahale", @@ -158,9 +152,9 @@ }, { "author": "whyrusleeping", - "hash": "QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d", + "hash": "QmXhhVSpXMUjpf9XgQDyePxug2iHm8ZvZD99aA9N6kuqMN", "name": "go-libp2p-peerstore", - "version": "1.2.2" + "version": "1.2.3" }, { "author": "whyrusleeping", @@ -176,9 +170,9 @@ }, { "author": "whyrusleeping", - "hash": "QmcRHLm2aqDabkpcto1NzLad7YQhH99MGDHSWWvwMxKiZw", + "hash": "QmSp3diFRRv4zR25nHU4MWNCdhT4R6cxrTPLx12MCi1TZb", "name": "autobatch", - "version": "0.2.1" + "version": "0.2.2" }, { "author": "jbenet", @@ -188,21 +182,93 @@ }, { "author": "whyrusleeping", - "hash": "QmV71dCdjYivZwta22a7YvNmeS86r1EpnBjq9XAD21rBV9", + "hash": "QmPF5kxTYFkzhaY5LmkExood7aTTZBHWQC6cjdDQBuGrjp", "name": "retry-datastore", - "version": "1.1.1" + "version": "1.1.2" }, { "author": "whyrusleeping", - "hash": "QmQzoB7kvw15FiCBpsYhu96wyweGTwCSNXcaNtwUefy9kE", + "hash": "QmUtQ7vagCwHfEaCssxWzSShgrk6uA3Rx5t2E4R5aoLckg", "name": "failstore", - "version": "1.0.1" + "version": "1.0.2" }, { "author": "whyrusleeping", - "hash": "Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS", + "hash": "QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t", "name": "go-libp2p", - "version": "3.4.1" + "version": "3.4.2" + }, + { + "author": "whyrusleeping", + "hash": "QmSXEMQ9yXxVm84YNXXyyDzu5gyHa3K8FYSfwzPjNXSfHq", + "name": "go-libp2p-kad-dht", + "version": "1.0.1" + }, + { + "author": "whyrusleeping", + "hash": "Qmc5r13R4j3V75ucMkGzHimsQDgkg4aUanX5upcUWns7XM", + "name": "go-libp2p-kbucket", + "version": "1.0.1" + }, + { + "author": "whyrusleeping", + "hash": "Qme7D9iKHYxwq28p6PzCymywsYSRBx9uyGzW7qNB3s9VbC", + "name": "go-libp2p-record", + "version": "1.0.1" + }, + { + "author": "whyrusleeping", + "hash": "QmYQadj3iegqmRPWjaWMRc8DG52hZa2HMkmyPkto5chDvs", + "name": "go-libp2p-routing", + "version": "1.0.1" + }, + { + "author": "whyrusleeping", + "hash": "QmYrv4LgCC8FhG2Ab4bwuq5DqBdwMtx3hMb3KKJDZcr2d7", + "name": "go-libp2p-loggables", + "version": "1.0.11" + }, + { + "author": "whyrusleeping", + "hash": "QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p", + "name": "go-libp2p-peer", + "version": "2.0.4" + }, + { + "author": "whyrusleeping", + "hash": "QmYpVUnnedgGrp6cX2pBii5HRQgcSr778FiKVe7o7nF5Z3", + "name": "go-testutil", + "version": "1.0.2" + }, + { + "author": "whyrusleeping", + "hash": "QmQNQhNmY4STU1MURjH9vYEMpx2ncMS4gbwxXWtrEjzVAq", + "name": "go-todocounter", + "version": "1.0.1" + }, + { + "author": "whyrusleeping", + "hash": "Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew", + "name": "go-key", + "version": "1.0.2" + }, + { + "author": "whyrusleeping", + "hash": "QmU4VzzKNLJXJ72SedXBQKyf5Jo8W89iWpbWQjHn9qef8N", + "name": "go-ds-flatfs", + "version": "1.0.0" + }, + { + "author": "whyrusleeping", + "hash": "QmeqtHtxGfcsfXiou7wqHJARWPKUTUcPdtSfSYYHp48dtQ", + "name": "go-ds-measure", + "version": "1.0.1" + }, + { + "author": "whyrusleeping", + "hash": "QmUHmMGmcwCrjHQHcYhBnqGCSWs5pBSMbGZmfwavETR1gg", + "name": "go-ds-leveldb", + "version": "1.0.0" } ], "gxVersion": "0.4.0", diff --git a/path/path.go b/path/path.go index 790168de092..f5018fb8091 100644 --- a/path/path.go +++ b/path/path.go @@ -5,7 +5,7 @@ import ( "path" "strings" - key "github.com/ipfs/go-ipfs/blocks/key" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" b58 "gx/ipfs/QmT8rehPR3F6bmwL6zjUN8XpiDBFFpMP2myPdC6ApsWfJf/go-base58" mh "gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash" diff --git a/path/resolver.go b/path/resolver.go index a254f456c13..aab6b350a9f 100644 --- a/path/resolver.go +++ b/path/resolver.go @@ -9,9 +9,9 @@ import ( mh "gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash" "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" - key "github.com/ipfs/go-ipfs/blocks/key" merkledag "github.com/ipfs/go-ipfs/merkledag" logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) var log = logging.Logger("path") diff --git a/path/resolver_test.go b/path/resolver_test.go index 735a79e6d2b..8111c393292 100644 --- a/path/resolver_test.go +++ b/path/resolver_test.go @@ -6,11 +6,11 @@ import ( context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" - key "github.com/ipfs/go-ipfs/blocks/key" merkledag "github.com/ipfs/go-ipfs/merkledag" dagmock "github.com/ipfs/go-ipfs/merkledag/test" path "github.com/ipfs/go-ipfs/path" util "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) func randNode() (*merkledag.Node, key.Key) { diff --git a/pin/gc/gc.go b/pin/gc/gc.go index 0eb87f867e9..4b1d79c492f 100644 --- a/pin/gc/gc.go +++ b/pin/gc/gc.go @@ -2,11 +2,11 @@ package gc import ( bstore "github.com/ipfs/go-ipfs/blocks/blockstore" - key "github.com/ipfs/go-ipfs/blocks/key" bserv "github.com/ipfs/go-ipfs/blockservice" offline "github.com/ipfs/go-ipfs/exchange/offline" dag "github.com/ipfs/go-ipfs/merkledag" pin "github.com/ipfs/go-ipfs/pin" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" diff --git a/pin/indirect.go b/pin/indirect.go index 22e3a1fb47c..a837d60fd03 100644 --- a/pin/indirect.go +++ b/pin/indirect.go @@ -1,7 +1,7 @@ package pin import ( - key "github.com/ipfs/go-ipfs/blocks/key" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) type indirectPin struct { diff --git a/pin/pin.go b/pin/pin.go index d034cbc43bb..9c4c1b01916 100644 --- a/pin/pin.go +++ b/pin/pin.go @@ -7,12 +7,12 @@ import ( "sync" "time" - key "github.com/ipfs/go-ipfs/blocks/key" "github.com/ipfs/go-ipfs/blocks/set" mdag "github.com/ipfs/go-ipfs/merkledag" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) var log = logging.Logger("pin") diff --git a/pin/pin_test.go b/pin/pin_test.go index 91c6b8c0e90..7979c22da3b 100644 --- a/pin/pin_test.go +++ b/pin/pin_test.go @@ -7,13 +7,13 @@ import ( context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" "github.com/ipfs/go-ipfs/blocks/blockstore" - key "github.com/ipfs/go-ipfs/blocks/key" bs "github.com/ipfs/go-ipfs/blockservice" "github.com/ipfs/go-ipfs/exchange/offline" mdag "github.com/ipfs/go-ipfs/merkledag" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - dssync "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/sync" "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" + ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + dssync "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/sync" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) func randNode() (*mdag.Node, key.Key) { diff --git a/pin/set.go b/pin/set.go index 7257ccaecb9..60f54d4ac69 100644 --- a/pin/set.go +++ b/pin/set.go @@ -11,11 +11,11 @@ import ( "sort" "unsafe" - "github.com/ipfs/go-ipfs/blocks/key" "github.com/ipfs/go-ipfs/merkledag" "github.com/ipfs/go-ipfs/pin/internal/pb" "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto" "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) const ( diff --git a/pin/set_test.go b/pin/set_test.go index 83d65dd02fc..663c38ddcff 100644 --- a/pin/set_test.go +++ b/pin/set_test.go @@ -5,15 +5,15 @@ import ( "testing/quick" "github.com/ipfs/go-ipfs/blocks/blockstore" - "github.com/ipfs/go-ipfs/blocks/key" "github.com/ipfs/go-ipfs/blockservice" "github.com/ipfs/go-ipfs/exchange/offline" "github.com/ipfs/go-ipfs/merkledag" - "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - dssync "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/sync" mh "gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash" u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + dssync "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/sync" + "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) func ignoreKeys(key.Key) {} diff --git a/repo/config/init.go b/repo/config/init.go index d640b1b9c31..7e17faa0513 100644 --- a/repo/config/init.go +++ b/repo/config/init.go @@ -7,7 +7,7 @@ import ( "io" ci "gx/ipfs/QmVoi5es8D5fNHZDqoW6DgDAEPEV5hQp8GBz161vZXiwpQ/go-libp2p-crypto" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" ) func Init(out io.Writer, nBitsForKeypair int) (*Config, error) { diff --git a/repo/fsrepo/defaultds.go b/repo/fsrepo/defaultds.go index 375be683372..ed8fbafe702 100644 --- a/repo/fsrepo/defaultds.go +++ b/repo/fsrepo/defaultds.go @@ -7,12 +7,12 @@ import ( repo "github.com/ipfs/go-ipfs/repo" config "github.com/ipfs/go-ipfs/repo/config" "github.com/ipfs/go-ipfs/thirdparty/dir" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/flatfs" - levelds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/leveldb" - "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/measure" - mount "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/syncmount" + "gx/ipfs/QmU4VzzKNLJXJ72SedXBQKyf5Jo8W89iWpbWQjHn9qef8N/go-ds-flatfs" + levelds "gx/ipfs/QmUHmMGmcwCrjHQHcYhBnqGCSWs5pBSMbGZmfwavETR1gg/go-ds-leveldb" ldbopts "gx/ipfs/QmbBhyDKsY4mbY6xsKt3qu9Y7FPvMJ6qbD8AMjYYvPRw1g/goleveldb/leveldb/opt" + ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + mount "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/syncmount" + "gx/ipfs/QmeqtHtxGfcsfXiou7wqHJARWPKUTUcPdtSfSYYHp48dtQ/go-ds-measure" ) const ( diff --git a/repo/fsrepo/fsrepo.go b/repo/fsrepo/fsrepo.go index a491541cba7..0046f35dd83 100644 --- a/repo/fsrepo/fsrepo.go +++ b/repo/fsrepo/fsrepo.go @@ -18,9 +18,9 @@ import ( mfsr "github.com/ipfs/go-ipfs/repo/fsrepo/migrations" serialize "github.com/ipfs/go-ipfs/repo/fsrepo/serialize" dir "github.com/ipfs/go-ipfs/thirdparty/dir" - "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/measure" logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" util "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" + "gx/ipfs/QmeqtHtxGfcsfXiou7wqHJARWPKUTUcPdtSfSYYHp48dtQ/go-ds-measure" ) var log = logging.Logger("fsrepo") diff --git a/repo/fsrepo/fsrepo_test.go b/repo/fsrepo/fsrepo_test.go index 6de46dc0a3a..6696b9c82ef 100644 --- a/repo/fsrepo/fsrepo_test.go +++ b/repo/fsrepo/fsrepo_test.go @@ -9,7 +9,7 @@ import ( "github.com/ipfs/go-ipfs/repo/config" "github.com/ipfs/go-ipfs/thirdparty/assert" - datastore "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" + datastore "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" ) // swap arg order diff --git a/repo/repo.go b/repo/repo.go index 96864b64654..d95af0446dd 100644 --- a/repo/repo.go +++ b/repo/repo.go @@ -5,7 +5,7 @@ import ( "io" config "github.com/ipfs/go-ipfs/repo/config" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" + ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" ) var ( diff --git a/routing/dht/dht.go b/routing/dht/dht.go deleted file mode 100644 index 6de362e13cd..00000000000 --- a/routing/dht/dht.go +++ /dev/null @@ -1,340 +0,0 @@ -// Package dht implements a distributed hash table that satisfies the ipfs routing -// interface. This DHT is modeled after kademlia with Coral and S/Kademlia modifications. -package dht - -import ( - "bytes" - "errors" - "fmt" - "sync" - "time" - - key "github.com/ipfs/go-ipfs/blocks/key" - routing "github.com/ipfs/go-ipfs/routing" - pb "github.com/ipfs/go-ipfs/routing/dht/pb" - providers "github.com/ipfs/go-ipfs/routing/dht/providers" - kb "github.com/ipfs/go-ipfs/routing/kbucket" - record "github.com/ipfs/go-ipfs/routing/record" - - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - goprocess "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess" - goprocessctx "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess/context" - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" - logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" - ci "gx/ipfs/QmVoi5es8D5fNHZDqoW6DgDAEPEV5hQp8GBz161vZXiwpQ/go-libp2p-crypto" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" - proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto" - context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" - host "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/host" - protocol "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/protocol" -) - -var log = logging.Logger("dht") - -var ProtocolDHT protocol.ID = "/ipfs/dht" - -// NumBootstrapQueries defines the number of random dht queries to do to -// collect members of the routing table. -const NumBootstrapQueries = 5 - -// TODO. SEE https://github.com/jbenet/node-ipfs/blob/master/submodules/ipfs-dht/index.js - -// IpfsDHT is an implementation of Kademlia with Coral and S/Kademlia modifications. -// It is used to implement the base IpfsRouting module. -type IpfsDHT struct { - host host.Host // the network services we need - self peer.ID // Local peer (yourself) - peerstore pstore.Peerstore // Peer Registry - - datastore ds.Datastore // Local data - - routingTable *kb.RoutingTable // Array of routing tables for differently distanced nodes - providers *providers.ProviderManager - - birth time.Time // When this peer started up - diaglock sync.Mutex // lock to make diagnostics work better - - Validator record.Validator // record validator funcs - Selector record.Selector // record selection funcs - - ctx context.Context - proc goprocess.Process - - strmap map[peer.ID]*messageSender - smlk sync.Mutex -} - -// NewDHT creates a new DHT object with the given peer as the 'local' host -func NewDHT(ctx context.Context, h host.Host, dstore ds.Batching) *IpfsDHT { - dht := new(IpfsDHT) - dht.datastore = dstore - dht.self = h.ID() - dht.peerstore = h.Peerstore() - dht.host = h - - // register for network notifs. - dht.host.Network().Notify((*netNotifiee)(dht)) - - dht.proc = goprocess.WithTeardown(func() error { - // remove ourselves from network notifs. - dht.host.Network().StopNotify((*netNotifiee)(dht)) - return nil - }) - - dht.strmap = make(map[peer.ID]*messageSender) - dht.ctx = ctx - - h.SetStreamHandler(ProtocolDHT, dht.handleNewStream) - dht.providers = providers.NewProviderManager(dht.ctx, dht.self, dstore) - dht.proc.AddChild(dht.providers.Process()) - goprocessctx.CloseAfterContext(dht.proc, ctx) - - dht.routingTable = kb.NewRoutingTable(20, kb.ConvertPeerID(dht.self), time.Minute, dht.peerstore) - dht.birth = time.Now() - - dht.Validator = make(record.Validator) - dht.Validator["pk"] = record.PublicKeyValidator - - dht.Selector = make(record.Selector) - dht.Selector["pk"] = record.PublicKeySelector - - return dht -} - -// putValueToPeer stores the given key/value pair at the peer 'p' -func (dht *IpfsDHT) putValueToPeer(ctx context.Context, p peer.ID, - key key.Key, rec *pb.Record) error { - - pmes := pb.NewMessage(pb.Message_PUT_VALUE, string(key), 0) - pmes.Record = rec - rpmes, err := dht.sendRequest(ctx, p, pmes) - switch err { - case ErrReadTimeout: - log.Warningf("read timeout: %s %s", p.Pretty(), key) - fallthrough - default: - return err - case nil: - break - } - - if err != nil { - return err - } - - if !bytes.Equal(rpmes.GetRecord().Value, pmes.GetRecord().Value) { - return errors.New("value not put correctly") - } - return nil -} - -var errInvalidRecord = errors.New("received invalid record") - -// getValueOrPeers queries a particular peer p for the value for -// key. It returns either the value or a list of closer peers. -// NOTE: It will update the dht's peerstore with any new addresses -// it finds for the given peer. -func (dht *IpfsDHT) getValueOrPeers(ctx context.Context, p peer.ID, - key key.Key) (*pb.Record, []pstore.PeerInfo, error) { - - pmes, err := dht.getValueSingle(ctx, p, key) - if err != nil { - return nil, nil, err - } - - // Perhaps we were given closer peers - peers := pb.PBPeersToPeerInfos(pmes.GetCloserPeers()) - - if record := pmes.GetRecord(); record != nil { - // Success! We were given the value - log.Debug("getValueOrPeers: got value") - - // make sure record is valid. - err = dht.verifyRecordOnline(ctx, record) - if err != nil { - log.Info("Received invalid record! (discarded)") - // return a sentinal to signify an invalid record was received - err = errInvalidRecord - record = new(pb.Record) - } - return record, peers, err - } - - if len(peers) > 0 { - log.Debug("getValueOrPeers: peers") - return nil, peers, nil - } - - log.Warning("getValueOrPeers: routing.ErrNotFound") - return nil, nil, routing.ErrNotFound -} - -// getValueSingle simply performs the get value RPC with the given parameters -func (dht *IpfsDHT) getValueSingle(ctx context.Context, p peer.ID, - key key.Key) (*pb.Message, error) { - defer log.EventBegin(ctx, "getValueSingle", p, &key).Done() - - pmes := pb.NewMessage(pb.Message_GET_VALUE, string(key), 0) - resp, err := dht.sendRequest(ctx, p, pmes) - switch err { - case nil: - return resp, nil - case ErrReadTimeout: - log.Warningf("read timeout: %s %s", p.Pretty(), key) - fallthrough - default: - return nil, err - } -} - -// getLocal attempts to retrieve the value from the datastore -func (dht *IpfsDHT) getLocal(key key.Key) (*pb.Record, error) { - - log.Debug("getLocal %s", key) - v, err := dht.datastore.Get(key.DsKey()) - if err != nil { - return nil, err - } - log.Debug("found in db") - - byt, ok := v.([]byte) - if !ok { - return nil, errors.New("value stored in datastore not []byte") - } - rec := new(pb.Record) - err = proto.Unmarshal(byt, rec) - if err != nil { - return nil, err - } - - err = dht.verifyRecordLocally(rec) - if err != nil { - log.Debugf("local record verify failed: %s (discarded)", err) - return nil, err - } - - return rec, nil -} - -// getOwnPrivateKey attempts to load the local peers private -// key from the peerstore. -func (dht *IpfsDHT) getOwnPrivateKey() (ci.PrivKey, error) { - sk := dht.peerstore.PrivKey(dht.self) - if sk == nil { - log.Warningf("%s dht cannot get own private key!", dht.self) - return nil, fmt.Errorf("cannot get private key to sign record!") - } - return sk, nil -} - -// putLocal stores the key value pair in the datastore -func (dht *IpfsDHT) putLocal(key key.Key, rec *pb.Record) error { - data, err := proto.Marshal(rec) - if err != nil { - return err - } - - return dht.datastore.Put(key.DsKey(), data) -} - -// Update signals the routingTable to Update its last-seen status -// on the given peer. -func (dht *IpfsDHT) Update(ctx context.Context, p peer.ID) { - log.Event(ctx, "updatePeer", p) - dht.routingTable.Update(p) -} - -// FindLocal looks for a peer with a given ID connected to this dht and returns the peer and the table it was found in. -func (dht *IpfsDHT) FindLocal(id peer.ID) pstore.PeerInfo { - p := dht.routingTable.Find(id) - if p != "" { - return dht.peerstore.PeerInfo(p) - } - return pstore.PeerInfo{} -} - -// findPeerSingle asks peer 'p' if they know where the peer with id 'id' is -func (dht *IpfsDHT) findPeerSingle(ctx context.Context, p peer.ID, id peer.ID) (*pb.Message, error) { - defer log.EventBegin(ctx, "findPeerSingle", p, id).Done() - - pmes := pb.NewMessage(pb.Message_FIND_NODE, string(id), 0) - resp, err := dht.sendRequest(ctx, p, pmes) - switch err { - case nil: - return resp, nil - case ErrReadTimeout: - log.Warningf("read timeout: %s %s", p.Pretty(), id) - fallthrough - default: - return nil, err - } -} - -func (dht *IpfsDHT) findProvidersSingle(ctx context.Context, p peer.ID, key key.Key) (*pb.Message, error) { - defer log.EventBegin(ctx, "findProvidersSingle", p, &key).Done() - - pmes := pb.NewMessage(pb.Message_GET_PROVIDERS, string(key), 0) - resp, err := dht.sendRequest(ctx, p, pmes) - switch err { - case nil: - return resp, nil - case ErrReadTimeout: - log.Warningf("read timeout: %s %s", p.Pretty(), key) - fallthrough - default: - return nil, err - } -} - -// nearestPeersToQuery returns the routing tables closest peers. -func (dht *IpfsDHT) nearestPeersToQuery(pmes *pb.Message, count int) []peer.ID { - key := key.Key(pmes.GetKey()) - closer := dht.routingTable.NearestPeers(kb.ConvertKey(key), count) - return closer -} - -// betterPeerToQuery returns nearestPeersToQuery, but iff closer than self. -func (dht *IpfsDHT) betterPeersToQuery(pmes *pb.Message, p peer.ID, count int) []peer.ID { - closer := dht.nearestPeersToQuery(pmes, count) - - // no node? nil - if closer == nil { - return nil - } - - // == to self? thats bad - for _, p := range closer { - if p == dht.self { - log.Debug("attempted to return self! this shouldn't happen...") - return nil - } - } - - var filtered []peer.ID - for _, clp := range closer { - // Dont send a peer back themselves - if p == clp { - continue - } - - filtered = append(filtered, clp) - } - - // ok seems like closer nodes - return filtered -} - -// Context return dht's context -func (dht *IpfsDHT) Context() context.Context { - return dht.ctx -} - -// Process return dht's process -func (dht *IpfsDHT) Process() goprocess.Process { - return dht.proc -} - -// Close calls Process Close -func (dht *IpfsDHT) Close() error { - return dht.proc.Close() -} diff --git a/routing/dht/dht_bootstrap.go b/routing/dht/dht_bootstrap.go deleted file mode 100644 index 46f549ab9c2..00000000000 --- a/routing/dht/dht_bootstrap.go +++ /dev/null @@ -1,182 +0,0 @@ -// Package dht implements a distributed hash table that satisfies the ipfs routing -// interface. This DHT is modeled after kademlia with Coral and S/Kademlia modifications. -package dht - -import ( - "crypto/rand" - "fmt" - "sync" - "time" - - routing "github.com/ipfs/go-ipfs/routing" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" - u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" - - goprocess "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess" - periodicproc "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess/periodic" - context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" -) - -// BootstrapConfig specifies parameters used bootstrapping the DHT. -// -// Note there is a tradeoff between the bootstrap period and the -// number of queries. We could support a higher period with less -// queries. -type BootstrapConfig struct { - Queries int // how many queries to run per period - Period time.Duration // how often to run periodi cbootstrap. - Timeout time.Duration // how long to wait for a bootstrao query to run -} - -var DefaultBootstrapConfig = BootstrapConfig{ - // For now, this is set to 1 query. - // We are currently more interested in ensuring we have a properly formed - // DHT than making sure our dht minimizes traffic. Once we are more certain - // of our implementation's robustness, we should lower this down to 8 or 4. - Queries: 1, - - // For now, this is set to 1 minute, which is a medium period. We are - // We are currently more interested in ensuring we have a properly formed - // DHT than making sure our dht minimizes traffic. - Period: time.Duration(5 * time.Minute), - - Timeout: time.Duration(10 * time.Second), -} - -// Bootstrap ensures the dht routing table remains healthy as peers come and go. -// it builds up a list of peers by requesting random peer IDs. The Bootstrap -// process will run a number of queries each time, and run every time signal fires. -// These parameters are configurable. -// -// As opposed to BootstrapWithConfig, Bootstrap satisfies the routing interface -func (dht *IpfsDHT) Bootstrap(ctx context.Context) error { - proc, err := dht.BootstrapWithConfig(DefaultBootstrapConfig) - if err != nil { - return err - } - - // wait till ctx or dht.Context exits. - // we have to do it this way to satisfy the Routing interface (contexts) - go func() { - defer proc.Close() - select { - case <-ctx.Done(): - case <-dht.Context().Done(): - } - }() - - return nil -} - -// BootstrapWithConfig ensures the dht routing table remains healthy as peers come and go. -// it builds up a list of peers by requesting random peer IDs. The Bootstrap -// process will run a number of queries each time, and run every time signal fires. -// These parameters are configurable. -// -// BootstrapWithConfig returns a process, so the user can stop it. -func (dht *IpfsDHT) BootstrapWithConfig(config BootstrapConfig) (goprocess.Process, error) { - sig := time.Tick(config.Period) - return dht.BootstrapOnSignal(config, sig) -} - -// SignalBootstrap ensures the dht routing table remains healthy as peers come and go. -// it builds up a list of peers by requesting random peer IDs. The Bootstrap -// process will run a number of queries each time, and run every time signal fires. -// These parameters are configurable. -// -// SignalBootstrap returns a process, so the user can stop it. -func (dht *IpfsDHT) BootstrapOnSignal(cfg BootstrapConfig, signal <-chan time.Time) (goprocess.Process, error) { - if cfg.Queries <= 0 { - return nil, fmt.Errorf("invalid number of queries: %d", cfg.Queries) - } - - if signal == nil { - return nil, fmt.Errorf("invalid signal: %v", signal) - } - - proc := periodicproc.Ticker(signal, func(worker goprocess.Process) { - // it would be useful to be able to send out signals of when we bootstrap, too... - // maybe this is a good case for whole module event pub/sub? - - ctx := dht.Context() - if err := dht.runBootstrap(ctx, cfg); err != nil { - log.Warning(err) - // A bootstrapping error is important to notice but not fatal. - } - }) - - return proc, nil -} - -// runBootstrap builds up list of peers by requesting random peer IDs -func (dht *IpfsDHT) runBootstrap(ctx context.Context, cfg BootstrapConfig) error { - bslog := func(msg string) { - log.Debugf("DHT %s dhtRunBootstrap %s -- routing table size: %d", dht.self, msg, dht.routingTable.Size()) - } - bslog("start") - defer bslog("end") - defer log.EventBegin(ctx, "dhtRunBootstrap").Done() - - var merr u.MultiErr - - randomID := func() peer.ID { - // 16 random bytes is not a valid peer id. it may be fine becuase - // the dht will rehash to its own keyspace anyway. - id := make([]byte, 16) - rand.Read(id) - id = u.Hash(id) - return peer.ID(id) - } - - // bootstrap sequentially, as results will compound - ctx, cancel := context.WithTimeout(ctx, cfg.Timeout) - defer cancel() - runQuery := func(ctx context.Context, id peer.ID) { - p, err := dht.FindPeer(ctx, id) - if err == routing.ErrNotFound { - // this isn't an error. this is precisely what we expect. - } else if err != nil { - merr = append(merr, err) - } else { - // woah, actually found a peer with that ID? this shouldn't happen normally - // (as the ID we use is not a real ID). this is an odd error worth logging. - err := fmt.Errorf("Bootstrap peer error: Actually FOUND peer. (%s, %s)", id, p) - log.Warningf("%s", err) - merr = append(merr, err) - } - } - - sequential := true - if sequential { - // these should be parallel normally. but can make them sequential for debugging. - // note that the core/bootstrap context deadline should be extended too for that. - for i := 0; i < cfg.Queries; i++ { - id := randomID() - log.Debugf("Bootstrapping query (%d/%d) to random ID: %s", i+1, cfg.Queries, id) - runQuery(ctx, id) - } - - } else { - // note on parallelism here: the context is passed in to the queries, so they - // **should** exit when it exceeds, making this function exit on ctx cancel. - // normally, we should be selecting on ctx.Done() here too, but this gets - // complicated to do with WaitGroup, and doesnt wait for the children to exit. - var wg sync.WaitGroup - for i := 0; i < cfg.Queries; i++ { - wg.Add(1) - go func() { - defer wg.Done() - - id := randomID() - log.Debugf("Bootstrapping query (%d/%d) to random ID: %s", i+1, cfg.Queries, id) - runQuery(ctx, id) - }() - } - wg.Wait() - } - - if len(merr) > 0 { - return merr - } - return nil -} diff --git a/routing/dht/dht_net.go b/routing/dht/dht_net.go deleted file mode 100644 index 92819b43746..00000000000 --- a/routing/dht/dht_net.go +++ /dev/null @@ -1,250 +0,0 @@ -package dht - -import ( - "fmt" - "sync" - "time" - - pb "github.com/ipfs/go-ipfs/routing/dht/pb" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" - ctxio "gx/ipfs/QmX6DhWrpBB5NtadXmPSXYNdVvuLfJXoFNMvUMoVvP5UJa/go-context/io" - ggio "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/io" - context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" - inet "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/net" -) - -var dhtReadMessageTimeout = time.Minute -var ErrReadTimeout = fmt.Errorf("timed out reading response") - -// handleNewStream implements the inet.StreamHandler -func (dht *IpfsDHT) handleNewStream(s inet.Stream) { - go dht.handleNewMessage(s) -} - -func (dht *IpfsDHT) handleNewMessage(s inet.Stream) { - defer s.Close() - - ctx := dht.Context() - cr := ctxio.NewReader(ctx, s) // ok to use. we defer close stream in this func - cw := ctxio.NewWriter(ctx, s) // ok to use. we defer close stream in this func - r := ggio.NewDelimitedReader(cr, inet.MessageSizeMax) - w := ggio.NewDelimitedWriter(cw) - mPeer := s.Conn().RemotePeer() - - for { - // receive msg - pmes := new(pb.Message) - if err := r.ReadMsg(pmes); err != nil { - log.Debugf("Error unmarshaling data: %s", err) - return - } - - // update the peer (on valid msgs only) - dht.updateFromMessage(ctx, mPeer, pmes) - - // get handler for this msg type. - handler := dht.handlerForMsgType(pmes.GetType()) - if handler == nil { - log.Debug("got back nil handler from handlerForMsgType") - return - } - - // dispatch handler. - rpmes, err := handler(ctx, mPeer, pmes) - if err != nil { - log.Debugf("handle message error: %s", err) - return - } - - // if nil response, return it before serializing - if rpmes == nil { - log.Debug("got back nil response from request") - continue - } - - // send out response msg - if err := w.WriteMsg(rpmes); err != nil { - log.Debugf("send response error: %s", err) - return - } - } -} - -// sendRequest sends out a request, but also makes sure to -// measure the RTT for latency measurements. -func (dht *IpfsDHT) sendRequest(ctx context.Context, p peer.ID, pmes *pb.Message) (*pb.Message, error) { - - ms := dht.messageSenderForPeer(p) - - start := time.Now() - - rpmes, err := ms.SendRequest(ctx, pmes) - if err != nil { - return nil, err - } - - // update the peer (on valid msgs only) - dht.updateFromMessage(ctx, p, rpmes) - - dht.peerstore.RecordLatency(p, time.Since(start)) - log.Event(ctx, "dhtReceivedMessage", dht.self, p, rpmes) - return rpmes, nil -} - -// sendMessage sends out a message -func (dht *IpfsDHT) sendMessage(ctx context.Context, p peer.ID, pmes *pb.Message) error { - - ms := dht.messageSenderForPeer(p) - - if err := ms.SendMessage(ctx, pmes); err != nil { - return err - } - log.Event(ctx, "dhtSentMessage", dht.self, p, pmes) - return nil -} - -func (dht *IpfsDHT) updateFromMessage(ctx context.Context, p peer.ID, mes *pb.Message) error { - dht.Update(ctx, p) - return nil -} - -func (dht *IpfsDHT) messageSenderForPeer(p peer.ID) *messageSender { - dht.smlk.Lock() - defer dht.smlk.Unlock() - - ms, ok := dht.strmap[p] - if !ok { - ms = dht.newMessageSender(p) - dht.strmap[p] = ms - } - - return ms -} - -type messageSender struct { - s inet.Stream - r ggio.ReadCloser - w ggio.WriteCloser - lk sync.Mutex - p peer.ID - dht *IpfsDHT - - singleMes int -} - -func (dht *IpfsDHT) newMessageSender(p peer.ID) *messageSender { - return &messageSender{p: p, dht: dht} -} - -func (ms *messageSender) prep() error { - if ms.s != nil { - return nil - } - - nstr, err := ms.dht.host.NewStream(ms.dht.ctx, ms.p, ProtocolDHT) - if err != nil { - return err - } - - ms.r = ggio.NewDelimitedReader(nstr, inet.MessageSizeMax) - ms.w = ggio.NewDelimitedWriter(nstr) - ms.s = nstr - - return nil -} - -// streamReuseTries is the number of times we will try to reuse a stream to a -// given peer before giving up and reverting to the old one-message-per-stream -// behaviour. -const streamReuseTries = 3 - -func (ms *messageSender) SendMessage(ctx context.Context, pmes *pb.Message) error { - ms.lk.Lock() - defer ms.lk.Unlock() - if err := ms.prep(); err != nil { - return err - } - - if err := ms.writeMessage(pmes); err != nil { - return err - } - - if ms.singleMes > streamReuseTries { - ms.s.Close() - ms.s = nil - } - - return nil -} - -func (ms *messageSender) writeMessage(pmes *pb.Message) error { - err := ms.w.WriteMsg(pmes) - if err != nil { - // If the other side isnt expecting us to be reusing streams, we're gonna - // end up erroring here. To make sure things work seamlessly, lets retry once - // before continuing - - log.Infof("error writing message: ", err) - ms.s.Close() - ms.s = nil - if err := ms.prep(); err != nil { - return err - } - - if err := ms.w.WriteMsg(pmes); err != nil { - return err - } - - // keep track of this happening. If it happens a few times, its - // likely we can assume the otherside will never support stream reuse - ms.singleMes++ - } - return nil -} - -func (ms *messageSender) SendRequest(ctx context.Context, pmes *pb.Message) (*pb.Message, error) { - ms.lk.Lock() - defer ms.lk.Unlock() - if err := ms.prep(); err != nil { - return nil, err - } - - if err := ms.writeMessage(pmes); err != nil { - return nil, err - } - - log.Event(ctx, "dhtSentMessage", ms.dht.self, ms.p, pmes) - - mes := new(pb.Message) - if err := ms.ctxReadMsg(ctx, mes); err != nil { - ms.s.Close() - ms.s = nil - return nil, err - } - - if ms.singleMes > streamReuseTries { - ms.s.Close() - ms.s = nil - } - - return mes, nil -} - -func (ms *messageSender) ctxReadMsg(ctx context.Context, mes *pb.Message) error { - errc := make(chan error, 1) - go func(r ggio.ReadCloser) { - errc <- r.ReadMsg(mes) - }(ms.r) - - t := time.NewTimer(dhtReadMessageTimeout) - defer t.Stop() - - select { - case err := <-errc: - return err - case <-ctx.Done(): - return ctx.Err() - case <-t.C: - return ErrReadTimeout - } -} diff --git a/routing/dht/dht_test.go b/routing/dht/dht_test.go deleted file mode 100644 index 8243d2ed974..00000000000 --- a/routing/dht/dht_test.go +++ /dev/null @@ -1,828 +0,0 @@ -package dht - -import ( - "bytes" - "fmt" - "math/rand" - "sort" - "sync" - "testing" - "time" - - key "github.com/ipfs/go-ipfs/blocks/key" - routing "github.com/ipfs/go-ipfs/routing" - record "github.com/ipfs/go-ipfs/routing/record" - ci "github.com/ipfs/go-ipfs/thirdparty/testutil/ci" - travisci "github.com/ipfs/go-ipfs/thirdparty/testutil/ci/travis" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - dssync "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/sync" - - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" - ma "gx/ipfs/QmYzDkkgAEmrcNzFCiYo6L1dTX4EAG1gZkbtdbd9trL4vd/go-multiaddr" - u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" - context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" - netutil "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/test/util" -) - -var testCaseValues = map[key.Key][]byte{} - -func init() { - testCaseValues["hello"] = []byte("world") - for i := 0; i < 100; i++ { - k := fmt.Sprintf("%d -- key", i) - v := fmt.Sprintf("%d -- value", i) - testCaseValues[key.Key(k)] = []byte(v) - } -} - -func setupDHT(ctx context.Context, t *testing.T) *IpfsDHT { - h := netutil.GenHostSwarm(t, ctx) - - dss := dssync.MutexWrap(ds.NewMapDatastore()) - d := NewDHT(ctx, h, dss) - - d.Validator["v"] = &record.ValidChecker{ - Func: func(key.Key, []byte) error { - return nil - }, - Sign: false, - } - return d -} - -func setupDHTS(ctx context.Context, n int, t *testing.T) ([]ma.Multiaddr, []peer.ID, []*IpfsDHT) { - addrs := make([]ma.Multiaddr, n) - dhts := make([]*IpfsDHT, n) - peers := make([]peer.ID, n) - - sanityAddrsMap := make(map[string]struct{}) - sanityPeersMap := make(map[string]struct{}) - - for i := 0; i < n; i++ { - dhts[i] = setupDHT(ctx, t) - peers[i] = dhts[i].self - addrs[i] = dhts[i].peerstore.Addrs(dhts[i].self)[0] - - if _, lol := sanityAddrsMap[addrs[i].String()]; lol { - t.Fatal("While setting up DHTs address got duplicated.") - } else { - sanityAddrsMap[addrs[i].String()] = struct{}{} - } - if _, lol := sanityPeersMap[peers[i].String()]; lol { - t.Fatal("While setting up DHTs peerid got duplicated.") - } else { - sanityPeersMap[peers[i].String()] = struct{}{} - } - } - - return addrs, peers, dhts -} - -func connect(t *testing.T, ctx context.Context, a, b *IpfsDHT) { - - idB := b.self - addrB := b.peerstore.Addrs(idB) - if len(addrB) == 0 { - t.Fatal("peers setup incorrectly: no local address") - } - - a.peerstore.AddAddrs(idB, addrB, pstore.TempAddrTTL) - pi := pstore.PeerInfo{ID: idB} - if err := a.host.Connect(ctx, pi); err != nil { - t.Fatal(err) - } - - // loop until connection notification has been received. - // under high load, this may not happen as immediately as we would like. - for a.routingTable.Find(b.self) == "" { - time.Sleep(time.Millisecond * 5) - } - - for b.routingTable.Find(a.self) == "" { - time.Sleep(time.Millisecond * 5) - } -} - -func bootstrap(t *testing.T, ctx context.Context, dhts []*IpfsDHT) { - - ctx, cancel := context.WithCancel(ctx) - log.Debugf("Bootstrapping DHTs...") - - // tried async. sequential fares much better. compare: - // 100 async https://gist.github.com/jbenet/56d12f0578d5f34810b2 - // 100 sync https://gist.github.com/jbenet/6c59e7c15426e48aaedd - // probably because results compound - - var cfg BootstrapConfig - cfg = DefaultBootstrapConfig - cfg.Queries = 3 - - start := rand.Intn(len(dhts)) // randomize to decrease bias. - for i := range dhts { - dht := dhts[(start+i)%len(dhts)] - dht.runBootstrap(ctx, cfg) - } - cancel() -} - -func TestValueGetSet(t *testing.T) { - // t.Skip("skipping test to debug another") - - ctx := context.Background() - - dhtA := setupDHT(ctx, t) - dhtB := setupDHT(ctx, t) - - defer dhtA.Close() - defer dhtB.Close() - defer dhtA.host.Close() - defer dhtB.host.Close() - - vf := &record.ValidChecker{ - Func: func(key.Key, []byte) error { - return nil - }, - Sign: false, - } - nulsel := func(_ key.Key, bs [][]byte) (int, error) { - return 0, nil - } - - dhtA.Validator["v"] = vf - dhtB.Validator["v"] = vf - dhtA.Selector["v"] = nulsel - dhtB.Selector["v"] = nulsel - - connect(t, ctx, dhtA, dhtB) - - ctxT, _ := context.WithTimeout(ctx, time.Second) - dhtA.PutValue(ctxT, "/v/hello", []byte("world")) - - ctxT, _ = context.WithTimeout(ctx, time.Second*2) - val, err := dhtA.GetValue(ctxT, "/v/hello") - if err != nil { - t.Fatal(err) - } - - if string(val) != "world" { - t.Fatalf("Expected 'world' got '%s'", string(val)) - } - - ctxT, _ = context.WithTimeout(ctx, time.Second*2) - val, err = dhtB.GetValue(ctxT, "/v/hello") - if err != nil { - t.Fatal(err) - } - - if string(val) != "world" { - t.Fatalf("Expected 'world' got '%s'", string(val)) - } -} - -func TestProvides(t *testing.T) { - // t.Skip("skipping test to debug another") - ctx := context.Background() - - _, _, dhts := setupDHTS(ctx, 4, t) - defer func() { - for i := 0; i < 4; i++ { - dhts[i].Close() - defer dhts[i].host.Close() - } - }() - - connect(t, ctx, dhts[0], dhts[1]) - connect(t, ctx, dhts[1], dhts[2]) - connect(t, ctx, dhts[1], dhts[3]) - - for k, v := range testCaseValues { - log.Debugf("adding local values for %s = %s", k, v) - sk := dhts[3].peerstore.PrivKey(dhts[3].self) - rec, err := record.MakePutRecord(sk, k, v, false) - if err != nil { - t.Fatal(err) - } - - err = dhts[3].putLocal(k, rec) - if err != nil { - t.Fatal(err) - } - - bits, err := dhts[3].getLocal(k) - if err != nil { - t.Fatal(err) - } - if !bytes.Equal(bits.GetValue(), v) { - t.Fatalf("didn't store the right bits (%s, %s)", k, v) - } - } - - for k := range testCaseValues { - log.Debugf("announcing provider for %s", k) - if err := dhts[3].Provide(ctx, k); err != nil { - t.Fatal(err) - } - } - - // what is this timeout for? was 60ms before. - time.Sleep(time.Millisecond * 6) - - n := 0 - for k := range testCaseValues { - n = (n + 1) % 3 - - log.Debugf("getting providers for %s from %d", k, n) - ctxT, _ := context.WithTimeout(ctx, time.Second) - provchan := dhts[n].FindProvidersAsync(ctxT, k, 1) - - select { - case prov := <-provchan: - if prov.ID == "" { - t.Fatal("Got back nil provider") - } - if prov.ID != dhts[3].self { - t.Fatal("Got back wrong provider") - } - case <-ctxT.Done(): - t.Fatal("Did not get a provider back.") - } - } -} - -// if minPeers or avgPeers is 0, dont test for it. -func waitForWellFormedTables(t *testing.T, dhts []*IpfsDHT, minPeers, avgPeers int, timeout time.Duration) bool { - // test "well-formed-ness" (>= minPeers peers in every routing table) - - checkTables := func() bool { - totalPeers := 0 - for _, dht := range dhts { - rtlen := dht.routingTable.Size() - totalPeers += rtlen - if minPeers > 0 && rtlen < minPeers { - t.Logf("routing table for %s only has %d peers (should have >%d)", dht.self, rtlen, minPeers) - return false - } - } - actualAvgPeers := totalPeers / len(dhts) - t.Logf("avg rt size: %d", actualAvgPeers) - if avgPeers > 0 && actualAvgPeers < avgPeers { - t.Logf("avg rt size: %d < %d", actualAvgPeers, avgPeers) - return false - } - return true - } - - timeoutA := time.After(timeout) - for { - select { - case <-timeoutA: - log.Debugf("did not reach well-formed routing tables by %s", timeout) - return false // failed - case <-time.After(5 * time.Millisecond): - if checkTables() { - return true // succeeded - } - } - } -} - -func printRoutingTables(dhts []*IpfsDHT) { - // the routing tables should be full now. let's inspect them. - fmt.Printf("checking routing table of %d\n", len(dhts)) - for _, dht := range dhts { - fmt.Printf("checking routing table of %s\n", dht.self) - dht.routingTable.Print() - fmt.Println("") - } -} - -func TestBootstrap(t *testing.T) { - // t.Skip("skipping test to debug another") - if testing.Short() { - t.SkipNow() - } - - ctx := context.Background() - - nDHTs := 30 - _, _, dhts := setupDHTS(ctx, nDHTs, t) - defer func() { - for i := 0; i < nDHTs; i++ { - dhts[i].Close() - defer dhts[i].host.Close() - } - }() - - t.Logf("connecting %d dhts in a ring", nDHTs) - for i := 0; i < nDHTs; i++ { - connect(t, ctx, dhts[i], dhts[(i+1)%len(dhts)]) - } - - <-time.After(100 * time.Millisecond) - // bootstrap a few times until we get good tables. - stop := make(chan struct{}) - go func() { - for { - t.Logf("bootstrapping them so they find each other", nDHTs) - ctxT, _ := context.WithTimeout(ctx, 5*time.Second) - bootstrap(t, ctxT, dhts) - - select { - case <-time.After(50 * time.Millisecond): - continue // being explicit - case <-stop: - return - } - } - }() - - waitForWellFormedTables(t, dhts, 7, 10, 20*time.Second) - close(stop) - - if u.Debug { - // the routing tables should be full now. let's inspect them. - printRoutingTables(dhts) - } -} - -func TestPeriodicBootstrap(t *testing.T) { - // t.Skip("skipping test to debug another") - if ci.IsRunning() { - t.Skip("skipping on CI. highly timing dependent") - } - if testing.Short() { - t.SkipNow() - } - - ctx := context.Background() - - nDHTs := 30 - _, _, dhts := setupDHTS(ctx, nDHTs, t) - defer func() { - for i := 0; i < nDHTs; i++ { - dhts[i].Close() - defer dhts[i].host.Close() - } - }() - - // signal amplifier - amplify := func(signal chan time.Time, other []chan time.Time) { - for t := range signal { - for _, s := range other { - s <- t - } - } - for _, s := range other { - close(s) - } - } - - signal := make(chan time.Time) - allSignals := []chan time.Time{} - - var cfg BootstrapConfig - cfg = DefaultBootstrapConfig - cfg.Queries = 5 - - // kick off periodic bootstrappers with instrumented signals. - for _, dht := range dhts { - s := make(chan time.Time) - allSignals = append(allSignals, s) - dht.BootstrapOnSignal(cfg, s) - } - go amplify(signal, allSignals) - - t.Logf("dhts are not connected.", nDHTs) - for _, dht := range dhts { - rtlen := dht.routingTable.Size() - if rtlen > 0 { - t.Errorf("routing table for %s should have 0 peers. has %d", dht.self, rtlen) - } - } - - for i := 0; i < nDHTs; i++ { - connect(t, ctx, dhts[i], dhts[(i+1)%len(dhts)]) - } - - t.Logf("DHTs are now connected to 1-2 others.", nDHTs) - for _, dht := range dhts { - rtlen := dht.routingTable.Size() - if rtlen > 2 { - t.Errorf("routing table for %s should have at most 2 peers. has %d", dht.self, rtlen) - } - } - - if u.Debug { - printRoutingTables(dhts) - } - - t.Logf("bootstrapping them so they find each other", nDHTs) - signal <- time.Now() - - // this is async, and we dont know when it's finished with one cycle, so keep checking - // until the routing tables look better, or some long timeout for the failure case. - waitForWellFormedTables(t, dhts, 7, 10, 20*time.Second) - - if u.Debug { - printRoutingTables(dhts) - } -} - -func TestProvidesMany(t *testing.T) { - t.Skip("this test doesn't work") - // t.Skip("skipping test to debug another") - ctx := context.Background() - - nDHTs := 40 - _, _, dhts := setupDHTS(ctx, nDHTs, t) - defer func() { - for i := 0; i < nDHTs; i++ { - dhts[i].Close() - defer dhts[i].host.Close() - } - }() - - t.Logf("connecting %d dhts in a ring", nDHTs) - for i := 0; i < nDHTs; i++ { - connect(t, ctx, dhts[i], dhts[(i+1)%len(dhts)]) - } - - <-time.After(100 * time.Millisecond) - t.Logf("bootstrapping them so they find each other", nDHTs) - ctxT, _ := context.WithTimeout(ctx, 20*time.Second) - bootstrap(t, ctxT, dhts) - - if u.Debug { - // the routing tables should be full now. let's inspect them. - t.Logf("checking routing table of %d", nDHTs) - for _, dht := range dhts { - fmt.Printf("checking routing table of %s\n", dht.self) - dht.routingTable.Print() - fmt.Println("") - } - } - - var providers = map[key.Key]peer.ID{} - - d := 0 - for k, v := range testCaseValues { - d = (d + 1) % len(dhts) - dht := dhts[d] - providers[k] = dht.self - - t.Logf("adding local values for %s = %s (on %s)", k, v, dht.self) - rec, err := record.MakePutRecord(nil, k, v, false) - if err != nil { - t.Fatal(err) - } - - err = dht.putLocal(k, rec) - if err != nil { - t.Fatal(err) - } - - bits, err := dht.getLocal(k) - if err != nil { - t.Fatal(err) - } - if !bytes.Equal(bits.GetValue(), v) { - t.Fatalf("didn't store the right bits (%s, %s)", k, v) - } - - t.Logf("announcing provider for %s", k) - if err := dht.Provide(ctx, k); err != nil { - t.Fatal(err) - } - } - - // what is this timeout for? was 60ms before. - time.Sleep(time.Millisecond * 6) - - errchan := make(chan error) - - ctxT, _ = context.WithTimeout(ctx, 5*time.Second) - - var wg sync.WaitGroup - getProvider := func(dht *IpfsDHT, k key.Key) { - defer wg.Done() - - expected := providers[k] - - provchan := dht.FindProvidersAsync(ctxT, k, 1) - select { - case prov := <-provchan: - actual := prov.ID - if actual == "" { - errchan <- fmt.Errorf("Got back nil provider (%s at %s)", k, dht.self) - } else if actual != expected { - errchan <- fmt.Errorf("Got back wrong provider (%s != %s) (%s at %s)", - expected, actual, k, dht.self) - } - case <-ctxT.Done(): - errchan <- fmt.Errorf("Did not get a provider back (%s at %s)", k, dht.self) - } - } - - for k := range testCaseValues { - // everyone should be able to find it... - for _, dht := range dhts { - log.Debugf("getting providers for %s at %s", k, dht.self) - wg.Add(1) - go getProvider(dht, k) - } - } - - // we need this because of printing errors - go func() { - wg.Wait() - close(errchan) - }() - - for err := range errchan { - t.Error(err) - } -} - -func TestProvidesAsync(t *testing.T) { - // t.Skip("skipping test to debug another") - if testing.Short() { - t.SkipNow() - } - - ctx := context.Background() - - _, _, dhts := setupDHTS(ctx, 4, t) - defer func() { - for i := 0; i < 4; i++ { - dhts[i].Close() - defer dhts[i].host.Close() - } - }() - - connect(t, ctx, dhts[0], dhts[1]) - connect(t, ctx, dhts[1], dhts[2]) - connect(t, ctx, dhts[1], dhts[3]) - - k := key.Key("hello") - val := []byte("world") - sk := dhts[3].peerstore.PrivKey(dhts[3].self) - rec, err := record.MakePutRecord(sk, k, val, false) - if err != nil { - t.Fatal(err) - } - - err = dhts[3].putLocal(k, rec) - if err != nil { - t.Fatal(err) - } - - bits, err := dhts[3].getLocal(k) - if err != nil && bytes.Equal(bits.GetValue(), val) { - t.Fatal(err) - } - - err = dhts[3].Provide(ctx, key.Key("hello")) - if err != nil { - t.Fatal(err) - } - - time.Sleep(time.Millisecond * 60) - - ctxT, _ := context.WithTimeout(ctx, time.Millisecond*300) - provs := dhts[0].FindProvidersAsync(ctxT, key.Key("hello"), 5) - select { - case p, ok := <-provs: - if !ok { - t.Fatal("Provider channel was closed...") - } - if p.ID == "" { - t.Fatal("Got back nil provider!") - } - if p.ID != dhts[3].self { - t.Fatalf("got a provider, but not the right one. %s", p) - } - case <-ctxT.Done(): - t.Fatal("Didnt get back providers") - } -} - -func TestLayeredGet(t *testing.T) { - // t.Skip("skipping test to debug another") - if testing.Short() { - t.SkipNow() - } - - ctx := context.Background() - - _, _, dhts := setupDHTS(ctx, 4, t) - defer func() { - for i := 0; i < 4; i++ { - dhts[i].Close() - defer dhts[i].host.Close() - } - }() - - connect(t, ctx, dhts[0], dhts[1]) - connect(t, ctx, dhts[1], dhts[2]) - connect(t, ctx, dhts[1], dhts[3]) - - err := dhts[3].Provide(ctx, key.Key("/v/hello")) - if err != nil { - t.Fatal(err) - } - - time.Sleep(time.Millisecond * 6) - - t.Log("interface was changed. GetValue should not use providers.") - ctxT, _ := context.WithTimeout(ctx, time.Second) - val, err := dhts[0].GetValue(ctxT, key.Key("/v/hello")) - if err != routing.ErrNotFound { - t.Error(err) - } - if string(val) == "world" { - t.Error("should not get value.") - } - if len(val) > 0 && string(val) != "world" { - t.Error("worse, there's a value and its not even the right one.") - } -} - -func TestFindPeer(t *testing.T) { - // t.Skip("skipping test to debug another") - if testing.Short() { - t.SkipNow() - } - - ctx := context.Background() - - _, peers, dhts := setupDHTS(ctx, 4, t) - defer func() { - for i := 0; i < 4; i++ { - dhts[i].Close() - dhts[i].host.Close() - } - }() - - connect(t, ctx, dhts[0], dhts[1]) - connect(t, ctx, dhts[1], dhts[2]) - connect(t, ctx, dhts[1], dhts[3]) - - ctxT, _ := context.WithTimeout(ctx, time.Second) - p, err := dhts[0].FindPeer(ctxT, peers[2]) - if err != nil { - t.Fatal(err) - } - - if p.ID == "" { - t.Fatal("Failed to find peer.") - } - - if p.ID != peers[2] { - t.Fatal("Didnt find expected peer.") - } -} - -func TestFindPeersConnectedToPeer(t *testing.T) { - t.Skip("not quite correct (see note)") - - if testing.Short() { - t.SkipNow() - } - - ctx := context.Background() - - _, peers, dhts := setupDHTS(ctx, 4, t) - defer func() { - for i := 0; i < 4; i++ { - dhts[i].Close() - dhts[i].host.Close() - } - }() - - // topology: - // 0-1, 1-2, 1-3, 2-3 - connect(t, ctx, dhts[0], dhts[1]) - connect(t, ctx, dhts[1], dhts[2]) - connect(t, ctx, dhts[1], dhts[3]) - connect(t, ctx, dhts[2], dhts[3]) - - // fmt.Println("0 is", peers[0]) - // fmt.Println("1 is", peers[1]) - // fmt.Println("2 is", peers[2]) - // fmt.Println("3 is", peers[3]) - - ctxT, _ := context.WithTimeout(ctx, time.Second) - pchan, err := dhts[0].FindPeersConnectedToPeer(ctxT, peers[2]) - if err != nil { - t.Fatal(err) - } - - // shouldFind := []peer.ID{peers[1], peers[3]} - var found []pstore.PeerInfo - for nextp := range pchan { - found = append(found, nextp) - } - - // fmt.Printf("querying 0 (%s) FindPeersConnectedToPeer 2 (%s)\n", peers[0], peers[2]) - // fmt.Println("should find 1, 3", shouldFind) - // fmt.Println("found", found) - - // testPeerListsMatch(t, shouldFind, found) - - log.Warning("TestFindPeersConnectedToPeer is not quite correct") - if len(found) == 0 { - t.Fatal("didn't find any peers.") - } -} - -func testPeerListsMatch(t *testing.T, p1, p2 []peer.ID) { - - if len(p1) != len(p2) { - t.Fatal("did not find as many peers as should have", p1, p2) - } - - ids1 := make([]string, len(p1)) - ids2 := make([]string, len(p2)) - - for i, p := range p1 { - ids1[i] = string(p) - } - - for i, p := range p2 { - ids2[i] = string(p) - } - - sort.Sort(sort.StringSlice(ids1)) - sort.Sort(sort.StringSlice(ids2)) - - for i := range ids1 { - if ids1[i] != ids2[i] { - t.Fatal("Didnt find expected peer", ids1[i], ids2) - } - } -} - -func TestConnectCollision(t *testing.T) { - // t.Skip("skipping test to debug another") - if testing.Short() { - t.SkipNow() - } - if travisci.IsRunning() { - t.Skip("Skipping on Travis-CI.") - } - - runTimes := 10 - - for rtime := 0; rtime < runTimes; rtime++ { - log.Info("Running Time: ", rtime) - - ctx := context.Background() - - dhtA := setupDHT(ctx, t) - dhtB := setupDHT(ctx, t) - - addrA := dhtA.peerstore.Addrs(dhtA.self)[0] - addrB := dhtB.peerstore.Addrs(dhtB.self)[0] - - peerA := dhtA.self - peerB := dhtB.self - - errs := make(chan error) - go func() { - dhtA.peerstore.AddAddr(peerB, addrB, pstore.TempAddrTTL) - pi := pstore.PeerInfo{ID: peerB} - err := dhtA.host.Connect(ctx, pi) - errs <- err - }() - go func() { - dhtB.peerstore.AddAddr(peerA, addrA, pstore.TempAddrTTL) - pi := pstore.PeerInfo{ID: peerA} - err := dhtB.host.Connect(ctx, pi) - errs <- err - }() - - timeout := time.After(5 * time.Second) - select { - case e := <-errs: - if e != nil { - t.Fatal(e) - } - case <-timeout: - t.Fatal("Timeout received!") - } - select { - case e := <-errs: - if e != nil { - t.Fatal(e) - } - case <-timeout: - t.Fatal("Timeout received!") - } - - dhtA.Close() - dhtB.Close() - dhtA.host.Close() - dhtB.host.Close() - } -} diff --git a/routing/dht/ext_test.go b/routing/dht/ext_test.go deleted file mode 100644 index bbfe025384f..00000000000 --- a/routing/dht/ext_test.go +++ /dev/null @@ -1,290 +0,0 @@ -package dht - -import ( - "io" - "math/rand" - "testing" - "time" - - key "github.com/ipfs/go-ipfs/blocks/key" - routing "github.com/ipfs/go-ipfs/routing" - pb "github.com/ipfs/go-ipfs/routing/dht/pb" - record "github.com/ipfs/go-ipfs/routing/record" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - dssync "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/sync" - - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" - ggio "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/io" - u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" - context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" - inet "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/net" - mocknet "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/net/mock" -) - -func TestGetFailures(t *testing.T) { - if testing.Short() { - t.SkipNow() - } - - ctx := context.Background() - mn, err := mocknet.FullMeshConnected(ctx, 2) - if err != nil { - t.Fatal(err) - } - hosts := mn.Hosts() - - tsds := dssync.MutexWrap(ds.NewMapDatastore()) - d := NewDHT(ctx, hosts[0], tsds) - d.Update(ctx, hosts[1].ID()) - - // Reply with failures to every message - hosts[1].SetStreamHandler(ProtocolDHT, func(s inet.Stream) { - s.Close() - }) - - // This one should time out - ctx1, _ := context.WithTimeout(context.Background(), 200*time.Millisecond) - if _, err := d.GetValue(ctx1, key.Key("test")); err != nil { - if merr, ok := err.(u.MultiErr); ok && len(merr) > 0 { - err = merr[0] - } - - if err != io.EOF { - t.Fatal("Got different error than we expected", err) - } - } else { - t.Fatal("Did not get expected error!") - } - - t.Log("Timeout test passed.") - - // Reply with failures to every message - hosts[1].SetStreamHandler(ProtocolDHT, func(s inet.Stream) { - defer s.Close() - - pbr := ggio.NewDelimitedReader(s, inet.MessageSizeMax) - pbw := ggio.NewDelimitedWriter(s) - - pmes := new(pb.Message) - if err := pbr.ReadMsg(pmes); err != nil { - panic(err) - } - - resp := &pb.Message{ - Type: pmes.Type, - } - if err := pbw.WriteMsg(resp); err != nil { - panic(err) - } - }) - - // This one should fail with NotFound. - // long context timeout to ensure we dont end too early. - // the dht should be exhausting its query and returning not found. - // (was 3 seconds before which should be _plenty_ of time, but maybe - // travis machines really have a hard time...) - ctx2, _ := context.WithTimeout(context.Background(), 20*time.Second) - _, err = d.GetValue(ctx2, key.Key("test")) - if err != nil { - if merr, ok := err.(u.MultiErr); ok && len(merr) > 0 { - err = merr[0] - } - if err != routing.ErrNotFound { - t.Fatalf("Expected ErrNotFound, got: %s", err) - } - } else { - t.Fatal("expected error, got none.") - } - - t.Log("ErrNotFound check passed!") - - // Now we test this DHT's handleGetValue failure - { - typ := pb.Message_GET_VALUE - str := "hello" - - sk, err := d.getOwnPrivateKey() - if err != nil { - t.Fatal(err) - } - - rec, err := record.MakePutRecord(sk, key.Key(str), []byte("blah"), true) - if err != nil { - t.Fatal(err) - } - req := pb.Message{ - Type: &typ, - Key: &str, - Record: rec, - } - - s, err := hosts[1].NewStream(context.Background(), hosts[0].ID(), ProtocolDHT) - if err != nil { - t.Fatal(err) - } - defer s.Close() - - pbr := ggio.NewDelimitedReader(s, inet.MessageSizeMax) - pbw := ggio.NewDelimitedWriter(s) - - if err := pbw.WriteMsg(&req); err != nil { - t.Fatal(err) - } - - pmes := new(pb.Message) - if err := pbr.ReadMsg(pmes); err != nil { - t.Fatal(err) - } - if pmes.GetRecord() != nil { - t.Fatal("shouldnt have value") - } - if pmes.GetProviderPeers() != nil { - t.Fatal("shouldnt have provider peers") - } - } -} - -func TestNotFound(t *testing.T) { - // t.Skip("skipping test to debug another") - if testing.Short() { - t.SkipNow() - } - - ctx := context.Background() - mn, err := mocknet.FullMeshConnected(ctx, 16) - if err != nil { - t.Fatal(err) - } - hosts := mn.Hosts() - tsds := dssync.MutexWrap(ds.NewMapDatastore()) - d := NewDHT(ctx, hosts[0], tsds) - - for _, p := range hosts { - d.Update(ctx, p.ID()) - } - - // Reply with random peers to every message - for _, host := range hosts { - host := host // shadow loop var - host.SetStreamHandler(ProtocolDHT, func(s inet.Stream) { - defer s.Close() - - pbr := ggio.NewDelimitedReader(s, inet.MessageSizeMax) - pbw := ggio.NewDelimitedWriter(s) - - pmes := new(pb.Message) - if err := pbr.ReadMsg(pmes); err != nil { - panic(err) - } - - switch pmes.GetType() { - case pb.Message_GET_VALUE: - resp := &pb.Message{Type: pmes.Type} - - ps := []pstore.PeerInfo{} - for i := 0; i < 7; i++ { - p := hosts[rand.Intn(len(hosts))].ID() - pi := host.Peerstore().PeerInfo(p) - ps = append(ps, pi) - } - - resp.CloserPeers = pb.PeerInfosToPBPeers(d.host.Network(), ps) - if err := pbw.WriteMsg(resp); err != nil { - panic(err) - } - - default: - panic("Shouldnt recieve this.") - } - }) - } - - // long timeout to ensure timing is not at play. - ctx, cancel := context.WithTimeout(ctx, time.Second*20) - defer cancel() - v, err := d.GetValue(ctx, key.Key("hello")) - log.Debugf("get value got %v", v) - if err != nil { - if merr, ok := err.(u.MultiErr); ok && len(merr) > 0 { - err = merr[0] - } - switch err { - case routing.ErrNotFound: - //Success! - return - case u.ErrTimeout: - t.Fatal("Should not have gotten timeout!") - default: - t.Fatalf("Got unexpected error: %s", err) - } - } - t.Fatal("Expected to recieve an error.") -} - -// If less than K nodes are in the entire network, it should fail when we make -// a GET rpc and nobody has the value -func TestLessThanKResponses(t *testing.T) { - // t.Skip("skipping test to debug another") - // t.Skip("skipping test because it makes a lot of output") - - ctx := context.Background() - mn, err := mocknet.FullMeshConnected(ctx, 6) - if err != nil { - t.Fatal(err) - } - hosts := mn.Hosts() - - tsds := dssync.MutexWrap(ds.NewMapDatastore()) - d := NewDHT(ctx, hosts[0], tsds) - - for i := 1; i < 5; i++ { - d.Update(ctx, hosts[i].ID()) - } - - // Reply with random peers to every message - for _, host := range hosts { - host := host // shadow loop var - host.SetStreamHandler(ProtocolDHT, func(s inet.Stream) { - defer s.Close() - - pbr := ggio.NewDelimitedReader(s, inet.MessageSizeMax) - pbw := ggio.NewDelimitedWriter(s) - - pmes := new(pb.Message) - if err := pbr.ReadMsg(pmes); err != nil { - panic(err) - } - - switch pmes.GetType() { - case pb.Message_GET_VALUE: - pi := host.Peerstore().PeerInfo(hosts[1].ID()) - resp := &pb.Message{ - Type: pmes.Type, - CloserPeers: pb.PeerInfosToPBPeers(d.host.Network(), []pstore.PeerInfo{pi}), - } - - if err := pbw.WriteMsg(resp); err != nil { - panic(err) - } - default: - panic("Shouldnt recieve this.") - } - - }) - } - - ctx, cancel := context.WithTimeout(ctx, time.Second*30) - defer cancel() - if _, err := d.GetValue(ctx, key.Key("hello")); err != nil { - switch err { - case routing.ErrNotFound: - //Success! - return - case u.ErrTimeout: - t.Fatal("Should not have gotten timeout!") - default: - t.Fatalf("Got unexpected error: %s", err) - } - } - t.Fatal("Expected to recieve an error.") -} diff --git a/routing/dht/handlers.go b/routing/dht/handlers.go deleted file mode 100644 index b12582a9470..00000000000 --- a/routing/dht/handlers.go +++ /dev/null @@ -1,287 +0,0 @@ -package dht - -import ( - "errors" - "fmt" - "time" - - key "github.com/ipfs/go-ipfs/blocks/key" - pb "github.com/ipfs/go-ipfs/routing/dht/pb" - lgbl "github.com/ipfs/go-ipfs/thirdparty/loggables" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" - proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto" - u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" - context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" -) - -// The number of closer peers to send on requests. -var CloserPeerCount = KValue - -// dhthandler specifies the signature of functions that handle DHT messages. -type dhtHandler func(context.Context, peer.ID, *pb.Message) (*pb.Message, error) - -func (dht *IpfsDHT) handlerForMsgType(t pb.Message_MessageType) dhtHandler { - switch t { - case pb.Message_GET_VALUE: - return dht.handleGetValue - case pb.Message_PUT_VALUE: - return dht.handlePutValue - case pb.Message_FIND_NODE: - return dht.handleFindPeer - case pb.Message_ADD_PROVIDER: - return dht.handleAddProvider - case pb.Message_GET_PROVIDERS: - return dht.handleGetProviders - case pb.Message_PING: - return dht.handlePing - default: - return nil - } -} - -func (dht *IpfsDHT) handleGetValue(ctx context.Context, p peer.ID, pmes *pb.Message) (*pb.Message, error) { - defer log.EventBegin(ctx, "handleGetValue", p).Done() - log.Debugf("%s handleGetValue for key: %s", dht.self, pmes.GetKey()) - - // setup response - resp := pb.NewMessage(pmes.GetType(), pmes.GetKey(), pmes.GetClusterLevel()) - - // first, is there even a key? - k := key.Key(pmes.GetKey()) - if k == "" { - return nil, errors.New("handleGetValue but no key was provided") - // TODO: send back an error response? could be bad, but the other node's hanging. - } - - rec, err := dht.checkLocalDatastore(k) - if err != nil { - return nil, err - } - resp.Record = rec - - // Find closest peer on given cluster to desired key and reply with that info - closer := dht.betterPeersToQuery(pmes, p, CloserPeerCount) - if len(closer) > 0 { - closerinfos := pstore.PeerInfos(dht.peerstore, closer) - for _, pi := range closerinfos { - log.Debugf("handleGetValue returning closer peer: '%s'", pi.ID) - if len(pi.Addrs) < 1 { - log.Errorf(`no addresses on peer being sent! - [local:%s] - [sending:%s] - [remote:%s]`, dht.self, pi.ID, p) - } - } - - resp.CloserPeers = pb.PeerInfosToPBPeers(dht.host.Network(), closerinfos) - } - - return resp, nil -} - -func (dht *IpfsDHT) checkLocalDatastore(k key.Key) (*pb.Record, error) { - log.Debugf("%s handleGetValue looking into ds", dht.self) - dskey := k.DsKey() - iVal, err := dht.datastore.Get(dskey) - log.Debugf("%s handleGetValue looking into ds GOT %v", dht.self, iVal) - - if err == ds.ErrNotFound { - return nil, nil - } - - // if we got an unexpected error, bail. - if err != nil { - return nil, err - } - - // if we have the value, send it back - log.Debugf("%s handleGetValue success!", dht.self) - - byts, ok := iVal.([]byte) - if !ok { - return nil, fmt.Errorf("datastore had non byte-slice value for %v", dskey) - } - - rec := new(pb.Record) - err = proto.Unmarshal(byts, rec) - if err != nil { - log.Debug("failed to unmarshal DHT record from datastore") - return nil, err - } - - // if its our record, dont bother checking the times on it - if peer.ID(rec.GetAuthor()) == dht.self { - return rec, nil - } - - var recordIsBad bool - recvtime, err := u.ParseRFC3339(rec.GetTimeReceived()) - if err != nil { - log.Info("either no receive time set on record, or it was invalid: ", err) - recordIsBad = true - } - - if time.Now().Sub(recvtime) > MaxRecordAge { - log.Debug("old record found, tossing.") - recordIsBad = true - } - - // NOTE: We do not verify the record here beyond checking these timestamps. - // we put the burden of checking the records on the requester as checking a record - // may be computationally expensive - - if recordIsBad { - err := dht.datastore.Delete(dskey) - if err != nil { - log.Error("Failed to delete bad record from datastore: ", err) - } - - return nil, nil // can treat this as not having the record at all - } - - return rec, nil -} - -// Store a value in this peer local storage -func (dht *IpfsDHT) handlePutValue(ctx context.Context, p peer.ID, pmes *pb.Message) (*pb.Message, error) { - defer log.EventBegin(ctx, "handlePutValue", p).Done() - dskey := key.Key(pmes.GetKey()).DsKey() - - if err := dht.verifyRecordLocally(pmes.GetRecord()); err != nil { - log.Warningf("Bad dht record in PUT from: %s. %s", key.Key(pmes.GetRecord().GetAuthor()), err) - return nil, err - } - - rec := pmes.GetRecord() - - // record the time we receive every record - rec.TimeReceived = proto.String(u.FormatRFC3339(time.Now())) - - data, err := proto.Marshal(rec) - if err != nil { - return nil, err - } - - err = dht.datastore.Put(dskey, data) - log.Debugf("%s handlePutValue %v", dht.self, dskey) - return pmes, err -} - -func (dht *IpfsDHT) handlePing(_ context.Context, p peer.ID, pmes *pb.Message) (*pb.Message, error) { - log.Debugf("%s Responding to ping from %s!\n", dht.self, p) - return pmes, nil -} - -func (dht *IpfsDHT) handleFindPeer(ctx context.Context, p peer.ID, pmes *pb.Message) (*pb.Message, error) { - defer log.EventBegin(ctx, "handleFindPeer", p).Done() - resp := pb.NewMessage(pmes.GetType(), "", pmes.GetClusterLevel()) - var closest []peer.ID - - // if looking for self... special case where we send it on CloserPeers. - if peer.ID(pmes.GetKey()) == dht.self { - closest = []peer.ID{dht.self} - } else { - closest = dht.betterPeersToQuery(pmes, p, CloserPeerCount) - } - - if closest == nil { - log.Infof("%s handleFindPeer %s: could not find anything.", dht.self, p) - return resp, nil - } - - var withAddresses []pstore.PeerInfo - closestinfos := pstore.PeerInfos(dht.peerstore, closest) - for _, pi := range closestinfos { - if len(pi.Addrs) > 0 { - withAddresses = append(withAddresses, pi) - log.Debugf("handleFindPeer: sending back '%s'", pi.ID) - } - } - - resp.CloserPeers = pb.PeerInfosToPBPeers(dht.host.Network(), withAddresses) - return resp, nil -} - -func (dht *IpfsDHT) handleGetProviders(ctx context.Context, p peer.ID, pmes *pb.Message) (*pb.Message, error) { - lm := make(lgbl.DeferredMap) - lm["peer"] = func() interface{} { return p.Pretty() } - defer log.EventBegin(ctx, "handleGetProviders", lm).Done() - - resp := pb.NewMessage(pmes.GetType(), pmes.GetKey(), pmes.GetClusterLevel()) - key := key.Key(pmes.GetKey()) - lm["key"] = func() interface{} { return key.B58String() } - - // debug logging niceness. - reqDesc := fmt.Sprintf("%s handleGetProviders(%s, %s): ", dht.self, p, key) - log.Debugf("%s begin", reqDesc) - defer log.Debugf("%s end", reqDesc) - - // check if we have this value, to add ourselves as provider. - has, err := dht.datastore.Has(key.DsKey()) - if err != nil && err != ds.ErrNotFound { - log.Debugf("unexpected datastore error: %v\n", err) - has = false - } - - // setup providers - providers := dht.providers.GetProviders(ctx, key) - if has { - providers = append(providers, dht.self) - log.Debugf("%s have the value. added self as provider", reqDesc) - } - - if providers != nil && len(providers) > 0 { - infos := pstore.PeerInfos(dht.peerstore, providers) - resp.ProviderPeers = pb.PeerInfosToPBPeers(dht.host.Network(), infos) - log.Debugf("%s have %d providers: %s", reqDesc, len(providers), infos) - } - - // Also send closer peers. - closer := dht.betterPeersToQuery(pmes, p, CloserPeerCount) - if closer != nil { - infos := pstore.PeerInfos(dht.peerstore, closer) - resp.CloserPeers = pb.PeerInfosToPBPeers(dht.host.Network(), infos) - log.Debugf("%s have %d closer peers: %s", reqDesc, len(closer), infos) - } - - return resp, nil -} - -func (dht *IpfsDHT) handleAddProvider(ctx context.Context, p peer.ID, pmes *pb.Message) (*pb.Message, error) { - lm := make(lgbl.DeferredMap) - lm["peer"] = func() interface{} { return p.Pretty() } - - defer log.EventBegin(ctx, "handleAddProvider", lm).Done() - key := key.Key(pmes.GetKey()) - lm["key"] = func() interface{} { return key.B58String() } - - log.Debugf("%s adding %s as a provider for '%s'\n", dht.self, p, key) - - // add provider should use the address given in the message - pinfos := pb.PBPeersToPeerInfos(pmes.GetProviderPeers()) - for _, pi := range pinfos { - if pi.ID != p { - // we should ignore this provider reccord! not from originator. - // (we chould sign them and check signature later...) - log.Debugf("handleAddProvider received provider %s from %s. Ignore.", pi.ID, p) - continue - } - - if len(pi.Addrs) < 1 { - log.Debugf("%s got no valid addresses for provider %s. Ignore.", dht.self, p) - continue - } - - log.Infof("received provider %s for %s (addrs: %s)", p, key, pi.Addrs) - if pi.ID != dht.self { // dont add own addrs. - // add the received addresses to our peerstore. - dht.peerstore.AddAddrs(pi.ID, pi.Addrs, pstore.ProviderAddrTTL) - } - dht.providers.AddProvider(ctx, key, p) - } - - return nil, nil -} diff --git a/routing/dht/lookup.go b/routing/dht/lookup.go deleted file mode 100644 index 2a279c89ffc..00000000000 --- a/routing/dht/lookup.go +++ /dev/null @@ -1,111 +0,0 @@ -package dht - -import ( - key "github.com/ipfs/go-ipfs/blocks/key" - notif "github.com/ipfs/go-ipfs/notifications" - kb "github.com/ipfs/go-ipfs/routing/kbucket" - pset "github.com/ipfs/go-ipfs/thirdparty/peerset" - - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" - context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" -) - -// Required in order for proper JSON marshaling -func pointerizePeerInfos(pis []pstore.PeerInfo) []*pstore.PeerInfo { - out := make([]*pstore.PeerInfo, len(pis)) - for i, p := range pis { - np := p - out[i] = &np - } - return out -} - -// Kademlia 'node lookup' operation. Returns a channel of the K closest peers -// to the given key -func (dht *IpfsDHT) GetClosestPeers(ctx context.Context, key key.Key) (<-chan peer.ID, error) { - e := log.EventBegin(ctx, "getClosestPeers", &key) - tablepeers := dht.routingTable.NearestPeers(kb.ConvertKey(key), KValue) - if len(tablepeers) == 0 { - return nil, kb.ErrLookupFailure - } - - out := make(chan peer.ID, KValue) - peerset := pset.NewLimited(KValue) - - for _, p := range tablepeers { - select { - case out <- p: - case <-ctx.Done(): - return nil, ctx.Err() - } - peerset.Add(p) - } - - // since the query doesnt actually pass our context down - // we have to hack this here. whyrusleeping isnt a huge fan of goprocess - parent := ctx - query := dht.newQuery(key, func(ctx context.Context, p peer.ID) (*dhtQueryResult, error) { - // For DHT query command - notif.PublishQueryEvent(parent, ¬if.QueryEvent{ - Type: notif.SendingQuery, - ID: p, - }) - - closer, err := dht.closerPeersSingle(ctx, key, p) - if err != nil { - log.Debugf("error getting closer peers: %s", err) - return nil, err - } - - var filtered []pstore.PeerInfo - for _, clp := range closer { - if kb.Closer(clp, dht.self, key) && peerset.TryAdd(clp) { - select { - case out <- clp: - case <-ctx.Done(): - return nil, ctx.Err() - } - filtered = append(filtered, dht.peerstore.PeerInfo(clp)) - } - } - - // For DHT query command - notif.PublishQueryEvent(parent, ¬if.QueryEvent{ - Type: notif.PeerResponse, - ID: p, - Responses: pointerizePeerInfos(filtered), - }) - - return &dhtQueryResult{closerPeers: filtered}, nil - }) - - go func() { - defer close(out) - defer e.Done() - // run it! - _, err := query.Run(ctx, tablepeers) - if err != nil { - log.Debugf("closestPeers query run error: %s", err) - } - }() - - return out, nil -} - -func (dht *IpfsDHT) closerPeersSingle(ctx context.Context, key key.Key, p peer.ID) ([]peer.ID, error) { - pmes, err := dht.findPeerSingle(ctx, p, peer.ID(key)) - if err != nil { - return nil, err - } - - var out []peer.ID - for _, pbp := range pmes.GetCloserPeers() { - pid := peer.ID(pbp.GetId()) - if pid != dht.self { // dont add self - dht.peerstore.AddAddrs(pid, pbp.Addresses(), pstore.TempAddrTTL) - out = append(out, pid) - } - } - return out, nil -} diff --git a/routing/dht/notif.go b/routing/dht/notif.go deleted file mode 100644 index 4a55724bf4f..00000000000 --- a/routing/dht/notif.go +++ /dev/null @@ -1,39 +0,0 @@ -package dht - -import ( - ma "gx/ipfs/QmYzDkkgAEmrcNzFCiYo6L1dTX4EAG1gZkbtdbd9trL4vd/go-multiaddr" - - inet "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/net" -) - -// netNotifiee defines methods to be used with the IpfsDHT -type netNotifiee IpfsDHT - -func (nn *netNotifiee) DHT() *IpfsDHT { - return (*IpfsDHT)(nn) -} - -func (nn *netNotifiee) Connected(n inet.Network, v inet.Conn) { - dht := nn.DHT() - select { - case <-dht.Process().Closing(): - return - default: - } - dht.Update(dht.Context(), v.RemotePeer()) -} - -func (nn *netNotifiee) Disconnected(n inet.Network, v inet.Conn) { - dht := nn.DHT() - select { - case <-dht.Process().Closing(): - return - default: - } - dht.routingTable.Remove(v.RemotePeer()) -} - -func (nn *netNotifiee) OpenedStream(n inet.Network, v inet.Stream) {} -func (nn *netNotifiee) ClosedStream(n inet.Network, v inet.Stream) {} -func (nn *netNotifiee) Listen(n inet.Network, a ma.Multiaddr) {} -func (nn *netNotifiee) ListenClose(n inet.Network, a ma.Multiaddr) {} diff --git a/routing/dht/pb/Makefile b/routing/dht/pb/Makefile deleted file mode 100644 index 08ac883d0d0..00000000000 --- a/routing/dht/pb/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -PB = $(wildcard *.proto) -GO = $(PB:.proto=.pb.go) - -all: $(GO) - -%.pb.go: %.proto - protoc --gogo_out=. --proto_path=../../../../../../:/usr/local/opt/protobuf/include:. $< - -clean: - rm -f *.pb.go - rm -f *.go diff --git a/routing/dht/pb/dht.pb.go b/routing/dht/pb/dht.pb.go deleted file mode 100644 index 24dc2e5be35..00000000000 --- a/routing/dht/pb/dht.pb.go +++ /dev/null @@ -1,272 +0,0 @@ -// Code generated by protoc-gen-gogo. -// source: dht.proto -// DO NOT EDIT! - -/* -Package dht_pb is a generated protocol buffer package. - -It is generated from these files: - dht.proto - -It has these top-level messages: - Message - Record -*/ -package dht_pb - -import proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto" -import math "math" - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = math.Inf - -type Message_MessageType int32 - -const ( - Message_PUT_VALUE Message_MessageType = 0 - Message_GET_VALUE Message_MessageType = 1 - Message_ADD_PROVIDER Message_MessageType = 2 - Message_GET_PROVIDERS Message_MessageType = 3 - Message_FIND_NODE Message_MessageType = 4 - Message_PING Message_MessageType = 5 -) - -var Message_MessageType_name = map[int32]string{ - 0: "PUT_VALUE", - 1: "GET_VALUE", - 2: "ADD_PROVIDER", - 3: "GET_PROVIDERS", - 4: "FIND_NODE", - 5: "PING", -} -var Message_MessageType_value = map[string]int32{ - "PUT_VALUE": 0, - "GET_VALUE": 1, - "ADD_PROVIDER": 2, - "GET_PROVIDERS": 3, - "FIND_NODE": 4, - "PING": 5, -} - -func (x Message_MessageType) Enum() *Message_MessageType { - p := new(Message_MessageType) - *p = x - return p -} -func (x Message_MessageType) String() string { - return proto.EnumName(Message_MessageType_name, int32(x)) -} -func (x *Message_MessageType) UnmarshalJSON(data []byte) error { - value, err := proto.UnmarshalJSONEnum(Message_MessageType_value, data, "Message_MessageType") - if err != nil { - return err - } - *x = Message_MessageType(value) - return nil -} - -type Message_ConnectionType int32 - -const ( - // sender does not have a connection to peer, and no extra information (default) - Message_NOT_CONNECTED Message_ConnectionType = 0 - // sender has a live connection to peer - Message_CONNECTED Message_ConnectionType = 1 - // sender recently connected to peer - Message_CAN_CONNECT Message_ConnectionType = 2 - // sender recently tried to connect to peer repeatedly but failed to connect - // ("try" here is loose, but this should signal "made strong effort, failed") - Message_CANNOT_CONNECT Message_ConnectionType = 3 -) - -var Message_ConnectionType_name = map[int32]string{ - 0: "NOT_CONNECTED", - 1: "CONNECTED", - 2: "CAN_CONNECT", - 3: "CANNOT_CONNECT", -} -var Message_ConnectionType_value = map[string]int32{ - "NOT_CONNECTED": 0, - "CONNECTED": 1, - "CAN_CONNECT": 2, - "CANNOT_CONNECT": 3, -} - -func (x Message_ConnectionType) Enum() *Message_ConnectionType { - p := new(Message_ConnectionType) - *p = x - return p -} -func (x Message_ConnectionType) String() string { - return proto.EnumName(Message_ConnectionType_name, int32(x)) -} -func (x *Message_ConnectionType) UnmarshalJSON(data []byte) error { - value, err := proto.UnmarshalJSONEnum(Message_ConnectionType_value, data, "Message_ConnectionType") - if err != nil { - return err - } - *x = Message_ConnectionType(value) - return nil -} - -type Message struct { - // defines what type of message it is. - Type *Message_MessageType `protobuf:"varint,1,opt,name=type,enum=dht.pb.Message_MessageType" json:"type,omitempty"` - // defines what coral cluster level this query/response belongs to. - ClusterLevelRaw *int32 `protobuf:"varint,10,opt,name=clusterLevelRaw" json:"clusterLevelRaw,omitempty"` - // Used to specify the key associated with this message. - // PUT_VALUE, GET_VALUE, ADD_PROVIDER, GET_PROVIDERS - Key *string `protobuf:"bytes,2,opt,name=key" json:"key,omitempty"` - // Used to return a value - // PUT_VALUE, GET_VALUE - Record *Record `protobuf:"bytes,3,opt,name=record" json:"record,omitempty"` - // Used to return peers closer to a key in a query - // GET_VALUE, GET_PROVIDERS, FIND_NODE - CloserPeers []*Message_Peer `protobuf:"bytes,8,rep,name=closerPeers" json:"closerPeers,omitempty"` - // Used to return Providers - // GET_VALUE, ADD_PROVIDER, GET_PROVIDERS - ProviderPeers []*Message_Peer `protobuf:"bytes,9,rep,name=providerPeers" json:"providerPeers,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Message) Reset() { *m = Message{} } -func (m *Message) String() string { return proto.CompactTextString(m) } -func (*Message) ProtoMessage() {} - -func (m *Message) GetType() Message_MessageType { - if m != nil && m.Type != nil { - return *m.Type - } - return Message_PUT_VALUE -} - -func (m *Message) GetClusterLevelRaw() int32 { - if m != nil && m.ClusterLevelRaw != nil { - return *m.ClusterLevelRaw - } - return 0 -} - -func (m *Message) GetKey() string { - if m != nil && m.Key != nil { - return *m.Key - } - return "" -} - -func (m *Message) GetRecord() *Record { - if m != nil { - return m.Record - } - return nil -} - -func (m *Message) GetCloserPeers() []*Message_Peer { - if m != nil { - return m.CloserPeers - } - return nil -} - -func (m *Message) GetProviderPeers() []*Message_Peer { - if m != nil { - return m.ProviderPeers - } - return nil -} - -type Message_Peer struct { - // ID of a given peer. - Id *string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"` - // multiaddrs for a given peer - Addrs [][]byte `protobuf:"bytes,2,rep,name=addrs" json:"addrs,omitempty"` - // used to signal the sender's connection capabilities to the peer - Connection *Message_ConnectionType `protobuf:"varint,3,opt,name=connection,enum=dht.pb.Message_ConnectionType" json:"connection,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Message_Peer) Reset() { *m = Message_Peer{} } -func (m *Message_Peer) String() string { return proto.CompactTextString(m) } -func (*Message_Peer) ProtoMessage() {} - -func (m *Message_Peer) GetId() string { - if m != nil && m.Id != nil { - return *m.Id - } - return "" -} - -func (m *Message_Peer) GetAddrs() [][]byte { - if m != nil { - return m.Addrs - } - return nil -} - -func (m *Message_Peer) GetConnection() Message_ConnectionType { - if m != nil && m.Connection != nil { - return *m.Connection - } - return Message_NOT_CONNECTED -} - -// Record represents a dht record that contains a value -// for a key value pair -type Record struct { - // The key that references this record - Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"` - // The actual value this record is storing - Value []byte `protobuf:"bytes,2,opt,name=value" json:"value,omitempty"` - // hash of the authors public key - Author *string `protobuf:"bytes,3,opt,name=author" json:"author,omitempty"` - // A PKI signature for the key+value+author - Signature []byte `protobuf:"bytes,4,opt,name=signature" json:"signature,omitempty"` - // Time the record was received, set by receiver - TimeReceived *string `protobuf:"bytes,5,opt,name=timeReceived" json:"timeReceived,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Record) Reset() { *m = Record{} } -func (m *Record) String() string { return proto.CompactTextString(m) } -func (*Record) ProtoMessage() {} - -func (m *Record) GetKey() string { - if m != nil && m.Key != nil { - return *m.Key - } - return "" -} - -func (m *Record) GetValue() []byte { - if m != nil { - return m.Value - } - return nil -} - -func (m *Record) GetAuthor() string { - if m != nil && m.Author != nil { - return *m.Author - } - return "" -} - -func (m *Record) GetSignature() []byte { - if m != nil { - return m.Signature - } - return nil -} - -func (m *Record) GetTimeReceived() string { - if m != nil && m.TimeReceived != nil { - return *m.TimeReceived - } - return "" -} - -func init() { - proto.RegisterEnum("dht.pb.Message_MessageType", Message_MessageType_name, Message_MessageType_value) - proto.RegisterEnum("dht.pb.Message_ConnectionType", Message_ConnectionType_name, Message_ConnectionType_value) -} diff --git a/routing/dht/pb/dht.proto b/routing/dht/pb/dht.proto deleted file mode 100644 index de88c3451b8..00000000000 --- a/routing/dht/pb/dht.proto +++ /dev/null @@ -1,81 +0,0 @@ -package dht.pb; - -//run `protoc --go_out=. *.proto` to generate - -message Message { - enum MessageType { - PUT_VALUE = 0; - GET_VALUE = 1; - ADD_PROVIDER = 2; - GET_PROVIDERS = 3; - FIND_NODE = 4; - PING = 5; - } - - enum ConnectionType { - // sender does not have a connection to peer, and no extra information (default) - NOT_CONNECTED = 0; - - // sender has a live connection to peer - CONNECTED = 1; - - // sender recently connected to peer - CAN_CONNECT = 2; - - // sender recently tried to connect to peer repeatedly but failed to connect - // ("try" here is loose, but this should signal "made strong effort, failed") - CANNOT_CONNECT = 3; - } - - message Peer { - // ID of a given peer. - optional string id = 1; - - // multiaddrs for a given peer - repeated bytes addrs = 2; - - // used to signal the sender's connection capabilities to the peer - optional ConnectionType connection = 3; - } - - // defines what type of message it is. - optional MessageType type = 1; - - // defines what coral cluster level this query/response belongs to. - optional int32 clusterLevelRaw = 10; - - // Used to specify the key associated with this message. - // PUT_VALUE, GET_VALUE, ADD_PROVIDER, GET_PROVIDERS - optional string key = 2; - - // Used to return a value - // PUT_VALUE, GET_VALUE - optional Record record = 3; - - // Used to return peers closer to a key in a query - // GET_VALUE, GET_PROVIDERS, FIND_NODE - repeated Peer closerPeers = 8; - - // Used to return Providers - // GET_VALUE, ADD_PROVIDER, GET_PROVIDERS - repeated Peer providerPeers = 9; -} - -// Record represents a dht record that contains a value -// for a key value pair -message Record { - // The key that references this record - optional string key = 1; - - // The actual value this record is storing - optional bytes value = 2; - - // hash of the authors public key - optional string author = 3; - - // A PKI signature for the key+value+author - optional bytes signature = 4; - - // Time the record was received, set by receiver - optional string timeReceived = 5; -} diff --git a/routing/dht/pb/message.go b/routing/dht/pb/message.go deleted file mode 100644 index d7c4dd7d2ca..00000000000 --- a/routing/dht/pb/message.go +++ /dev/null @@ -1,185 +0,0 @@ -package dht_pb - -import ( - ma "gx/ipfs/QmYzDkkgAEmrcNzFCiYo6L1dTX4EAG1gZkbtdbd9trL4vd/go-multiaddr" - - key "github.com/ipfs/go-ipfs/blocks/key" - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" - logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" - inet "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/net" -) - -var log = logging.Logger("dht.pb") - -type PeerRoutingInfo struct { - pstore.PeerInfo - inet.Connectedness -} - -// NewMessage constructs a new dht message with given type, key, and level -func NewMessage(typ Message_MessageType, key string, level int) *Message { - m := &Message{ - Type: &typ, - Key: &key, - } - m.SetClusterLevel(level) - return m -} - -func peerRoutingInfoToPBPeer(p PeerRoutingInfo) *Message_Peer { - pbp := new(Message_Peer) - - pbp.Addrs = make([][]byte, len(p.Addrs)) - for i, maddr := range p.Addrs { - pbp.Addrs[i] = maddr.Bytes() // Bytes, not String. Compressed. - } - s := string(p.ID) - pbp.Id = &s - c := ConnectionType(p.Connectedness) - pbp.Connection = &c - return pbp -} - -func peerInfoToPBPeer(p pstore.PeerInfo) *Message_Peer { - pbp := new(Message_Peer) - - pbp.Addrs = make([][]byte, len(p.Addrs)) - for i, maddr := range p.Addrs { - pbp.Addrs[i] = maddr.Bytes() // Bytes, not String. Compressed. - } - s := string(p.ID) - pbp.Id = &s - return pbp -} - -// PBPeerToPeer turns a *Message_Peer into its pstore.PeerInfo counterpart -func PBPeerToPeerInfo(pbp *Message_Peer) pstore.PeerInfo { - return pstore.PeerInfo{ - ID: peer.ID(pbp.GetId()), - Addrs: pbp.Addresses(), - } -} - -// RawPeerInfosToPBPeers converts a slice of Peers into a slice of *Message_Peers, -// ready to go out on the wire. -func RawPeerInfosToPBPeers(peers []pstore.PeerInfo) []*Message_Peer { - pbpeers := make([]*Message_Peer, len(peers)) - for i, p := range peers { - pbpeers[i] = peerInfoToPBPeer(p) - } - return pbpeers -} - -// PeersToPBPeers converts given []peer.Peer into a set of []*Message_Peer, -// which can be written to a message and sent out. the key thing this function -// does (in addition to PeersToPBPeers) is set the ConnectionType with -// information from the given inet.Network. -func PeerInfosToPBPeers(n inet.Network, peers []pstore.PeerInfo) []*Message_Peer { - pbps := RawPeerInfosToPBPeers(peers) - for i, pbp := range pbps { - c := ConnectionType(n.Connectedness(peers[i].ID)) - pbp.Connection = &c - } - return pbps -} - -func PeerRoutingInfosToPBPeers(peers []PeerRoutingInfo) []*Message_Peer { - pbpeers := make([]*Message_Peer, len(peers)) - for i, p := range peers { - pbpeers[i] = peerRoutingInfoToPBPeer(p) - } - return pbpeers -} - -// PBPeersToPeerInfos converts given []*Message_Peer into []pstore.PeerInfo -// Invalid addresses will be silently omitted. -func PBPeersToPeerInfos(pbps []*Message_Peer) []pstore.PeerInfo { - peers := make([]pstore.PeerInfo, 0, len(pbps)) - for _, pbp := range pbps { - peers = append(peers, PBPeerToPeerInfo(pbp)) - } - return peers -} - -// Addresses returns a multiaddr associated with the Message_Peer entry -func (m *Message_Peer) Addresses() []ma.Multiaddr { - if m == nil { - return nil - } - - maddrs := make([]ma.Multiaddr, 0, len(m.Addrs)) - for _, addr := range m.Addrs { - maddr, err := ma.NewMultiaddrBytes(addr) - if err != nil { - log.Warningf("error decoding Multiaddr for peer: %s", m.GetId()) - continue - } - - maddrs = append(maddrs, maddr) - } - return maddrs -} - -// GetClusterLevel gets and adjusts the cluster level on the message. -// a +/- 1 adjustment is needed to distinguish a valid first level (1) and -// default "no value" protobuf behavior (0) -func (m *Message) GetClusterLevel() int { - level := m.GetClusterLevelRaw() - 1 - if level < 0 { - return 0 - } - return int(level) -} - -// SetClusterLevel adjusts and sets the cluster level on the message. -// a +/- 1 adjustment is needed to distinguish a valid first level (1) and -// default "no value" protobuf behavior (0) -func (m *Message) SetClusterLevel(level int) { - lvl := int32(level) - m.ClusterLevelRaw = &lvl -} - -// Loggable turns a Message into machine-readable log output -func (m *Message) Loggable() map[string]interface{} { - return map[string]interface{}{ - "message": map[string]string{ - "type": m.Type.String(), - "key": key.Key(m.GetKey()).B58String(), - }, - } -} - -// ConnectionType returns a Message_ConnectionType associated with the -// inet.Connectedness. -func ConnectionType(c inet.Connectedness) Message_ConnectionType { - switch c { - default: - return Message_NOT_CONNECTED - case inet.NotConnected: - return Message_NOT_CONNECTED - case inet.Connected: - return Message_CONNECTED - case inet.CanConnect: - return Message_CAN_CONNECT - case inet.CannotConnect: - return Message_CANNOT_CONNECT - } -} - -// Connectedness returns an inet.Connectedness associated with the -// Message_ConnectionType. -func Connectedness(c Message_ConnectionType) inet.Connectedness { - switch c { - default: - return inet.NotConnected - case Message_NOT_CONNECTED: - return inet.NotConnected - case Message_CONNECTED: - return inet.Connected - case Message_CAN_CONNECT: - return inet.CanConnect - case Message_CANNOT_CONNECT: - return inet.CannotConnect - } -} diff --git a/routing/dht/pb/message_test.go b/routing/dht/pb/message_test.go deleted file mode 100644 index 71f4abdc5ec..00000000000 --- a/routing/dht/pb/message_test.go +++ /dev/null @@ -1,15 +0,0 @@ -package dht_pb - -import ( - "testing" -) - -func TestBadAddrsDontReturnNil(t *testing.T) { - mp := new(Message_Peer) - mp.Addrs = [][]byte{[]byte("NOT A VALID MULTIADDR")} - - addrs := mp.Addresses() - if len(addrs) > 0 { - t.Fatal("shouldnt have any multiaddrs") - } -} diff --git a/routing/dht/providers/providers.go b/routing/dht/providers/providers.go deleted file mode 100644 index e48aaccef3c..00000000000 --- a/routing/dht/providers/providers.go +++ /dev/null @@ -1,353 +0,0 @@ -package providers - -import ( - "encoding/binary" - "fmt" - "strings" - "time" - - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - dsq "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/query" - goprocess "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess" - goprocessctx "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess/context" - logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" - lru "gx/ipfs/QmVYxfoJQiZijTgPNHCHgHELvQpbsJNTg6Crmc3dQkj3yy/golang-lru" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" - base32 "gx/ipfs/Qmb1DA2A9LS2wR4FFweB4uEDomFsdmnw1VLawLE1yQzudj/base32" - autobatch "gx/ipfs/QmcRHLm2aqDabkpcto1NzLad7YQhH99MGDHSWWvwMxKiZw/autobatch" - - key "github.com/ipfs/go-ipfs/blocks/key" - flags "github.com/ipfs/go-ipfs/flags" - - context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" -) - -var batchBufferSize = 256 - -func init() { - if flags.LowMemMode { - batchBufferSize = 8 - } -} - -var log = logging.Logger("providers") - -var lruCacheSize = 256 -var ProvideValidity = time.Hour * 24 -var defaultCleanupInterval = time.Hour - -type ProviderManager struct { - // all non channel fields are meant to be accessed only within - // the run method - providers *lru.Cache - lpeer peer.ID - dstore ds.Datastore - - newprovs chan *addProv - getprovs chan *getProv - period time.Duration - proc goprocess.Process - - cleanupInterval time.Duration -} - -type providerSet struct { - providers []peer.ID - set map[peer.ID]time.Time -} - -type addProv struct { - k key.Key - val peer.ID -} - -type getProv struct { - k key.Key - resp chan []peer.ID -} - -func NewProviderManager(ctx context.Context, local peer.ID, dstore ds.Batching) *ProviderManager { - pm := new(ProviderManager) - pm.getprovs = make(chan *getProv) - pm.newprovs = make(chan *addProv) - pm.dstore = autobatch.NewAutoBatching(dstore, batchBufferSize) - cache, err := lru.New(lruCacheSize) - if err != nil { - panic(err) //only happens if negative value is passed to lru constructor - } - pm.providers = cache - - pm.proc = goprocessctx.WithContext(ctx) - pm.cleanupInterval = defaultCleanupInterval - pm.proc.Go(func(p goprocess.Process) { pm.run() }) - - return pm -} - -const providersKeyPrefix = "/providers/" - -func mkProvKey(k key.Key) ds.Key { - return ds.NewKey(providersKeyPrefix + base32.RawStdEncoding.EncodeToString([]byte(k))) -} - -func (pm *ProviderManager) Process() goprocess.Process { - return pm.proc -} - -func (pm *ProviderManager) providersForKey(k key.Key) ([]peer.ID, error) { - pset, err := pm.getProvSet(k) - if err != nil { - return nil, err - } - return pset.providers, nil -} - -func (pm *ProviderManager) getProvSet(k key.Key) (*providerSet, error) { - cached, ok := pm.providers.Get(k) - if ok { - return cached.(*providerSet), nil - } - - pset, err := loadProvSet(pm.dstore, k) - if err != nil { - return nil, err - } - - if len(pset.providers) > 0 { - pm.providers.Add(k, pset) - } - - return pset, nil -} - -func loadProvSet(dstore ds.Datastore, k key.Key) (*providerSet, error) { - res, err := dstore.Query(dsq.Query{Prefix: mkProvKey(k).String()}) - if err != nil { - return nil, err - } - - out := newProviderSet() - for e := range res.Next() { - if e.Error != nil { - log.Error("got an error: ", e.Error) - continue - } - parts := strings.Split(e.Key, "/") - if len(parts) != 4 { - log.Warning("incorrectly formatted key: ", e.Key) - continue - } - - decstr, err := base32.RawStdEncoding.DecodeString(parts[len(parts)-1]) - if err != nil { - log.Error("base32 decoding error: ", err) - continue - } - - pid := peer.ID(decstr) - - t, err := readTimeValue(e.Value) - if err != nil { - log.Warning("parsing providers record from disk: ", err) - continue - } - - out.setVal(pid, t) - } - - return out, nil -} - -func readTimeValue(i interface{}) (time.Time, error) { - data, ok := i.([]byte) - if !ok { - return time.Time{}, fmt.Errorf("data was not a []byte") - } - - nsec, _ := binary.Varint(data) - - return time.Unix(0, nsec), nil -} - -func (pm *ProviderManager) addProv(k key.Key, p peer.ID) error { - iprovs, ok := pm.providers.Get(k) - if !ok { - iprovs = newProviderSet() - pm.providers.Add(k, iprovs) - } - provs := iprovs.(*providerSet) - now := time.Now() - provs.setVal(p, now) - - return writeProviderEntry(pm.dstore, k, p, now) -} - -func writeProviderEntry(dstore ds.Datastore, k key.Key, p peer.ID, t time.Time) error { - dsk := mkProvKey(k).ChildString(base32.RawStdEncoding.EncodeToString([]byte(p))) - - buf := make([]byte, 16) - n := binary.PutVarint(buf, t.UnixNano()) - - return dstore.Put(dsk, buf[:n]) -} - -func (pm *ProviderManager) deleteProvSet(k key.Key) error { - pm.providers.Remove(k) - - res, err := pm.dstore.Query(dsq.Query{ - KeysOnly: true, - Prefix: mkProvKey(k).String(), - }) - - entries, err := res.Rest() - if err != nil { - return err - } - - for _, e := range entries { - err := pm.dstore.Delete(ds.NewKey(e.Key)) - if err != nil { - log.Error("deleting provider set: ", err) - } - } - return nil -} - -func (pm *ProviderManager) getAllProvKeys() ([]key.Key, error) { - res, err := pm.dstore.Query(dsq.Query{ - KeysOnly: true, - Prefix: providersKeyPrefix, - }) - - if err != nil { - return nil, err - } - - entries, err := res.Rest() - if err != nil { - return nil, err - } - - out := make([]key.Key, 0, len(entries)) - seen := make(map[key.Key]struct{}) - for _, e := range entries { - parts := strings.Split(e.Key, "/") - if len(parts) != 4 { - log.Warning("incorrectly formatted provider entry in datastore") - continue - } - decoded, err := base32.RawStdEncoding.DecodeString(parts[2]) - if err != nil { - log.Warning("error decoding base32 provider key") - continue - } - - k := key.Key(decoded) - if _, ok := seen[k]; !ok { - out = append(out, key.Key(decoded)) - seen[k] = struct{}{} - } - } - - return out, nil -} - -func (pm *ProviderManager) run() { - tick := time.NewTicker(pm.cleanupInterval) - for { - select { - case np := <-pm.newprovs: - err := pm.addProv(np.k, np.val) - if err != nil { - log.Error("error adding new providers: ", err) - } - case gp := <-pm.getprovs: - provs, err := pm.providersForKey(gp.k) - if err != nil && err != ds.ErrNotFound { - log.Error("error reading providers: ", err) - } - - gp.resp <- provs - case <-tick.C: - keys, err := pm.getAllProvKeys() - if err != nil { - log.Error("Error loading provider keys: ", err) - continue - } - for _, k := range keys { - provs, err := pm.getProvSet(k) - if err != nil { - log.Error("error loading known provset: ", err) - continue - } - var filtered []peer.ID - for p, t := range provs.set { - if time.Now().Sub(t) > ProvideValidity { - delete(provs.set, p) - } else { - filtered = append(filtered, p) - } - } - - if len(filtered) > 0 { - provs.providers = filtered - } else { - err := pm.deleteProvSet(k) - if err != nil { - log.Error("error deleting provider set: ", err) - } - } - } - case <-pm.proc.Closing(): - return - } - } -} - -func (pm *ProviderManager) AddProvider(ctx context.Context, k key.Key, val peer.ID) { - prov := &addProv{ - k: k, - val: val, - } - select { - case pm.newprovs <- prov: - case <-ctx.Done(): - } -} - -func (pm *ProviderManager) GetProviders(ctx context.Context, k key.Key) []peer.ID { - gp := &getProv{ - k: k, - resp: make(chan []peer.ID, 1), // buffered to prevent sender from blocking - } - select { - case <-ctx.Done(): - return nil - case pm.getprovs <- gp: - } - select { - case <-ctx.Done(): - return nil - case peers := <-gp.resp: - return peers - } -} - -func newProviderSet() *providerSet { - return &providerSet{ - set: make(map[peer.ID]time.Time), - } -} - -func (ps *providerSet) Add(p peer.ID) { - ps.setVal(p, time.Now()) -} - -func (ps *providerSet) setVal(p peer.ID, t time.Time) { - _, found := ps.set[p] - if !found { - ps.providers = append(ps.providers, p) - } - - ps.set[p] = t -} diff --git a/routing/dht/providers/providers_test.go b/routing/dht/providers/providers_test.go deleted file mode 100644 index 32ede446911..00000000000 --- a/routing/dht/providers/providers_test.go +++ /dev/null @@ -1,150 +0,0 @@ -package providers - -import ( - "fmt" - "testing" - "time" - - key "github.com/ipfs/go-ipfs/blocks/key" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" - - context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" -) - -func TestProviderManager(t *testing.T) { - ctx := context.Background() - mid := peer.ID("testing") - p := NewProviderManager(ctx, mid, ds.NewMapDatastore()) - a := key.Key("test") - p.AddProvider(ctx, a, peer.ID("testingprovider")) - resp := p.GetProviders(ctx, a) - if len(resp) != 1 { - t.Fatal("Could not retrieve provider.") - } - p.proc.Close() -} - -func TestProvidersDatastore(t *testing.T) { - old := lruCacheSize - lruCacheSize = 10 - defer func() { lruCacheSize = old }() - - ctx := context.Background() - mid := peer.ID("testing") - p := NewProviderManager(ctx, mid, ds.NewMapDatastore()) - defer p.proc.Close() - - friend := peer.ID("friend") - var keys []key.Key - for i := 0; i < 100; i++ { - k := key.Key(fmt.Sprint(i)) - keys = append(keys, k) - p.AddProvider(ctx, k, friend) - } - - for _, k := range keys { - resp := p.GetProviders(ctx, k) - if len(resp) != 1 { - t.Fatal("Could not retrieve provider.") - } - if resp[0] != friend { - t.Fatal("expected provider to be 'friend'") - } - } -} - -func TestProvidersSerialization(t *testing.T) { - dstore := ds.NewMapDatastore() - - k := key.Key("my key!") - p1 := peer.ID("peer one") - p2 := peer.ID("peer two") - pt1 := time.Now() - pt2 := pt1.Add(time.Hour) - - err := writeProviderEntry(dstore, k, p1, pt1) - if err != nil { - t.Fatal(err) - } - - err = writeProviderEntry(dstore, k, p2, pt2) - if err != nil { - t.Fatal(err) - } - - pset, err := loadProvSet(dstore, k) - if err != nil { - t.Fatal(err) - } - - lt1, ok := pset.set[p1] - if !ok { - t.Fatal("failed to load set correctly") - } - - if pt1 != lt1 { - t.Fatal("time wasnt serialized correctly") - } - - lt2, ok := pset.set[p2] - if !ok { - t.Fatal("failed to load set correctly") - } - - if pt2 != lt2 { - t.Fatal("time wasnt serialized correctly") - } -} - -func TestProvidesExpire(t *testing.T) { - pval := ProvideValidity - cleanup := defaultCleanupInterval - ProvideValidity = time.Second / 2 - defaultCleanupInterval = time.Second / 2 - defer func() { - ProvideValidity = pval - defaultCleanupInterval = cleanup - }() - - ctx := context.Background() - mid := peer.ID("testing") - p := NewProviderManager(ctx, mid, ds.NewMapDatastore()) - - peers := []peer.ID{"a", "b"} - var keys []key.Key - for i := 0; i < 10; i++ { - k := key.Key(i) - keys = append(keys, k) - p.AddProvider(ctx, k, peers[0]) - p.AddProvider(ctx, k, peers[1]) - } - - for i := 0; i < 10; i++ { - out := p.GetProviders(ctx, keys[i]) - if len(out) != 2 { - t.Fatal("expected providers to still be there") - } - } - - time.Sleep(time.Second) - for i := 0; i < 10; i++ { - out := p.GetProviders(ctx, keys[i]) - if len(out) > 2 { - t.Fatal("expected providers to be cleaned up") - } - } - - if p.providers.Len() != 0 { - t.Fatal("providers map not cleaned up") - } - - allprovs, err := p.getAllProvKeys() - if err != nil { - t.Fatal(err) - } - - if len(allprovs) != 0 { - t.Fatal("expected everything to be cleaned out of the datastore") - } -} diff --git a/routing/dht/query.go b/routing/dht/query.go deleted file mode 100644 index 2b1efb337e8..00000000000 --- a/routing/dht/query.go +++ /dev/null @@ -1,297 +0,0 @@ -package dht - -import ( - "sync" - - key "github.com/ipfs/go-ipfs/blocks/key" - notif "github.com/ipfs/go-ipfs/notifications" - "github.com/ipfs/go-ipfs/routing" - pset "github.com/ipfs/go-ipfs/thirdparty/peerset" - todoctr "github.com/ipfs/go-ipfs/thirdparty/todocounter" - - process "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess" - ctxproc "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess/context" - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" - queue "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore/queue" - logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" - u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" - context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" -) - -var maxQueryConcurrency = AlphaValue - -type dhtQuery struct { - dht *IpfsDHT - key key.Key // the key we're querying for - qfunc queryFunc // the function to execute per peer - concurrency int // the concurrency parameter -} - -type dhtQueryResult struct { - value []byte // GetValue - peer pstore.PeerInfo // FindPeer - providerPeers []pstore.PeerInfo // GetProviders - closerPeers []pstore.PeerInfo // * - success bool -} - -// constructs query -func (dht *IpfsDHT) newQuery(k key.Key, f queryFunc) *dhtQuery { - return &dhtQuery{ - key: k, - dht: dht, - qfunc: f, - concurrency: maxQueryConcurrency, - } -} - -// QueryFunc is a function that runs a particular query with a given peer. -// It returns either: -// - the value -// - a list of peers potentially better able to serve the query -// - an error -type queryFunc func(context.Context, peer.ID) (*dhtQueryResult, error) - -// Run runs the query at hand. pass in a list of peers to use first. -func (q *dhtQuery) Run(ctx context.Context, peers []peer.ID) (*dhtQueryResult, error) { - select { - case <-ctx.Done(): - return nil, ctx.Err() - default: - } - - ctx, cancel := context.WithCancel(ctx) - defer cancel() - - runner := newQueryRunner(q) - return runner.Run(ctx, peers) -} - -type dhtQueryRunner struct { - query *dhtQuery // query to run - peersSeen *pset.PeerSet // all peers queried. prevent querying same peer 2x - peersToQuery *queue.ChanQueue // peers remaining to be queried - peersRemaining todoctr.Counter // peersToQuery + currently processing - - result *dhtQueryResult // query result - errs u.MultiErr // result errors. maybe should be a map[peer.ID]error - - rateLimit chan struct{} // processing semaphore - log logging.EventLogger - - runCtx context.Context - - proc process.Process - sync.RWMutex -} - -func newQueryRunner(q *dhtQuery) *dhtQueryRunner { - proc := process.WithParent(process.Background()) - ctx := ctxproc.OnClosingContext(proc) - return &dhtQueryRunner{ - query: q, - peersToQuery: queue.NewChanQueue(ctx, queue.NewXORDistancePQ(string(q.key))), - peersRemaining: todoctr.NewSyncCounter(), - peersSeen: pset.New(), - rateLimit: make(chan struct{}, q.concurrency), - proc: proc, - } -} - -func (r *dhtQueryRunner) Run(ctx context.Context, peers []peer.ID) (*dhtQueryResult, error) { - r.log = log - r.runCtx = ctx - - if len(peers) == 0 { - log.Warning("Running query with no peers!") - return nil, nil - } - - // setup concurrency rate limiting - for i := 0; i < r.query.concurrency; i++ { - r.rateLimit <- struct{}{} - } - - // add all the peers we got first. - for _, p := range peers { - r.addPeerToQuery(p) - } - - // go do this thing. - // do it as a child proc to make sure Run exits - // ONLY AFTER spawn workers has exited. - r.proc.Go(r.spawnWorkers) - - // so workers are working. - - // wait until they're done. - err := routing.ErrNotFound - - // now, if the context finishes, close the proc. - // we have to do it here because the logic before is setup, which - // should run without closing the proc. - ctxproc.CloseAfterContext(r.proc, ctx) - - select { - case <-r.peersRemaining.Done(): - r.proc.Close() - r.RLock() - defer r.RUnlock() - - err = routing.ErrNotFound - - // if every query to every peer failed, something must be very wrong. - if len(r.errs) > 0 && len(r.errs) == r.peersSeen.Size() { - log.Debugf("query errs: %s", r.errs) - err = r.errs[0] - } - - case <-r.proc.Closed(): - r.RLock() - defer r.RUnlock() - err = context.DeadlineExceeded - } - - if r.result != nil && r.result.success { - return r.result, nil - } - - return nil, err -} - -func (r *dhtQueryRunner) addPeerToQuery(next peer.ID) { - // if new peer is ourselves... - if next == r.query.dht.self { - r.log.Debug("addPeerToQuery skip self") - return - } - - if !r.peersSeen.TryAdd(next) { - return - } - - notif.PublishQueryEvent(r.runCtx, ¬if.QueryEvent{ - Type: notif.AddingPeer, - ID: next, - }) - - r.peersRemaining.Increment(1) - select { - case r.peersToQuery.EnqChan <- next: - case <-r.proc.Closing(): - } -} - -func (r *dhtQueryRunner) spawnWorkers(proc process.Process) { - for { - - select { - case <-r.peersRemaining.Done(): - return - - case <-r.proc.Closing(): - return - - case <-r.rateLimit: - select { - case p, more := <-r.peersToQuery.DeqChan: - if !more { - return // channel closed. - } - - // do it as a child func to make sure Run exits - // ONLY AFTER spawn workers has exited. - proc.Go(func(proc process.Process) { - r.queryPeer(proc, p) - }) - case <-r.proc.Closing(): - return - case <-r.peersRemaining.Done(): - return - } - } - } -} - -func (r *dhtQueryRunner) queryPeer(proc process.Process, p peer.ID) { - // ok let's do this! - - // create a context from our proc. - ctx := ctxproc.OnClosingContext(proc) - - // make sure we do this when we exit - defer func() { - // signal we're done proccessing peer p - r.peersRemaining.Decrement(1) - r.rateLimit <- struct{}{} - }() - - // make sure we're connected to the peer. - // FIXME abstract away into the network layer - if conns := r.query.dht.host.Network().ConnsToPeer(p); len(conns) == 0 { - log.Debug("not connected. dialing.") - - notif.PublishQueryEvent(r.runCtx, ¬if.QueryEvent{ - Type: notif.DialingPeer, - ID: p, - }) - // while we dial, we do not take up a rate limit. this is to allow - // forward progress during potentially very high latency dials. - r.rateLimit <- struct{}{} - - pi := pstore.PeerInfo{ID: p} - - if err := r.query.dht.host.Connect(ctx, pi); err != nil { - log.Debugf("Error connecting: %s", err) - - notif.PublishQueryEvent(r.runCtx, ¬if.QueryEvent{ - Type: notif.QueryError, - Extra: err.Error(), - ID: p, - }) - - r.Lock() - r.errs = append(r.errs, err) - r.Unlock() - <-r.rateLimit // need to grab it again, as we deferred. - return - } - <-r.rateLimit // need to grab it again, as we deferred. - log.Debugf("connected. dial success.") - } - - // finally, run the query against this peer - res, err := r.query.qfunc(ctx, p) - - if err != nil { - log.Debugf("ERROR worker for: %v %v", p, err) - r.Lock() - r.errs = append(r.errs, err) - r.Unlock() - - } else if res.success { - log.Debugf("SUCCESS worker for: %v %s", p, res) - r.Lock() - r.result = res - r.Unlock() - go r.proc.Close() // signal to everyone that we're done. - // must be async, as we're one of the children, and Close blocks. - - } else if len(res.closerPeers) > 0 { - log.Debugf("PEERS CLOSER -- worker for: %v (%d closer peers)", p, len(res.closerPeers)) - for _, next := range res.closerPeers { - if next.ID == r.query.dht.self { // dont add self. - log.Debugf("PEERS CLOSER -- worker for: %v found self", p) - continue - } - - // add their addresses to the dialer's peerstore - r.query.dht.peerstore.AddAddrs(next.ID, next.Addrs, pstore.TempAddrTTL) - r.addPeerToQuery(next.ID) - log.Debugf("PEERS CLOSER -- worker for: %v added %v (%v)", p, next.ID, next.Addrs) - } - } else { - log.Debugf("QUERY worker for: %v - not found, and no closer peers.", p) - } -} diff --git a/routing/dht/records.go b/routing/dht/records.go deleted file mode 100644 index 0b461382af2..00000000000 --- a/routing/dht/records.go +++ /dev/null @@ -1,149 +0,0 @@ -package dht - -import ( - "fmt" - "time" - - routing "github.com/ipfs/go-ipfs/routing" - pb "github.com/ipfs/go-ipfs/routing/dht/pb" - record "github.com/ipfs/go-ipfs/routing/record" - ci "gx/ipfs/QmVoi5es8D5fNHZDqoW6DgDAEPEV5hQp8GBz161vZXiwpQ/go-libp2p-crypto" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" - ctxfrac "gx/ipfs/QmX6DhWrpBB5NtadXmPSXYNdVvuLfJXoFNMvUMoVvP5UJa/go-context/frac" - "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" -) - -// MaxRecordAge specifies the maximum time that any node will hold onto a record -// from the time its received. This does not apply to any other forms of validity that -// the record may contain. -// For example, a record may contain an ipns entry with an EOL saying its valid -// until the year 2020 (a great time in the future). For that record to stick around -// it must be rebroadcasted more frequently than once every 'MaxRecordAge' -const MaxRecordAge = time.Hour * 36 - -func (dht *IpfsDHT) GetPublicKey(ctx context.Context, p peer.ID) (ci.PubKey, error) { - log.Debugf("getPublicKey for: %s", p) - - // check locally. - pk := dht.peerstore.PubKey(p) - if pk != nil { - return pk, nil - } - - // ok, try the node itself. if they're overwhelmed or slow we can move on. - ctxT, cancelFunc := ctxfrac.WithDeadlineFraction(ctx, 0.3) - defer cancelFunc() - if pk, err := dht.getPublicKeyFromNode(ctx, p); err == nil { - err := dht.peerstore.AddPubKey(p, pk) - if err != nil { - return pk, err - } - return pk, nil - } - - // last ditch effort: let's try the dht. - log.Debugf("pk for %s not in peerstore, and peer failed. Trying DHT.", p) - pkkey := routing.KeyForPublicKey(p) - - val, err := dht.GetValue(ctxT, pkkey) - if err != nil { - log.Warning("Failed to find requested public key.") - return nil, err - } - - pk, err = ci.UnmarshalPublicKey(val) - if err != nil { - log.Debugf("Failed to unmarshal public key: %s", err) - return nil, err - } - - return pk, dht.peerstore.AddPubKey(p, pk) -} - -func (dht *IpfsDHT) getPublicKeyFromNode(ctx context.Context, p peer.ID) (ci.PubKey, error) { - - // check locally, just in case... - pk := dht.peerstore.PubKey(p) - if pk != nil { - return pk, nil - } - - pkkey := routing.KeyForPublicKey(p) - pmes, err := dht.getValueSingle(ctx, p, pkkey) - if err != nil { - return nil, err - } - - // node doesn't have key :( - record := pmes.GetRecord() - if record == nil { - return nil, fmt.Errorf("Node not responding with its public key: %s", p) - } - - // Success! We were given the value. we don't need to check - // validity because a) we can't. b) we know the hash of the - // key we're looking for. - val := record.GetValue() - log.Debug("DHT got a value from other peer") - - pk, err = ci.UnmarshalPublicKey(val) - if err != nil { - return nil, err - } - - id, err := peer.IDFromPublicKey(pk) - if err != nil { - return nil, err - } - if id != p { - return nil, fmt.Errorf("public key does not match id: %s", p) - } - - // ok! it's valid. we got it! - log.Debugf("DHT got public key from node itself.") - return pk, nil -} - -// verifyRecordLocally attempts to verify a record. if we do not have the public -// key, we fail. we do not search the dht. -func (dht *IpfsDHT) verifyRecordLocally(r *pb.Record) error { - - if len(r.Signature) > 0 { - // First, validate the signature - p := peer.ID(r.GetAuthor()) - pk := dht.peerstore.PubKey(p) - if pk == nil { - return fmt.Errorf("do not have public key for %s", p) - } - - if err := record.CheckRecordSig(r, pk); err != nil { - return err - } - } - - return dht.Validator.VerifyRecord(r) -} - -// verifyRecordOnline verifies a record, searching the DHT for the public key -// if necessary. The reason there is a distinction in the functions is that -// retrieving arbitrary public keys from the DHT as a result of passively -// receiving records (e.g. through a PUT_VALUE or ADD_PROVIDER) can cause a -// massive amplification attack on the dht. Use with care. -func (dht *IpfsDHT) verifyRecordOnline(ctx context.Context, r *pb.Record) error { - - if len(r.Signature) > 0 { - // get the public key, search for it if necessary. - p := peer.ID(r.GetAuthor()) - pk, err := dht.GetPublicKey(ctx, p) - if err != nil { - return err - } - - err = record.CheckRecordSig(r, pk) - if err != nil { - return err - } - } - - return dht.Validator.VerifyRecord(r) -} diff --git a/routing/dht/routing.go b/routing/dht/routing.go deleted file mode 100644 index abd9c42ff41..00000000000 --- a/routing/dht/routing.go +++ /dev/null @@ -1,537 +0,0 @@ -package dht - -import ( - "bytes" - "fmt" - "runtime" - "sync" - "time" - - key "github.com/ipfs/go-ipfs/blocks/key" - notif "github.com/ipfs/go-ipfs/notifications" - "github.com/ipfs/go-ipfs/routing" - pb "github.com/ipfs/go-ipfs/routing/dht/pb" - kb "github.com/ipfs/go-ipfs/routing/kbucket" - record "github.com/ipfs/go-ipfs/routing/record" - pset "github.com/ipfs/go-ipfs/thirdparty/peerset" - - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" - context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" - inet "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/net" -) - -// asyncQueryBuffer is the size of buffered channels in async queries. This -// buffer allows multiple queries to execute simultaneously, return their -// results and continue querying closer peers. Note that different query -// results will wait for the channel to drain. -var asyncQueryBuffer = 10 - -// This file implements the Routing interface for the IpfsDHT struct. - -// Basic Put/Get - -// PutValue adds value corresponding to given Key. -// This is the top level "Store" operation of the DHT -func (dht *IpfsDHT) PutValue(ctx context.Context, key key.Key, value []byte) error { - log.Debugf("PutValue %s", key) - sk, err := dht.getOwnPrivateKey() - if err != nil { - return err - } - - sign, err := dht.Validator.IsSigned(key) - if err != nil { - return err - } - - rec, err := record.MakePutRecord(sk, key, value, sign) - if err != nil { - log.Debug("creation of record failed!") - return err - } - - err = dht.putLocal(key, rec) - if err != nil { - return err - } - - pchan, err := dht.GetClosestPeers(ctx, key) - if err != nil { - return err - } - - wg := sync.WaitGroup{} - for p := range pchan { - wg.Add(1) - go func(p peer.ID) { - ctx, cancel := context.WithCancel(ctx) - defer cancel() - defer wg.Done() - notif.PublishQueryEvent(ctx, ¬if.QueryEvent{ - Type: notif.Value, - ID: p, - }) - - err := dht.putValueToPeer(ctx, p, key, rec) - if err != nil { - log.Debugf("failed putting value to peer: %s", err) - } - }(p) - } - wg.Wait() - return nil -} - -// GetValue searches for the value corresponding to given Key. -func (dht *IpfsDHT) GetValue(ctx context.Context, key key.Key) ([]byte, error) { - ctx, cancel := context.WithTimeout(ctx, time.Minute) - defer cancel() - - vals, err := dht.GetValues(ctx, key, 16) - if err != nil { - return nil, err - } - - var recs [][]byte - for _, v := range vals { - if v.Val != nil { - recs = append(recs, v.Val) - } - } - - i, err := dht.Selector.BestRecord(key, recs) - if err != nil { - return nil, err - } - - best := recs[i] - log.Debugf("GetValue %v %v", key, best) - if best == nil { - log.Errorf("GetValue yielded correct record with nil value.") - return nil, routing.ErrNotFound - } - - fixupRec, err := record.MakePutRecord(dht.peerstore.PrivKey(dht.self), key, best, true) - if err != nil { - // probably shouldnt actually 'error' here as we have found a value we like, - // but this call failing probably isnt something we want to ignore - return nil, err - } - - for _, v := range vals { - // if someone sent us a different 'less-valid' record, lets correct them - if !bytes.Equal(v.Val, best) { - go func(v routing.RecvdVal) { - if v.From == dht.self { - err := dht.putLocal(key, fixupRec) - if err != nil { - log.Error("Error correcting local dht entry:", err) - } - return - } - ctx, cancel := context.WithTimeout(dht.Context(), time.Second*30) - defer cancel() - err := dht.putValueToPeer(ctx, v.From, key, fixupRec) - if err != nil { - log.Error("Error correcting DHT entry: ", err) - } - }(v) - } - } - - return best, nil -} - -func (dht *IpfsDHT) GetValues(ctx context.Context, key key.Key, nvals int) ([]routing.RecvdVal, error) { - var vals []routing.RecvdVal - var valslock sync.Mutex - - // If we have it local, dont bother doing an RPC! - lrec, err := dht.getLocal(key) - if err == nil { - // TODO: this is tricky, we dont always want to trust our own value - // what if the authoritative source updated it? - log.Debug("have it locally") - vals = append(vals, routing.RecvdVal{ - Val: lrec.GetValue(), - From: dht.self, - }) - - if nvals <= 1 { - return vals, nil - } - } else if nvals == 0 { - return nil, err - } - - // get closest peers in the routing table - rtp := dht.routingTable.NearestPeers(kb.ConvertKey(key), KValue) - log.Debugf("peers in rt: %s", len(rtp), rtp) - if len(rtp) == 0 { - log.Warning("No peers from routing table!") - return nil, kb.ErrLookupFailure - } - - // setup the Query - parent := ctx - query := dht.newQuery(key, func(ctx context.Context, p peer.ID) (*dhtQueryResult, error) { - notif.PublishQueryEvent(parent, ¬if.QueryEvent{ - Type: notif.SendingQuery, - ID: p, - }) - - rec, peers, err := dht.getValueOrPeers(ctx, p, key) - switch err { - case routing.ErrNotFound: - // in this case, they responded with nothing, - // still send a notification so listeners can know the - // request has completed 'successfully' - notif.PublishQueryEvent(parent, ¬if.QueryEvent{ - Type: notif.PeerResponse, - ID: p, - }) - return nil, err - default: - return nil, err - - case nil, errInvalidRecord: - // in either of these cases, we want to keep going - } - - res := &dhtQueryResult{closerPeers: peers} - - if rec.GetValue() != nil || err == errInvalidRecord { - rv := routing.RecvdVal{ - Val: rec.GetValue(), - From: p, - } - valslock.Lock() - vals = append(vals, rv) - - // If weve collected enough records, we're done - if len(vals) >= nvals { - res.success = true - } - valslock.Unlock() - } - - notif.PublishQueryEvent(parent, ¬if.QueryEvent{ - Type: notif.PeerResponse, - ID: p, - Responses: pointerizePeerInfos(peers), - }) - - return res, nil - }) - - // run it! - _, err = query.Run(ctx, rtp) - if len(vals) == 0 { - if err != nil { - return nil, err - } - } - - return vals, nil - -} - -// Value provider layer of indirection. -// This is what DSHTs (Coral and MainlineDHT) do to store large values in a DHT. - -// Provide makes this node announce that it can provide a value for the given key -func (dht *IpfsDHT) Provide(ctx context.Context, key key.Key) error { - defer log.EventBegin(ctx, "provide", &key).Done() - - // add self locally - dht.providers.AddProvider(ctx, key, dht.self) - - peers, err := dht.GetClosestPeers(ctx, key) - if err != nil { - return err - } - - mes, err := dht.makeProvRecord(key) - if err != nil { - return err - } - - wg := sync.WaitGroup{} - for p := range peers { - wg.Add(1) - go func(p peer.ID) { - defer wg.Done() - log.Debugf("putProvider(%s, %s)", key, p) - notif.PublishQueryEvent(ctx, ¬if.QueryEvent{ - Type: notif.FinalPeer, - ID: p, - }) - err := dht.sendMessage(ctx, p, mes) - if err != nil { - log.Debug(err) - } - }(p) - } - wg.Wait() - return nil -} - -func (dht *IpfsDHT) makeProvRecord(skey key.Key) (*pb.Message, error) { - pi := pstore.PeerInfo{ - ID: dht.self, - Addrs: dht.host.Addrs(), - } - - // // only share WAN-friendly addresses ?? - // pi.Addrs = addrutil.WANShareableAddrs(pi.Addrs) - if len(pi.Addrs) < 1 { - return nil, fmt.Errorf("no known addresses for self. cannot put provider.") - } - - pmes := pb.NewMessage(pb.Message_ADD_PROVIDER, string(skey), 0) - pmes.ProviderPeers = pb.RawPeerInfosToPBPeers([]pstore.PeerInfo{pi}) - return pmes, nil -} - -// FindProviders searches until the context expires. -func (dht *IpfsDHT) FindProviders(ctx context.Context, key key.Key) ([]pstore.PeerInfo, error) { - var providers []pstore.PeerInfo - for p := range dht.FindProvidersAsync(ctx, key, KValue) { - providers = append(providers, p) - } - return providers, nil -} - -// FindProvidersAsync is the same thing as FindProviders, but returns a channel. -// Peers will be returned on the channel as soon as they are found, even before -// the search query completes. -func (dht *IpfsDHT) FindProvidersAsync(ctx context.Context, key key.Key, count int) <-chan pstore.PeerInfo { - log.Event(ctx, "findProviders", &key) - peerOut := make(chan pstore.PeerInfo, count) - go dht.findProvidersAsyncRoutine(ctx, key, count, peerOut) - return peerOut -} - -func (dht *IpfsDHT) findProvidersAsyncRoutine(ctx context.Context, key key.Key, count int, peerOut chan pstore.PeerInfo) { - defer log.EventBegin(ctx, "findProvidersAsync", &key).Done() - defer close(peerOut) - - ps := pset.NewLimited(count) - provs := dht.providers.GetProviders(ctx, key) - for _, p := range provs { - // NOTE: Assuming that this list of peers is unique - if ps.TryAdd(p) { - select { - case peerOut <- dht.peerstore.PeerInfo(p): - case <-ctx.Done(): - return - } - } - - // If we have enough peers locally, dont bother with remote RPC - if ps.Size() >= count { - return - } - } - - // setup the Query - parent := ctx - query := dht.newQuery(key, func(ctx context.Context, p peer.ID) (*dhtQueryResult, error) { - notif.PublishQueryEvent(parent, ¬if.QueryEvent{ - Type: notif.SendingQuery, - ID: p, - }) - pmes, err := dht.findProvidersSingle(ctx, p, key) - if err != nil { - return nil, err - } - - log.Debugf("%d provider entries", len(pmes.GetProviderPeers())) - provs := pb.PBPeersToPeerInfos(pmes.GetProviderPeers()) - log.Debugf("%d provider entries decoded", len(provs)) - - // Add unique providers from request, up to 'count' - for _, prov := range provs { - log.Debugf("got provider: %s", prov) - if ps.TryAdd(prov.ID) { - log.Debugf("using provider: %s", prov) - select { - case peerOut <- prov: - case <-ctx.Done(): - log.Debug("context timed out sending more providers") - return nil, ctx.Err() - } - } - if ps.Size() >= count { - log.Debugf("got enough providers (%d/%d)", ps.Size(), count) - return &dhtQueryResult{success: true}, nil - } - } - - // Give closer peers back to the query to be queried - closer := pmes.GetCloserPeers() - clpeers := pb.PBPeersToPeerInfos(closer) - log.Debugf("got closer peers: %d %s", len(clpeers), clpeers) - - notif.PublishQueryEvent(parent, ¬if.QueryEvent{ - Type: notif.PeerResponse, - ID: p, - Responses: pointerizePeerInfos(clpeers), - }) - return &dhtQueryResult{closerPeers: clpeers}, nil - }) - - peers := dht.routingTable.NearestPeers(kb.ConvertKey(key), KValue) - _, err := query.Run(ctx, peers) - if err != nil { - log.Debugf("Query error: %s", err) - // Special handling for issue: https://github.com/ipfs/go-ipfs/issues/3032 - if fmt.Sprint(err) == "" { - log.Error("reproduced bug 3032:") - log.Errorf("Errors type information: %#v", err) - log.Errorf("go version: %s", runtime.Version()) - log.Error("please report this information to: https://github.com/ipfs/go-ipfs/issues/3032") - - // replace problematic error with something that won't crash the daemon - err = fmt.Errorf("") - } - notif.PublishQueryEvent(ctx, ¬if.QueryEvent{ - Type: notif.QueryError, - Extra: err.Error(), - }) - } -} - -// FindPeer searches for a peer with given ID. -func (dht *IpfsDHT) FindPeer(ctx context.Context, id peer.ID) (pstore.PeerInfo, error) { - defer log.EventBegin(ctx, "FindPeer", id).Done() - - // Check if were already connected to them - if pi := dht.FindLocal(id); pi.ID != "" { - return pi, nil - } - - peers := dht.routingTable.NearestPeers(kb.ConvertPeerID(id), KValue) - if len(peers) == 0 { - return pstore.PeerInfo{}, kb.ErrLookupFailure - } - - // Sanity... - for _, p := range peers { - if p == id { - log.Debug("found target peer in list of closest peers...") - return dht.peerstore.PeerInfo(p), nil - } - } - - // setup the Query - parent := ctx - query := dht.newQuery(key.Key(id), func(ctx context.Context, p peer.ID) (*dhtQueryResult, error) { - notif.PublishQueryEvent(parent, ¬if.QueryEvent{ - Type: notif.SendingQuery, - ID: p, - }) - - pmes, err := dht.findPeerSingle(ctx, p, id) - if err != nil { - return nil, err - } - - closer := pmes.GetCloserPeers() - clpeerInfos := pb.PBPeersToPeerInfos(closer) - - // see it we got the peer here - for _, npi := range clpeerInfos { - if npi.ID == id { - return &dhtQueryResult{ - peer: npi, - success: true, - }, nil - } - } - - notif.PublishQueryEvent(parent, ¬if.QueryEvent{ - Type: notif.PeerResponse, - Responses: pointerizePeerInfos(clpeerInfos), - }) - - return &dhtQueryResult{closerPeers: clpeerInfos}, nil - }) - - // run it! - result, err := query.Run(ctx, peers) - if err != nil { - return pstore.PeerInfo{}, err - } - - log.Debugf("FindPeer %v %v", id, result.success) - if result.peer.ID == "" { - return pstore.PeerInfo{}, routing.ErrNotFound - } - - return result.peer, nil -} - -// FindPeersConnectedToPeer searches for peers directly connected to a given peer. -func (dht *IpfsDHT) FindPeersConnectedToPeer(ctx context.Context, id peer.ID) (<-chan pstore.PeerInfo, error) { - - peerchan := make(chan pstore.PeerInfo, asyncQueryBuffer) - peersSeen := make(map[peer.ID]struct{}) - - peers := dht.routingTable.NearestPeers(kb.ConvertPeerID(id), KValue) - if len(peers) == 0 { - return nil, kb.ErrLookupFailure - } - - // setup the Query - query := dht.newQuery(key.Key(id), func(ctx context.Context, p peer.ID) (*dhtQueryResult, error) { - - pmes, err := dht.findPeerSingle(ctx, p, id) - if err != nil { - return nil, err - } - - var clpeers []pstore.PeerInfo - closer := pmes.GetCloserPeers() - for _, pbp := range closer { - pi := pb.PBPeerToPeerInfo(pbp) - - // skip peers already seen - if _, found := peersSeen[pi.ID]; found { - continue - } - peersSeen[pi.ID] = struct{}{} - - // if peer is connected, send it to our client. - if pb.Connectedness(*pbp.Connection) == inet.Connected { - select { - case <-ctx.Done(): - return nil, ctx.Err() - case peerchan <- pi: - } - } - - // if peer is the peer we're looking for, don't bother querying it. - // TODO maybe query it? - if pb.Connectedness(*pbp.Connection) != inet.Connected { - clpeers = append(clpeers, pi) - } - } - - return &dhtQueryResult{closerPeers: clpeers}, nil - }) - - // run it! run it asynchronously to gen peers as results are found. - // this does no error checking - go func() { - if _, err := query.Run(ctx, peers); err != nil { - log.Debug(err) - } - - // close the peerchan channel when done. - close(peerchan) - }() - - return peerchan, nil -} diff --git a/routing/dht/util.go b/routing/dht/util.go deleted file mode 100644 index a605759a955..00000000000 --- a/routing/dht/util.go +++ /dev/null @@ -1,39 +0,0 @@ -package dht - -import ( - "sync" -) - -// Pool size is the number of nodes used for group find/set RPC calls -var PoolSize = 6 - -// K is the maximum number of requests to perform before returning failure. -var KValue = 20 - -// Alpha is the concurrency factor for asynchronous requests. -var AlphaValue = 3 - -// A counter for incrementing a variable across multiple threads -type counter struct { - n int - mut sync.Mutex -} - -func (c *counter) Increment() { - c.mut.Lock() - c.n++ - c.mut.Unlock() -} - -func (c *counter) Decrement() { - c.mut.Lock() - c.n-- - c.mut.Unlock() -} - -func (c *counter) Size() (s int) { - c.mut.Lock() - s = c.n - c.mut.Unlock() - return -} diff --git a/routing/kbucket/bucket.go b/routing/kbucket/bucket.go deleted file mode 100644 index 171436279ac..00000000000 --- a/routing/kbucket/bucket.go +++ /dev/null @@ -1,108 +0,0 @@ -package kbucket - -import ( - "container/list" - "sync" - - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" -) - -// Bucket holds a list of peers. -type Bucket struct { - lk sync.RWMutex - list *list.List -} - -func newBucket() *Bucket { - b := new(Bucket) - b.list = list.New() - return b -} - -func (b *Bucket) Peers() []peer.ID { - b.lk.RLock() - defer b.lk.RUnlock() - ps := make([]peer.ID, 0, b.list.Len()) - for e := b.list.Front(); e != nil; e = e.Next() { - id := e.Value.(peer.ID) - ps = append(ps, id) - } - return ps -} - -func (b *Bucket) Has(id peer.ID) bool { - b.lk.RLock() - defer b.lk.RUnlock() - for e := b.list.Front(); e != nil; e = e.Next() { - if e.Value.(peer.ID) == id { - return true - } - } - return false -} - -func (b *Bucket) Remove(id peer.ID) { - b.lk.Lock() - defer b.lk.Unlock() - for e := b.list.Front(); e != nil; e = e.Next() { - if e.Value.(peer.ID) == id { - b.list.Remove(e) - } - } -} - -func (b *Bucket) MoveToFront(id peer.ID) { - b.lk.Lock() - defer b.lk.Unlock() - for e := b.list.Front(); e != nil; e = e.Next() { - if e.Value.(peer.ID) == id { - b.list.MoveToFront(e) - } - } -} - -func (b *Bucket) PushFront(p peer.ID) { - b.lk.Lock() - b.list.PushFront(p) - b.lk.Unlock() -} - -func (b *Bucket) PopBack() peer.ID { - b.lk.Lock() - defer b.lk.Unlock() - last := b.list.Back() - b.list.Remove(last) - return last.Value.(peer.ID) -} - -func (b *Bucket) Len() int { - b.lk.RLock() - defer b.lk.RUnlock() - return b.list.Len() -} - -// Split splits a buckets peers into two buckets, the methods receiver will have -// peers with CPL equal to cpl, the returned bucket will have peers with CPL -// greater than cpl (returned bucket has closer peers) -func (b *Bucket) Split(cpl int, target ID) *Bucket { - b.lk.Lock() - defer b.lk.Unlock() - - out := list.New() - newbuck := newBucket() - newbuck.list = out - e := b.list.Front() - for e != nil { - peerID := ConvertPeerID(e.Value.(peer.ID)) - peerCPL := commonPrefixLen(peerID, target) - if peerCPL > cpl { - cur := e - out.PushBack(e.Value) - e = e.Next() - b.list.Remove(cur) - continue - } - e = e.Next() - } - return newbuck -} diff --git a/routing/kbucket/sorting.go b/routing/kbucket/sorting.go deleted file mode 100644 index 19ea84f680c..00000000000 --- a/routing/kbucket/sorting.go +++ /dev/null @@ -1,55 +0,0 @@ -package kbucket - -import ( - "container/list" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" - "sort" -) - -// A helper struct to sort peers by their distance to the local node -type peerDistance struct { - p peer.ID - distance ID -} - -// peerSorterArr implements sort.Interface to sort peers by xor distance -type peerSorterArr []*peerDistance - -func (p peerSorterArr) Len() int { return len(p) } -func (p peerSorterArr) Swap(a, b int) { p[a], p[b] = p[b], p[a] } -func (p peerSorterArr) Less(a, b int) bool { - return p[a].distance.less(p[b].distance) -} - -// - -func copyPeersFromList(target ID, peerArr peerSorterArr, peerList *list.List) peerSorterArr { - for e := peerList.Front(); e != nil; e = e.Next() { - p := e.Value.(peer.ID) - pID := ConvertPeerID(p) - pd := peerDistance{ - p: p, - distance: xor(target, pID), - } - peerArr = append(peerArr, &pd) - } - return peerArr -} - -func SortClosestPeers(peers []peer.ID, target ID) []peer.ID { - var psarr peerSorterArr - for _, p := range peers { - pID := ConvertPeerID(p) - pd := &peerDistance{ - p: p, - distance: xor(target, pID), - } - psarr = append(psarr, pd) - } - sort.Sort(psarr) - var out []peer.ID - for _, p := range psarr { - out = append(out, p.p) - } - return out -} diff --git a/routing/kbucket/table.go b/routing/kbucket/table.go deleted file mode 100644 index 47a3228caf2..00000000000 --- a/routing/kbucket/table.go +++ /dev/null @@ -1,225 +0,0 @@ -// package kbucket implements a kademlia 'k-bucket' routing table. -package kbucket - -import ( - "fmt" - "sort" - "sync" - "time" - - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" - logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" -) - -var log = logging.Logger("table") - -// RoutingTable defines the routing table. -type RoutingTable struct { - - // ID of the local peer - local ID - - // Blanket lock, refine later for better performance - tabLock sync.RWMutex - - // latency metrics - metrics pstore.Metrics - - // Maximum acceptable latency for peers in this cluster - maxLatency time.Duration - - // kBuckets define all the fingers to other nodes. - Buckets []*Bucket - bucketsize int -} - -// NewRoutingTable creates a new routing table with a given bucketsize, local ID, and latency tolerance. -func NewRoutingTable(bucketsize int, localID ID, latency time.Duration, m pstore.Metrics) *RoutingTable { - rt := new(RoutingTable) - rt.Buckets = []*Bucket{newBucket()} - rt.bucketsize = bucketsize - rt.local = localID - rt.maxLatency = latency - rt.metrics = m - return rt -} - -// Update adds or moves the given peer to the front of its respective bucket -// If a peer gets removed from a bucket, it is returned -func (rt *RoutingTable) Update(p peer.ID) { - peerID := ConvertPeerID(p) - cpl := commonPrefixLen(peerID, rt.local) - - rt.tabLock.Lock() - defer rt.tabLock.Unlock() - bucketID := cpl - if bucketID >= len(rt.Buckets) { - bucketID = len(rt.Buckets) - 1 - } - - bucket := rt.Buckets[bucketID] - if bucket.Has(p) { - // If the peer is already in the table, move it to the front. - // This signifies that it it "more active" and the less active nodes - // Will as a result tend towards the back of the list - bucket.MoveToFront(p) - return - } - - if rt.metrics.LatencyEWMA(p) > rt.maxLatency { - // Connection doesnt meet requirements, skip! - return - } - - // New peer, add to bucket - bucket.PushFront(p) - - // Are we past the max bucket size? - if bucket.Len() > rt.bucketsize { - // If this bucket is the rightmost bucket, and its full - // we need to split it and create a new bucket - if bucketID == len(rt.Buckets)-1 { - rt.nextBucket() - return - } else { - // If the bucket cant split kick out least active node - bucket.PopBack() - return - } - } -} - -// Remove deletes a peer from the routing table. This is to be used -// when we are sure a node has disconnected completely. -func (rt *RoutingTable) Remove(p peer.ID) { - rt.tabLock.Lock() - defer rt.tabLock.Unlock() - peerID := ConvertPeerID(p) - cpl := commonPrefixLen(peerID, rt.local) - - bucketID := cpl - if bucketID >= len(rt.Buckets) { - bucketID = len(rt.Buckets) - 1 - } - - bucket := rt.Buckets[bucketID] - bucket.Remove(p) -} - -func (rt *RoutingTable) nextBucket() peer.ID { - bucket := rt.Buckets[len(rt.Buckets)-1] - newBucket := bucket.Split(len(rt.Buckets)-1, rt.local) - rt.Buckets = append(rt.Buckets, newBucket) - if newBucket.Len() > rt.bucketsize { - return rt.nextBucket() - } - - // If all elements were on left side of split... - if bucket.Len() > rt.bucketsize { - return bucket.PopBack() - } - return "" -} - -// Find a specific peer by ID or return nil -func (rt *RoutingTable) Find(id peer.ID) peer.ID { - srch := rt.NearestPeers(ConvertPeerID(id), 1) - if len(srch) == 0 || srch[0] != id { - return "" - } - return srch[0] -} - -// NearestPeer returns a single peer that is nearest to the given ID -func (rt *RoutingTable) NearestPeer(id ID) peer.ID { - peers := rt.NearestPeers(id, 1) - if len(peers) > 0 { - return peers[0] - } - - log.Debugf("NearestPeer: Returning nil, table size = %d", rt.Size()) - return "" -} - -// NearestPeers returns a list of the 'count' closest peers to the given ID -func (rt *RoutingTable) NearestPeers(id ID, count int) []peer.ID { - cpl := commonPrefixLen(id, rt.local) - - rt.tabLock.RLock() - - // Get bucket at cpl index or last bucket - var bucket *Bucket - if cpl >= len(rt.Buckets) { - cpl = len(rt.Buckets) - 1 - } - bucket = rt.Buckets[cpl] - - var peerArr peerSorterArr - peerArr = copyPeersFromList(id, peerArr, bucket.list) - if len(peerArr) < count { - // In the case of an unusual split, one bucket may be short or empty. - // if this happens, search both surrounding buckets for nearby peers - if cpl > 0 { - plist := rt.Buckets[cpl-1].list - peerArr = copyPeersFromList(id, peerArr, plist) - } - - if cpl < len(rt.Buckets)-1 { - plist := rt.Buckets[cpl+1].list - peerArr = copyPeersFromList(id, peerArr, plist) - } - } - rt.tabLock.RUnlock() - - // Sort by distance to local peer - sort.Sort(peerArr) - - var out []peer.ID - for i := 0; i < count && i < peerArr.Len(); i++ { - out = append(out, peerArr[i].p) - } - - return out -} - -// Size returns the total number of peers in the routing table -func (rt *RoutingTable) Size() int { - var tot int - rt.tabLock.RLock() - for _, buck := range rt.Buckets { - tot += buck.Len() - } - rt.tabLock.RUnlock() - return tot -} - -// ListPeers takes a RoutingTable and returns a list of all peers from all buckets in the table. -// NOTE: This is potentially unsafe... use at your own risk -func (rt *RoutingTable) ListPeers() []peer.ID { - var peers []peer.ID - rt.tabLock.RLock() - for _, buck := range rt.Buckets { - peers = append(peers, buck.Peers()...) - } - rt.tabLock.RUnlock() - return peers -} - -// Print prints a descriptive statement about the provided RoutingTable -func (rt *RoutingTable) Print() { - fmt.Printf("Routing Table, bs = %d, Max latency = %d\n", rt.bucketsize, rt.maxLatency) - rt.tabLock.RLock() - - for i, b := range rt.Buckets { - fmt.Printf("\tbucket: %d\n", i) - - b.lk.RLock() - for e := b.list.Front(); e != nil; e = e.Next() { - p := e.Value.(peer.ID) - fmt.Printf("\t\t- %s %s\n", p.Pretty(), rt.metrics.LatencyEWMA(p).String()) - } - b.lk.RUnlock() - } - rt.tabLock.RUnlock() -} diff --git a/routing/kbucket/table_test.go b/routing/kbucket/table_test.go deleted file mode 100644 index 115fd34ea39..00000000000 --- a/routing/kbucket/table_test.go +++ /dev/null @@ -1,187 +0,0 @@ -package kbucket - -import ( - "math/rand" - "testing" - "time" - - tu "github.com/ipfs/go-ipfs/thirdparty/testutil" - - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" -) - -// Test basic features of the bucket struct -func TestBucket(t *testing.T) { - b := newBucket() - - peers := make([]peer.ID, 100) - for i := 0; i < 100; i++ { - peers[i] = tu.RandPeerIDFatal(t) - b.PushFront(peers[i]) - } - - local := tu.RandPeerIDFatal(t) - localID := ConvertPeerID(local) - - i := rand.Intn(len(peers)) - if !b.Has(peers[i]) { - t.Errorf("Failed to find peer: %v", peers[i]) - } - - spl := b.Split(0, ConvertPeerID(local)) - llist := b.list - for e := llist.Front(); e != nil; e = e.Next() { - p := ConvertPeerID(e.Value.(peer.ID)) - cpl := commonPrefixLen(p, localID) - if cpl > 0 { - t.Fatalf("Split failed. found id with cpl > 0 in 0 bucket") - } - } - - rlist := spl.list - for e := rlist.Front(); e != nil; e = e.Next() { - p := ConvertPeerID(e.Value.(peer.ID)) - cpl := commonPrefixLen(p, localID) - if cpl == 0 { - t.Fatalf("Split failed. found id with cpl == 0 in non 0 bucket") - } - } -} - -// Right now, this just makes sure that it doesnt hang or crash -func TestTableUpdate(t *testing.T) { - local := tu.RandPeerIDFatal(t) - m := pstore.NewMetrics() - rt := NewRoutingTable(10, ConvertPeerID(local), time.Hour, m) - - peers := make([]peer.ID, 100) - for i := 0; i < 100; i++ { - peers[i] = tu.RandPeerIDFatal(t) - } - - // Testing Update - for i := 0; i < 10000; i++ { - rt.Update(peers[rand.Intn(len(peers))]) - } - - for i := 0; i < 100; i++ { - id := ConvertPeerID(tu.RandPeerIDFatal(t)) - ret := rt.NearestPeers(id, 5) - if len(ret) == 0 { - t.Fatal("Failed to find node near ID.") - } - } -} - -func TestTableFind(t *testing.T) { - local := tu.RandPeerIDFatal(t) - m := pstore.NewMetrics() - rt := NewRoutingTable(10, ConvertPeerID(local), time.Hour, m) - - peers := make([]peer.ID, 100) - for i := 0; i < 5; i++ { - peers[i] = tu.RandPeerIDFatal(t) - rt.Update(peers[i]) - } - - t.Logf("Searching for peer: '%s'", peers[2]) - found := rt.NearestPeer(ConvertPeerID(peers[2])) - if !(found == peers[2]) { - t.Fatalf("Failed to lookup known node...") - } -} - -func TestTableFindMultiple(t *testing.T) { - local := tu.RandPeerIDFatal(t) - m := pstore.NewMetrics() - rt := NewRoutingTable(20, ConvertPeerID(local), time.Hour, m) - - peers := make([]peer.ID, 100) - for i := 0; i < 18; i++ { - peers[i] = tu.RandPeerIDFatal(t) - rt.Update(peers[i]) - } - - t.Logf("Searching for peer: '%s'", peers[2]) - found := rt.NearestPeers(ConvertPeerID(peers[2]), 15) - if len(found) != 15 { - t.Fatalf("Got back different number of peers than we expected.") - } -} - -// Looks for race conditions in table operations. For a more 'certain' -// test, increase the loop counter from 1000 to a much higher number -// and set GOMAXPROCS above 1 -func TestTableMultithreaded(t *testing.T) { - local := peer.ID("localPeer") - m := pstore.NewMetrics() - tab := NewRoutingTable(20, ConvertPeerID(local), time.Hour, m) - var peers []peer.ID - for i := 0; i < 500; i++ { - peers = append(peers, tu.RandPeerIDFatal(t)) - } - - done := make(chan struct{}) - go func() { - for i := 0; i < 1000; i++ { - n := rand.Intn(len(peers)) - tab.Update(peers[n]) - } - done <- struct{}{} - }() - - go func() { - for i := 0; i < 1000; i++ { - n := rand.Intn(len(peers)) - tab.Update(peers[n]) - } - done <- struct{}{} - }() - - go func() { - for i := 0; i < 1000; i++ { - n := rand.Intn(len(peers)) - tab.Find(peers[n]) - } - done <- struct{}{} - }() - <-done - <-done - <-done -} - -func BenchmarkUpdates(b *testing.B) { - b.StopTimer() - local := ConvertKey("localKey") - m := pstore.NewMetrics() - tab := NewRoutingTable(20, local, time.Hour, m) - - var peers []peer.ID - for i := 0; i < b.N; i++ { - peers = append(peers, tu.RandPeerIDFatal(b)) - } - - b.StartTimer() - for i := 0; i < b.N; i++ { - tab.Update(peers[i]) - } -} - -func BenchmarkFinds(b *testing.B) { - b.StopTimer() - local := ConvertKey("localKey") - m := pstore.NewMetrics() - tab := NewRoutingTable(20, local, time.Hour, m) - - var peers []peer.ID - for i := 0; i < b.N; i++ { - peers = append(peers, tu.RandPeerIDFatal(b)) - tab.Update(peers[i]) - } - - b.StartTimer() - for i := 0; i < b.N; i++ { - tab.Find(peers[i]) - } -} diff --git a/routing/kbucket/util.go b/routing/kbucket/util.go deleted file mode 100644 index 58cd3c3e3b6..00000000000 --- a/routing/kbucket/util.go +++ /dev/null @@ -1,63 +0,0 @@ -package kbucket - -import ( - "bytes" - "crypto/sha256" - "errors" - - key "github.com/ipfs/go-ipfs/blocks/key" - ks "github.com/ipfs/go-ipfs/routing/keyspace" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" - u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" -) - -// Returned if a routing table query returns no results. This is NOT expected -// behaviour -var ErrLookupFailure = errors.New("failed to find any peer in table") - -// ID for IpfsDHT is in the XORKeySpace -// -// The type dht.ID signifies that its contents have been hashed from either a -// peer.ID or a util.Key. This unifies the keyspace -type ID []byte - -func (id ID) equal(other ID) bool { - return bytes.Equal(id, other) -} - -func (id ID) less(other ID) bool { - a := ks.Key{Space: ks.XORKeySpace, Bytes: id} - b := ks.Key{Space: ks.XORKeySpace, Bytes: other} - return a.Less(b) -} - -func xor(a, b ID) ID { - return ID(u.XOR(a, b)) -} - -func commonPrefixLen(a, b ID) int { - return ks.ZeroPrefixLen(u.XOR(a, b)) -} - -// ConvertPeerID creates a DHT ID by hashing a Peer ID (Multihash) -func ConvertPeerID(id peer.ID) ID { - hash := sha256.Sum256([]byte(id)) - return hash[:] -} - -// ConvertKey creates a DHT ID by hashing a local key (String) -func ConvertKey(id key.Key) ID { - hash := sha256.Sum256([]byte(id)) - return hash[:] -} - -// Closer returns true if a is closer to key than b is -func Closer(a, b peer.ID, key key.Key) bool { - aid := ConvertPeerID(a) - bid := ConvertPeerID(b) - tgt := ConvertKey(key) - adist := xor(aid, tgt) - bdist := xor(bid, tgt) - - return adist.less(bdist) -} diff --git a/routing/mock/centralized_client.go b/routing/mock/centralized_client.go index 26437b310bd..dcf9856b509 100644 --- a/routing/mock/centralized_client.go +++ b/routing/mock/centralized_client.go @@ -4,15 +4,15 @@ import ( "errors" "time" - key "github.com/ipfs/go-ipfs/blocks/key" - routing "github.com/ipfs/go-ipfs/routing" - dhtpb "github.com/ipfs/go-ipfs/routing/dht/pb" - "github.com/ipfs/go-ipfs/thirdparty/testutil" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" + routing "gx/ipfs/QmYQadj3iegqmRPWjaWMRc8DG52hZa2HMkmyPkto5chDvs/go-libp2p-routing" + "gx/ipfs/QmYpVUnnedgGrp6cX2pBii5HRQgcSr778FiKVe7o7nF5Z3/go-testutil" + ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" + recpb "gx/ipfs/Qme7D9iKHYxwq28p6PzCymywsYSRBx9uyGzW7qNB3s9VbC/go-libp2p-record/pb" - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" + pstore "gx/ipfs/QmXhhVSpXMUjpf9XgQDyePxug2iHm8ZvZD99aA9N6kuqMN/go-libp2p-peerstore" ma "gx/ipfs/QmYzDkkgAEmrcNzFCiYo6L1dTX4EAG1gZkbtdbd9trL4vd/go-multiaddr" proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto" u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" @@ -30,7 +30,7 @@ type client struct { // FIXME(brian): is this method meant to simulate putting a value into the network? func (c *client) PutValue(ctx context.Context, key key.Key, val []byte) error { log.Debugf("PutValue: %s", key) - rec := new(dhtpb.Record) + rec := new(recpb.Record) rec.Value = val rec.Key = proto.String(string(key)) rec.TimeReceived = proto.String(u.FormatRFC3339(time.Now())) @@ -55,7 +55,7 @@ func (c *client) GetValue(ctx context.Context, key key.Key) ([]byte, error) { return nil, errors.New("could not cast value from datastore") } - rec := new(dhtpb.Record) + rec := new(recpb.Record) err = proto.Unmarshal(data, rec) if err != nil { return nil, err diff --git a/routing/mock/centralized_server.go b/routing/mock/centralized_server.go index b7fe52d9a7c..a90e4cfd7f9 100644 --- a/routing/mock/centralized_server.go +++ b/routing/mock/centralized_server.go @@ -5,13 +5,13 @@ import ( "sync" "time" - key "github.com/ipfs/go-ipfs/blocks/key" - "github.com/ipfs/go-ipfs/thirdparty/testutil" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - dssync "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/sync" + "gx/ipfs/QmYpVUnnedgGrp6cX2pBii5HRQgcSr778FiKVe7o7nF5Z3/go-testutil" + ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + dssync "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/sync" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" + pstore "gx/ipfs/QmXhhVSpXMUjpf9XgQDyePxug2iHm8ZvZD99aA9N6kuqMN/go-libp2p-peerstore" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" ) diff --git a/routing/mock/centralized_test.go b/routing/mock/centralized_test.go index 3cd8e388a01..c23aa9ee99f 100644 --- a/routing/mock/centralized_test.go +++ b/routing/mock/centralized_test.go @@ -4,11 +4,11 @@ import ( "testing" "time" - key "github.com/ipfs/go-ipfs/blocks/key" delay "github.com/ipfs/go-ipfs/thirdparty/delay" - "github.com/ipfs/go-ipfs/thirdparty/testutil" + "gx/ipfs/QmYpVUnnedgGrp6cX2pBii5HRQgcSr778FiKVe7o7nF5Z3/go-testutil" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" + pstore "gx/ipfs/QmXhhVSpXMUjpf9XgQDyePxug2iHm8ZvZD99aA9N6kuqMN/go-libp2p-peerstore" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" ) diff --git a/routing/mock/dht.go b/routing/mock/dht.go index 7e09cdf288b..6c88fda84a3 100644 --- a/routing/mock/dht.go +++ b/routing/mock/dht.go @@ -1,12 +1,12 @@ package mockrouting import ( - dht "github.com/ipfs/go-ipfs/routing/dht" - "github.com/ipfs/go-ipfs/thirdparty/testutil" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - sync "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/sync" + dht "gx/ipfs/QmSXEMQ9yXxVm84YNXXyyDzu5gyHa3K8FYSfwzPjNXSfHq/go-libp2p-kad-dht" + mocknet "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/net/mock" + "gx/ipfs/QmYpVUnnedgGrp6cX2pBii5HRQgcSr778FiKVe7o7nF5Z3/go-testutil" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" - mocknet "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/net/mock" + ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + sync "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/sync" ) type mocknetserver struct { diff --git a/routing/mock/interface.go b/routing/mock/interface.go index b86e25f067c..94493d1e5a8 100644 --- a/routing/mock/interface.go +++ b/routing/mock/interface.go @@ -5,14 +5,14 @@ package mockrouting import ( - key "github.com/ipfs/go-ipfs/blocks/key" - routing "github.com/ipfs/go-ipfs/routing" delay "github.com/ipfs/go-ipfs/thirdparty/delay" - "github.com/ipfs/go-ipfs/thirdparty/testutil" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" + pstore "gx/ipfs/QmXhhVSpXMUjpf9XgQDyePxug2iHm8ZvZD99aA9N6kuqMN/go-libp2p-peerstore" + routing "gx/ipfs/QmYQadj3iegqmRPWjaWMRc8DG52hZa2HMkmyPkto5chDvs/go-libp2p-routing" + "gx/ipfs/QmYpVUnnedgGrp6cX2pBii5HRQgcSr778FiKVe7o7nF5Z3/go-testutil" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) // Server provides mockrouting Clients diff --git a/routing/none/none_client.go b/routing/none/none_client.go index 2ff9fa68e5d..061c068e72c 100644 --- a/routing/none/none_client.go +++ b/routing/none/none_client.go @@ -3,14 +3,14 @@ package nilrouting import ( "errors" - key "github.com/ipfs/go-ipfs/blocks/key" repo "github.com/ipfs/go-ipfs/repo" - routing "github.com/ipfs/go-ipfs/routing" - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + p2phost "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/host" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" + pstore "gx/ipfs/QmXhhVSpXMUjpf9XgQDyePxug2iHm8ZvZD99aA9N6kuqMN/go-libp2p-peerstore" + routing "gx/ipfs/QmYQadj3iegqmRPWjaWMRc8DG52hZa2HMkmyPkto5chDvs/go-libp2p-routing" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" - p2phost "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/host" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) var log = logging.Logger("mockrouter") diff --git a/routing/offline/offline.go b/routing/offline/offline.go index 855f35191df..3ff0afbce25 100644 --- a/routing/offline/offline.go +++ b/routing/offline/offline.go @@ -4,16 +4,16 @@ import ( "errors" "time" - key "github.com/ipfs/go-ipfs/blocks/key" - routing "github.com/ipfs/go-ipfs/routing" - pb "github.com/ipfs/go-ipfs/routing/dht/pb" - record "github.com/ipfs/go-ipfs/routing/record" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" + routing "gx/ipfs/QmYQadj3iegqmRPWjaWMRc8DG52hZa2HMkmyPkto5chDvs/go-libp2p-routing" + ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" + record "gx/ipfs/Qme7D9iKHYxwq28p6PzCymywsYSRBx9uyGzW7qNB3s9VbC/go-libp2p-record" + pb "gx/ipfs/Qme7D9iKHYxwq28p6PzCymywsYSRBx9uyGzW7qNB3s9VbC/go-libp2p-record/pb" - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" ci "gx/ipfs/QmVoi5es8D5fNHZDqoW6DgDAEPEV5hQp8GBz161vZXiwpQ/go-libp2p-crypto" - "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" + pstore "gx/ipfs/QmXhhVSpXMUjpf9XgQDyePxug2iHm8ZvZD99aA9N6kuqMN/go-libp2p-peerstore" proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" ) diff --git a/routing/record/record.go b/routing/record/record.go deleted file mode 100644 index 316763f7f75..00000000000 --- a/routing/record/record.go +++ /dev/null @@ -1,48 +0,0 @@ -package record - -import ( - "bytes" - - proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto" - - key "github.com/ipfs/go-ipfs/blocks/key" - pb "github.com/ipfs/go-ipfs/routing/dht/pb" - logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" - ci "gx/ipfs/QmVoi5es8D5fNHZDqoW6DgDAEPEV5hQp8GBz161vZXiwpQ/go-libp2p-crypto" -) - -var log = logging.Logger("routing/record") - -// MakePutRecord creates and signs a dht record for the given key/value pair -func MakePutRecord(sk ci.PrivKey, key key.Key, value []byte, sign bool) (*pb.Record, error) { - record := new(pb.Record) - - record.Key = proto.String(string(key)) - record.Value = value - - pkh, err := sk.GetPublic().Hash() - if err != nil { - return nil, err - } - - record.Author = proto.String(string(pkh)) - if sign { - blob := RecordBlobForSig(record) - - sig, err := sk.Sign(blob) - if err != nil { - return nil, err - } - - record.Signature = sig - } - return record, nil -} - -// RecordBlobForSig returns the blob protected by the record signature -func RecordBlobForSig(r *pb.Record) []byte { - k := []byte(r.GetKey()) - v := []byte(r.GetValue()) - a := []byte(r.GetAuthor()) - return bytes.Join([][]byte{k, v, a}, []byte{}) -} diff --git a/routing/record/selection.go b/routing/record/selection.go deleted file mode 100644 index 8e68006c17e..00000000000 --- a/routing/record/selection.go +++ /dev/null @@ -1,40 +0,0 @@ -package record - -import ( - "errors" - - key "github.com/ipfs/go-ipfs/blocks/key" - path "github.com/ipfs/go-ipfs/path" -) - -// A SelectorFunc selects the best value for the given key from -// a slice of possible values and returns the index of the chosen one -type SelectorFunc func(key.Key, [][]byte) (int, error) - -type Selector map[string]SelectorFunc - -func (s Selector) BestRecord(k key.Key, recs [][]byte) (int, error) { - if len(recs) == 0 { - return 0, errors.New("no records given!") - } - - parts := path.SplitList(string(k)) - if len(parts) < 3 { - log.Infof("Record key does not have selectorfunc: %s", k) - return 0, errors.New("record key does not have selectorfunc") - } - - sel, ok := s[parts[1]] - if !ok { - log.Infof("Unrecognized key prefix: %s", parts[1]) - return 0, ErrInvalidRecordType - } - - return sel(k, recs) -} - -// PublicKeySelector just selects the first entry. -// All valid public key records will be equivalent. -func PublicKeySelector(k key.Key, vals [][]byte) (int, error) { - return 0, nil -} diff --git a/routing/record/validation.go b/routing/record/validation.go deleted file mode 100644 index a17e36fad8c..00000000000 --- a/routing/record/validation.go +++ /dev/null @@ -1,114 +0,0 @@ -package record - -import ( - "bytes" - "errors" - "fmt" - - key "github.com/ipfs/go-ipfs/blocks/key" - path "github.com/ipfs/go-ipfs/path" - pb "github.com/ipfs/go-ipfs/routing/dht/pb" - ci "gx/ipfs/QmVoi5es8D5fNHZDqoW6DgDAEPEV5hQp8GBz161vZXiwpQ/go-libp2p-crypto" - mh "gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash" - u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" -) - -// ValidatorFunc is a function that is called to validate a given -// type of DHTRecord. -type ValidatorFunc func(key.Key, []byte) error - -// ErrBadRecord is returned any time a dht record is found to be -// incorrectly formatted or signed. -var ErrBadRecord = errors.New("bad dht record") - -// ErrInvalidRecordType is returned if a DHTRecord keys prefix -// is not found in the Validator map of the DHT. -var ErrInvalidRecordType = errors.New("invalid record keytype") - -// Validator is an object that helps ensure routing records are valid. -// It is a collection of validator functions, each of which implements -// its own notion of validity. -type Validator map[string]*ValidChecker - -type ValidChecker struct { - Func ValidatorFunc - Sign bool -} - -// VerifyRecord checks a record and ensures it is still valid. -// It runs needed validators -func (v Validator) VerifyRecord(r *pb.Record) error { - // Now, check validity func - parts := path.SplitList(r.GetKey()) - if len(parts) < 3 { - log.Infof("Record key does not have validator: %s", key.Key(r.GetKey())) - return nil - } - - val, ok := v[parts[1]] - if !ok { - log.Infof("Unrecognized key prefix: %s", parts[1]) - return ErrInvalidRecordType - } - - return val.Func(key.Key(r.GetKey()), r.GetValue()) -} - -func (v Validator) IsSigned(k key.Key) (bool, error) { - // Now, check validity func - parts := path.SplitList(string(k)) - if len(parts) < 3 { - log.Infof("Record key does not have validator: %s", k) - return false, nil - } - - val, ok := v[parts[1]] - if !ok { - log.Infof("Unrecognized key prefix: %s", parts[1]) - return false, ErrInvalidRecordType - } - - return val.Sign, nil -} - -// ValidatePublicKeyRecord implements ValidatorFunc and -// verifies that the passed in record value is the PublicKey -// that matches the passed in key. -func ValidatePublicKeyRecord(k key.Key, val []byte) error { - if len(k) < 5 { - return errors.New("invalid public key record key") - } - - prefix := string(k[:4]) - if prefix != "/pk/" { - return errors.New("key was not prefixed with /pk/") - } - - keyhash := []byte(k[4:]) - if _, err := mh.Cast(keyhash); err != nil { - return fmt.Errorf("key did not contain valid multihash: %s", err) - } - - pkh := u.Hash(val) - if !bytes.Equal(keyhash, pkh) { - return errors.New("public key does not match storage key") - } - return nil -} - -var PublicKeyValidator = &ValidChecker{ - Func: ValidatePublicKeyRecord, - Sign: false, -} - -func CheckRecordSig(r *pb.Record, pk ci.PubKey) error { - blob := RecordBlobForSig(r) - good, err := pk.Verify(blob, r.Signature) - if err != nil { - return nil - } - if !good { - return errors.New("invalid record signature") - } - return nil -} diff --git a/routing/record/validation_test.go b/routing/record/validation_test.go deleted file mode 100644 index 56bf6a8421b..00000000000 --- a/routing/record/validation_test.go +++ /dev/null @@ -1,35 +0,0 @@ -package record - -import ( - "encoding/base64" - "testing" - - key "github.com/ipfs/go-ipfs/blocks/key" - ci "gx/ipfs/QmVoi5es8D5fNHZDqoW6DgDAEPEV5hQp8GBz161vZXiwpQ/go-libp2p-crypto" -) - -var OffensiveKey = "CAASXjBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQDjXAQQMal4SB2tSnX6NJIPmC69/BT8A8jc7/gDUZNkEhdhYHvc7k7S4vntV/c92nJGxNdop9fKJyevuNMuXhhHAgMBAAE=" - -func TestValidatePublicKey(t *testing.T) { - pkb, err := base64.StdEncoding.DecodeString(OffensiveKey) - if err != nil { - t.Fatal(err) - } - - pubk, err := ci.UnmarshalPublicKey(pkb) - if err != nil { - t.Fatal(err) - } - - pkh, err := pubk.Hash() - if err != nil { - t.Fatal(err) - } - - k := key.Key("/pk/" + string(pkh)) - - err = ValidatePublicKeyRecord(k, pkb) - if err != nil { - t.Fatal(err) - } -} diff --git a/routing/routing.go b/routing/routing.go deleted file mode 100644 index ad12981f24a..00000000000 --- a/routing/routing.go +++ /dev/null @@ -1,105 +0,0 @@ -// package routing defines the interface for a routing system used by ipfs. -package routing - -import ( - "errors" - - key "github.com/ipfs/go-ipfs/blocks/key" - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" - ci "gx/ipfs/QmVoi5es8D5fNHZDqoW6DgDAEPEV5hQp8GBz161vZXiwpQ/go-libp2p-crypto" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" - context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" -) - -// ErrNotFound is returned when a search fails to find anything -var ErrNotFound = errors.New("routing: not found") - -// ContentRouting is a value provider layer of indirection. It is used to find -// information about who has what content. -type ContentRouting interface { - // Announce that this node can provide value for given key - Provide(context.Context, key.Key) error - - // Search for peers who are able to provide a given key - FindProvidersAsync(context.Context, key.Key, 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) -} - -type ValueStore interface { - // Basic Put/Get - - // PutValue adds value corresponding to given Key. - PutValue(context.Context, key.Key, []byte) error - - // GetValue searches for the value corresponding to given Key. - GetValue(context.Context, key.Key) ([]byte, error) - - // GetValues searches for values corresponding to given Key. - // - // Passing a value of '0' for the count argument will cause the - // routing interface to return values only from cached or local storage - // and return an error if no cached value is found. - // - // Passing a value of '1' will return a local value if found, and query - // the network for the first value it finds otherwise. - // As a result, a value of '1' is mostly useful for cases where the record - // in question has only one valid value (such as public keys) - GetValues(c context.Context, k key.Key, count int) ([]RecvdVal, 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 - Bootstrap(context.Context) error - - // TODO expose io.Closer or plain-old Close error -} - -// RecvdVal represents a dht value record that has been received from a given peer -// it is used to track peers with expired records in order to correct them. -type RecvdVal struct { - From peer.ID - Val []byte -} - -type PubKeyFetcher interface { - GetPublicKey(context.Context, peer.ID) (ci.PubKey, error) -} - -// KeyForPublicKey returns the key used to retrieve public keys -// from the dht. -func KeyForPublicKey(id peer.ID) key.Key { - return key.Key("/pk/" + string(id)) -} - -func GetPublicKey(r ValueStore, ctx context.Context, pkhash []byte) (ci.PubKey, error) { - if dht, ok := r.(PubKeyFetcher); ok { - // If we have a DHT as our routing system, use optimized fetcher - return dht.GetPublicKey(ctx, peer.ID(pkhash)) - } else { - key := key.Key("/pk/" + string(pkhash)) - pkval, err := r.GetValue(ctx, key) - if err != nil { - return nil, err - } - - // get PublicKey from node.Data - return ci.UnmarshalPublicKey(pkval) - } -} diff --git a/routing/supernode/client.go b/routing/supernode/client.go index 17839f3aa80..7c1ff981841 100644 --- a/routing/supernode/client.go +++ b/routing/supernode/client.go @@ -5,18 +5,19 @@ import ( "errors" "time" - key "github.com/ipfs/go-ipfs/blocks/key" - routing "github.com/ipfs/go-ipfs/routing" - pb "github.com/ipfs/go-ipfs/routing/dht/pb" proxy "github.com/ipfs/go-ipfs/routing/supernode/proxy" - loggables "github.com/ipfs/go-ipfs/thirdparty/loggables" + pb "gx/ipfs/QmSXEMQ9yXxVm84YNXXyyDzu5gyHa3K8FYSfwzPjNXSfHq/go-libp2p-kad-dht/pb" + routing "gx/ipfs/QmYQadj3iegqmRPWjaWMRc8DG52hZa2HMkmyPkto5chDvs/go-libp2p-routing" + loggables "gx/ipfs/QmYrv4LgCC8FhG2Ab4bwuq5DqBdwMtx3hMb3KKJDZcr2d7/go-libp2p-loggables" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" + recpb "gx/ipfs/Qme7D9iKHYxwq28p6PzCymywsYSRBx9uyGzW7qNB3s9VbC/go-libp2p-record/pb" - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/host" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" + pstore "gx/ipfs/QmXhhVSpXMUjpf9XgQDyePxug2iHm8ZvZD99aA9N6kuqMN/go-libp2p-peerstore" proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" - "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/host" ) var log = logging.Logger("supernode") @@ -131,13 +132,13 @@ func (c *Client) FindPeer(ctx context.Context, id peer.ID) (pstore.PeerInfo, err } // creates and signs a record for the given key/value pair -func makeRecord(ps pstore.Peerstore, p peer.ID, k key.Key, v []byte) (*pb.Record, error) { +func makeRecord(ps pstore.Peerstore, p peer.ID, k key.Key, v []byte) (*recpb.Record, error) { blob := bytes.Join([][]byte{[]byte(k), v, []byte(p)}, []byte{}) sig, err := ps.PrivKey(p).Sign(blob) if err != nil { return nil, err } - return &pb.Record{ + return &recpb.Record{ Key: proto.String(string(k)), Value: v, Author: proto.String(string(p)), diff --git a/routing/supernode/proxy/loopback.go b/routing/supernode/proxy/loopback.go index 379527f07b3..4b3dd62c266 100644 --- a/routing/supernode/proxy/loopback.go +++ b/routing/supernode/proxy/loopback.go @@ -4,9 +4,9 @@ import ( ggio "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/io" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" - dhtpb "github.com/ipfs/go-ipfs/routing/dht/pb" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" - inet "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/net" + dhtpb "gx/ipfs/QmSXEMQ9yXxVm84YNXXyyDzu5gyHa3K8FYSfwzPjNXSfHq/go-libp2p-kad-dht/pb" + inet "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/net" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" ) // RequestHandler handles routing requests locally diff --git a/routing/supernode/proxy/standard.go b/routing/supernode/proxy/standard.go index 693fe6bc9b4..24fa8e6fb7b 100644 --- a/routing/supernode/proxy/standard.go +++ b/routing/supernode/proxy/standard.go @@ -6,16 +6,16 @@ import ( ggio "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/io" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" - host "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/host" - inet "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/net" - - key "github.com/ipfs/go-ipfs/blocks/key" - dhtpb "github.com/ipfs/go-ipfs/routing/dht/pb" - kbucket "github.com/ipfs/go-ipfs/routing/kbucket" - loggables "github.com/ipfs/go-ipfs/thirdparty/loggables" + host "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/host" + inet "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/net" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" + pstore "gx/ipfs/QmXhhVSpXMUjpf9XgQDyePxug2iHm8ZvZD99aA9N6kuqMN/go-libp2p-peerstore" + + dhtpb "gx/ipfs/QmSXEMQ9yXxVm84YNXXyyDzu5gyHa3K8FYSfwzPjNXSfHq/go-libp2p-kad-dht/pb" + loggables "gx/ipfs/QmYrv4LgCC8FhG2Ab4bwuq5DqBdwMtx3hMb3KKJDZcr2d7/go-libp2p-loggables" + kbucket "gx/ipfs/Qmc5r13R4j3V75ucMkGzHimsQDgkg4aUanX5upcUWns7XM/go-libp2p-kbucket" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) const ProtocolSNR = "/ipfs/supernoderouting" diff --git a/routing/supernode/server.go b/routing/supernode/server.go index f34c5eb2bf8..92833f75a14 100644 --- a/routing/supernode/server.go +++ b/routing/supernode/server.go @@ -4,14 +4,15 @@ import ( "errors" "fmt" - key "github.com/ipfs/go-ipfs/blocks/key" - dhtpb "github.com/ipfs/go-ipfs/routing/dht/pb" - record "github.com/ipfs/go-ipfs/routing/record" proxy "github.com/ipfs/go-ipfs/routing/supernode/proxy" - datastore "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + dhtpb "gx/ipfs/QmSXEMQ9yXxVm84YNXXyyDzu5gyHa3K8FYSfwzPjNXSfHq/go-libp2p-kad-dht/pb" + datastore "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" + record "gx/ipfs/Qme7D9iKHYxwq28p6PzCymywsYSRBx9uyGzW7qNB3s9VbC/go-libp2p-record" + recpb "gx/ipfs/Qme7D9iKHYxwq28p6PzCymywsYSRBx9uyGzW7qNB3s9VbC/go-libp2p-record/pb" + + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" + pstore "gx/ipfs/QmXhhVSpXMUjpf9XgQDyePxug2iHm8ZvZD99aA9N6kuqMN/go-libp2p-peerstore" proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" ) @@ -115,7 +116,7 @@ func (s *Server) handleMessage( var _ proxy.RequestHandler = &Server{} var _ proxy.Proxy = &Server{} -func getRoutingRecord(ds datastore.Datastore, k key.Key) (*dhtpb.Record, error) { +func getRoutingRecord(ds datastore.Datastore, k key.Key) (*recpb.Record, error) { dskey := k.DsKey() val, err := ds.Get(dskey) if err != nil { @@ -125,14 +126,14 @@ func getRoutingRecord(ds datastore.Datastore, k key.Key) (*dhtpb.Record, error) if !ok { return nil, fmt.Errorf("datastore had non byte-slice value for %v", dskey) } - var record dhtpb.Record + var record recpb.Record if err := proto.Unmarshal(recordBytes, &record); err != nil { return nil, errors.New("failed to unmarshal dht record from datastore") } return &record, nil } -func putRoutingRecord(ds datastore.Datastore, k key.Key, value *dhtpb.Record) error { +func putRoutingRecord(ds datastore.Datastore, k key.Key, value *recpb.Record) error { data, err := proto.Marshal(value) if err != nil { return err @@ -204,7 +205,7 @@ func providerKey(k key.Key) datastore.Key { return datastore.KeyWithNamespaces([]string{"routing", "providers", k.String()}) } -func verify(ps pstore.Peerstore, r *dhtpb.Record) error { +func verify(ps pstore.Peerstore, r *recpb.Record) error { v := make(record.Validator) v["pk"] = record.PublicKeyValidator p := peer.ID(r.GetAuthor()) diff --git a/routing/supernode/server_test.go b/routing/supernode/server_test.go index 25c54ec32a2..3883f25648a 100644 --- a/routing/supernode/server_test.go +++ b/routing/supernode/server_test.go @@ -3,9 +3,9 @@ package supernode import ( "testing" - key "github.com/ipfs/go-ipfs/blocks/key" - dhtpb "github.com/ipfs/go-ipfs/routing/dht/pb" - datastore "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" + dhtpb "gx/ipfs/QmSXEMQ9yXxVm84YNXXyyDzu5gyHa3K8FYSfwzPjNXSfHq/go-libp2p-kad-dht/pb" + datastore "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) func TestPutProviderDoesntResultInDuplicates(t *testing.T) { diff --git a/test/integration/addcat_test.go b/test/integration/addcat_test.go index 6fed6e17e98..9f494856066 100644 --- a/test/integration/addcat_test.go +++ b/test/integration/addcat_test.go @@ -16,11 +16,11 @@ import ( "github.com/ipfs/go-ipfs/core" coreunix "github.com/ipfs/go-ipfs/core/coreunix" mock "github.com/ipfs/go-ipfs/core/mock" - testutil "github.com/ipfs/go-ipfs/thirdparty/testutil" "github.com/ipfs/go-ipfs/thirdparty/unit" - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" - mocknet "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/net/mock" + mocknet "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/net/mock" + pstore "gx/ipfs/QmXhhVSpXMUjpf9XgQDyePxug2iHm8ZvZD99aA9N6kuqMN/go-libp2p-peerstore" + testutil "gx/ipfs/QmYpVUnnedgGrp6cX2pBii5HRQgcSr778FiKVe7o7nF5Z3/go-testutil" ) var log = logging.Logger("epictest") diff --git a/test/integration/bench_cat_test.go b/test/integration/bench_cat_test.go index 833acb2ae33..3c7979cfaa5 100644 --- a/test/integration/bench_cat_test.go +++ b/test/integration/bench_cat_test.go @@ -10,11 +10,11 @@ import ( "github.com/ipfs/go-ipfs/core" coreunix "github.com/ipfs/go-ipfs/core/coreunix" mock "github.com/ipfs/go-ipfs/core/mock" - testutil "github.com/ipfs/go-ipfs/thirdparty/testutil" "github.com/ipfs/go-ipfs/thirdparty/unit" - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" + mocknet "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/net/mock" + pstore "gx/ipfs/QmXhhVSpXMUjpf9XgQDyePxug2iHm8ZvZD99aA9N6kuqMN/go-libp2p-peerstore" + testutil "gx/ipfs/QmYpVUnnedgGrp6cX2pBii5HRQgcSr778FiKVe7o7nF5Z3/go-testutil" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" - mocknet "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/net/mock" ) func BenchmarkCat1MB(b *testing.B) { benchmarkVarCat(b, unit.MB*1) } diff --git a/test/integration/bench_test.go b/test/integration/bench_test.go index 702e5ea2c7e..1a267c28479 100644 --- a/test/integration/bench_test.go +++ b/test/integration/bench_test.go @@ -3,8 +3,8 @@ package integrationtest import ( "testing" - testutil "github.com/ipfs/go-ipfs/thirdparty/testutil" "github.com/ipfs/go-ipfs/thirdparty/unit" + testutil "gx/ipfs/QmYpVUnnedgGrp6cX2pBii5HRQgcSr778FiKVe7o7nF5Z3/go-testutil" ) func benchmarkAddCat(numBytes int64, conf testutil.LatencyConfig, b *testing.B) { diff --git a/test/integration/bitswap_wo_routing_test.go b/test/integration/bitswap_wo_routing_test.go index e315ecb5698..5de0fed7473 100644 --- a/test/integration/bitswap_wo_routing_test.go +++ b/test/integration/bitswap_wo_routing_test.go @@ -7,8 +7,8 @@ import ( "github.com/ipfs/go-ipfs/blocks" "github.com/ipfs/go-ipfs/core" "github.com/ipfs/go-ipfs/core/mock" + mocknet "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/net/mock" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" - mocknet "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/net/mock" ) func TestBitswapWithoutRouting(t *testing.T) { diff --git a/test/integration/grandcentral_test.go b/test/integration/grandcentral_test.go index 5ddfcc2aad4..d661fbe30e8 100644 --- a/test/integration/grandcentral_test.go +++ b/test/integration/grandcentral_test.go @@ -8,20 +8,20 @@ import ( "math" "testing" - "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - syncds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/sync" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + syncds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/sync" - key "github.com/ipfs/go-ipfs/blocks/key" core "github.com/ipfs/go-ipfs/core" "github.com/ipfs/go-ipfs/core/corerouting" "github.com/ipfs/go-ipfs/core/coreunix" mock "github.com/ipfs/go-ipfs/core/mock" ds2 "github.com/ipfs/go-ipfs/thirdparty/datastore2" - testutil "github.com/ipfs/go-ipfs/thirdparty/testutil" "github.com/ipfs/go-ipfs/thirdparty/unit" - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" - mocknet "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/net/mock" + mocknet "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/net/mock" + pstore "gx/ipfs/QmXhhVSpXMUjpf9XgQDyePxug2iHm8ZvZD99aA9N6kuqMN/go-libp2p-peerstore" + testutil "gx/ipfs/QmYpVUnnedgGrp6cX2pBii5HRQgcSr778FiKVe7o7nF5Z3/go-testutil" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) func TestSupernodeBootstrappedAddCat(t *testing.T) { diff --git a/test/integration/three_legged_cat_test.go b/test/integration/three_legged_cat_test.go index 6cfefcc8132..aa16cb8597d 100644 --- a/test/integration/three_legged_cat_test.go +++ b/test/integration/three_legged_cat_test.go @@ -13,10 +13,10 @@ import ( core "github.com/ipfs/go-ipfs/core" coreunix "github.com/ipfs/go-ipfs/core/coreunix" mock "github.com/ipfs/go-ipfs/core/mock" - testutil "github.com/ipfs/go-ipfs/thirdparty/testutil" "github.com/ipfs/go-ipfs/thirdparty/unit" - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" - mocknet "gx/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS/go-libp2p/p2p/net/mock" + mocknet "gx/ipfs/QmUEtj7KAkoLULwUHm4KA4pbRAcziPLHpHDRQsvn9g1i6t/go-libp2p/p2p/net/mock" + pstore "gx/ipfs/QmXhhVSpXMUjpf9XgQDyePxug2iHm8ZvZD99aA9N6kuqMN/go-libp2p-peerstore" + testutil "gx/ipfs/QmYpVUnnedgGrp6cX2pBii5HRQgcSr778FiKVe7o7nF5Z3/go-testutil" ) func TestThreeLeggedCatTransfer(t *testing.T) { diff --git a/test/supernode_client/main.go b/test/supernode_client/main.go index 2903d9611ce..7d4840a8353 100644 --- a/test/supernode_client/main.go +++ b/test/supernode_client/main.go @@ -24,11 +24,11 @@ import ( ds2 "github.com/ipfs/go-ipfs/thirdparty/datastore2" "github.com/ipfs/go-ipfs/thirdparty/ipfsaddr" unit "github.com/ipfs/go-ipfs/thirdparty/unit" - "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - syncds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/sync" + "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + syncds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/sync" - pstore "gx/ipfs/QmSZi9ygLohBUGyHMqE5N6eToPwqcg7bZQTULeVLFu7Q6d/go-libp2p-peerstore" logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" + pstore "gx/ipfs/QmXhhVSpXMUjpf9XgQDyePxug2iHm8ZvZD99aA9N6kuqMN/go-libp2p-peerstore" ma "gx/ipfs/QmYzDkkgAEmrcNzFCiYo6L1dTX4EAG1gZkbtdbd9trL4vd/go-multiaddr" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" ) diff --git a/thirdparty/datastore2/datastore_closer.go b/thirdparty/datastore2/datastore_closer.go index db2734de124..9ad183e220b 100644 --- a/thirdparty/datastore2/datastore_closer.go +++ b/thirdparty/datastore2/datastore_closer.go @@ -3,7 +3,8 @@ package datastore2 import ( "io" - "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" + "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + syncds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/sync" ) type ThreadSafeDatastoreCloser interface { @@ -33,3 +34,8 @@ func (w *datastoreCloserWrapper) Batch() (datastore.Batch, error) { return bds.Batch() } + +// TODO(geoah) Move to ./testutils or somewhere else +func ThreadSafeCloserMapDatastore() ThreadSafeDatastoreCloser { + return CloserWrap(syncds.MutexWrap(datastore.NewMapDatastore())) +} diff --git a/thirdparty/datastore2/delayed.go b/thirdparty/datastore2/delayed.go index c4bf7d52b2c..4b258836796 100644 --- a/thirdparty/datastore2/delayed.go +++ b/thirdparty/datastore2/delayed.go @@ -1,8 +1,8 @@ package datastore2 import ( - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - dsq "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/query" + ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + dsq "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/query" delay "github.com/ipfs/go-ipfs/thirdparty/delay" ) diff --git a/thirdparty/datastore2/threadsafe.go b/thirdparty/datastore2/threadsafe.go index b3d5198d005..1e65e529812 100644 --- a/thirdparty/datastore2/threadsafe.go +++ b/thirdparty/datastore2/threadsafe.go @@ -3,7 +3,7 @@ package datastore2 import ( "io" - "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" + "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" ) // ClaimThreadSafe claims that a Datastore is threadsafe, even when diff --git a/thirdparty/ipfsaddr/ipfsaddr.go b/thirdparty/ipfsaddr/ipfsaddr.go index d56c354757d..503ecb2c97d 100644 --- a/thirdparty/ipfsaddr/ipfsaddr.go +++ b/thirdparty/ipfsaddr/ipfsaddr.go @@ -7,7 +7,7 @@ import ( path "github.com/ipfs/go-ipfs/path" logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" ) var log = logging.Logger("ipfsaddr") diff --git a/thirdparty/ipfsaddr/ipfsaddr_test.go b/thirdparty/ipfsaddr/ipfsaddr_test.go index 109b19427b1..91ca90e386a 100644 --- a/thirdparty/ipfsaddr/ipfsaddr_test.go +++ b/thirdparty/ipfsaddr/ipfsaddr_test.go @@ -4,7 +4,7 @@ import ( "testing" path "github.com/ipfs/go-ipfs/path" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" + peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer" ma "gx/ipfs/QmYzDkkgAEmrcNzFCiYo6L1dTX4EAG1gZkbtdbd9trL4vd/go-multiaddr" ) diff --git a/thirdparty/loggables/loggables.go b/thirdparty/loggables/loggables.go deleted file mode 100644 index ad31f9936ff..00000000000 --- a/thirdparty/loggables/loggables.go +++ /dev/null @@ -1,79 +0,0 @@ -// Package loggables includes a bunch of translator functions for -// commonplace/stdlib objects. This is boilerplate code that shouldn't change -// much, and not sprinkled all over the place (i.e. gather it here). -// -// NOTE: it may make sense to put all stdlib Loggable functions in the eventlog -// package. Putting it here for now in case we don't want to pollute it. -package loggables - -import ( - "net" - - uuid "gx/ipfs/QmcyaFHbyiZfoX5GTpcqqCPYmbjYNAhRDekXSJPFHdYNSV/go.uuid" - - ma "gx/ipfs/QmYzDkkgAEmrcNzFCiYo6L1dTX4EAG1gZkbtdbd9trL4vd/go-multiaddr" - - logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" - - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" -) - -// NetConn returns an eventlog.Metadata with the conn addresses -func NetConn(c net.Conn) logging.Loggable { - return logging.Metadata{ - "localAddr": c.LocalAddr(), - "remoteAddr": c.RemoteAddr(), - } -} - -// Error returns an eventlog.Metadata with an error -func Error(e error) logging.Loggable { - return logging.Metadata{ - "error": e.Error(), - } -} - -func Uuid(key string) logging.Metadata { - return logging.Metadata{ - key: uuid.NewV4().String(), - } -} - -// Dial metadata is metadata for dial events -func Dial(sys string, lid, rid peer.ID, laddr, raddr ma.Multiaddr) DeferredMap { - m := DeferredMap{} - m["subsystem"] = sys - if lid != "" { - m["localPeer"] = func() interface{} { return lid.Pretty() } - } - if laddr != nil { - m["localAddr"] = func() interface{} { return laddr.String() } - } - if rid != "" { - m["remotePeer"] = func() interface{} { return rid.Pretty() } - } - if raddr != nil { - m["remoteAddr"] = func() interface{} { return raddr.String() } - } - return m -} - -// DeferredMap is a Loggable which may contain deferred values. -type DeferredMap map[string]interface{} - -// Loggable describes objects that can be marshalled into Metadata for logging -func (m DeferredMap) Loggable() map[string]interface{} { - m2 := map[string]interface{}{} - for k, v := range m { - - if vf, ok := v.(func() interface{}); ok { - // if it's a DeferredVal, call it. - m2[k] = vf() - - } else { - // else use the value as is. - m2[k] = v - } - } - return m2 -} diff --git a/thirdparty/notifier/notifier.go b/thirdparty/notifier/notifier.go index c9e9475b32e..378e41806a6 100644 --- a/thirdparty/notifier/notifier.go +++ b/thirdparty/notifier/notifier.go @@ -6,8 +6,8 @@ package notifier import ( "sync" - process "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess" - ratelimit "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess/ratelimit" + process "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess" + ratelimit "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess/ratelimit" ) // Notifiee is a generic interface. Clients implement diff --git a/thirdparty/peerset/peerset.go b/thirdparty/peerset/peerset.go deleted file mode 100644 index 5d8d190b878..00000000000 --- a/thirdparty/peerset/peerset.go +++ /dev/null @@ -1,61 +0,0 @@ -package peerset - -import ( - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" - "sync" -) - -// PeerSet is a threadsafe set of peers -type PeerSet struct { - ps map[peer.ID]struct{} - lk sync.RWMutex - size int -} - -func New() *PeerSet { - ps := new(PeerSet) - ps.ps = make(map[peer.ID]struct{}) - ps.size = -1 - return ps -} - -func NewLimited(size int) *PeerSet { - ps := new(PeerSet) - ps.ps = make(map[peer.ID]struct{}) - ps.size = size - return ps -} - -func (ps *PeerSet) Add(p peer.ID) { - ps.lk.Lock() - ps.ps[p] = struct{}{} - ps.lk.Unlock() -} - -func (ps *PeerSet) Contains(p peer.ID) bool { - ps.lk.RLock() - _, ok := ps.ps[p] - ps.lk.RUnlock() - return ok -} - -func (ps *PeerSet) Size() int { - ps.lk.RLock() - defer ps.lk.RUnlock() - return len(ps.ps) -} - -// TryAdd Attempts to add the given peer into the set. -// This operation can fail for one of two reasons: -// 1) The given peer is already in the set -// 2) The number of peers in the set is equal to size -func (ps *PeerSet) TryAdd(p peer.ID) bool { - var success bool - ps.lk.Lock() - if _, ok := ps.ps[p]; !ok && (len(ps.ps) < ps.size || ps.size == -1) { - success = true - ps.ps[p] = struct{}{} - } - ps.lk.Unlock() - return success -} diff --git a/thirdparty/testutil/ci/ci.go b/thirdparty/testutil/ci/ci.go deleted file mode 100644 index 490b890001a..00000000000 --- a/thirdparty/testutil/ci/ci.go +++ /dev/null @@ -1,46 +0,0 @@ -// Package ci implements some helper functions to use during -// tests. Many times certain facilities are not available, or tests -// must run differently. -package ci - -import ( - "os" - - travis "github.com/ipfs/go-ipfs/thirdparty/testutil/ci/travis" -) - -// EnvVar is a type to use travis-only env var names with -// the type system. -type EnvVar string - -// Environment variables that TravisCI uses. -const ( - VarCI EnvVar = "CI" - VarNoFuse EnvVar = "TEST_NO_FUSE" - VarVerbose EnvVar = "TEST_VERBOSE" -) - -// IsRunning attempts to determine whether this process is -// running on CI. This is done by checking any of: -// -// CI=true -// travis.IsRunning() -// -func IsRunning() bool { - return os.Getenv(string(VarCI)) == "true" || travis.IsRunning() -} - -// Env returns the value of a CI env variable. -func Env(v EnvVar) string { - return os.Getenv(string(v)) -} - -// Returns whether FUSE is explicitly disabled wiht TEST_NO_FUSE. -func NoFuse() bool { - return os.Getenv(string(VarNoFuse)) == "1" -} - -// Returns whether TEST_VERBOSE is enabled. -func Verbose() bool { - return os.Getenv(string(VarVerbose)) == "1" -} diff --git a/thirdparty/testutil/ci/travis/travis.go b/thirdparty/testutil/ci/travis/travis.go deleted file mode 100644 index e22fb903612..00000000000 --- a/thirdparty/testutil/ci/travis/travis.go +++ /dev/null @@ -1,57 +0,0 @@ -// Package travis implements some helper functions to use during -// tests. Many times certain facilities are not available, or tests -// must run differently. -package travis - -import "os" - -// EnvVar is a type to use travis-only env var names with -// the type system. -type EnvVar string - -// Environment variables that TravisCI uses. -const ( - VarCI EnvVar = "CI" - VarTravis EnvVar = "TRAVIS" - VarBranch EnvVar = "TRAVIS_BRANCH" - VarBuildDir EnvVar = "TRAVIS_BUILD_DIR" - VarBuildId EnvVar = "TRAVIS_BUILD_ID" - VarBuildNumber EnvVar = "TRAVIS_BUILD_NUMBER" - VarCommit EnvVar = "TRAVIS_COMMIT" - VarCommitRange EnvVar = "TRAVIS_COMMIT_RANGE" - VarJobId EnvVar = "TRAVIS_JOB_ID" - VarJobNumber EnvVar = "TRAVIS_JOB_NUMBER" - VarPullRequest EnvVar = "TRAVIS_PULL_REQUEST" - VarSecureEnvVars EnvVar = "TRAVIS_SECURE_ENV_VARS" - VarRepoSlug EnvVar = "TRAVIS_REPO_SLUG" - VarOsName EnvVar = "TRAVIS_OS_NAME" - VarTag EnvVar = "TRAVIS_TAG" - VarGoVersion EnvVar = "TRAVIS_GO_VERSION" -) - -// IsRunning attempts to determine whether this process is -// running on Travis-CI. This is done by checking ALL of the -// following env vars are set: -// -// CI=true -// TRAVIS=true -// -// NOTE: cannot just check CI. -func IsRunning() bool { - return Env(VarCI) == "true" && Env(VarTravis) == "true" -} - -// Env returns the value of a travis env variable. -func Env(v EnvVar) string { - return os.Getenv(string(v)) -} - -// JobId returns the travis JOB_ID of this build. -func JobId() string { - return Env(VarJobId) -} - -// JobNumber returns the travis JOB_NUMBER of this build. -func JobNumber() string { - return Env(VarJobNumber) -} diff --git a/thirdparty/testutil/ci/travis/travis_test.go b/thirdparty/testutil/ci/travis/travis_test.go deleted file mode 100644 index f7b92595185..00000000000 --- a/thirdparty/testutil/ci/travis/travis_test.go +++ /dev/null @@ -1,13 +0,0 @@ -package travis - -import ( - "os" - "testing" -) - -func TestIsRunning(t *testing.T) { - tr := os.Getenv("TRAVIS") == "true" && os.Getenv("CI") == "true" - if tr != IsRunning() { - t.Error("IsRunning() does not match TRAVIS && CI env var check") - } -} diff --git a/thirdparty/testutil/datastore.go b/thirdparty/testutil/datastore.go deleted file mode 100644 index 56a28fe8e85..00000000000 --- a/thirdparty/testutil/datastore.go +++ /dev/null @@ -1,11 +0,0 @@ -package testutil - -import ( - ds2 "github.com/ipfs/go-ipfs/thirdparty/datastore2" - "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - syncds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/sync" -) - -func ThreadSafeCloserMapDatastore() ds2.ThreadSafeDatastoreCloser { - return ds2.CloserWrap(syncds.MutexWrap(datastore.NewMapDatastore())) -} diff --git a/thirdparty/testutil/gen.go b/thirdparty/testutil/gen.go deleted file mode 100644 index 402cb6927fd..00000000000 --- a/thirdparty/testutil/gen.go +++ /dev/null @@ -1,156 +0,0 @@ -package testutil - -import ( - "bytes" - "errors" - "fmt" - "io" - "sync" - "testing" - - ci "gx/ipfs/QmVoi5es8D5fNHZDqoW6DgDAEPEV5hQp8GBz161vZXiwpQ/go-libp2p-crypto" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" - u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" - - ma "gx/ipfs/QmYzDkkgAEmrcNzFCiYo6L1dTX4EAG1gZkbtdbd9trL4vd/go-multiaddr" -) - -// ZeroLocalTCPAddress is the "zero" tcp local multiaddr. This means: -// /ip4/127.0.0.1/tcp/0 -var ZeroLocalTCPAddress ma.Multiaddr - -func init() { - // initialize ZeroLocalTCPAddress - maddr, err := ma.NewMultiaddr("/ip4/127.0.0.1/tcp/0") - if err != nil { - panic(err) - } - ZeroLocalTCPAddress = maddr -} - -func RandTestKeyPair(bits int) (ci.PrivKey, ci.PubKey, error) { - return ci.GenerateKeyPairWithReader(ci.RSA, bits, u.NewTimeSeededRand()) -} - -func SeededTestKeyPair(seed int64) (ci.PrivKey, ci.PubKey, error) { - return ci.GenerateKeyPairWithReader(ci.RSA, 512, u.NewSeededRand(seed)) -} - -// RandPeerID generates random "valid" peer IDs. it does not NEED to generate -// keys because it is as if we lost the key right away. fine to read randomness -// and hash it. to generate proper keys and corresponding PeerID, use: -// sk, pk, _ := testutil.RandKeyPair() -// id, _ := peer.IDFromPublicKey(pk) -func RandPeerID() (peer.ID, error) { - buf := make([]byte, 16) - if _, err := io.ReadFull(u.NewTimeSeededRand(), buf); err != nil { - return "", err - } - h := u.Hash(buf) - return peer.ID(h), nil -} - -func RandPeerIDFatal(t testing.TB) peer.ID { - p, err := RandPeerID() - if err != nil { - t.Fatal(err) - } - return p -} - -// RandLocalTCPAddress returns a random multiaddr. it suppresses errors -// for nice composability-- do check the address isn't nil. -// -// NOTE: for real network tests, use ZeroLocalTCPAddress so the kernel -// assigns an unused TCP port. otherwise you may get clashes. This -// function remains here so that p2p/net/mock (which does not touch the -// real network) can assign different addresses to peers. -func RandLocalTCPAddress() ma.Multiaddr { - - // chances are it will work out, but it **might** fail if the port is in use - // most ports above 10000 aren't in use by long running processes, so yay. - // (maybe there should be a range of "loopback" ports that are guaranteed - // to be open for the process, but naturally can only talk to self.) - - lastPort.Lock() - if lastPort.port == 0 { - lastPort.port = 10000 + SeededRand.Intn(50000) - } - port := lastPort.port - lastPort.port++ - lastPort.Unlock() - - addr := fmt.Sprintf("/ip4/127.0.0.1/tcp/%d", port) - maddr, _ := ma.NewMultiaddr(addr) - return maddr -} - -var lastPort = struct { - port int - sync.Mutex -}{} - -// PeerNetParams is a struct to bundle together the four things -// you need to run a connection with a peer: id, 2keys, and addr. -type PeerNetParams struct { - ID peer.ID - PrivKey ci.PrivKey - PubKey ci.PubKey - Addr ma.Multiaddr -} - -func (p *PeerNetParams) checkKeys() error { - if !p.ID.MatchesPrivateKey(p.PrivKey) { - return errors.New("p.ID does not match p.PrivKey") - } - - if !p.ID.MatchesPublicKey(p.PubKey) { - return errors.New("p.ID does not match p.PubKey") - } - - buf := new(bytes.Buffer) - buf.Write([]byte("hello world. this is me, I swear.")) - b := buf.Bytes() - - sig, err := p.PrivKey.Sign(b) - if err != nil { - return fmt.Errorf("sig signing failed: %s", err) - } - - sigok, err := p.PubKey.Verify(b, sig) - if err != nil { - return fmt.Errorf("sig verify failed: %s", err) - } - if !sigok { - return fmt.Errorf("sig verify failed: sig invalid") - } - - return nil // ok. move along. -} - -func RandPeerNetParamsOrFatal(t *testing.T) PeerNetParams { - p, err := RandPeerNetParams() - if err != nil { - t.Fatal(err) - return PeerNetParams{} // TODO return nil - } - return *p -} - -func RandPeerNetParams() (*PeerNetParams, error) { - var p PeerNetParams - var err error - p.Addr = ZeroLocalTCPAddress - p.PrivKey, p.PubKey, err = RandTestKeyPair(512) - if err != nil { - return nil, err - } - p.ID, err = peer.IDFromPublicKey(p.PubKey) - if err != nil { - return nil, err - } - if err := p.checkKeys(); err != nil { - return nil, err - } - return &p, nil -} diff --git a/thirdparty/testutil/identity.go b/thirdparty/testutil/identity.go deleted file mode 100644 index c21076c1978..00000000000 --- a/thirdparty/testutil/identity.go +++ /dev/null @@ -1,55 +0,0 @@ -package testutil - -import ( - "testing" - - ci "gx/ipfs/QmVoi5es8D5fNHZDqoW6DgDAEPEV5hQp8GBz161vZXiwpQ/go-libp2p-crypto" - peer "gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer" - ma "gx/ipfs/QmYzDkkgAEmrcNzFCiYo6L1dTX4EAG1gZkbtdbd9trL4vd/go-multiaddr" -) - -type Identity interface { - Address() ma.Multiaddr - ID() peer.ID - PrivateKey() ci.PrivKey - PublicKey() ci.PubKey -} - -// TODO add a cheaper way to generate identities - -func RandIdentity() (Identity, error) { - p, err := RandPeerNetParams() - if err != nil { - return nil, err - } - return &identity{*p}, nil -} - -func RandIdentityOrFatal(t *testing.T) Identity { - p, err := RandPeerNetParams() - if err != nil { - t.Fatal(err) - } - return &identity{*p} -} - -// identity is a temporary shim to delay binding of PeerNetParams. -type identity struct { - PeerNetParams -} - -func (p *identity) ID() peer.ID { - return p.PeerNetParams.ID -} - -func (p *identity) Address() ma.Multiaddr { - return p.Addr -} - -func (p *identity) PrivateKey() ci.PrivKey { - return p.PrivKey -} - -func (p *identity) PublicKey() ci.PubKey { - return p.PubKey -} diff --git a/thirdparty/testutil/latency_config.go b/thirdparty/testutil/latency_config.go deleted file mode 100644 index 5628d9ed16b..00000000000 --- a/thirdparty/testutil/latency_config.go +++ /dev/null @@ -1,48 +0,0 @@ -package testutil - -import "time" - -type LatencyConfig struct { - BlockstoreLatency time.Duration - NetworkLatency time.Duration - RoutingLatency time.Duration -} - -func (c LatencyConfig) AllInstantaneous() LatencyConfig { - // Could use a zero value but whatever. Consistency of interface - c.NetworkLatency = 0 - c.RoutingLatency = 0 - c.BlockstoreLatency = 0 - return c -} - -func (c LatencyConfig) NetworkNYtoSF() LatencyConfig { - c.NetworkLatency = 20 * time.Millisecond - return c -} - -func (c LatencyConfig) NetworkIntraDatacenter2014() LatencyConfig { - c.NetworkLatency = 250 * time.Microsecond - return c -} - -func (c LatencyConfig) BlockstoreFastSSD2014() LatencyConfig { - const iops = 100000 - c.BlockstoreLatency = (1 / iops) * time.Second - return c -} - -func (c LatencyConfig) BlockstoreSlowSSD2014() LatencyConfig { - c.BlockstoreLatency = 150 * time.Microsecond - return c -} - -func (c LatencyConfig) Blockstore7200RPM() LatencyConfig { - c.BlockstoreLatency = 8 * time.Millisecond - return c -} - -func (c LatencyConfig) RoutingSlow() LatencyConfig { - c.RoutingLatency = 200 * time.Millisecond - return c -} diff --git a/thirdparty/testutil/rand.go b/thirdparty/testutil/rand.go deleted file mode 100644 index 9630bc1448f..00000000000 --- a/thirdparty/testutil/rand.go +++ /dev/null @@ -1,36 +0,0 @@ -package testutil - -import ( - "math/rand" - "sync" - "time" -) - -var SeededRand *rand.Rand - -func init() { - SeededRand = NewSeededRand(time.Now().UTC().UnixNano()) -} - -func NewSeededRand(seed int64) *rand.Rand { - src := rand.NewSource(seed) - return rand.New(&LockedRandSource{src: src}) -} - -type LockedRandSource struct { - lk sync.Mutex - src rand.Source -} - -func (r *LockedRandSource) Int63() (n int64) { - r.lk.Lock() - n = r.src.Int63() - r.lk.Unlock() - return -} - -func (r *LockedRandSource) Seed(seed int64) { - r.lk.Lock() - r.src.Seed(seed) - r.lk.Unlock() -} diff --git a/thirdparty/todocounter/counter.go b/thirdparty/todocounter/counter.go deleted file mode 100644 index 0df63820427..00000000000 --- a/thirdparty/todocounter/counter.go +++ /dev/null @@ -1,118 +0,0 @@ -package todocounter - -import ( - "sync" -) - -// Counter records things remaining to process. It is needed for complicated -// cases where multiple goroutines are spawned to process items, and they may -// generate more items to process. For example, say a query over a set of nodes -// may yield either a result value, or more nodes to query. Signaling is subtly -// complicated, because the queue may be empty while items are being processed, -// that will end up adding more items to the queue. -// -// Use Counter like this: -// -// todos := make(chan int, 10) -// ctr := todoctr.NewCounter() -// -// process := func(item int) { -// fmt.Println("processing %d\n...", item) -// -// // this task may randomly generate more tasks -// if rand.Intn(5) == 0 { -// todos<- item + 1 -// ctr.Increment(1) // increment counter for new task. -// } -// -// ctr.Decrement(1) // decrement one to signal the task being done. -// } -// -// // add some tasks. -// todos<- 1 -// todos<- 2 -// todos<- 3 -// todos<- 4 -// ctr.Increment(4) -// -// for { -// select { -// case item := <- todos: -// go process(item) -// case <-ctr.Done(): -// fmt.Println("done processing everything.") -// close(todos) -// } -// } -type Counter interface { - // Incrememnt adds a number of todos to track. - // If the counter is **below** zero, it panics. - Increment(i uint32) - - // Decrement removes a number of todos to track. - // If the count drops to zero, signals done and destroys the counter. - // If the count drops **below** zero, panics. It means you have tried to remove - // more things than you added, i.e. sync issues. - Decrement(i uint32) - - // Done returns a channel to wait upon. Use it in selects: - // - // select { - // case <-ctr.Done(): - // // done processing all items - // } - // - Done() <-chan struct{} -} - -type todoCounter struct { - count int32 - done chan struct{} - sync.RWMutex -} - -// NewSyncCounter constructs a new counter -func NewSyncCounter() Counter { - return &todoCounter{ - done: make(chan struct{}), - } -} - -func (c *todoCounter) Increment(i uint32) { - c.Lock() - defer c.Unlock() - - if c.count < 0 { - panic("counter already signaled done. use a new counter.") - } - - // increment count - c.count += int32(i) -} - -// Decrement removes a number of todos to track. -// If the count drops to zero, signals done and destroys the counter. -// If the count drops **below** zero, panics. It means you have tried to remove -// more things than you added, i.e. sync issues. -func (c *todoCounter) Decrement(i uint32) { - c.Lock() - defer c.Unlock() - - if c.count < 0 { - panic("counter already signaled done. probably have sync issues.") - } - - if int32(i) > c.count { - panic("decrement amount creater than counter. sync issues.") - } - - c.count -= int32(i) - if c.count == 0 { // done! signal it. - c.count-- // set it to -1 to prevent reuse - close(c.done) // a closed channel will always return nil - } -} - -func (c *todoCounter) Done() <-chan struct{} { - return c.done -} diff --git a/unixfs/io/dirbuilder.go b/unixfs/io/dirbuilder.go index 3db0b9ef968..9a33c099e18 100644 --- a/unixfs/io/dirbuilder.go +++ b/unixfs/io/dirbuilder.go @@ -3,9 +3,9 @@ package io import ( "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" - key "github.com/ipfs/go-ipfs/blocks/key" mdag "github.com/ipfs/go-ipfs/merkledag" format "github.com/ipfs/go-ipfs/unixfs" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" ) type directoryBuilder struct { diff --git a/unixfs/mod/dagmodifier.go b/unixfs/mod/dagmodifier.go index 784cef8a492..fc106e502c2 100644 --- a/unixfs/mod/dagmodifier.go +++ b/unixfs/mod/dagmodifier.go @@ -6,13 +6,13 @@ import ( "io" "os" - key "github.com/ipfs/go-ipfs/blocks/key" chunk "github.com/ipfs/go-ipfs/importer/chunk" help "github.com/ipfs/go-ipfs/importer/helpers" trickle "github.com/ipfs/go-ipfs/importer/trickle" mdag "github.com/ipfs/go-ipfs/merkledag" ft "github.com/ipfs/go-ipfs/unixfs" uio "github.com/ipfs/go-ipfs/unixfs/io" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" mh "gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash" diff --git a/unixfs/mod/dagmodifier_test.go b/unixfs/mod/dagmodifier_test.go index 815ac5fc0b0..6ea3c31f060 100644 --- a/unixfs/mod/dagmodifier_test.go +++ b/unixfs/mod/dagmodifier_test.go @@ -18,10 +18,10 @@ import ( ft "github.com/ipfs/go-ipfs/unixfs" uio "github.com/ipfs/go-ipfs/unixfs/io" - ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore" - "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore/sync" u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" + ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" + "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/sync" ) func getMockDagServ(t testing.TB) mdag.DAGService {