{"id":14956081,"url":"https://github.com/ipfs/go-graphsync","last_synced_at":"2025-04-14T01:08:47.967Z","repository":{"id":38996738,"uuid":"168623476","full_name":"ipfs/go-graphsync","owner":"ipfs","description":"Initial Implementation Of GraphSync Wire Protocol","archived":false,"fork":false,"pushed_at":"2025-03-28T18:15:17.000Z","size":33446,"stargazers_count":101,"open_issues_count":46,"forks_count":38,"subscribers_count":21,"default_branch":"main","last_synced_at":"2025-04-14T01:08:36.111Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ipfs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-01T01:27:06.000Z","updated_at":"2025-04-04T02:15:58.000Z","dependencies_parsed_at":"2023-02-09T15:16:23.457Z","dependency_job_id":"aebba3ee-0034-429b-91d9-b89a577b1081","html_url":"https://github.com/ipfs/go-graphsync","commit_stats":{"total_commits":406,"total_committers":29,"mean_commits":14.0,"dds":0.3448275862068966,"last_synced_commit":"ac31f44988178d20f89473701e3f43acc722ee6b"},"previous_names":[],"tags_count":76,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipfs%2Fgo-graphsync","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipfs%2Fgo-graphsync/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipfs%2Fgo-graphsync/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipfs%2Fgo-graphsync/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ipfs","download_url":"https://codeload.github.com/ipfs/go-graphsync/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248804803,"owners_count":21164134,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-24T13:12:17.066Z","updated_at":"2025-04-14T01:08:47.940Z","avatar_url":"https://github.com/ipfs.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-graphsync\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![Coverage Status](https://codecov.io/gh/ipfs/go-graphsync/branch/master/graph/badge.svg)](https://codecov.io/gh/ipfs/go-graphsync/branch/master)\n[![Build Status](https://circleci.com/gh/ipfs/go-bitswap.svg?style=svg)](https://circleci.com/gh/ipfs/go-graphsync)\n\n\u003e An implementation of the [graphsync protocol](https://github.com/ipld/specs/blob/master/block-layer/graphsync/graphsync.md) in go!\n\n## Table of Contents\n\n- [Background](#background)\n- [Install](#install)\n- [Usage](#usage)\n- [Architecture](#architecture)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Background\n\n[GraphSync](https://github.com/ipld/specs/blob/master/block-layer/graphsync/graphsync.md) is a protocol for synchronizing IPLD graphs among peers. It allows a host to make a single request to a remote peer for all of the results of traversing an [IPLD selector](https://ipld.io/specs/selectors/) on the remote peer's local IPLD graph. \n\n`go-graphsync` provides an implementation of the Graphsync protocol in go.\n\n### Go-IPLD-Prime\n\n`go-graphsync` relies on `go-ipld-prime` to traverse IPLD Selectors in an IPLD graph. `go-ipld-prime` implements the [IPLD specification](https://github.com/ipld/specs) in go and is an alternative to older implementations such as `go-ipld-format` and `go-ipld-cbor`. In order to use `go-graphsync`, some understanding and use of `go-ipld-prime` concepts is necessary. \n\nIf your existing library (i.e. `go-ipfs` or `go-filecoin`) uses these other older libraries, you can largely use go-graphsync without switching to `go-ipld-prime` across your codebase, but it will require some translations\n\n## Install\n\n`go-graphsync` requires Go \u003e= 1.13 and can be installed using Go modules\n\n## Usage\n\n### Initializing a GraphSync Exchange\n\n```golang\nimport (\n  graphsync \"github.com/ipfs/go-graphsync/impl\"\n  gsnet \"github.com/ipfs/go-graphsync/network\"\n  ipld \"github.com/ipld/go-ipld-prime\"\n)\n\nvar ctx context.Context\nvar host libp2p.Host\nvar lsys ipld.LinkSystem\n\nnetwork := gsnet.NewFromLibp2pHost(host)\nexchange := graphsync.New(ctx, network, lsys)\n```\n\nParameter Notes:\n\n1. `context` is just the parent context for all of GraphSync\n2. `network` is a network abstraction provided to Graphsync on top\nof libp2p. This allows graphsync to be tested without the actual network\n3. `lsys` is an go-ipld-prime LinkSystem, which provides mechanisms loading and constructing go-ipld-prime nodes from a link, and saving ipld prime nodes to serialized data\n\n### Using GraphSync With An IPFS BlockStore\n\nGraphSync provides a convenience function in the `storeutil` package for\nintegrating with BlockStore's from IPFS.\n\n```golang\nimport (\n  graphsync \"github.com/ipfs/go-graphsync/impl\"\n  gsnet \"github.com/ipfs/go-graphsync/network\"\n  storeutil \"github.com/ipfs/go-graphsync/storeutil\"\n  ipld \"github.com/ipld/go-ipld-prime\"\n  blockstore \"github.com/ipfs/go-ipfs-blockstore\"\n)\n\nvar ctx context.Context\nvar host libp2p.Host\nvar bs blockstore.Blockstore\n\nnetwork := gsnet.NewFromLibp2pHost(host)\nlsys := storeutil.LinkSystemForBlockstore(bs)\n\nexchange := graphsync.New(ctx, network, lsys)\n```\n\n### Calling Graphsync\n\n```golang\nvar exchange graphsync.GraphSync\nvar ctx context.Context\nvar p peer.ID\nvar selector ipld.Node\nvar rootLink ipld.Link\n\nvar responseProgress \u003c-chan graphsync.ResponseProgress\nvar errors \u003c-chan error\n\nresponseProgress, errors = exchange.Request(ctx context.Context, p peer.ID, root ipld.Link, selector ipld.Node)\n```\n\nParamater Notes:\n1. `ctx` is the context for this request. To cancel an in progress request, cancel the context.\n2. `p` is the peer you will send this request to\n3. `link` is an IPLD Link, i.e. a CID (cidLink.Link{Cid})\n4. `selector` is an IPLD selector node. Recommend using selector builders from go-ipld-prime to construct these\n\n### Response Type\n\n```golang\n\ntype ResponseProgress struct {\n  Node      ipld.Node // a node which matched the graphsync query\n  Path      ipld.Path // the path of that node relative to the traversal start\n\tLastBlock struct {  // LastBlock stores the Path and Link of the last block edge we had to load. \n\t\tipld.Path\n\t\tipld.Link\n\t}\n}\n\n```\n\nThe above provides both immediate and relevant metadata for matching nodes in a traversal, and is very similar to the information provided by a local IPLD selector traversal in `go-ipld-prime`\n\n## Contribute\n\nPRs are welcome!\n\nBefore doing anything heavy, checkout the [Graphsync Architecture](docs/architecture.md)\n\nSee our [Contributing Guidelines](https://github.com/ipfs/go-graphsync/blob/master/CONTRIBUTING.md) for more info.\n\n## License\n\nThis library is dual-licensed under Apache 2.0 and MIT terms.\n\nCopyright 2019. Protocol Labs, Inc.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fipfs%2Fgo-graphsync","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fipfs%2Fgo-graphsync","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fipfs%2Fgo-graphsync/lists"}