Skip to content

Commit

Permalink
ipfs: use dag session to download remote blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed Oct 7, 2023
1 parent 896eee7 commit c978a1a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion ipfs/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (n *Node) DownloadCID(ctx context.Context, c cid.Cid) (io.ReadSeekCloser, e
return nil, fmt.Errorf("failed to get root node: %w", err)
}

dr, err := fsio.NewDagReader(ctx, rootNode, n.dagService)
dr, err := fsio.NewDagReader(ctx, rootNode, dagSess)
return dr, err
}

Expand Down
16 changes: 8 additions & 8 deletions ipfs/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package ipfs_test

import (
"context"
"crypto/sha256"
"encoding/hex"
"io"
"os"
"path/filepath"
"sync"
"testing"
Expand Down Expand Up @@ -152,7 +153,7 @@ func TestTest(t *testing.T) {
}
defer node.Close()

time.Sleep(5 * time.Second)
time.Sleep(time.Second)

t.Log(node.PeerID())
t.Log(node.Peers())
Expand All @@ -162,20 +163,19 @@ func TestTest(t *testing.T) {
downloadCtx, cancel := context.WithTimeout(ctx, 15*time.Second)
defer cancel()

// note: this currently only downloads the root CID. Need to walk the DAG
r, err := node.DownloadCID(downloadCtx, c)
if err != nil {
t.Fatal(err)
}
defer r.Close()

f, err := os.Open("test.png")
if err != nil {
h := sha256.New()
if _, err := io.Copy(h, r); err != nil {
t.Fatal(err)
}
defer f.Close()

if _, err := io.Copy(f, r); err != nil {
t.Fatal(err)
shaChecksum := hex.EncodeToString(h.Sum(nil))
if shaChecksum != "f0fe7b43114786cf72649551290761a01b27cd85d9f1a97da7f58c2b505d4cf3" {
t.Fatalf("unexpected hash: %x", h.Sum(nil))
}
}

0 comments on commit c978a1a

Please sign in to comment.