Skip to content

Commit

Permalink
Merge pull request #8046 from ipfs/feat/node-api
Browse files Browse the repository at this point in the history
Node API
  • Loading branch information
hannahhoward authored Apr 24, 2021
2 parents 8d0ee3b + 7f716a1 commit 98b792a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
2 changes: 2 additions & 0 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/ipfs/go-ipfs-pinner"

bserv "github.com/ipfs/go-blockservice"
"github.com/ipfs/go-fetcher"
"github.com/ipfs/go-graphsync"
bstore "github.com/ipfs/go-ipfs-blockstore"
exchange "github.com/ipfs/go-ipfs-exchange-interface"
Expand Down Expand Up @@ -77,6 +78,7 @@ type IpfsNode struct {
Blocks bserv.BlockService // the block service, get/add blocks.
DAG ipld.DAGService // the merkle dag service, get/add objects.
Resolver *resolver.Resolver // the path resolution system
FetcherFactory fetcher.Factory // an implementation of the fetcher
Reporter *metrics.BandwidthCounter `optional:"true"`
Discovery discovery.Service `optional:"true"`
FilesRoot *mfs.Root
Expand Down
27 changes: 24 additions & 3 deletions core/coreapi/coreapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import (
"fmt"

bserv "github.com/ipfs/go-blockservice"
"github.com/ipfs/go-dagwriter"
bsdagwriter "github.com/ipfs/go-dagwriter/impl/blockservice"
"github.com/ipfs/go-fetcher"
blockstore "github.com/ipfs/go-ipfs-blockstore"
exchange "github.com/ipfs/go-ipfs-exchange-interface"
offlinexch "github.com/ipfs/go-ipfs-exchange-offline"
Expand Down Expand Up @@ -57,6 +60,8 @@ type CoreAPI struct {

blocks bserv.BlockService
dag ipld.DAGService
fetcherFactory fetcher.Factory
dagWriter dagwriter.DagWritingService
resolver *resolver.Resolver
peerstore pstore.Peerstore
peerHost p2phost.Host
Expand Down Expand Up @@ -106,6 +111,19 @@ func (api *CoreAPI) Dag() coreiface.APIDagService {
}
}

type nodeAPI struct {
fetcher.Factory
dagwriter.DagWritingService
}

// Node returns the Node interface implementation backed by the go-ipfs node
func (api *CoreAPI) Node() coreiface.NodeAPI {
return &nodeAPI{
api.fetcherFactory,
api.dagWriter,
}
}

// Name returns the NameAPI interface implementation backed by the go-ipfs node
func (api *CoreAPI) Name() coreiface.NameAPI {
return (*NameAPI)(api)
Expand Down Expand Up @@ -166,9 +184,10 @@ func (api *CoreAPI) WithOptions(opts ...options.ApiOption) (coreiface.CoreAPI, e
baseBlocks: n.BaseBlocks,
pinning: n.Pinning,

blocks: n.Blocks,
dag: n.DAG,
resolver: n.Resolver,
blocks: n.Blocks,
dag: n.DAG,
resolver: n.Resolver,
fetcherFactory: n.FetcherFactory,

peerstore: n.Peerstore,
peerHost: n.PeerHost,
Expand All @@ -185,6 +204,8 @@ func (api *CoreAPI) WithOptions(opts ...options.ApiOption) (coreiface.CoreAPI, e
parentOpts: settings,
}

subApi.dagWriter = bsdagwriter.NewDagWriter(subApi.blocks)

subApi.checkOnline = func(allowOffline bool) error {
if !n.IsOnline && !allowOffline {
return coreiface.ErrOffline
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
github.com/ipfs/go-blockservice v0.1.4
github.com/ipfs/go-cid v0.0.7
github.com/ipfs/go-cidutil v0.0.2
github.com/ipfs/go-dagwriter v0.0.0-20210410024744-41183870fd1b
github.com/ipfs/go-datastore v0.4.5
github.com/ipfs/go-detect-race v0.0.1
github.com/ipfs/go-ds-badger v0.2.6
Expand Down Expand Up @@ -57,7 +58,7 @@ require (
github.com/ipfs/go-unixfs v0.2.4
github.com/ipfs/go-unixfsnode v1.1.1
github.com/ipfs/go-verifcid v0.0.1
github.com/ipfs/interface-go-ipfs-core v0.4.1-0.20210326022702-98763dda3e52
github.com/ipfs/interface-go-ipfs-core v0.4.1-0.20210410030100-56c2e678cb62
github.com/ipld/go-car v0.2.1-0.20210312021557-7afab98d034f
github.com/ipld/go-codec-dagpb v1.2.1-0.20210405170603-d0b86f7623c2
github.com/ipld/go-ipld-prime v0.9.1-0.20210402181957-7406578571d1
Expand Down
14 changes: 8 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ github.com/ipfs/go-cid v0.0.7 h1:ysQJVJA3fNDF1qigJbsSQOdjhVLsOEoPdh0+R97k3jY=
github.com/ipfs/go-cid v0.0.7/go.mod h1:6Ux9z5e+HpkQdckYoX1PG/6xqKspzlEIR5SDmgqgC/I=
github.com/ipfs/go-cidutil v0.0.2 h1:CNOboQf1t7Qp0nuNh8QMmhJs0+Q//bRL1axtCnIB1Yo=
github.com/ipfs/go-cidutil v0.0.2/go.mod h1:ewllrvrxG6AMYStla3GD7Cqn+XYSLqjK0vc+086tB6s=
github.com/ipfs/go-dagwriter v0.0.0-20210410024744-41183870fd1b h1:iGEokY1rwqatEY6XxWQ/4fzGrdmOpvSM9YrudFMg8ww=
github.com/ipfs/go-dagwriter v0.0.0-20210410024744-41183870fd1b/go.mod h1:rytn1TKuQ3zg9oMJxoVsSUt7BXonIRWxChvDR6LkG98=
github.com/ipfs/go-datastore v0.0.1/go.mod h1:d4KVXhMt913cLBEI/PXAy6ko+W7e9AhyAKBGh803qeE=
github.com/ipfs/go-datastore v0.0.5/go.mod h1:d4KVXhMt913cLBEI/PXAy6ko+W7e9AhyAKBGh803qeE=
github.com/ipfs/go-datastore v0.1.0/go.mod h1:d4KVXhMt913cLBEI/PXAy6ko+W7e9AhyAKBGh803qeE=
Expand Down Expand Up @@ -387,7 +389,8 @@ github.com/ipfs/go-ds-leveldb v0.4.2 h1:QmQoAJ9WkPMUfBLnu1sBVy0xWWlJPg0m4kRAiJL9
github.com/ipfs/go-ds-leveldb v0.4.2/go.mod h1:jpbku/YqBSsBc1qgME8BkWS4AxzF2cEu1Ii2r79Hh9s=
github.com/ipfs/go-ds-measure v0.1.0 h1:vE4TyY4aeLeVgnnPBC5QzKIjKrqzha0NCujTfgvVbVQ=
github.com/ipfs/go-ds-measure v0.1.0/go.mod h1:1nDiFrhLlwArTME1Ees2XaBOl49OoCgd2A3f8EchMSY=
github.com/ipfs/go-fetcher v1.1.0/go.mod h1:RHp10iwAdiJCsxqNvz6JMv1S7tajHSpC36oR6mJuF5M=
github.com/ipfs/go-fetcher v1.2.0/go.mod h1:RFvn2LiuWIfyXt3ChONqIvQfsbEhBYWhwUeatYjFPIA=
github.com/ipfs/go-fetcher v1.2.1-0.20210410025415-5325cff258c0/go.mod h1:mlpkadjgVO4a/SW822rtK2b7vIAjtvtw/f6ensvCImI=
github.com/ipfs/go-fetcher v1.3.0 h1:XlF4GCg9LkdAfQk3Kdd3JD0dZ5TgqfydJ7+gog/Eotc=
github.com/ipfs/go-fetcher v1.3.0/go.mod h1:lld7kBIARmpCvhQ/Rob5oOGEKfVjil8L8y4j9jtLdqo=
github.com/ipfs/go-filestore v0.0.3 h1:MhZ1jT5K3NewZwim6rS/akcJLm1xM+r6nz6foeB9EwE=
Expand Down Expand Up @@ -481,7 +484,7 @@ github.com/ipfs/go-metrics-prometheus v0.0.2/go.mod h1:ELLU99AQQNi+zX6GCGm2lAgnz
github.com/ipfs/go-mfs v0.1.2 h1:DlelNSmH+yz/Riy0RjPKlooPg0KML4lXGdLw7uZkfAg=
github.com/ipfs/go-mfs v0.1.2/go.mod h1:T1QBiZPEpkPLzDqEJLNnbK55BVKVlNi2a+gVm4diFo0=
github.com/ipfs/go-path v0.0.7/go.mod h1:6KTKmeRnBXgqrTvzFrPV3CamxcgvXX/4z79tfAd2Sno=
github.com/ipfs/go-path v0.0.10-0.20210324191207-6a600cd3f256/go.mod h1:QHYtDmpHe3xD5RQSkoco+BM7Vv0sg/tLHWv000t60sw=
github.com/ipfs/go-path v0.0.10-0.20210405201800-40f1060226f7/go.mod h1:g8egwymo/MjfPUu/ojghk4YQKwjn6MGO+UUv4eUw08M=
github.com/ipfs/go-path v0.0.10-0.20210421213242-802a897dfcd8 h1:YT89FH52ynHRCZJIM95z+/4fz0rQ7nFPFLRufOzm9AE=
github.com/ipfs/go-path v0.0.10-0.20210421213242-802a897dfcd8/go.mod h1:YMCaFyukoM1bSaPm1eL9Q6IPr0z4WytNeVKlBSm8a0c=
github.com/ipfs/go-peertaskqueue v0.0.4/go.mod h1:03H8fhyeMfKNFWqzYEVyMbcPUeYrqP1MX6Kd+aN+rMQ=
Expand All @@ -494,18 +497,17 @@ github.com/ipfs/go-pinning-service-http-client v0.1.0/go.mod h1:tcCKmlkWWH9JUUkK
github.com/ipfs/go-unixfs v0.1.0/go.mod h1:lysk5ELhOso8+Fed9U1QTGey2ocsfaZ18h0NCO2Fj9s=
github.com/ipfs/go-unixfs v0.2.4 h1:6NwppOXefWIyysZ4LR/qUBPvXd5//8J3jiMdvpbw6Lo=
github.com/ipfs/go-unixfs v0.2.4/go.mod h1:SUdisfUjNoSDzzhGVxvCL9QO/nKdwXdr+gbMUdqcbYw=
github.com/ipfs/go-unixfsnode v1.0.0/go.mod h1:xmhbd5wPvHYzJAGVJFJ4Oi+U5NGEiax0TatZLOq2imk=
github.com/ipfs/go-unixfsnode v1.0.1-0.20210402214142-de45652f269f/go.mod h1:Xk4qvd3Nb8H31OJapZrLDAE4aBNmKUCvAzypIUZ3ACQ=
github.com/ipfs/go-unixfsnode v1.1.1 h1:YjYe5nQgkloOVlyRUumVGke7ngRFRZmtbI866YkTUgM=
github.com/ipfs/go-unixfsnode v1.1.1/go.mod h1:Xk4qvd3Nb8H31OJapZrLDAE4aBNmKUCvAzypIUZ3ACQ=
github.com/ipfs/go-verifcid v0.0.1 h1:m2HI7zIuR5TFyQ1b79Da5N9dnnCP1vcu2QqawmWlK2E=
github.com/ipfs/go-verifcid v0.0.1/go.mod h1:5Hrva5KBeIog4A+UpqlaIU+DEstipcJYQQZc0g37pY0=
github.com/ipfs/interface-go-ipfs-core v0.4.0/go.mod h1:UJBcU6iNennuI05amq3FQ7g0JHUkibHFAfhfUIy927o=
github.com/ipfs/interface-go-ipfs-core v0.4.1-0.20210326022702-98763dda3e52 h1:NKvFg6nPuEhMMyoOUswEReIr3PWBNSgwNT6mDPLAcTo=
github.com/ipfs/interface-go-ipfs-core v0.4.1-0.20210326022702-98763dda3e52/go.mod h1:kSN12HNPXg8TrQfdyQOPbPIQVk5j8PcHTn2AAKCaZ6Q=
github.com/ipfs/interface-go-ipfs-core v0.4.1-0.20210410030100-56c2e678cb62 h1:PJ5gH7jjJtQ8OT+iACcolpMnvhCpfRtpegWfMF785uk=
github.com/ipfs/interface-go-ipfs-core v0.4.1-0.20210410030100-56c2e678cb62/go.mod h1:leFsW1rX9F7+0N9Tss2kR82w9oafDmczBdE8z4VWGRo=
github.com/ipld/go-car v0.2.1-0.20210312021557-7afab98d034f h1:417+6v+keLsNoVi2vPJamDsW/ewuAs2uE3hlFt5muGs=
github.com/ipld/go-car v0.2.1-0.20210312021557-7afab98d034f/go.mod h1:kHunAcD305JwLqwI9MfKvuQu4ljwWRZQWfDWPrkkhcg=
github.com/ipld/go-codec-dagpb v1.0.2-0.20210308154810-d05d02fa186e/go.mod h1:oYexiw3WkBIVD5UTNkVuOd0iyEcLxqytAQa90F3nH9M=
github.com/ipld/go-codec-dagpb v1.1.0/go.mod h1:6nBN7X7h8EOsEejZGqC7tej5drsdBAXbMHyBT+Fne5s=
github.com/ipld/go-codec-dagpb v1.2.0/go.mod h1:6nBN7X7h8EOsEejZGqC7tej5drsdBAXbMHyBT+Fne5s=
github.com/ipld/go-codec-dagpb v1.2.1-0.20210330082435-8ec6b0fbad18/go.mod h1:GMLfso6KSkYJlIbd2cGKdGMe/hM5/IukeXRQ+u6zTrQ=
github.com/ipld/go-codec-dagpb v1.2.1-0.20210405170603-d0b86f7623c2 h1:m/ZZEoOdswHrrcikTC+fX4x6tnevJs0hoyNzijlT41A=
Expand Down

0 comments on commit 98b792a

Please sign in to comment.