Skip to content

Commit

Permalink
add trickle-dag support to the urlstore
Browse files Browse the repository at this point in the history
fixes #5241

License: MIT
Signed-off-by: Steven Allen <[email protected]>
  • Loading branch information
Stebalien committed Jul 16, 2018
1 parent 89e1d9f commit 19caad2
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions core/commands/urlstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
filestore "github.com/ipfs/go-ipfs/filestore"
balanced "github.com/ipfs/go-ipfs/importer/balanced"
ihelper "github.com/ipfs/go-ipfs/importer/helpers"
trickle "github.com/ipfs/go-ipfs/importer/trickle"

cmds "gx/ipfs/QmNueRyPRQiV7PUEpnP4GgGLuK1rKQLaRW7sfPvUetYig1/go-ipfs-cmds"
mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
Expand Down Expand Up @@ -42,6 +43,9 @@ found. It may disappear or the semantics can change at any
time.
`,
},
Options: []cmdkit.Option{
cmdkit.BoolOption(trickleOptionName, "t", "Use trickle-dag format for dag generation."),
},
Arguments: []cmdkit.Argument{
cmdkit.StringArg("url", true, false, "URL to add to IPFS"),
},
Expand Down Expand Up @@ -71,6 +75,8 @@ time.
return
}

useTrickledag, _ := req.Options[trickleOptionName].(bool)

hreq, err := http.NewRequest("GET", url, nil)
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
Expand Down Expand Up @@ -98,14 +104,18 @@ time.
URL: url,
}

blc, err := balanced.Layout(dbp.New(chk))
layout := balanced.Layout
if useTrickledag {
layout = trickle.Layout
}
root, err := layout(dbp.New(chk))
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
return
}

cmds.EmitOnce(res, BlockStat{
Key: blc.Cid().String(),
Key: root.Cid().String(),
Size: int(hres.ContentLength),
})
},
Expand Down

0 comments on commit 19caad2

Please sign in to comment.