Skip to content

Commit

Permalink
Allow embedding of CORS proxy in fetch relay_url (#1189)
Browse files Browse the repository at this point in the history
Extends the syntax of relay_url for fetch to:

    fetch[:CORS-PROXY-URL]

where CORS-PROXY-URL is a full URL pointing to the CORS proxy server, for example:

    fetch:https://example.com/?url=

* pass options.net_device to NetworkAdapter constructors

- aligned construction of WispNetworkAdapter and FetchNetworkAdapter classes
- supported members in object options.net_device (all optional):
  id, router_mac, router_ip, vm_ip, masquerade, dns_method, doh_server, cors_proxy
- completed support for free choice between fake network DNS methods "static" and "doh"
  • Loading branch information
chschnell authored Dec 11, 2024
1 parent 298da23 commit e0e8077
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/browser/fetch_network.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ function FetchNetworkAdapter(bus, config)
this.vm_ip = new Uint8Array((config.vm_ip || "192.168.86.100").split(".").map(function(x) { return parseInt(x, 10); }));
this.masquerade = config.masquerade === undefined || !!config.masquerade;
this.vm_mac = new Uint8Array(6);
this.dns_method = config.dns_method || "static";
this.doh_server = config.doh_server;
this.tcp_conn = {};
this.eth_encoder_buf = create_eth_encoder_buf();
this.dns_method = "static";

// Ex: 'https://corsproxy.io/?'
this.cors_proxy = config.cors_proxy;
Expand Down
6 changes: 6 additions & 0 deletions src/browser/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1737,6 +1737,11 @@
settings.relay_url = $("relay_url").value;
if(!DEFAULT_NETWORKING_PROXIES.includes(settings.relay_url)) new_query_args.set("relay_url", settings.relay_url);
}
if(settings.relay_url.startsWith("fetch:"))
{
settings.cors_proxy = settings.relay_url.slice(6);
settings.relay_url = "fetch";
}
settings.disable_audio = $("disable_audio").checked || settings.disable_audio;
if(settings.disable_audio) new_query_args.set("mute", "1");

Expand Down Expand Up @@ -1852,6 +1857,7 @@
net_device: {
type: settings.net_device_type || "ne2k",
relay_url: settings.relay_url,
cors_proxy: settings.cors_proxy
},
autostart: true,

Expand Down
4 changes: 2 additions & 2 deletions src/browser/starter.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,11 @@ V86.prototype.continue_init = async function(emulator, options)
// TODO: remove bus, use direct calls instead
if(relay_url === "fetch")
{
this.network_adapter = new FetchNetworkAdapter(this.bus);
this.network_adapter = new FetchNetworkAdapter(this.bus, options.net_device);
}
else if(relay_url.startsWith("wisp://") || relay_url.startsWith("wisps://"))
{
this.network_adapter = new WispNetworkAdapter(relay_url, this.bus, options);
this.network_adapter = new WispNetworkAdapter(relay_url, this.bus, options.net_device);
}
else
{
Expand Down
5 changes: 3 additions & 2 deletions src/browser/wisp_network.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/**
* @constructor
*
* @param {String} wisp_url
* @param {BusConnector} bus
* @param {*=} config
*/
Expand All @@ -21,10 +22,10 @@ function WispNetworkAdapter(wisp_url, bus, config)
this.vm_ip = new Uint8Array((config.vm_ip || "192.168.86.100").split(".").map(function(x) { return parseInt(x, 10); }));
this.masquerade = config.masquerade === undefined || !!config.masquerade;
this.vm_mac = new Uint8Array(6);
this.dns_method = config.dns_method || "doh";
this.doh_server = config.doh_server;
this.tcp_conn = {};
this.eth_encoder_buf = create_eth_encoder_buf();
this.dns_method = "doh";
this.doh_server = config.doh_server;

this.bus.register("net" + this.id + "-mac", function(mac) {
this.vm_mac = new Uint8Array(mac.split(":").map(function(x) { return parseInt(x, 16); }));
Expand Down

0 comments on commit e0e8077

Please sign in to comment.