bitpay / bitcore-p2p

Interface to the bitcoin P2P network for bitcore
MIT License
81 stars 275 forks source link

Support Connecting to Peers in a Browser #21

Open braydonf opened 9 years ago

braydonf commented 9 years ago

Connect to the Bitcoin network via WebSocket proxies (would need to be implemented in parallel).

throughnothing commented 9 years ago

I'm working on a (crude) way to do this in Chrome specifically (with an eye towards Chromebooks) here: https://github.com/throughnothing/BitcoinSPVCrx

It uses chrome-net to replace node's net when built for the browser (webpack handles this via the webpack.conf.js). Presumably you could do the same exact thing, by re-implementing node's net module interface and using WebSocket proxies underneath, and then just plug that in when built for the browser.

You also run into issues with browsers not providing DNS, which bitcore needs. In my implementation, I have a js/chrome-statdns.js file that uses statdns's HTTP REST API to resolve DNS for peer lookups. It implements only what bitcore-p2p uses of the node dns module (just the resolve method) and "resolves" the dns via an HTTP call. It's not great, but it works for now.

braydonf commented 9 years ago

Interesting

throughnothing commented 9 years ago

@braydonf I am happy to work on adding in some 'detection' code directly into peer.js in bitcore-p2p so that it can run in (supported) browsers out of the box, but I wasn't sure if that would be accepted, or even if it's desirable, when external solutions like my approach are possible.

Maybe 'solutions' like mine should just be documented to show people how to use it in the browser. I'm happy to help with docs also :)

throughnothing commented 9 years ago

My project can now (crudely, and very naively/simply) fully sync and validate the blockchain headers in Chrome using bitcore/bitcore-p2p :)

maraoz commented 9 years ago

@throughnothing BitcoinSPVCrx looks great! I found some problems trying to install it and test it, but it looks like a project we'd like to feature on http://bitcore.io/#projects if you are fine with it

throughnothing commented 9 years ago

@maraoz thanks! I wouldn't mind putting it on bitcore.io/#projects eventually, but I don't think its ready for that just yet. Once I think it is, I'll let you know.

theveloped commented 9 years ago

I'm working on an version of bitcore-p2p that should work with ionic/cordova apps (codova-bitcore) similar to what @throughnothing has done for chrome. Up to now it seems connection with the nodes is handled correctly although I can't seem te get any response from the peer when sending the initial version message. Any idea's on possible causes of this problem?

stefanhuber commented 8 years ago

@theveloped I managed to port most of the peer and pool classes for cordova: https://github.com/getbitpocket/bitcore-p2p-cordova. Works so far...