diff --git a/core/coreapi/coreapi.go b/core/coreapi/coreapi.go index 5b638826b..8bad01c27 100644 --- a/core/coreapi/coreapi.go +++ b/core/coreapi/coreapi.go @@ -19,11 +19,11 @@ import ( "fmt" bserv "github.com/ipfs/go-blockservice" - "github.com/ipfs/go-ipfs-blockstore" - "github.com/ipfs/go-ipfs-exchange-interface" + blockstore "github.com/ipfs/go-ipfs-blockstore" + exchange "github.com/ipfs/go-ipfs-exchange-interface" offlinexch "github.com/ipfs/go-ipfs-exchange-offline" - "github.com/ipfs/go-ipfs-pinner" - "github.com/ipfs/go-ipfs-provider" + pin "github.com/ipfs/go-ipfs-pinner" + provider "github.com/ipfs/go-ipfs-provider" offlineroute "github.com/ipfs/go-ipfs-routing/offline" ipld "github.com/ipfs/go-ipld-format" dag "github.com/ipfs/go-merkledag" @@ -38,6 +38,7 @@ import ( record "github.com/libp2p/go-libp2p-record" "github.com/ipfs/go-ipfs/core" + "github.com/ipfs/go-ipfs/core/coreunix" "github.com/ipfs/go-ipfs/core/node" "github.com/ipfs/go-ipfs/namesys" "github.com/ipfs/go-ipfs/repo" @@ -56,6 +57,7 @@ type CoreAPI struct { blocks bserv.BlockService dag ipld.DAGService + bfs *coreunix.BigFileStore //XXX peerstore pstore.Peerstore peerHost p2phost.Host @@ -167,6 +169,7 @@ func (api *CoreAPI) WithOptions(opts ...options.ApiOption) (coreiface.CoreAPI, e blocks: n.Blocks, dag: n.DAG, + bfs: nil, // XXX: initialize big file store, e.g. coreunix.NewBigFileStore(???), peerstore: n.Peerstore, peerHost: n.PeerHost, diff --git a/core/coreapi/unixfs.go b/core/coreapi/unixfs.go index 631fec37f..8579344fb 100644 --- a/core/coreapi/unixfs.go +++ b/core/coreapi/unixfs.go @@ -119,7 +119,7 @@ func (api *UnixfsAPI) Add(ctx context.Context, files files.Node, opts ...options } } - fileAdder, err := coreunix.NewAdder(ctx, pinning, addblockstore, syncDserv) + fileAdder, err := coreunix.NewAdder(ctx, pinning, addblockstore, syncDserv, api.bfs) if err != nil { return nil, err } diff --git a/core/coreunix/add.go b/core/coreunix/add.go index 0e5727a9a..64560f8b1 100644 --- a/core/coreunix/add.go +++ b/core/coreunix/add.go @@ -46,7 +46,7 @@ type syncer interface { } // NewAdder Returns a new Adder used for a file add operation. -func NewAdder(ctx context.Context, p pin.Pinner, bs bstore.GCLocker, ds ipld.DAGService) (*Adder, error) { +func NewAdder(ctx context.Context, p pin.Pinner, bs bstore.GCLocker, ds ipld.DAGService, bfs *BigFileStore) (*Adder, error) { bufferedDS := ipld.NewBufferedDAG(ctx, ds) return &Adder{ @@ -55,6 +55,7 @@ func NewAdder(ctx context.Context, p pin.Pinner, bs bstore.GCLocker, ds ipld.DAG gcLocker: bs, dagService: ds, bufferedDS: bufferedDS, + bfs: bfs, Progress: false, Pin: true, Trickle: false, @@ -69,6 +70,7 @@ type Adder struct { gcLocker bstore.GCLocker dagService ipld.DAGService bufferedDS *ipld.BufferedDAG + bfs *BigFileStore Out chan<- interface{} Progress bool Pin bool diff --git a/core/coreunix/bigfilestore.go b/core/coreunix/bigfilestore.go index 3f24c4757..7cee4ec9c 100644 --- a/core/coreunix/bigfilestore.go +++ b/core/coreunix/bigfilestore.go @@ -7,7 +7,7 @@ import ( dshelp "github.com/ipfs/go-ipfs-ds-help" ) -type bigFileStore struct { +type BigFileStore struct { dstore ds.Datastore } @@ -15,13 +15,13 @@ type bigFileStore struct { var bigFilePrefix = ds.NewKey("bigfiles") // NewBigFileStore creates a new bifFileStore -func NewBigFileStore(dstore ds.Datastore) *bigFileStore { - return &bigFileStore{ +func NewBigFileStore(dstore ds.Datastore) *BigFileStore { + return &BigFileStore{ dstore: dsns.Wrap(dstore, bigFilePrefix), } } -func (b *bigFileStore) Put(streamCid cid.Cid, chunks []*ChunkingManifestChunk) error { +func (b *BigFileStore) Put(streamCid cid.Cid, chunks []*ChunkingManifestChunk) error { chunkData, err := serializeChunks(chunks) if err != nil { return err @@ -31,7 +31,7 @@ func (b *bigFileStore) Put(streamCid cid.Cid, chunks []*ChunkingManifestChunk) e return b.dstore.Put(dsk, chunkData) } -func (b *bigFileStore) Get(streamCid cid.Cid) ([]*ChunkingManifestChunk, error) { +func (b *BigFileStore) Get(streamCid cid.Cid) ([]*ChunkingManifestChunk, error) { data, err := b.dstore.Get(dshelp.CidToDsKey(streamCid)) if err != nil { return nil, err