Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bitswap): convert to serial walk in style of UnixFS.Get #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion testbed/testbed/utils/bitswap.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,30 @@ func (n *BitswapNode) EmitMetrics(recorder MetricsRecorder) error {
return err
}

// completely serialized walk, similar to traversing with unixfs file
func serialWalk(ctx context.Context, c cid.Cid, ng ipld.NodeGetter) error {
nd, err := ng.Get(ctx, c)
if err != nil {
return err
}

return walkChildren(ctx, nd, ng)
}

func walkChildren(ctx context.Context, nd ipld.Node, ng ipld.NodeGetter) error {
for _, lnk := range nd.Links() {
err := serialWalk(ctx, lnk.Cid, ng)
if err != nil {
return err
}
}

return nil
}

func (n *BitswapNode) Fetch(ctx context.Context, c cid.Cid, _ []PeerInfo) (files.Node, error) {
err := merkledag.FetchGraph(ctx, c, n.dserv)
ng := merkledag.NewSession(ctx, n.dserv)
err := serialWalk(ctx, c, ng)
if err != nil {
return nil, err
}
Expand Down