-
Notifications
You must be signed in to change notification settings - Fork 183
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
Browser support #452
Comments
I have been using hypercore and much of the hyper-ecosystem extensively in browser with minimal issues. Easiest solution for me earilier on was to use browserify. But now, I use rollup . Edit: But rollup comes with a bit more complexity, so I'd suggest doing browserify way. |
Thank you for your reply. I tried what you mentioned and below I have an example running on browser using browserify
The problem is that I get
when trying to replicate . |
Yeah, I could never get any noise streams to pipe to each other through browser. So, to do any kind of replicating, I use the 'dht relay socket' library. |
Just to go on, I think the reason is, only so many cryptography functions from sodium library (e.g. noise algos) works in browser (javascript) where it has to be 'handled' by a microservice thus the relay. And I also believe that is why its so hard for p2p to get 'browser surface'. Check out the failed p2p browser beaker. |
I found the problem . In @hyperswarm/secret-stream if you go to lib/handshake.js in line 12
I think if you remove the curve it will work |
MY expertise in cryptography is deep enough to understand and implement, but still would hope someone more specialized in cyber security would make the nitty gritty parts of it. But removing that noise would most likely remove it's ability to replicate to common peers (anyone that doesn't have that version that removes the curve). And I'm pretty sure you'll remove the 'append only' concept to the hypercore as well. |
I get this error when on the line that tries to call import Corestore from 'corestore';
import random from 'random-access-idb';
const fileName = 'cool';
const storage = random(fileName);
const store = new Corestore(storage);
const input = store.get({name: 'input'});
const output = store.get({name: 'output', valueEncoding: 'json'});
goodbye(async () => {
await Promise.all([input.close(), output.close()]);
});
await Promise.all([input.ready(), output.ready()]); // Error: this.storage.truncate is not a function #oplog.js:171:22
|
Old version of random-access-idb... I decided to create my own repo with mods I've used. Here is mine: https://github.com/zacharygriffee/random-access-idb I also found another group trying to update it as well here: https://github.com/random-access-storage/random-access-idb The one you get from npm e.g. "npm i random-access-idb" is old. |
I did want to mention, as I just thought about eating dinner, during 'development' when testing out these tools, I utilize cdn esm.run (e.g. cdn.jsdelivr.net/npm/hyperswarm/+esm) to then import either by importmap or directly in type=module script element. Just load a relay on your machine with port forwarding to that relay. This doesn't even need an http server to run***, just plop right into an HTML file. Saves me the bundling until production. *** The html file doesn't need http to run. The relay will need http for upgrade.
|
@zacharygriffee Very nice example . I was wondering since you are using Hyperswarm Relay
Do you have any idea how this can scale (horizontally)? |
This is what I've done in attempt to scale horizontally. 1: I've implemented the relay in a digital ocean, and a few computers at home. As a note @hyperswarm/dht-relay github does say its not ready for production use, but I've been getting pretty good results with it. Hope this helps. I know its not a simple direct answer. But this may help you devise a stack to work with the browser limitations. If you got any thoughts as well please share. |
Sorry for the late reply but I had to do some tests and found some issues . One of them is the fact that I could not make a private swarm. Secondly I wanted to be able for my internal network to create a swarm and that swarm does not have an internet connection. Thirdly I want to be able to connect both my internal and external networks. To put the above in more detail . I have 3 or more desktop apps that need to connect internally using the home network. Also I have mobile devices that need also to be able to connect to those desktop apps via either a relay hosted on VPS or via an internal relay hosted on one of the desktop apps. The mobile + desktop connectiviy should happen either when any of them loose internet connectivity but connected to the same local network. What I found was that if you do not have internet connectivity even on your local bootstrap dht-relay server you cannot connect. Another problem also is that mobile devices when they have limited internet connectivity from the local wifi they tend to switch to mobile carrier and thus loosing the connectiviy to the local network. Thus I found that the best approach is to create your own relay server for the internal home network and connect to both hyperswarm and own relay-server. Also from some tests that I've made 99.9 percent when using the hyperswarm from my local network the connections made between the desktop apps where all through relay servers and thus if you did not have any internet you could not join them. Overall I found that, for internal home network use, Desktop apps and Mobile devices should connect together using use a local relay-server(your own not the one provided), together with the hyperswarm network or hyperswarm dht-relay. Another interesting thing is that I could not find anywhere how to build my own boostrap server like 'node1.hyperdht.org' together with the relay. If anyone has an idea please share. ( and I don't mean the example that is included in the hyperdht repo. ) Thanks @zacharygriffee for your reply |
Have to have internet.Sadly I haven't found a way around that, and I have even raised issue at the @holepunchto/hyperswarm-dht-relay here at the beginning of the year. Also mentioned here. I felt that a private network independent of the internet would be invaluable for SOOO many things. I didn't dig too hard into the code with that, maybe I need to do it. But the plate full blah blah. Self hosted swarm / bootstrapI have some personal test cases buried on another laptop, however, for now, have you checked the test cases on HyperDHT as well? HyperDHT 'testnet' implements a 'private' network for their tests: https://github.com/holepunchto/hyperdht/blob/main/testnet.js Line 8, 13, 15 Aside from the testnet, the few things I found to be important in my tests was:
If all this doesn't work I can dig into my other laptop where I had a successful one. But it was from a older version of the dht but it should still be applicable.
I have actually not tested network switching of a mobile phone. That is something that will be on my moderately important TODO list and report back. Cause, that is important for me as well. I have not had any problems switching networks with a laptop for example but have not tried mobile phone. Note to mods: I know this discussion is weakly related to the hypercore problem and strongly related to the hyperDHT. But I feel really hard to find exactly where to raise these issues when they're so interconnected other than discord |
Another thing. This may go without saying but thought worth the mention. Regarding network switching. During testing, I have it set where the 'webpage' I have connecting to the services has two different ip to connect to. 1: The local area network ip: ws://192.168.x.x:port/path So when the socket closes because of the network switch, it will attempt both ip's. So when you loose connection to the local it will try the public. |
I use a jst-like-templating with custom seperators so I can add to the url a custom relay address with testing as well.
|
Is there any plans to fix and support on browser?
The text was updated successfully, but these errors were encountered: