Skip to content

Commit

Permalink
ipfs, sia: broadcast pinned CIDs
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed Nov 19, 2023
1 parent 76b9564 commit f8e18e7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ipfs/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ func mustParsePeer(s string) peer.AddrInfo {
return *info
}

// Provide broadcasts a CID to the network
func (n *Node) Provide(c cid.Cid) error {
return n.provider.Provide(c)
}

// NewNode creates a new IPFS node
func NewNode(ctx context.Context, privateKey crypto.PrivKey, cfg config.IPFS, ds datastore.Batching, bs blockstore.Blockstore) (*Node, error) {
cmgr, err := connmgr.NewConnManager(600, 900)
Expand Down
18 changes: 17 additions & 1 deletion sia/sia.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,16 @@ type (
AllKeysChan(ctx context.Context) (<-chan cid.Cid, error)
}

// An IPFSProvider broadcasts CIDs to the IPFS network
IPFSProvider interface {
Provide(cid.Cid) error
}

// A Node is a specialized IPFS gateway that retrieves data from a renterd
// node
Node struct {
store Store
ipfs IPFSProvider
log *zap.Logger

renterd config.Renterd
Expand Down Expand Up @@ -107,10 +113,20 @@ func (n *Node) UploadCID(ctx context.Context, c cid.Cid, r io.Reader) error {
default:
}

blocks := dagSvc.Blocks()

if rootNode.Cid().Hash().B58String() != c.Hash().B58String() {
return fmt.Errorf("unexpected root cid: %s", rootNode.Cid().Hash().B58String())
} else if err := n.store.AddBlocks(ctx, blocks); err != nil {
return fmt.Errorf("failed to add blocks to store: %w", err)
}
return n.store.AddBlocks(ctx, dagSvc.Blocks())

for _, b := range blocks {
if err := n.ipfs.Provide(b.CID); err != nil {
return fmt.Errorf("failed to provide block: %w", err)
}
}
return nil
}

// ProxyHTTPDownload proxies an http download request to the renterd node
Expand Down

0 comments on commit f8e18e7

Please sign in to comment.