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);
});
if (config.dns) {
config.udp = config.dns;
delete config.dns;
updated = true;
}
return updated;
}
async function createStorage(filename, filetype) {

View File

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

View File

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