Unverified Commit faf1a196 authored by Hannah Howard's avatar Hannah Howard Committed by GitHub

Merge pull request #17 from ipfs/chore/mock-selector-interfaces-4

Setup IPLD Bridge and provide mock-interface and "beta" implementation
parents cca24684 d6fbc28b
...@@ -4,11 +4,51 @@ ...@@ -4,11 +4,51 @@
package "go-ipld-prime" { package "go-ipld-prime" {
interface Node { interface Node {
} }
interface NodeBuilder {
}
interface Path {
}
package traversal {
package selector {
interface Selector { interface Selector {
} }
object "PackagePublicFunctions" as goSelectorPF {
ReifySelector(cidRootedSelector Node) (Selector, error)
}
}
interface AdvVisitFn {
}
class TraversalConfig {
ctx context.Context
linkLoader LinkLoader
}
class TraversalProgress {
TraverseInformatively(Node, Selector, AdvVisitFn)
}
TraversalProgress *-- TraversalConfig
}
package repose {
interface RawLoader {
}
interface MulticodecDecodeTable {
}
interface NodeBuilderChooser {
}
interface LinkLoader {
}
object "Package Public Functions" as goIPLDReposePf {
ComposeLinkLoader(RawLoader, NodeBuilderChooser, MulticodecDecodeTable)
EncoderDagCbor(Node, io.Writer)
DecodeDagCbor(NodeBuilder, io.Writer)
}
}
} }
package "go-graphsync" { package "go-graphsync" {
...@@ -17,11 +57,16 @@ package "go-graphsync" { ...@@ -17,11 +57,16 @@ package "go-graphsync" {
network : GraphySyncNetwork network : GraphySyncNetwork
requestManager : RequestManager requestManager : RequestManager
responseManager: ResponseManager responseManager: ResponseManager
Request(p peer.ID, selector Selector, root Cid) chan Block ipldBridge: IPLDBridge
rawLoader: RawLoader
Request(ctx context.Context, p peer.ID, cidRootedSelector Node) chan Block
ReceiveMessage(ctx context.Context, sender peer.ID, incoming GraphSyncMessage) ReceiveMessage(ctx context.Context, sender peer.ID, incoming GraphSyncMessage)
ReceiveError(error) ReceiveError(error)
} }
GraphSync *-- RawLoader
package network { package network {
interface Receiver { interface Receiver {
...@@ -58,8 +103,9 @@ package "go-graphsync" { ...@@ -58,8 +103,9 @@ package "go-graphsync" {
package requestmanager { package requestmanager {
class RequestManager { class RequestManager {
network : GraphSyncNetwork network : GraphSyncNetwork
ipldBridge: GraphSyncNetwork
SendRequest(p peer.ID, selector Selector, root Cid) chan Block SendRequest(ctx context.Context, p peer.ID, cidRootedSelector Node) chan Block
ProcessResponses(responses []GraphSyncResponse) ProcessResponses(responses []GraphSyncResponse)
} }
RequestManager *-- GraphSyncNetwork RequestManager *-- GraphSyncNetwork
...@@ -69,10 +115,14 @@ package "go-graphsync" { ...@@ -69,10 +115,14 @@ package "go-graphsync" {
package responsemanager { package responsemanager {
class ResponseManager { class ResponseManager {
network : GraphySyncNetwork network : GraphySyncNetwork
ipldBridge: IPLDBridge
rawLoader: RawLoader
ProcessRequests(p peer.ID, requests []GraphSyncRequests) ProcessRequests(p peer.ID, requests []GraphSyncRequests)
} }
ResponseManager *-- GraphSyncNetwork ResponseManager *-- GraphSyncNetwork
GraphSync *-- ResponseManager GraphSync *-- ResponseManager
ResponseManager *-- RawLoader
} }
package message { package message {
object "Package Public Functions" as goGraphSyncMessagePF { object "Package Public Functions" as goGraphSyncMessagePF {
...@@ -111,8 +161,39 @@ package "go-graphsync" { ...@@ -111,8 +161,39 @@ package "go-graphsync" {
} }
package ipldbridge {
interface IPLDBridge {
ComposeLinkLoader(actualLoader RawLoader) LinkLoader
ValidateSelectorSpec(cidRootedSelector ipld.Node) []error
EncodeNode(ipld.Node) ([]byte, error)
DecodeNode([]byte) (ipld.Node, error)
DecodeSelectorSpec(cidRootedSelector ipld.Node) (ipld.Node, Selector, error)
Traverse(ctx context.Context, loader LinkLoader, root ipld.Node, s Selector, fn AdvVisitFn) error
}
GraphSync *-- IPLDBridge
RequestManager *-- IPLDBridge
ResponseManager *-- IPLDBridge
class ipldBridge {
nodeBuilderChooser: NodeBuilderChooser
multicodecTable: MulticodecDecodeTable
}
object "PackagePublicFunctions" as goIPLDBridge {
NewIPLDBridge(nodeBuilderChooser NodeBuilderChooser, multicodecTable MulticodecDecodeTable) IPLDBridge
}
IPLDBridge <|-- ipldBridge
goIPLDBridge .. ipldBridge
ipldBridge *-- MulticodecDecodeTable
ipldBridge *-- NodeBuilderChooser
ipldBridge .. TraversalProgress
ipldBridge .. goSelectorPF
ipldBridge .. goIPLDReposePf
}
object "PackagePublicFunctions" as goGraphsyncPf { object "PackagePublicFunctions" as goGraphsyncPf {
New(ctx context.Context, network GraphSyncNetwork) GraphSync New(ctx context.Context, network GraphSyncNetwork, rawLoader RawLoader, multicodecDecodeTable MulticodecDecodeTable, nodeBuilderChooser NodeBuilderChooser) GraphSync
} }
} }
...@@ -121,12 +202,18 @@ package "go-filecoin" { ...@@ -121,12 +202,18 @@ package "go-filecoin" {
class "go-filecoin" { class "go-filecoin" {
graphSync : GraphSync graphSync : GraphSync
host: libp2pHost.Host host: libp2pHost.Host
nodeBuilderChooser: NodeBuilderChooser
multicodecTable: MulticodecDecodeTable
rawLoader: RawLoader
} }
"go-filecoin" *-- GraphSync "go-filecoin" *-- GraphSync
"go-filecoin" .. goGraphsyncPf "go-filecoin" .. goGraphsyncPf
"go-filecoin" .. goGraphSyncNetworkPF "go-filecoin" .. goGraphSyncNetworkPF
"go-filecoin" .. Selector "go-filecoin" .. goIPLDBridge
"go-filecoin" *-- RawLoader
"go-filecoin" *-- MulticodecDecodeTable
"go-filecoin" *-- NodeBuilderChooser
} }
......
github.com/AndreasBriese/bbloom v0.0.0-20180913140656-343706a395b7/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8=
github.com/Kubuxu/go-os-helper v0.0.1/go.mod h1:N8B+I7vPCT80IcP58r50u4+gEEcsZETFUpAzWW2ep1Y=
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32 h1:qkOC5Gd33k54tobS36cXdAzJbeHaduLtnLQQwNoIi78=
github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32/go.mod h1:DrZx5ec/dmnfpw9KyYoQyYo7d0KEvTkk/5M/vbZjAr8=
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
github.com/btcsuite/btcutil v0.0.0-20190207003914-4c204d697803/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg=
github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY=
github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY=
github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs=
github.com/coreos/go-semver v0.2.0 h1:3Jm3tLmsgAYcjC+4Up7hJrFBPr+n7rAqYeSw/SZazuY=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgraph-io/badger v1.5.5-0.20190226225317-8115aed38f8f/go.mod h1:VZxzAIRPHRVNRKRo6AXrX9BJegn6il06VMTZVJYCIjQ=
github.com/dgryski/go-farm v0.0.0-20190104051053-3adb47b1fb0f/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98=
github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE=
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gxed/hashland/keccakpg v0.0.1 h1:wrk3uMNaMxbXiHibbPO4S0ymqJMm41WiudyFSs7UnsU=
github.com/gxed/hashland/keccakpg v0.0.1/go.mod h1:kRzw3HkwxFU1mpmPP8v1WyQzwdGfmKFJ6tItnhQ67kU=
github.com/gxed/hashland/murmur3 v0.0.1 h1:SheiaIt0sda5K+8FLz952/1iWS9zrnKsEJaOJu4ZbSc=
github.com/gxed/hashland/murmur3 v0.0.1/go.mod h1:KjXop02n4/ckmZSnY2+HKcLud/tcmvhST0bie/0lS48=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/ipfs/go-block-format v0.0.2 h1:qPDvcP19izTjU8rgo6p7gTXZlkMkF5bz5G3fqIsSCPE=
github.com/ipfs/go-block-format v0.0.2/go.mod h1:AWR46JfpcObNfg3ok2JHDUfdiHRgWhJgCQF+KIgOPJY=
github.com/ipfs/go-cid v0.0.1 h1:GBjWPktLnNyX0JiQCNFpUuUSoMw5KMyqrsejHYlILBE=
github.com/ipfs/go-cid v0.0.1/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM=
github.com/ipfs/go-datastore v0.0.1/go.mod h1:d4KVXhMt913cLBEI/PXAy6ko+W7e9AhyAKBGh803qeE=
github.com/ipfs/go-ds-badger v0.0.2/go.mod h1:Y3QpeSFWQf6MopLTiZD+VT6IC1yZqaGmjvRcKeSGij8=
github.com/ipfs/go-ds-leveldb v0.0.1/go.mod h1:feO8V3kubwsEF22n0YRQCffeb79OOYIykR4L04tMOYc=
github.com/ipfs/go-ipfs-blocksutil v0.0.1 h1:Eh/H4pc1hsvhzsQoMEP3Bke/aW5P5rVM1IWFJMcGIPQ=
github.com/ipfs/go-ipfs-blocksutil v0.0.1/go.mod h1:Yq4M86uIOmxmGPUHv/uI7uKqZNtLb449gwKqXjIsnRk=
github.com/ipfs/go-ipfs-delay v0.0.0-20181109222059-70721b86a9a8/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw=
github.com/ipfs/go-ipfs-util v0.0.1 h1:Wz9bL2wB2YBJqggkA4dD7oSmqB4cAnpNbGrlHJulv50=
github.com/ipfs/go-ipfs-util v0.0.1/go.mod h1:spsl5z8KUnrve+73pOhSVZND1SIxPW5RyBCNzQxlJBc=
github.com/ipfs/go-log v0.0.1 h1:9XTUN/rW64BCG1YhPK9Hoy3q8nr4gOmHHBpgFdfw6Lc=
github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM=
github.com/ipld/go-ipld-prime v0.0.0-20190227132703-aaea73ad73c5 h1:Fm+tk5iaitTL/3L1nRlwibgLFtI5Eld4nIrjX4ajcKY=
github.com/ipld/go-ipld-prime v0.0.0-20190227132703-aaea73ad73c5/go.mod h1:hSGXgXt4BSdqvjA3Kkxhzcg4Rsk9yvIeEuEVCPCi7/A=
github.com/ipld/go-ipld-prime v0.0.0-20190306022502-066284669cf6 h1:FJW7rDl8g/580E6ZuR5rXzDT/9SsJvCuAEQCq8cbdPQ=
github.com/ipld/go-ipld-prime v0.0.0-20190306022502-066284669cf6/go.mod h1:hSGXgXt4BSdqvjA3Kkxhzcg4Rsk9yvIeEuEVCPCi7/A=
github.com/jbenet/go-random v0.0.0-20190219211222-123a90aedc0c h1:uUx61FiAa1GI6ZmVd2wf2vULeQZIKG66eybjNXKYCz4=
github.com/jbenet/go-random v0.0.0-20190219211222-123a90aedc0c/go.mod h1:sdx1xVM9UuLw1tXnhJWN3piypTUO3vCIHYmG15KE/dU=
github.com/jbenet/goprocess v0.0.0-20160826012719-b497e2f366b8 h1:bspPhN+oKYFk5fcGNuQzp6IGzYQSenLEgH3s6jkXrWw=
github.com/jbenet/goprocess v0.0.0-20160826012719-b497e2f366b8/go.mod h1:Ly/wlsjFq/qrU3Rar62tu1gASgGw6chQbSh/XgIIXCY=
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/libp2p/go-buffer-pool v0.0.1/go.mod h1:xtyIz9PMobb13WaxR6Zo1Pd1zXJKYg0a8KiIvDp3TzQ=
github.com/libp2p/go-libp2p-crypto v0.0.1 h1:JNQd8CmoGTohO/akqrH16ewsqZpci2CbgYH/LmYl8gw=
github.com/libp2p/go-libp2p-crypto v0.0.1/go.mod h1:yJkNyDmO341d5wwXxDUGO0LykUVT72ImHNUqh5D/dBE=
github.com/libp2p/go-libp2p-host v0.0.1 h1:dnqusU+DheGcdxrE718kG4XgHNuL2n9eEv8Rg5zy8hQ=
github.com/libp2p/go-libp2p-host v0.0.1/go.mod h1:qWd+H1yuU0m5CwzAkvbSjqKairayEHdR5MMl7Cwa7Go=
github.com/libp2p/go-libp2p-interface-connmgr v0.0.1 h1:Q9EkNSLAOF+u90L88qmE9z/fTdjLh8OsJwGw74mkwk4=
github.com/libp2p/go-libp2p-interface-connmgr v0.0.1/go.mod h1:GarlRLH0LdeWcLnYM/SaBykKFl9U5JFnbBGruAk/D5k=
github.com/libp2p/go-libp2p-net v0.0.1 h1:xJ4Vh4yKF/XKb8fd1Ev0ebAGzVjMxXzrxG2kjtU+F5Q=
github.com/libp2p/go-libp2p-net v0.0.1/go.mod h1:Yt3zgmlsHOgUWSXmt5V/Jpz9upuJBE8EgNU9DrCcR8c=
github.com/libp2p/go-libp2p-peer v0.0.1 h1:0qwAOljzYewINrU+Kndoc+1jAL7vzY/oY2Go4DCGfyY=
github.com/libp2p/go-libp2p-peer v0.0.1/go.mod h1:nXQvOBbwVqoP+T5Y5nCjeH4sP9IX/J0AMzcDUVruVoo=
github.com/libp2p/go-libp2p-peerstore v0.0.1 h1:twKovq8YK5trLrd3nB7PD2Zu9JcyAIdm7Bz9yBWjhq8=
github.com/libp2p/go-libp2p-peerstore v0.0.1/go.mod h1:RabLyPVJLuNQ+GFyoEkfi8H4Ti6k/HtZJ7YKgtSq+20=
github.com/libp2p/go-libp2p-protocol v0.0.1 h1:+zkEmZ2yFDi5adpVE3t9dqh/N9TbpFWywowzeEzBbLM=
github.com/libp2p/go-libp2p-protocol v0.0.1/go.mod h1:Af9n4PiruirSDjHycM1QuiMi/1VZNHYcK8cLgFJLZ4s=
github.com/libp2p/go-stream-muxer v0.0.1 h1:Ce6e2Pyu+b5MC1k3eeFtAax0pW4gc6MosYSLV05UeLw=
github.com/libp2p/go-stream-muxer v0.0.1/go.mod h1:bAo8x7YkSpadMTbtTaxGVHWUQsR/l5MEaHbKaliuT14=
github.com/mattn/go-colorable v0.1.1 h1:G1f5SKeVxmagw/IyvzvtZE4Gybcc4Tr1tf7I8z0XgOg=
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
github.com/mattn/go-isatty v0.0.5 h1:tHXDdz1cpzGaovsTB+TVB8q90WEokoVmfMqoVcrLUgw=
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 h1:lYpkrQH5ajf0OXOcUbGjvZxxijuBwbbmlSxLiuofa+g=
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ=
github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16 h1:5W7KhL8HVF3XCFOweFD3BNESdnO8ewyYTFT2R+/b8FQ=
github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U=
github.com/mr-tron/base58 v1.1.0 h1:Y51FGVJ91WBqCEabAi5OPUz38eAx8DakuAm5svLcsfQ=
github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8=
github.com/multiformats/go-base32 v0.0.3 h1:tw5+NhuwaOjJCC5Pp82QuXbrmLzWg7uxlMFp8Nq/kkI=
github.com/multiformats/go-base32 v0.0.3/go.mod h1:pLiuGC8y0QR3Ue4Zug5UzK9LjgbkL8NSQj0zQ5Nz/AA=
github.com/multiformats/go-multiaddr v0.0.1 h1:/QUV3VBMDI6pi6xfiw7lr6xhDWWvQKn9udPn68kLSdY=
github.com/multiformats/go-multiaddr v0.0.1/go.mod h1:xKVEak1K9cS1VdmPZW3LSIb6lgmoS58qz/pzqmAxV44=
github.com/multiformats/go-multiaddr-dns v0.0.1/go.mod h1:9kWcqw/Pj6FwxAwW38n/9403szc57zJPs45fmnznu3Q=
github.com/multiformats/go-multiaddr-net v0.0.1/go.mod h1:nw6HSxNmCIQH27XPGBuX+d1tnvM7ihcFwHMSstNAVUU=
github.com/multiformats/go-multibase v0.0.1 h1:PN9/v21eLywrFWdFNsFKaU04kLJzuYzmrJR+ubhT9qA=
github.com/multiformats/go-multibase v0.0.1/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/gviWFaSteVbWT51qgs=
github.com/multiformats/go-multihash v0.0.1 h1:HHwN1K12I+XllBCrqKnhX949Orn4oawPkegHMu2vDqQ=
github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U=
github.com/multiformats/go-multistream v0.0.1 h1:JV4VfSdY9n7ECTtY59/TlSyFCzRILvYx4T4Ws8ZgihU=
github.com/multiformats/go-multistream v0.0.1/go.mod h1:fJTiDfXJVmItycydCnNx4+wSzZ5NwG2FEVAI30fiovg=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/opentracing/opentracing-go v1.0.2 h1:3jA2P6O1F9UOrWVpwrIo17pu01KWvNWg4X946/Y5Zwg=
github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/polydawn/refmt v0.0.0-20190221155625-df39d6c2d992 h1:bzMe+2coZJYHnhGgVlcQKuRy4FSny4ds8dLQjw5P1XE=
github.com/polydawn/refmt v0.0.0-20190221155625-df39d6c2d992/go.mod h1:uIp+gprXxxrWSjjklXD+mN4wed/tMfjMMmN/9+JsA9o=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1/go.mod h1:8UvriyWtv5Q5EOgjHaSseUEdkQfvwFv1I/In/O2M9gc=
github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc h1:9lDbC6Rz4bwmou+oE6Dt4Cb2BGMur5eR/GYptkKUVHo=
github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc/go.mod h1:bopw91TMyo8J3tvftk8xmU2kPmlrt4nScJQZU2hE5EM=
github.com/whyrusleeping/mafmt v1.2.8/go.mod h1:faQJFPbLSxzD9xpA02ttW/tS9vZykNvXwGvqIpk20FA=
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190225124518-7f87c0fbb88b h1:+/WWzjwW6gidDJnMKWLKLX1gxn7irUTF1fLpQovfQ5M=
golang.org/x/crypto v0.0.0-20190225124518-7f87c0fbb88b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190227160552-c95aed5357e7 h1:C2F/nMkR/9sfUTpvR3QrjBuTdvMUC/cFajkphs1YLQo=
golang.org/x/net v0.0.0-20190227160552-c95aed5357e7/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190219092855-153ac476189d/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
package ipldbridge
import (
"bytes"
"context"
"errors"
ipld "github.com/ipld/go-ipld-prime"
ipldfree "github.com/ipld/go-ipld-prime/impl/free"
ipldrepose "github.com/ipld/go-ipld-prime/repose"
ipldtraversal "github.com/ipld/go-ipld-prime/traversal"
ipldselector "github.com/ipld/go-ipld-prime/traversal/selector"
ipldtypesystem "github.com/ipld/go-ipld-prime/typed/system"
)
// not sure how these will come into being or from where
var cidRootedSelectorType ipldtypesystem.Type
var universe ipldtypesystem.Universe
// TraversalConfig is an alias from ipld, in case it's renamed/moved.
type TraversalConfig = ipldtraversal.TraversalConfig
type ipldBridge struct {
nodeBuilderChooser NodeBuilderChooser
multicodecTable MulticodecDecodeTable
}
// NewIPLDBridge returns an IPLD Bridge.
func NewIPLDBridge(nodeBuilderChooser NodeBuilderChooser,
multicodecTable MulticodecDecodeTable) IPLDBridge {
return &ipldBridge{nodeBuilderChooser, multicodecTable}
}
func (rb *ipldBridge) ComposeLinkLoader(
actualLoader RawLoader) LinkLoader {
return ipldrepose.ComposeLinkLoader(actualLoader, rb.nodeBuilderChooser, rb.multicodecTable)
}
func (rb *ipldBridge) Traverse(ctx context.Context, loader LinkLoader, root ipld.Node, s Selector, fn AdvVisitFn) error {
config := &TraversalConfig{Ctx: ctx, LinkLoader: loader}
return TraversalProgress{TraversalConfig: config}.TraverseInformatively(root, s, fn)
}
func (rb *ipldBridge) ValidateSelectorSpec(cidRootedSelector ipld.Node) []error {
return ipldtypesystem.Validate(universe, cidRootedSelectorType, cidRootedSelector)
}
func (rb *ipldBridge) EncodeNode(node ipld.Node) ([]byte, error) {
var buffer bytes.Buffer
err := ipldrepose.EncoderDagCbor(node, &buffer)
if err != nil {
return nil, err
}
return buffer.Bytes(), nil
}
func (rb *ipldBridge) DecodeNode(encoded []byte) (ipld.Node, error) {
reader := bytes.NewReader(encoded)
return ipldrepose.DecoderDagCbor(ipldfree.NodeBuilder(), reader)
}
func (rb *ipldBridge) DecodeSelectorSpec(cidRootedSelector ipld.Node) (ipld.Node, Selector, error) {
errs := rb.ValidateSelectorSpec(cidRootedSelector)
if len(errs) != 0 {
return nil, nil, errors.New("Node does not validate as selector spec")
}
root, err := cidRootedSelector.TraverseField("root")
if err != nil {
return nil, nil, err
}
rootCid, err := root.AsLink()
if err != nil {
return nil, nil, err
}
node, err := ipldfree.NodeBuilder().CreateLink(rootCid)
if err != nil {
return nil, nil, err
}
selector, err := ipldselector.ReifySelector(cidRootedSelector)
if err != nil {
return nil, nil, err
}
return node, selector, nil
}
package ipldbridge
import (
"context"
ipld "github.com/ipld/go-ipld-prime"
ipldrepose "github.com/ipld/go-ipld-prime/repose"
ipldtraversal "github.com/ipld/go-ipld-prime/traversal"
ipldselector "github.com/ipld/go-ipld-prime/traversal/selector"
)
// MulticodecDecodeTable is an alias from ipld, in case it's renamed/moved.
type MulticodecDecodeTable = ipldrepose.MulticodecDecodeTable
// NodeBuilderChooser is an an alias from ipld, in case it's renamed/moved.
type NodeBuilderChooser = ipldrepose.NodeBuilderChooser
// LinkLoader is alias from ipld, in case it.s renamed/moved.
type LinkLoader = ipldtraversal.LinkLoader
// RawLoader is an alias from ipld, in case it's renamed/moved.
type RawLoader = ipldrepose.ActualLoader
// AdvVisitFn is an alias from ipld, in case it's renamed/moved.
type AdvVisitFn = ipldtraversal.AdvVisitFn
// Selector is an alias from ipld, in case it's renamed/moved.
type Selector = ipldselector.Selector
// LinkContext is an alias from ipld, in case it's renamed/moved.
type LinkContext = ipldtraversal.LinkContext
// TraversalProgress is an alias from ipld, in case it's renamed/moved.
type TraversalProgress = ipldtraversal.TraversalProgress
// TraversalReason is an alias from ipld, in case it's renamed/moved.
type TraversalReason = ipldtraversal.TraversalReason
// IPLDBridge is an interface for making calls to IPLD, which can be
// replaced with alternative implementations
type IPLDBridge interface {
// ComposeLinkLoader converts a raw block loader into an IPLD node loader.
ComposeLinkLoader(actualLoader RawLoader) LinkLoader
// ValidateSelectorSpec verifies if a node matches the selector spec.
ValidateSelectorSpec(cidRootedSelector ipld.Node) []error
// EncodeNode encodes an IPLD Node to bytes for network transfer.
EncodeNode(ipld.Node) ([]byte, error)
// DecodeNode decodes bytes crossing a network to an IPLD Node.
DecodeNode([]byte) (ipld.Node, error)
// DecodeSelectorSpec checks if a generic IPLD node is a selector spec,
// and if so, converts it to a root node and a go-ipld-prime Selector.
DecodeSelectorSpec(cidRootedSelector ipld.Node) (ipld.Node, Selector, error)
// Traverse performs a selector traversal, starting at a given root, using the given selector,
// and the given link loader. The given visit function will be called for each node
// visited.
Traverse(ctx context.Context, loader LinkLoader, root ipld.Node, s Selector, fn AdvVisitFn) error
}
{
"author": "hannahhoward",
"bugs": {
"url": "https://github.com/ipfs/go-graphsync"
},
"gx": {
"dvcsimport": "github.com/ipfs/go-graphsync"
},
"gxDependencies": [
{
"author": "whyrusleeping",
"hash": "QmYxivS34F2M2n44WQQnRHGAKS8aoRUxwGpi9wk4Cdn4Jf",
"name": "go-libp2p",
"version": "6.0.30"
},
{
"author": "hsanjuan",
"hash": "QmVZ6cQXHoTQja4oo9GhhHZi7dThi4x98mRKgGtKnTy37u",
"name": "go-ipfs-routing",
"version": "0.1.13"
},
{
"author": "whyrusleeping",
"hash": "QmNvHv84aH2qZafDuSdKJCQ1cvPZ1kmQmyD4YtzjUHuk9v",
"name": "go-testutil",
"version": "1.2.15"
},
{
"author": "whyrusleeping",
"hash": "QmY5Grm8pJdiSSVsYxx4uNRgweY72EmYwuSDbRnbFok3iY",
"name": "go-libp2p-peer",
"version": "3.0.0"
},
{
"author": "whyrusleeping",
"hash": "QmdxUuburamoF6zF9qjeQC4WYcWGbWuRmdLacMEsW8ioD8",
"name": "gogo-protobuf",
"version": "0.0.0"
},
{
"author": "hsanjuan",
"hash": "QmZUbTDJ39JpvtFCSubiWeUTQRvMA1tVE5RZCJrY4oeAsC",
"name": "go-ipfs-pq",
"version": "0.0.1"
},
{
"author": "whyrusleeping",
"hash": "QmNohiVssaPw3KVLZik59DBVGTSm2dGvYT9eoXt5DQ36Yz",
"name": "go-ipfs-util",
"version": "1.2.9"
},
{
"author": "whyrusleeping",
"hash": "QmaoXrM4Z41PD48JY36YqQGKQpLGjyLA2cKcLsES7YddAq",
"name": "go-libp2p-host",
"version": "3.0.21"
},
{
"author": "hsanjuan",
"hash": "QmUe1WCHkQaz4UeNKiHDUBV2T6i9prc3DniqyHPXyfGaUq",
"name": "go-ipfs-delay",
"version": "0.1.0"
},
{
"hash": "QmcuXC5cxs79ro2cUuHs4HQ2bkDLJUYokwL8aivcX6HW3C",
"name": "go-log",
"version": "1.5.8"
},
{
"author": "whyrusleeping",
"hash": "QmcD6i5pkzKcy5AiSEU22xmj8MYkkPSaXVvbYo7Wx2hp6H",
"name": "go-libp2p-netutil",
"version": "0.4.18"
},
{
"author": "whyrusleeping",
"hash": "QmNgLg1NTw37iWbYPKcyK85YJ9Whs1MkPtJwhfqbNYAyKg",
"name": "go-libp2p-net",
"version": "3.0.22"
},
{
"author": "whyrusleeping",
"hash": "QmPiemjiKBC9VA7vZF82m4x1oygtg2c2YVqag8PX7dN1BD",
"name": "go-libp2p-peerstore",
"version": "2.0.13"
},
{
"author": "multiformats",
"hash": "QmNTCey11oxhb1AxDnQBRHtdhap6Ctud872NjAYPYYXPuc",
"name": "go-multiaddr",
"version": "1.4.0"
},
{
"author": "whyrusleeping",
"hash": "QmZNkThpqfVXs9GNbexPrfBbXSLNYeKrE7jwFM2oqHbyqN",
"name": "go-libp2p-protocol",
"version": "1.0.0"
},
{
"author": "whyrusleeping",
"hash": "QmWZnkipEJbsdUDhgTGBnKAN1iHM2WDMNqsXHyAuaAiCgo",
"name": "go-libp2p-loggables",
"version": "1.1.29"
},
{
"author": "why",
"hash": "QmSFo2QrMF4M1mKdB291ZqNtsie4NfwXCRdWgDU3inw4Ff",
"name": "go-libp2p-interface-connmgr",
"version": "0.0.27"
},
{
"hash": "QmTiRqrF5zkdZyrdsL5qndG1UbeWi8k8N2pYxCtXWrahR2",
"name": "go-libp2p-routing",
"version": "2.7.7"
},
{
"author": "jbenet",
"hash": "QmSJ9n2s9NUoA9D849W5jj5SJ94nMcZpj1jCgQJieiNqSt",
"name": "go-random",
"version": "1.0.0"
},
{
"author": "whyrusleeping",
"hash": "QmRL22E4paat7ky7vx9MLpR97JHHbFPrg3ytFQw6qp1y1s",
"name": "go-ipld-format",
"version": "0.8.0"
}
],
"gxVersion": "0.0.1",
"language": "go",
"license": "",
"name": "go-graphsync",
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
"version": "0.0.1"
}
package testbridge
import (
"fmt"
cid "github.com/ipfs/go-cid"
ipld "github.com/ipld/go-ipld-prime"
)
type mockSelectorSpec struct {
cidsVisited []cid.Cid
}
// NewMockSelectorSpec returns a new mock selector that will visit the given
// cids.
func NewMockSelectorSpec(cidsVisited []cid.Cid) ipld.Node {
return &mockSelectorSpec{cidsVisited}
}
func (mss *mockSelectorSpec) Kind() ipld.ReprKind { return ipld.ReprKind_Null }
func (mss *mockSelectorSpec) TraverseField(key string) (ipld.Node, error) {
return nil, fmt.Errorf("404")
}
func (mss *mockSelectorSpec) TraverseIndex(idx int) (ipld.Node, error) {
return nil, fmt.Errorf("404")
}
func (mss *mockSelectorSpec) Keys() ipld.KeyIterator { return &mockKeyIterator{} }
func (mss *mockSelectorSpec) KeysImmediate() ([]string, error) {
return nil, fmt.Errorf("404")
}
func (mss *mockSelectorSpec) Length() int { return 0 }
func (mss *mockSelectorSpec) IsNull() bool { return true }
func (mss *mockSelectorSpec) AsBool() (bool, error) { return false, fmt.Errorf("404") }
func (mss *mockSelectorSpec) AsInt() (int, error) { return 0, fmt.Errorf("404") }
func (mss *mockSelectorSpec) AsFloat() (float64, error) { return 0.0, fmt.Errorf("404") }
func (mss *mockSelectorSpec) AsString() (string, error) { return "", fmt.Errorf("404") }
func (mss *mockSelectorSpec) AsBytes() ([]byte, error) { return nil, fmt.Errorf("404") }
func (mss *mockSelectorSpec) AsLink() (cid.Cid, error) { return cid.Cid{}, fmt.Errorf("404") }
type mockKeyIterator struct {
}
func (mki *mockKeyIterator) Next() (string, error) { return "", fmt.Errorf("404") }
func (mki *mockKeyIterator) HasNext() bool { return false }
type mockBlockNode struct {
data []byte
}
// NewMockBlockNode returns a new node for a byte array
func NewMockBlockNode(data []byte) ipld.Node {
return &mockBlockNode{data}
}
func (mbn *mockBlockNode) Kind() ipld.ReprKind { return ipld.ReprKind_Bytes }
func (mbn *mockBlockNode) TraverseField(key string) (ipld.Node, error) {
return nil, fmt.Errorf("404")
}
func (mbn *mockBlockNode) TraverseIndex(idx int) (ipld.Node, error) {
return nil, fmt.Errorf("404")
}
func (mbn *mockBlockNode) Keys() ipld.KeyIterator { return &mockKeyIterator{} }
func (mbn *mockBlockNode) KeysImmediate() ([]string, error) {
return nil, fmt.Errorf("404")
}
func (mbn *mockBlockNode) Length() int { return 0 }
func (mbn *mockBlockNode) IsNull() bool { return false }
func (mbn *mockBlockNode) AsBool() (bool, error) { return false, fmt.Errorf("404") }
func (mbn *mockBlockNode) AsInt() (int, error) { return 0, fmt.Errorf("404") }
func (mbn *mockBlockNode) AsFloat() (float64, error) { return 0.0, fmt.Errorf("404") }
func (mbn *mockBlockNode) AsString() (string, error) { return "", fmt.Errorf("404") }
func (mbn *mockBlockNode) AsBytes() ([]byte, error) { return mbn.data, nil }
func (mbn *mockBlockNode) AsLink() (cid.Cid, error) { return cid.Cid{}, fmt.Errorf("404") }
package testbridge
import (
"github.com/ipfs/go-cid"
ipldbridge "github.com/ipfs/go-graphsync/ipldbridge"
ipld "github.com/ipld/go-ipld-prime"
)
type mockSelector struct {
cidsVisited []cid.Cid
}
func newMockSelector(mss *mockSelectorSpec) ipldbridge.Selector {
return &mockSelector{mss.cidsVisited}
}
func (ms *mockSelector) Explore(ipld.Node) (ipld.KeyIterator, ipldbridge.Selector) {
return nil, ms
}
func (ms *mockSelector) Decide(ipld.Node) bool { return false }
package testbridge
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
cid "github.com/ipfs/go-cid"
ipldbridge "github.com/ipfs/go-graphsync/ipldbridge"
ipld "github.com/ipld/go-ipld-prime"
multihash "github.com/multiformats/go-multihash"
)
type mockIPLDBridge struct {
}
// NewMockIPLDBridge returns an IPLD bridge that works with MockSelectors
func NewMockIPLDBridge() ipldbridge.IPLDBridge {
return &mockIPLDBridge{}
}
func (mb *mockIPLDBridge) ComposeLinkLoader(actualLoader ipldbridge.RawLoader) ipldbridge.LinkLoader {
return func(ctx context.Context, lnk cid.Cid, lnkCtx ipldbridge.LinkContext) (ipld.Node, error) {
r, err := actualLoader(ctx, lnk, lnkCtx)
if err != nil {
return nil, err
}
var buffer bytes.Buffer
io.Copy(&buffer, r)
data := buffer.Bytes()
hash, err := multihash.Sum(data, lnk.Prefix().MhType, lnk.Prefix().MhLength)
if err != nil {
return nil, err
}
if hash.B58String() != lnk.Hash().B58String() {
return nil, fmt.Errorf("hash mismatch")
}
return NewMockBlockNode(data), nil
}
}
func (mb *mockIPLDBridge) ValidateSelectorSpec(cidRootedSelector ipld.Node) []error {
_, ok := cidRootedSelector.(*mockSelectorSpec)
if !ok {
return []error{fmt.Errorf("not a selector")}
}
return nil
}
func (mb *mockIPLDBridge) EncodeNode(node ipld.Node) ([]byte, error) {
spec, ok := node.(*mockSelectorSpec)
if ok {
data, err := json.Marshal(spec.cidsVisited)
if err != nil {
return nil, err
}
return data, nil
}
return nil, fmt.Errorf("format not supported")
}
func (mb *mockIPLDBridge) DecodeNode(data []byte) (ipld.Node, error) {
var cidsVisited []cid.Cid
err := json.Unmarshal(data, &cidsVisited)
if err == nil {
return &mockSelectorSpec{cidsVisited}, nil
}
return nil, fmt.Errorf("format not supported")
}
func (mb *mockIPLDBridge) DecodeSelectorSpec(cidRootedSelector ipld.Node) (ipld.Node, ipldbridge.Selector, error) {
spec, ok := cidRootedSelector.(*mockSelectorSpec)
if !ok {
return nil, nil, fmt.Errorf("not a selector")
}
return nil, newMockSelector(spec), nil
}
func (mb *mockIPLDBridge) Traverse(ctx context.Context, loader ipldbridge.LinkLoader, root ipld.Node, s ipldbridge.Selector, fn ipldbridge.AdvVisitFn) error {
ms, ok := s.(*mockSelector)
if !ok {
return fmt.Errorf("not supported")
}
var lastErr error
for _, lnk := range ms.cidsVisited {
node, err := loader(ctx, lnk, ipldbridge.LinkContext{})
if err != nil {
lastErr = err
} else {
fn(ipldbridge.TraversalProgress{}, node, 0)
}
}
return lastErr
}
package testbridge
import (
"bytes"
"context"
"fmt"
"io"
"reflect"
"testing"
blocks "github.com/ipfs/go-block-format"
"github.com/ipld/go-ipld-prime"
"github.com/ipfs/go-cid"
"github.com/ipfs/go-graphsync/ipldbridge"
"github.com/ipfs/go-graphsync/testutil"
)
func TestSelectorTraversal(t *testing.T) {
blks := testutil.GenerateBlocksOfSize(5, 20)
cids := make([]cid.Cid, 0, 5)
for _, block := range blks {
cids = append(cids, block.Cid())
}
var uniqueBlocksVisited []blocks.Block
loader := func(ctx context.Context, lnk cid.Cid, lnkCtx ipldbridge.LinkContext) (io.Reader, error) {
for _, block := range blks {
if block.Cid() == lnk {
if testutil.ContainsBlock(uniqueBlocksVisited, block) {
return nil, fmt.Errorf("loaded block twice")
}
uniqueBlocksVisited = append(uniqueBlocksVisited, block)
return bytes.NewReader(block.RawData()), nil
}
}
return nil, fmt.Errorf("unable to load block")
}
bridge := NewMockIPLDBridge()
linkloader := bridge.ComposeLinkLoader(loader)
mockSelectorSpec := NewMockSelectorSpec(cids)
node, selector, err := bridge.DecodeSelectorSpec(mockSelectorSpec)
if err != nil {
t.Fatal("unable to decode selector")
}
var traversalFn ipldbridge.AdvVisitFn
traversalFn = func(tp ipldbridge.TraversalProgress, node ipld.Node, traversalReason ipldbridge.TraversalReason) error {
return nil
}
ctx := context.Background()
err = bridge.Traverse(ctx, linkloader, node, selector, traversalFn)
if err != nil {
t.Fatal(err.Error())
}
if len(uniqueBlocksVisited) != 5 {
t.Fatal("did not visit all blocks")
}
}
func TestEncodeDecodeSelectorSpec(t *testing.T) {
cids := testutil.GenerateCids(5)
spec := NewMockSelectorSpec(cids)
bridge := NewMockIPLDBridge()
data, err := bridge.EncodeNode(spec)
if err != nil {
t.Fatal("error encoding selector spec")
}
node, err := bridge.DecodeNode(data)
if err != nil {
t.Fatal("error decoding data")
}
returnedSpec, ok := node.(*mockSelectorSpec)
if !ok {
t.Fatal("did not decode a selector")
}
if len(returnedSpec.cidsVisited) != 5 {
t.Fatal("did not decode enough cids")
}
if !reflect.DeepEqual(cids, returnedSpec.cidsVisited) {
t.Fatal("did not decode correct cids")
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment