-
Notifications
You must be signed in to change notification settings - Fork 161
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: Better support of Gateway Subdomain spec #546
Conversation
da4ddbc
to
90c37d3
Compare
Host
header for aligning with Gateway Subdomain spec
Host
header for aligning with Gateway Subdomain spec
Can't figure out if we should do anything here with the note from spec:
Decode and then encode IPNS name? Or what? |
f084ea6
to
e6806ad
Compare
let res = do_request( | ||
"GET", | ||
&format!("localhost:{}", test_setup.gateway_addr.port()), | ||
"/ipns/k51qzi5uqu5dlvj2baxnqndepeb86cbk3ng7n3i46uzyxzyqj2xjonzllnv0v8", |
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.
nit: needs a separate test for legacy notation that was not a valid CID (e.g., 12D3KooWJHxkQKX8C5KAyqEPhn2ssT2in4TExyG9SXxi519tycL9
)
See explainer in multiformats/cid-utils-website#48
This is important feature of subdomain gateway: when a request is made to example.com/ipns/id
, subdomain set up on example.com
will return HTTP 301 redirect to proper subdomain.
Before redirect is made, id
is converted to cidv1-libp2p-key-base36
.
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.
Done
I had to add nasty from_peer_id
function for dealing with discrepancy between multihash:0.16
and multihash:0.17
. This func may be safely deleted after updating to multihash:0.17
cc @dignifiedquire Would you mind to release multiaddr 0.17 for bringing new multihash crate to rust-libp2p?
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.
@vmx what't the status here?
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.
@dignifiedquire I'm not maintaining rust-multiaddr, that's a question for @mxinden :)
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.
Kicked off release process here. Please approve. multiformats/rust-multiaddr#66
iroh-gateway/src/core.rs
Outdated
let res = do_request( | ||
"GET", | ||
&format!("localhost:{}", test_setup.gateway_addr.port()), | ||
"/ipns/ipfs-subdomain.ipfs-domain.eth", |
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.
nit: change to en.wikipedia-on-ipfs.org
? this is our usual test case for handling -
(i suggest avoiding using .eth in tests unrelated to ENS interop).
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.
Done.
Btw, while I was implementing code around -
processing with regular expressions I had faced that it is hard or even impossible to properly process cases like aaaa-b-aaaa.com
(a single symbol between 2 dashes) because captured groups were overlapping there (a-b
and b-a
with b
belonging to both groups) and it is forbidden in Regex
crate.
I mean, it may be useful to consider in E2E and other tests this case too cause it belongs to a separate equivalence class.
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.
fwiw Kubo also started with regex, realized it comes with footguns, and replaced with a plain function :)
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.
And it doesn't bring extra crate. You are right, dunno why I've decided regex would be better. It might be useful for complicated cases or expected future changes in format, but replacing dashes are definitely not this case.
iroh-gateway/src/regex.rs
Outdated
pub static SUBDOMAIN_REGEX: Lazy<Regex> = Lazy::new(|| { | ||
Regex::new(r"^(?P<cid_or_domain>[A-Za-z\d\-.]+)\.(?P<scheme>ip(?:ns|fs))\.(?P<hostname>[^.]+)$") | ||
.unwrap() |
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.
Just to make sure there are no regressions in the future, add tests for edge cases where hostname is the same as scheme, e.g.:
bafy.ipfs.ipfs.com
bafy.ipns.ipfs.com
bafy.ipns.ipns.com
bafy.ipns.ipfs.com
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.
Done
e6806ad
to
6669a68
Compare
iroh-resolver/src/resolver.rs
Outdated
@@ -47,6 +47,25 @@ pub struct Block { | |||
links: Vec<Cid>, | |||
} | |||
|
|||
// ToDo: Replace to PeerId::from_str after updating multihash crate to 0.17 |
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'd like to have this handled before we merge.
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 need a moment to fix it, but we should decide who will release multiaddr 0.17 and bring it through rust-libp2p and possibly other deps
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.
In regards to the gateway changes, this looks great. Regex is a bit scary looking.
Only thing I think we should do before the merge is resolve the multihash dependency.
No need to scare, I replace regex with function :) |
4b58fd6
to
3ad58b7
Compare
Almost done, but should not merge until I set proper version of libp2p in Cargo.toml |
I would love to merge this sooner rather than later, but I am not sure how long another libp2p release is out |
We may create an issue for cleaning things out after libp2p release and merge this PR as is. If it is ok, I'll prepare proper commits tomorrow |
Yeah I think this makes the most sense, appreciated |
c9f6b0e
to
db13ab9
Compare
Done. I've created reminding issue with "What-to-do" description |
5053dfe
to
1dd0e23
Compare
Cargo.toml
Outdated
@@ -45,3 +45,6 @@ incremental = false | |||
|
|||
[workspace.metadata.release] | |||
consolidate-commits = true | |||
|
|||
[workspace.dependencies] | |||
libp2p = { version = "0.50" } |
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.
can you remove this from this PR here please, see discussion on #595
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.
Done
6596d4e
to
1e07829
Compare
1e07829
to
b0076e8
Compare
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.
Just some very minor comments.
Need to get CI to pass, otherwise I'm happy to merge.
@@ -48,6 +52,9 @@ pub struct Config { | |||
/// set of user provided headers to attach to all responses | |||
#[serde(with = "http_serde::header_map")] | |||
pub headers: HeaderMap, | |||
/// Redirects to subdomains for path requests | |||
#[serde(default = "set_true")] | |||
pub redirect_to_subdomain: bool, |
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 default this to false. This requires additional config on the DNS side and making sure certificates are valid for anyone hosting it. Since there's the burden of configuration anyways, we should have this off by default and those interested can then just enable it.
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.
Done
@@ -1,6 +1,8 @@ | |||
use axum::http::{header::HeaderName, HeaderValue}; | |||
|
|||
// Headers | |||
pub static HEADER_X_FORWARDED_HOST: HeaderName = HeaderName::from_static("x-forwarded-host"); |
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.
This overlaps with #588, we should get both of these in. Think same tests are affected.
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.
Let's merge this one firstly and then I'll rebase and refine left one
iroh-gateway/src/client.rs
Outdated
pub format: ResponseFormat, | ||
pub cid: CidOrDomain, | ||
pub resolved_path: iroh_resolver::resolver::Path, | ||
pub query_file_name: String, | ||
pub download: bool, | ||
pub query_params: GetParams, | ||
pub is_subdomain_mode: bool, |
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.
Nitpick, can we make this subdomain_mode
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.
Done
iroh-gateway/src/handlers.rs
Outdated
@@ -46,27 +53,56 @@ use crate::{ | |||
templates::{icon_class_name, ICONS_STYLESHEET, STYLESHEET}, | |||
}; | |||
|
|||
enum RequestPreprocessingResult { | |||
ResponseImmediately(GatewayResponse), |
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.
Can we rename this to RespondImmediately
is a little bit more readable.
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.
Done
Argh, something happened during rebase, let me check what is wrong with the test |
52916de
to
9f6ceec
Compare
Fixed tests |
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!
* [feat] Support subdomains * pr: fixes * pr: fix test * fix: remove mut in iroh/src/run.rs
Added basic subdomain support by uplifting parameters extraction from
Host
header required for handlers.DnsLink part of spec is not supported in this PR.
Related to n0-computer/beetle#78
Spec:
Current PR won't cover URI router, I believe it is better to implement in a separate PR.