Skip to content

Commit a22dc82

Browse files
authored
Merge pull request #6892 from ipfs/feat/graphsync-server
feat(graphsync): mount the graphsync libp2p protocol
2 parents 682989a + 5857310 commit a22dc82

File tree

12 files changed

+592
-53
lines changed

12 files changed

+592
-53
lines changed

core/core.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/ipfs/go-ipfs-pinner"
1818

1919
bserv "github.com/ipfs/go-blockservice"
20+
"github.com/ipfs/go-graphsync"
2021
bstore "github.com/ipfs/go-ipfs-blockstore"
2122
exchange "github.com/ipfs/go-ipfs-exchange-interface"
2223
"github.com/ipfs/go-ipfs-provider"
@@ -81,13 +82,14 @@ type IpfsNode struct {
8182
RecordValidator record.Validator
8283

8384
// Online
84-
PeerHost p2phost.Host `optional:"true"` // the network host (server+client)
85-
Bootstrapper io.Closer `optional:"true"` // the periodic bootstrapper
86-
Routing routing.Routing `optional:"true"` // the routing system. recommend ipfs-dht
87-
Exchange exchange.Interface // the block exchange + strategy (bitswap)
88-
Namesys namesys.NameSystem // the name system, resolves paths to hashes
89-
Provider provider.System // the value provider system
90-
IpnsRepub *ipnsrp.Republisher `optional:"true"`
85+
PeerHost p2phost.Host `optional:"true"` // the network host (server+client)
86+
Bootstrapper io.Closer `optional:"true"` // the periodic bootstrapper
87+
Routing routing.Routing `optional:"true"` // the routing system. recommend ipfs-dht
88+
Exchange exchange.Interface // the block exchange + strategy (bitswap)
89+
Namesys namesys.NameSystem // the name system, resolves paths to hashes
90+
Provider provider.System // the value provider system
91+
IpnsRepub *ipnsrp.Republisher `optional:"true"`
92+
GraphExchange graphsync.GraphExchange `optional:"true"`
9193

9294
AutoNAT *autonat.AutoNATService `optional:"true"`
9395
PubSub *pubsub.PubSub `optional:"true"`

core/node/graphsync.go

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package node
2+
3+
import (
4+
"github.com/ipfs/go-graphsync"
5+
gsimpl "github.com/ipfs/go-graphsync/impl"
6+
"github.com/ipfs/go-graphsync/ipldbridge"
7+
"github.com/ipfs/go-graphsync/network"
8+
"github.com/ipfs/go-graphsync/storeutil"
9+
"github.com/ipfs/go-ipfs-blockstore"
10+
libp2p "github.com/libp2p/go-libp2p-core"
11+
"go.uber.org/fx"
12+
13+
"github.com/ipfs/go-ipfs/core/node/helpers"
14+
)
15+
16+
// Graphsync constructs a graphsync
17+
func Graphsync(lc fx.Lifecycle, mctx helpers.MetricsCtx, host libp2p.Host, bs blockstore.GCBlockstore) graphsync.GraphExchange {
18+
ctx := helpers.LifecycleCtx(mctx, lc)
19+
20+
network := network.NewFromLibp2pHost(host)
21+
ipldBridge := ipldbridge.NewIPLDBridge()
22+
return gsimpl.New(ctx,
23+
network, ipldBridge,
24+
storeutil.LoaderForBlockstore(bs),
25+
storeutil.StorerForBlockstore(bs),
26+
)
27+
}

core/node/groups.go

+1
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ func Online(bcfg *BuildCfg, cfg *config.Config) fx.Option {
231231

232232
return fx.Options(
233233
fx.Provide(OnlineExchange(shouldBitswapProvide)),
234+
maybeProvide(Graphsync, cfg.Experimental.GraphsyncEnabled),
234235
fx.Provide(Namesys(ipnsCacheSize)),
235236

236237
fx.Invoke(IpnsRepublisher(repubPeriod, recordLifetime)),

docs/experimental-features.md

+28
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ the above issue.
3030
- [AutoRelay](#autorelay)
3131
- [TLS 1.3 Handshake](#tls-13-as-default-handshake-protocol)
3232
- [Strategic Providing](#strategic-providing)
33+
- [Graphsync](graphsync)
3334

3435
---
3536

@@ -705,3 +706,30 @@ ipfs config --json Experimental.StrategicProviding true
705706
- [ ] provide roots
706707
- [ ] provide all
707708
- [ ] provide strategic
709+
710+
## GraphSync
711+
712+
### State
713+
714+
Experimental, disabled by default.
715+
716+
[GraphSync](https://github.com/ipfs/go-graphsync) is the next-gen graph exchange
717+
protocol for IPFS.
718+
719+
When this feature is enabled, IPFS will make files available over the graphsync
720+
protocol. However, IPFS will not currently use this protocol to _fetch_ files.
721+
722+
### How to enable
723+
724+
Modify your ipfs config:
725+
726+
```
727+
ipfs config --json Experimental.GraphsyncEnabled true
728+
```
729+
730+
### Road to being a real feature
731+
732+
- [ ] We need to confirm that it can't be used to DoS a node. The server-side
733+
logic for GraphSync is quite complex and, if we're not careful, the server
734+
might end up performing unbounded work when responding to a malicious
735+
request.

go.mod

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ require (
2727
github.com/ipfs/go-ds-measure v0.1.0
2828
github.com/ipfs/go-filestore v0.0.3
2929
github.com/ipfs/go-fs-lock v0.0.4
30+
github.com/ipfs/go-graphsync v0.0.4
3031
github.com/ipfs/go-ipfs-blockstore v0.1.4
3132
github.com/ipfs/go-ipfs-chunker v0.0.4
3233
github.com/ipfs/go-ipfs-cmds v0.1.1
33-
github.com/ipfs/go-ipfs-config v0.2.0
34+
github.com/ipfs/go-ipfs-config v0.2.1
3435
github.com/ipfs/go-ipfs-ds-help v0.1.1
3536
github.com/ipfs/go-ipfs-exchange-interface v0.0.1
3637
github.com/ipfs/go-ipfs-exchange-offline v0.0.1

go.sum

+29-4
Large diffs are not rendered by default.

test/bin/Rules.mk

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ $(d)/go-sleep: github.com/ipfs/go-ipfs/test/dependencies/go-sleep
1818
$(go-build-testdep)
1919
TGTS_$(d) += $(d)/go-sleep
2020

21+
.PHONY: github.com/ipfs/go-ipfs/test/dependencies/graphsync-get
22+
$(d)/graphsync-get: github.com/ipfs/go-ipfs/test/dependencies/graphsync-get
23+
$(go-build-testdep)
24+
TGTS_$(d) += $(d)/graphsync-get
25+
2126
.PHONY: github.com/ipfs/go-ipfs/test/dependencies/go-timeout
2227
$(d)/go-timeout: github.com/ipfs/go-ipfs/test/dependencies/go-timeout
2328
$(go-build-testdep)

test/dependencies/go.mod

+16-7
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,26 @@ go 1.13
55
require (
66
github.com/Kubuxu/gocovmerge v0.0.0-20161216165753-7ecaa51963cd
77
github.com/golangci/golangci-lint v1.18.0
8+
github.com/ipfs/go-blockservice v0.1.2
9+
github.com/ipfs/go-cid v0.0.5
810
github.com/ipfs/go-cidutil v0.0.2
9-
github.com/ipfs/go-log v0.0.1
11+
github.com/ipfs/go-datastore v0.4.4
12+
github.com/ipfs/go-graphsync v0.0.4
13+
github.com/ipfs/go-ipfs-blockstore v1.0.0
14+
github.com/ipfs/go-ipfs-exchange-offline v0.0.1
15+
github.com/ipfs/go-log v1.0.2
16+
github.com/ipfs/go-merkledag v0.3.1
17+
github.com/ipfs/go-unixfs v0.2.4
1018
github.com/ipfs/hang-fds v0.0.1
1119
github.com/ipfs/iptb v1.4.0
12-
github.com/ipfs/iptb-plugins v0.2.0
20+
github.com/ipfs/iptb-plugins v0.2.1
21+
github.com/ipld/go-ipld-prime v0.0.2-0.20191108012745-28a82f04c785
1322
github.com/jbenet/go-random v0.0.0-20190219211222-123a90aedc0c
1423
github.com/jbenet/go-random-files v0.0.0-20190219210431-31b3f20ebded
15-
github.com/multiformats/go-multiaddr v0.0.4
16-
github.com/multiformats/go-multiaddr-net v0.0.1
17-
github.com/multiformats/go-multihash v0.0.7
18-
github.com/ultraware/funlen v0.0.2 // indirect
19-
golang.org/x/tools v0.0.0-20190912185636-87d9f09c5d89 // indirect
24+
github.com/libp2p/go-libp2p v0.5.2
25+
github.com/libp2p/go-libp2p-core v0.3.1
26+
github.com/multiformats/go-multiaddr v0.2.0
27+
github.com/multiformats/go-multiaddr-net v0.1.2
28+
github.com/multiformats/go-multihash v0.0.13
2029
gotest.tools/gotestsum v0.3.5
2130
)

0 commit comments

Comments
 (0)