This repository was archived by the owner on Oct 23, 2022. It is now read-only.
File tree 4 files changed +41
-3
lines changed
4 files changed +41
-3
lines changed Original file line number Diff line number Diff line change @@ -33,7 +33,8 @@ const factory = createFactory(options)
33
33
// Phase 1.0-ish
34
34
//
35
35
tests . miscellaneous ( factory , { skip : [
36
- 'dns' ,
36
+ // recursive resolving is not implemented yet
37
+ 'should recursively resolve ipfs.io' ,
37
38
// the cidBase param is not implemented yet
38
39
'should resolve an IPFS hash and return a base64url encoded CID in path' ,
39
40
// different Cid, the /path/to/testfile.txt suffix shouldn't be there
Original file line number Diff line number Diff line change @@ -88,6 +88,7 @@ pub fn routes<T: IpfsTypes>(
88
88
and_boxed!( warp:: path!( "id" ) , id:: identity( ipfs) ) ,
89
89
and_boxed!( warp:: path!( "add" ) , root_files:: add( ipfs) ) ,
90
90
and_boxed!( warp:: path!( "cat" ) , root_files:: cat( ipfs) ) ,
91
+ and_boxed!( warp:: path!( "dns" ) , ipns:: dns( ipfs) ) ,
91
92
and_boxed!( warp:: path!( "get" ) , root_files:: get( ipfs) ) ,
92
93
and_boxed!( warp:: path!( "refs" / "local" ) , refs:: local( ipfs) ) ,
93
94
and_boxed!( warp:: path!( "refs" ) , refs:: refs( ipfs) ) ,
Original file line number Diff line number Diff line change @@ -43,3 +43,34 @@ async fn resolve_query<T: IpfsTypes>(
43
43
struct ResolveResponse {
44
44
path : String ,
45
45
}
46
+
47
+ #[ derive( Debug , Deserialize ) ]
48
+ pub struct DnsQuery {
49
+ // the name to resolve
50
+ arg : StringSerialized < IpfsPath > ,
51
+ }
52
+
53
+ pub fn dns < T : IpfsTypes > (
54
+ ipfs : & Ipfs < T > ,
55
+ ) -> impl Filter < Extract = ( impl Reply , ) , Error = Rejection > + Clone {
56
+ with_ipfs ( ipfs) . and ( query :: < DnsQuery > ( ) ) . and_then ( dns_query)
57
+ }
58
+
59
+ async fn dns_query < T : IpfsTypes > ( ipfs : Ipfs < T > , query : DnsQuery ) -> Result < impl Reply , Rejection > {
60
+ let DnsQuery { arg, .. } = query;
61
+ let path = ipfs
62
+ . resolve ( & arg. into_inner ( ) )
63
+ . await
64
+ . map_err ( StringError :: from) ?
65
+ . to_string ( ) ;
66
+
67
+ let response = DnsResponse { path } ;
68
+
69
+ Ok ( warp:: reply:: json ( & response) )
70
+ }
71
+
72
+ #[ derive( Debug , Serialize ) ]
73
+ #[ serde( rename_all = "PascalCase" ) ]
74
+ struct DnsResponse {
75
+ path : String ,
76
+ }
Original file line number Diff line number Diff line change @@ -24,8 +24,13 @@ impl FromStr for IpfsPath {
24
24
let empty = subpath. next ( ) . expect ( "there's always the first split" ) ;
25
25
26
26
let root = if !empty. is_empty ( ) {
27
- // by default if there is no prefix it's an ipfs or ipld path
28
- PathRoot :: Ipld ( Cid :: try_from ( empty) ?)
27
+ // by default if there is no prefix it's an ipfs or ipld path...
28
+ if let Ok ( cid) = Cid :: try_from ( empty) {
29
+ PathRoot :: Ipld ( cid)
30
+ } else {
31
+ // ...but if that isn't the case, it might be a domain name too
32
+ PathRoot :: Dns ( empty. to_string ( ) )
33
+ }
29
34
} else {
30
35
let root_type = subpath. next ( ) ;
31
36
let key = subpath. next ( ) ;
You can’t perform that action at this time.
0 commit comments