-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add free check (#1315) * chore: bump version to 1.6.1 (#1317) * fix legacy deal verified status (#1324) * fix: update go-unixfsnode enough to make sure unixfs-preload is available (#1323) * release v1.6.2-rc1 (#1328) * use full path (#1330) * fix bug (#1332) * use forks of graphsync, go-data-transfer and go-fil-markets (#1333) * refactor: use forks of graphsync, go-data-transfer and go-fil-markets * refactor: convert from data transfer v1 to v2 voucher type * fix: index provider validation voucher type * fix: pass index provider engine link system through to graphsync's transport configurer * feat: use tagged version of boost-gfm * fix: retrieval client imports * feat: tagged version of lotus * feat: require go 1.19 * lint: fix lint errors * fix: itests * fix: cbor-gen, docsgen * fix: update CI lint version * fix: lint * fix: docgen * fix: go mod tidy * fix: protocol proxy TestOutboundForwarding * fix: docsgen * fix: update filecoin-ffi submodule * fix: prometheus duplicate register panic * fix: cleanup imports * fix: legs voucher processing * chore: release v1.6.2-rc2 (#1340) * release v1.6.2-rc2 * fix test * fix: flaky TestLibp2pCarServerNewTransferCancelsPreviousTransfer (#1350) * fix: flaky TestDealCompletionOnProcessResumption (#1351) * fix: occasional panic on shutdown (#1353) * feat: query UI (#1352) * log insert * fix display error * refactor code * shorten status strings * remove comment * apply suggestion * feat: add download block link to inspect page (#1312) * fix(devnet): update golang and lotus default versions (#1354) * fix(devnet): bump golang to 1.19 * chore(devnet): bump lotus default version * chore(devnet): remove unused stable env * booster-http: implement IPFS HTTP gateway (#1225) * feat: implement http api gateway * feat: use go-libipfs lib (instead of copying to extern) * feat: bump booster-bitswap info minor version * feat: http gateway metrics * fix: TestHttpInfo * feat: by default only serve blocks and CARs, with option to serve original files (jpg, mov etc) * fix: correct link for download root block (#1355) * feat: option to cleanup data for offline deals after add piece (#1341) * chore: add support for multiple node.js versions in makefile (#1356) * chore: release v.1.7.0-rc1 (#1357) * release v.1.7.0-rc1 * fix version * fix: dagstore initialize-all parameter (#1363) * fix: show verifying commp state for offline deals (#1364) * fix: boost run missing staging-area dir (#1368) * merge(wip): main to lid TODO: remoteblockstore needs to handle nil metrics * fix: flaky TestNewHttpServer (#1372) * feat: group agent version by binary name (#1369) * fix: wrap stats in nil checks for now we should probably revisit how stats are handled now that we have all 3 transports being tracked * test(fix): incorrect test urls --------- Co-authored-by: LexLuthr <88259624+LexLuthr@users.noreply.github.com> Co-authored-by: Rod Vagg <rod@vagg.org> Co-authored-by: dirkmc <dirkmdev@gmail.com>
- Loading branch information
1 parent
d97805a
commit 1a87990
Showing
30 changed files
with
1,134 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,237 @@ | ||
package main | ||
|
||
// Copied from | ||
// https://github.com/ipfs/go-libipfs/blob/c76138366f1a7c416c481a89b3e71ed29e81a641/examples/gateway/common/blocks.go | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
gopath "path" | ||
|
||
"github.com/ipfs/go-blockservice" | ||
"github.com/ipfs/go-cid" | ||
bsfetcher "github.com/ipfs/go-fetcher/impl/blockservice" | ||
blockstore "github.com/ipfs/go-ipfs-blockstore" | ||
format "github.com/ipfs/go-ipld-format" | ||
"github.com/ipfs/go-libipfs/blocks" | ||
"github.com/ipfs/go-libipfs/files" | ||
"github.com/ipfs/go-merkledag" | ||
"github.com/ipfs/go-namesys" | ||
"github.com/ipfs/go-namesys/resolve" | ||
ipfspath "github.com/ipfs/go-path" | ||
"github.com/ipfs/go-path/resolver" | ||
"github.com/ipfs/go-unixfs" | ||
ufile "github.com/ipfs/go-unixfs/file" | ||
uio "github.com/ipfs/go-unixfs/io" | ||
"github.com/ipfs/go-unixfsnode" | ||
iface "github.com/ipfs/interface-go-ipfs-core" | ||
nsopts "github.com/ipfs/interface-go-ipfs-core/options/namesys" | ||
ifacepath "github.com/ipfs/interface-go-ipfs-core/path" | ||
dagpb "github.com/ipld/go-codec-dagpb" | ||
"github.com/ipld/go-ipld-prime" | ||
"github.com/ipld/go-ipld-prime/node/basicnode" | ||
"github.com/ipld/go-ipld-prime/schema" | ||
"github.com/libp2p/go-libp2p/core/peer" | ||
"github.com/libp2p/go-libp2p/core/routing" | ||
mc "github.com/multiformats/go-multicodec" | ||
) | ||
|
||
type BlocksGateway struct { | ||
blockStore blockstore.Blockstore | ||
blockService blockservice.BlockService | ||
dagService format.DAGService | ||
resolver resolver.Resolver | ||
|
||
// Optional routing system to handle /ipns addresses. | ||
namesys namesys.NameSystem | ||
routing routing.ValueStore | ||
} | ||
|
||
func NewBlocksGateway(blockService blockservice.BlockService, routing routing.ValueStore) (*BlocksGateway, error) { | ||
// Setup the DAG services, which use the CAR block store. | ||
dagService := merkledag.NewDAGService(blockService) | ||
|
||
// Setup the UnixFS resolver. | ||
fetcherConfig := bsfetcher.NewFetcherConfig(blockService) | ||
fetcherConfig.PrototypeChooser = dagpb.AddSupportToChooser(func(lnk ipld.Link, lnkCtx ipld.LinkContext) (ipld.NodePrototype, error) { | ||
if tlnkNd, ok := lnkCtx.LinkNode.(schema.TypedLinkNode); ok { | ||
return tlnkNd.LinkTargetNodePrototype(), nil | ||
} | ||
return basicnode.Prototype.Any, nil | ||
}) | ||
fetcher := fetcherConfig.WithReifier(unixfsnode.Reify) | ||
resolver := resolver.NewBasicResolver(fetcher) | ||
|
||
// Setup a name system so that we are able to resolve /ipns links. | ||
var ( | ||
ns namesys.NameSystem | ||
err error | ||
) | ||
if routing != nil { | ||
ns, err = namesys.NewNameSystem(routing) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
return &BlocksGateway{ | ||
blockStore: blockService.Blockstore(), | ||
blockService: blockService, | ||
dagService: dagService, | ||
resolver: resolver, | ||
routing: routing, | ||
namesys: ns, | ||
}, nil | ||
} | ||
|
||
func (api *BlocksGateway) GetUnixFsNode(ctx context.Context, p ifacepath.Resolved) (files.Node, error) { | ||
nd, err := api.resolveNode(ctx, p) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return ufile.NewUnixfsFile(ctx, api.dagService, nd) | ||
} | ||
|
||
func (api *BlocksGateway) LsUnixFsDir(ctx context.Context, p ifacepath.Resolved) (<-chan iface.DirEntry, error) { | ||
node, err := api.resolveNode(ctx, p) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
dir, err := uio.NewDirectoryFromNode(api.dagService, node) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
out := make(chan iface.DirEntry, uio.DefaultShardWidth) | ||
|
||
go func() { | ||
defer close(out) | ||
for l := range dir.EnumLinksAsync(ctx) { | ||
select { | ||
case out <- api.processLink(ctx, l): | ||
case <-ctx.Done(): | ||
return | ||
} | ||
} | ||
}() | ||
|
||
return out, nil | ||
} | ||
|
||
func (api *BlocksGateway) GetBlock(ctx context.Context, c cid.Cid) (blocks.Block, error) { | ||
return api.blockService.GetBlock(ctx, c) | ||
} | ||
|
||
func (api *BlocksGateway) GetIPNSRecord(ctx context.Context, c cid.Cid) ([]byte, error) { | ||
if api.routing == nil { | ||
return nil, routing.ErrNotSupported | ||
} | ||
|
||
// Fails fast if the CID is not an encoded Libp2p Key, avoids wasteful | ||
// round trips to the remote routing provider. | ||
if mc.Code(c.Type()) != mc.Libp2pKey { | ||
return nil, errors.New("provided cid is not an encoded libp2p key") | ||
} | ||
|
||
// The value store expects the key itself to be encoded as a multihash. | ||
id, err := peer.FromCid(c) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return api.routing.GetValue(ctx, "/ipns/"+string(id)) | ||
} | ||
|
||
func (api *BlocksGateway) GetDNSLinkRecord(ctx context.Context, hostname string) (ifacepath.Path, error) { | ||
if api.namesys != nil { | ||
p, err := api.namesys.Resolve(ctx, "/ipns/"+hostname, nsopts.Depth(1)) | ||
if err == namesys.ErrResolveRecursion { | ||
err = nil | ||
} | ||
return ifacepath.New(p.String()), err | ||
} | ||
|
||
return nil, errors.New("not implemented") | ||
} | ||
|
||
func (api *BlocksGateway) IsCached(ctx context.Context, p ifacepath.Path) bool { | ||
rp, err := api.ResolvePath(ctx, p) | ||
if err != nil { | ||
return false | ||
} | ||
|
||
has, _ := api.blockStore.Has(ctx, rp.Cid()) | ||
return has | ||
} | ||
|
||
func (api *BlocksGateway) ResolvePath(ctx context.Context, p ifacepath.Path) (ifacepath.Resolved, error) { | ||
if _, ok := p.(ifacepath.Resolved); ok { | ||
return p.(ifacepath.Resolved), nil | ||
} | ||
|
||
err := p.IsValid() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
ipath := ipfspath.Path(p.String()) | ||
if ipath.Segments()[0] == "ipns" { | ||
ipath, err = resolve.ResolveIPNS(ctx, api.namesys, ipath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
if ipath.Segments()[0] != "ipfs" { | ||
return nil, fmt.Errorf("unsupported path namespace: %s", p.Namespace()) | ||
} | ||
|
||
node, rest, err := api.resolver.ResolveToLastNode(ctx, ipath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
root, err := cid.Parse(ipath.Segments()[1]) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return ifacepath.NewResolvedPath(ipath, node, root, gopath.Join(rest...)), nil | ||
} | ||
|
||
func (api *BlocksGateway) resolveNode(ctx context.Context, p ifacepath.Path) (format.Node, error) { | ||
rp, err := api.ResolvePath(ctx, p) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
node, err := api.dagService.Get(ctx, rp.Cid()) | ||
if err != nil { | ||
return nil, fmt.Errorf("get node: %w", err) | ||
} | ||
return node, nil | ||
} | ||
|
||
func (api *BlocksGateway) processLink(ctx context.Context, result unixfs.LinkResult) iface.DirEntry { | ||
if result.Err != nil { | ||
return iface.DirEntry{Err: result.Err} | ||
} | ||
|
||
link := iface.DirEntry{ | ||
Name: result.Link.Name, | ||
Cid: result.Link.Cid, | ||
} | ||
|
||
switch link.Cid.Type() { | ||
case cid.Raw: | ||
link.Type = iface.TFile | ||
link.Size = result.Link.Size | ||
case cid.DagProtobuf: | ||
link.Size = result.Link.Size | ||
} | ||
|
||
return link | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.