massa-web3: linking towards decentralized websites
Intro
Relative links on the DeWeb
Currently, when a visitor is visiting a decentralized website, all the links towards other resources of that same website are relative (for example <img src="/img/mypicture.png">
or <a href="page2.html">Go To Page 2</a>
). This allows the browser to automatically resolve the absolute URI of the resource in order to query it. Let’s illustrate this: if I am visiting https://mysite.massa.network
on which there is the picture and the link taken as examples above, then my browser will automatically fetch the picture from https://mysite.massa.network/img/mypicture.png
and if I click on the Go To Page 2
link, it will send me to https://mysite.massa.network/page2.html
. If I am visiting the same website but from http://mysite.localhost:8080
, this image and link will still work as my browser will automatically resolve their URIs to http://mysite.localhost:8080/img/mypicture.png
and http://mysite.localhost:8080/page2.html
respectively.
Therefore, for all relative URIs, everything works smoothly out-of-the box on the Massa deweb!
Links from a decentralized website to another decentralized website
If however a decentralized website needs to link to a resource hosted on another decentralized website, a question arises: what prefix should be used in the resource URI ?
Example: I visit mysite.massa
from https://mysite.massa.network
and that page needs to link towards myothersite.massa
. A few options can be explored:
- the page on
mysite.massa
can contain a hardwritten link towards a given provider, for examplehttps://myothersite.massa.network
but this solution has multiple issues:- it causes centralization around a single provider (
massa.network
in this example) and if that provider is down, the link will be broken - it forces the user to visit a pre-defined provider, not leaving the user the choice of provider (ideally local) they want to use
- if the chosen provider is censored in a given country, the link will be broken in those countries
- if the hardwritten provider is
localhost:8080
then the link will be broken for all the visitors who have not installed a local provider
- it causes centralization around a single provider (
- the page on
mysite.massa
can use a script to strip the provider part of the resource URI and rewrite it by inserting the current provider being used in the URI. In our example, a link tomyothersite.massa/page2.html
would automatically prefix the provider currently in use to query the resource: it would behttps://myothersite.massa.network/page2.html
when I visithttps://mysite.massa.network/page2.html
and it would behttp://myothersite.localhost:8080
when I visitmysite.massa
from a local provider).- That way there is no hardcoded provider and links between decentralized websites are more consistent with user choices since the provider chosen by the user is kept when accessing other deweb resources
- The user would however not have the option to choose different providers for different resources. This is an issue if some providers block certain resources (typically through their block/allow-lists): links to websites blocked by the provider currently in use would be dead
Links from a normal clearweb site towards a decentralized website
Linking from a normal clearweb site towards a decentralized website raises similar issues as the decentralized-decentralized case above. However, since there is no “current provider” in use, automatically rewriting the URI would not be possible.
Proposed solution
To fix our issue we propose to update massa-web3
to expose a new function:
deweb_resolve(uri: String) -> [String]
That function resolves a resource URI in the format http://mysite.massa/subfolder/resource1.html?param1=3¶m2=4#anchor1
to a list of available absolute links:
[
"https://mysite.massa/subfolder/resource1.html?param1=3¶m2=4#anchor1",
"http://mysite.localhost:8080/subfolder/resource1.html?param1=3¶m2=4#anchor1",
"https://mysite.massa.network/subfolder/resource1.html?param1=3¶m2=4#anchor1",
"https://mysite.massahub.network/subfolder/resource1.html?param1=3¶m2=4#anchor1",
"https://mysite.someotherprovider.com/subfolder/resource1.html?param1=3¶m2=4#anchor1"
]
then the developer of the page can choose how to present the choice to the visitor.
The list is considered prioritized from highest to lowest priority.
The way the function works is the following:
- it first checks the URI (the domain must be in
.massa
) or returns an error - then it checks if the browser has directly access to
mysite.massa
adds the associated URI on top of the returned list if it is the case. This will be interesting for direct browser integration that supports.massa
natively. This is on top of the list because it has the most native support. - then it checks the availability of
mysite.localhost:8080
and appends it to the returned list if available. This is to account for local providers. - then it loads a list of published providers from an on-chain list (see the Lists proposal) and checks the availability of the site from each of them in order to append them on the list or not
For every check, first an https
request is attempted and if it fails, normal http
access is attempted.
Note that if it is detected that a provider XXXX is being used by the current page, and that provider responds correctly to serve the linked resource, that provider can be listed on top of the provider list under “Keep current provider: XXXX”.
As for the on-chain list of providers, it eventually needs to be curated in a decentralized way (eg. by a DAO).