renamed `dns` settings to `udp`

This commit is contained in:
tigerbot 2017-10-10 11:32:18 -06:00
parent 485a223f86
commit 8371170a14
3 changed files with 19 additions and 13 deletions

View File

@ -67,6 +67,12 @@ function fixRawConfig(config) {
updateDomains(config[key].domains); updateDomains(config[key].domains);
}); });
if (config.dns) {
config.udp = config.dns;
delete config.dns;
updated = true;
}
return updated; return updated;
} }
async function createStorage(filename, filetype) { async function createStorage(filename, filetype) {

View File

@ -132,7 +132,7 @@ var tcpSchema = {
} }
}; };
var dnsSchema = { var udpSchema = {
type: 'object' type: 'object'
, properties: { , properties: {
bind: { type: 'array', items: portSchema } bind: { type: 'array', items: portSchema }
@ -172,12 +172,12 @@ var deviceSchema = {
var mainSchema = { var mainSchema = {
type: 'object' type: 'object'
, required: [ 'http', 'tls', 'tcp', 'dns', 'mdns', 'ddns' ] , required: [ 'http', 'tls', 'tcp', 'udp', 'mdns', 'ddns' ]
, properties: { , properties: {
http: httpSchema http: httpSchema
, tls: tlsSchema , tls: tlsSchema
, tcp: tcpSchema , tcp: tcpSchema
, dns: dnsSchema , udp: udpSchema
, mdns: mdnsSchema , mdns: mdnsSchema
, ddns: ddnsSchema , ddns: ddnsSchema
, socks5: socks5Schema , socks5: socks5Schema
@ -264,7 +264,7 @@ class ConfigChanger {
this.tls.modules = new ModuleList(this.tls.modules); this.tls.modules = new ModuleList(this.tls.modules);
this.tls.domains = new DomainList(this.tls.domains); this.tls.domains = new DomainList(this.tls.domains);
this.tcp.modules = new ModuleList(this.tcp.modules); this.tcp.modules = new ModuleList(this.tcp.modules);
this.dns.modules = new ModuleList(this.dns.modules); this.udp.modules = new ModuleList(this.udp.modules);
} }
update(update) { update(update) {
@ -292,9 +292,9 @@ class ConfigChanger {
update.tcp.modules.forEach(self.tcp.modules.add.bind(self.tcp.modules)); update.tcp.modules.forEach(self.tcp.modules.add.bind(self.tcp.modules));
delete update.tcp.modules; delete update.tcp.modules;
} }
if (update.dns && update.dns.modules) { if (update.udp && update.udp.modules) {
update.dns.modules.forEach(self.dns.modules.add.bind(self.dns.modules)); update.udp.modules.forEach(self.udp.modules.add.bind(self.udp.modules));
delete update.dns.modules; delete update.udp.modules;
} }
function mergeSettings(orig, changes) { function mergeSettings(orig, changes) {

View File

@ -96,11 +96,11 @@ module.exports.create = function (deps, config) {
} }
function dnsListener(msg) { function dnsListener(msg) {
if (!Array.isArray(config.dns.modules)) { if (!Array.isArray(config.udp.modules)) {
return; return;
} }
var socket = require('dgram').createSocket('udp4'); var socket = require('dgram').createSocket('udp4');
config.dns.modules.forEach(function (mod) { config.udp.modules.forEach(function (mod) {
if (mod.type !== 'proxy') { if (mod.type !== 'proxy') {
console.warn('found bad DNS module', mod); console.warn('found bad DNS module', mod);
return; return;
@ -240,13 +240,13 @@ module.exports.create = function (deps, config) {
listenPromises.push(listeners.tcp.add(port, netHandler)); listenPromises.push(listeners.tcp.add(port, netHandler));
}); });
if (config.dns.bind) { if (config.udp.bind) {
if (Array.isArray(config.dns.bind)) { if (Array.isArray(config.udp.bind)) {
config.dns.bind.map(function (port) { config.udp.bind.map(function (port) {
listenPromises.push(listeners.udp.add(port, dnsListener)); listenPromises.push(listeners.udp.add(port, dnsListener));
}); });
} else { } else {
listenPromises.push(listeners.udp.add(config.dns.bind, dnsListener)); listenPromises.push(listeners.udp.add(config.udp.bind, dnsListener));
} }
} }