Sn_httpd - Serving Autonomi data over HTTP

I thought I should create a thread for sn_httpd, as I’m developing and testing various features on the test nets. A separate thread may help to consolidate sn_httpd related setup/config/testing results and also to keep track of new features I’m adding.

Note that this is not a Maidsafe project, but it is open source! It’s also highly experimental, as it’s my first Rust project, has zero unit testing and is a bubbling hotbed of me messing about to see what works!

So, what is sn_httpd? If you’ve not tried it out yet, it’s a HTTP daemon for Autonomi (aka, Safe Network - maybe a new prefix is needed? :smiley:). This allows regular web browsers to interact with Autonomic, including rendering web sites, images, streaming music, streaming video, etc.

You can run sn_httpd locally and have your own, private, web server to interact with. Or, you can run it on a remote instance, then allow access to yourself and others.

If you run it locally, it can also act as a forward web proxy for Autonomy. What is a forward web proxy? It is a service that sits between your browser and the Autonomy network. This allows any browser to interact with Autonomi and allows (experimental!) DNS to resolve names for Autonomi apps/sites.

If you would like to use the proxy feature, I’d recommend using a second browser for Autonomi and manually setting the HTTP proxy to 127.0.0.1:8080 (or whichever port you are running the local instance on).

For Firefox, the settings look like this:

As all requests on the browser using the proxy are forwarded to sn_httpd, the hostname can be pulled from the URL and used as a DNS style name to resolve. At this time (experimental!), Autonomi host names must end with ‘.autonomi’, e.g. http://traktion.autonomi/streaming.html.

Alternatively, localhost can be referred to directly to avoid and DNS style resolving, by using /safe/ URL formats, e.g. http://localhost:8080/safe/3509bad03dc869dec883c7b44662c3503d2517fa9e828bb64f4dbe719d3837bf.

If you would like to try it out, you can compile from source here: GitHub - traktion/sn_httpd: Safe Network httpd gateway server

Or download binaries here: Releases · traktion/sn_httpd · GitHub

Or pull the latest docker container here: Docker

Q & A

Q: How do file names map to Autonomi XOR addresses?
A: The DNS style name (e.g. traktion.autonomi) points to a app-config.json file, which provides a list of path/XOR maps. There is more information here: GitHub - traktion/sn_httpd: Safe Network httpd gateway server . Note that this format is experimental and set to change (to add cache TTL, MIMI type overrides, etc), but it’s great for trying stuff out in POC form.

Q: Can I set the proxy on my regular browser and use it for both clear net and Autonomi browsing?
A: With the standard build, this is currently disabled. It can be enabled by toggling PROXY_ENABLED in code, but there are some build issues on Arm platforms. However, using a separate browser prevents leakage between clear net and Autonomy, which may be desirable from a security perspective.

Q: Can I stream video or music straight from Autonomi to my browser?
A: Yes! I’ve tested this with Chrome and Firefox on Ubuntu, as well as Chrome on Android mobile. It uses 206 partial content responses to communicate smoothly with the browsers and allows you to start watching/listening stuff almost immediately.

Q: I can run this on Android too?!
A: Yes! If you install Termux, you can run the sn_httpd Android binary directly from the console. No need to jail break phone, etc. You can then access localhost or set it up as a proxy (in a second browser). I plan to experiment with making sn_httpd and Android service that can just be run in the background easily, but it’s early days. Termux lets us play with the concept though! Some notes here: PunchNet [24/04/24 Testnet] - #339 by Traktion

Q: Will there be a dedicated Autonomi web browser?
A: Yes, I’m sure there will! This offers a quick and simple way of getting content to a regular browser though and could help to feed in ideas on how both could live alongside one another. Building and maintaining a browser requires more effort than creating a HTTP service wrapper around Autonomi.

Q: Are there non-browser use cases for sn_httpd?
A: Yes! If you’re building out apps which exist in the clear net, but want to start using elements of Autonomi, sn_httpd can help to bridge the gap. HTTP is simple to integrate with, requiring no special libraries or languages. GETs and PUTs are supported, along with routing for SPAs (single page applications). In short, any backend could talk to a sn_httpd instance running nearby and store or retrieve data from Autonomi.

Q: How does SPA routing work?
A: See this example here: sn_httpd/app-config.json at 5abbee4948d65b10c65b99674ad9cbbf5b21e5ac · traktion/sn_httpd · GitHub . In short, URLs with pattern matches can be directed to your SPA root, allowing it to respond to requests directly, just as with the clear net. This allows Autonomi to be the backend to your SPA (e.g. Angular, React, etc) app/site, but communicating directly with Autonomi instead of needing a dedicated REST backend.

Q: Can I build an SPA app that doesn’t need a HTTP web service running somewhere?
A: Yes! The IMIM blogging platform is an example of this, which doesn’t use any clear net infrastructure other than sn_httpd. If sn_httpd is run on the client (e.g. as a proxy), then no clear net infrastructure is needed at all!

23 Likes

very impressive. bravo :clap: :clap:

9 Likes

Fantastic work.

I know opening content hosted on current test networks from my phone browser via your proxy was a highlight to me of how powerful this network will be. Well done and thanks for putting this out there!

5 Likes