Skip to content

Commit

Permalink
make doh_server and cors_proxy configurable in starter.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ProgrammerIn-wonderland committed Aug 4, 2024
1 parent e7cbcf0 commit 90d3ddf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 0 additions & 2 deletions src/browser/net_utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const DOH_SERVER = "https://dns.google/resolve";

// https://www.iana.org/assignments/ieee-802-numbers/ieee-802-numbers.xhtml
const ETHERTYPE_IPV4 = 0x0800;
const ETHERTYPE_ARP = 0x0806;
Expand Down
4 changes: 2 additions & 2 deletions src/browser/starter.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,10 @@ V86.prototype.continue_init = async function(emulator, options)
{
if(options.network_relay_url === "fetch")
{
this.network_adapter = new FetchNetworkAdapter(this.bus);
this.network_adapter = new FetchNetworkAdapter(this.bus, options);
}
else if(options.network_relay_url.startsWith("wisp://") || options.network_relay_url.startsWith("wisps://")) {
this.network_adapter = new WispNetworkAdapter(options.network_relay_url, this.bus);
this.network_adapter = new WispNetworkAdapter(options.network_relay_url, this.bus, options);
}
else
{
Expand Down
7 changes: 4 additions & 3 deletions src/browser/wisp_network.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"use strict";
const DEFAULT_DOH_SERVER = "cloudflare-dns.com";

/**
* @constructor
Expand All @@ -18,7 +19,7 @@ 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.doh_server = config.doh_server || DEFAULT_DOH_SERVER;
this.tcp_conn = {};

this.bus.register("net" + this.id + "-mac", function(mac) {
Expand Down Expand Up @@ -187,6 +188,7 @@ WispNetworkAdapter.prototype.send = function(data)
{
let packet = {};
parse_eth(data, packet);

if(packet.tcp) {
let reply = {};
reply.eth = { ethertype: ETHERTYPE_IPV4, src: this.router_mac, dest: packet.eth.src };
Expand Down Expand Up @@ -280,8 +282,7 @@ WispNetworkAdapter.prototype.send = function(data)
dest: packet.ipv4.src,
};
reply.udp = { sport: 53, dport: packet.udp.sport };
const fetchURL = "https://cloudflare-dns.com/dns-query";
const result = await ((await fetch(fetchURL, {method: "POST", headers: [["content-type", "application/dns-message"]], body: packet.udp.data})).arrayBuffer());
const result = await ((await fetch(`https://${this.doh_server}/dns-query`, {method: "POST", headers: [["content-type", "application/dns-message"]], body: packet.udp.data})).arrayBuffer());
reply.udp.data = new Uint8Array(result);
this.receive(make_packet(reply));

Expand Down

0 comments on commit 90d3ddf

Please sign in to comment.