Skip to content

Commit 7a906b1

Browse files
committed
feat(graphsync): mount the graphsync libp2p protocol
This won't fetch files from graphsync but will serve them. fixes #6830
1 parent aae957a commit 7a906b1

File tree

6 files changed

+96
-10
lines changed

6 files changed

+96
-10
lines changed

core/core.go

Lines changed: 9 additions & 7 deletions
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

Lines changed: 27 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 28 additions & 0 deletions
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

Lines changed: 2 additions & 1 deletion
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.1
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-0.20200212031627-f3919d2906ce
3435
github.com/ipfs/go-ipfs-ds-help v0.0.1
3536
github.com/ipfs/go-ipfs-exchange-interface v0.0.1
3637
github.com/ipfs/go-ipfs-exchange-offline v0.0.1

0 commit comments

Comments
 (0)