HelloZeroNet / ZeroNet

ZeroNet - Decentralized websites using Bitcoin crypto and BitTorrent network
https://zeronet.io
Other
18.33k stars 2.27k forks source link

HTTP API outside browser #2390

Closed dapplion closed 4 years ago

dapplion commented 4 years ago

Is your feature request related to a problem? Please describe.

I would like to distribute dynamic content updates and would require to consume ZeroNet sites from a NodeJS application.

Describe the solution you'd like

A very simple HTTP API to consume site content outside of a browser environment. It would just accept HTTP GET requests to the root as

curl http://localhost:43112/1DJst9UpppqHdWMo5hNTo1uuHmunn9ULgd/dappnode_package.json

without requiring nonce or tokens.

Describe alternatives you've considered

We've considered querying the current HTTP API but it returns HTML in most cases requiring unnecessary parsing. For example when querying a site that has not been downloaded yet it returns

<html>
<body>
...
<div class="content">
 <h1>Add new site</h1>
 <h2>Please confirm before adding a new site to the client</h2>
 <form action="/add/" method="POST">
  <input type="hidden" name="add_nonce" value="6fd48d7217771b129afd319ceae6719f9eb5dc24f7fa0dfba6455c1dc65aacbc">
  <input type="hidden" name="address" value="15BBnFVqF8JoFaqvXRCMvWBk5yqCN3SqF6">
  <input type="hidden" name="url" value="/15BBnFVqF8JoFaqvXRCMvWBk5yqCN3SqF6/dappnode_package.json">
  <input type="submit" class="button button-submit" id="button" value="Load site"/>
 </form>
</div>

</body>
</html>

Could that step be omitted? If not it could return a non 200 code.


Thank you so much for the amazing project. We can contribute to developing this API if necessary.

anoadragon453 commented 4 years ago

You can control the ZeroNet daemon in any way the browser can using the WebSocket API. Including downloading new sites and extracting files from them.

You can get an examples of interfacing with it from JavaScript here: https://zeroframe.js.org/

From Python here: https://pypi.org/project/zeroframe-ws-client/

And GDScript here: https://github.com/zam-org/godot-zeroframe-plugin

dapplion commented 4 years ago

@anoadragon453 Thank you so much, that's exactly what I was looking for! Is it necessary to keep one WebSocket connection open for each site or could they be grouped in one? Otherwise, is there a tested limit of open WebSocket connections for the ZeroNet client?


@Crypto-Anarchist I appreciate and share you deep enthusiasm for decentralization. I hear your concern and will remove the tag of the project I contribute to.

filips123 commented 4 years ago

@dapplion You need separate connection for each site. However, because you have access to WebSocket without wrapper, you can use as command to "execute command in other site's context".

This means that you can connect only to your main site, and then use as commands to access commands for other sites. But your main site (probably) needs to have ADMIN permission.

purplesyringa commented 4 years ago

This means that you can connect only to your main site, and then use as commands to access commands for other sites. But your main site (probably) needs to have ADMIN permission

ADMIN permission is not required if you use admin message IDs, i.e. greater than one million.

dapplion commented 4 years ago

@filips123 Thanks for the trick! @imachug How can I set the admin message IDs to greater than one million with ZeroFrameJS?

filips123 commented 4 years ago

You can set property nextMessageId to 1000000 on ZeroFrame object. But note that I haven't tested it if it works with as command, although it should work.

dapplion commented 4 years ago

@filips123 Is there a channel (i.e. Riot.im) we could continue the discussion to avoid polluting Github?

filips123 commented 4 years ago

Yes, there is ZeroNet room on Riot/Matrix and #zeronet channel on Freenode IRC.

dapplion commented 4 years ago

@filips123 Just joined the Matrix channel. Thank you so much for the help, I'll close this issue since it's the main question was answered