byteball / ocore

Core library for Obyte
https://obyte.org
MIT License
144 stars 92 forks source link

added support for connecting via HTTP proxy #291

Closed pmiklos closed 1 year ago

pmiklos commented 1 year ago

This PR allows connecting a wallet to the hub and peers via an http proxy server. Some stricter local networks might not allow connecting to the internet via a socks proxy and the only option might be an http proxy.

I wrote a test, but since it's more like an integration test that requires external systems like a proxy server and also hard to run it isolated or without side-effect, I have not added it to the PR, but for reference, I used the below test script. For proxy I used a docker container:

docker run --name squid --rm -d -p 3128:3128 ubuntu/squid
const test = require("ava");
const conf = require("../conf")
const network = require("../network");

async function connect(url) {
    return new Promise( (resolve, reject) => {
        network.findOutboundPeerOrConnect(url, (error, ws) => {
            if (error) return reject(error);
            resolve(ws);
        });
    });
}

test("Connects via http proxy", async (assert) => {
    conf.httpsProxy="http://localhost:3128"

    let ws = await connect("wss://obyte.org/bb")

    assert.truthy(ws)
    assert.true(ws.url === "wss://obyte.org/bb")
    assert.true(ws.bOutbound)
});
tonyofbyteball commented 1 year ago

Looks nice, thanks!