-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: add HTTP Gateway support for /ipns/ paths #2020
Conversation
tl;dr opening /ipns/tr.wikipedia-on-ipfs.org/wiki/Mars.html works Switched to js-ipfs with cherry-picked changes from: ipfs/js-ipfs#2020 ipfs/js-ipfs#1989 ipfs/js-ipfs#2002 ipfs/js-ipfs-http-response#22 ipfs-inactive/js-ipfs-mfs#48
571eb4b
to
c9fe577
Compare
It requires below to PRs to land first: #2002 ipfs/js-ipfs-http-response#19 ipfs-inactive/js-ipfs-mfs#48 License: MIT Signed-off-by: Marcin Rataj <lidel@lidel.org>
c9fe577
to
97d03fc
Compare
I rebased this PR and switched to released versions of Note: This PR resolves @alanshaw this is a fairly small change, do you want to merge this to compliment other IPNS-related backend PRs made by @hugomrdias? (Travis fails due to recent changes in master, not related to this PR: https://travis-ci.com/ipfs/js-ipfs/jobs/211405524#L3104) |
src/http/gateway/routes/gateway.js
Outdated
}, | ||
{ | ||
method: '*', | ||
path: '/ipns/{mutableId*}', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should define what we should call this id, libp2p-key, ipns-key-id, even ipns-cid (content been the hash of the pubkey) and we should PR to the spec https://github.com/ipfs/specs/tree/master/naming this new name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have libp2p-key multicodec now for presenting IPNS names as base32 CIDv1, but it can also be FQDN with DNSLink, so I renamed it to libp2pKeyOrFqdn
.
I did not touch mentioned spec as /ipns/base32(<HASH>)
mentioned there has direct implication on how things are implemented: https://github.com/ipfs/js-ipns/blob/v0.5.2/src/index.js#L214 (IPNS does not use <libp2p-key-in-cidv1b32>
but raw concatenation of /ipns/
and key buffer, and now they move to just buffer)
License: MIT Signed-off-by: Marcin Rataj <lidel@lidel.org>
License: MIT Signed-off-by: Marcin Rataj <lidel@lidel.org>
- remove custom arg passing and replace it with native Joi validation - decode escaped unicode in paths before passing to ipfs resolver - add tests for /ipns/ path (file and directory) License: MIT Signed-off-by: Marcin Rataj <lidel@lidel.org>
License: MIT Signed-off-by: Marcin Rataj <lidel@lidel.org>
License: MIT Signed-off-by: Marcin Rataj <lidel@lidel.org>
License: MIT Signed-off-by: Marcin Rataj <lidel@lidel.org>
License: MIT Signed-off-by: Marcin Rataj <lidel@lidel.org>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code changes LGTM, just one question.
const resources = require('../../gateway/resources') | ||
|
||
module.exports = [ | ||
{ | ||
method: '*', | ||
path: '/ipfs/{cid*}', | ||
path: '/ipfs/{path*}', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need an /ipns
handler also?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is only for /webui
and hardcoded /ipfs/{cid_of_webui}
on API port.
(/ipns/
is only available on the Gateway port)
// QmaRdtkDark8TgXPdDczwBneadyF44JvFGbrKLTkmTUhHk | ||
await http.api._ipfs.add([content('utf8/cat-with-óąśśł-and-أعظم._.jpg')]) | ||
// Publish QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ to IPNS using self key | ||
await http.api._ipfs.name.publish('QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ', { resolve: false }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note for the future: unless we're trying to validate particular content creates a particular CID we should add the content and store the returned CID for use in future tests. Hard coding CIDs like this is a maintenance nightmare when we want to change defaults.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am aware, but did not want to rewrite existing tests, so as a compromise I reused existing CID of cat-folder/cat.jpg
(was already present a few lines above)
This PR will add support for
/ipns/
paths at HTTP Gateway.Smoke test: /ipns/tr.wikipedia-on-ipfs.org (IPNS+DNSLink+HAMT-sharded website)
Do not merge it yet
This PR requires below PRs to be merged first:
(after merging Gateway Improvements: Streaming, Conditional and Range Requests #1989 I will rebase this PR, which will remove first two commits)
eg.
/ipns/<PeerId-as-multihash-b58>
/ipns/<libp2p-key-in-cidv1>
eg.
/ipns/<fqdn>/path/file
like/ipns/docs.ipfs.io/assets/logo.svg
eg.
/ipns/tr.wikipedia-on-ipfs.org/wiki/Anasayfa.html
(wiki
is a sharded directory)/ipns/