This commit is contained in:
parent
d16f8c3d8a
commit
da5285ac9b
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "nodename-core",
|
"name": "nodename-core",
|
||||||
"version": "0.3.0",
|
"version": "0.3.1",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"types": "lib/index.d.ts",
|
"types": "lib/index.d.ts",
|
||||||
"author": "Fabian Stamm <dev@fabianstamm.de>",
|
"author": "Fabian Stamm <dev@fabianstamm.de>",
|
||||||
|
@ -50,7 +50,7 @@ console.timeEnd("complete 10 answers")
|
|||||||
class TestMonitoringPlugin implements MonitoringPlugin {
|
class TestMonitoringPlugin implements MonitoringPlugin {
|
||||||
constructor() { }
|
constructor() { }
|
||||||
async init(core) { }
|
async init(core) { }
|
||||||
Priority = 0
|
priority = 0
|
||||||
onRequest(domain, hostname, type) { }
|
onRequest(domain, hostname, type) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,14 +81,14 @@ class ARR extends RecourceRecord {
|
|||||||
|
|
||||||
class TestQuestionPlugin implements QuestionPlugin {
|
class TestQuestionPlugin implements QuestionPlugin {
|
||||||
private Core: DnsCore
|
private Core: DnsCore
|
||||||
QuestionTypes = [RecordTypes.A]
|
question_types = [RecordTypes.A]
|
||||||
Priority = 0
|
priority = 0
|
||||||
async init(core) {
|
async init(core) {
|
||||||
this.Core = core;
|
this.Core = core;
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleQuestion(question: Question, request: AnswerHandler, next: () => void) {
|
async handleQuestion(question: Question, request: AnswerHandler, next: () => void) {
|
||||||
assert(this.QuestionTypes.find(e => e === <any>question.QTYPE), "Handler was called with not supported question type")
|
assert(this.question_types.find(e => e === <any>question.QTYPE), "Handler was called with not supported question type")
|
||||||
let parts = question.QNAME.split(".")
|
let parts = question.QNAME.split(".")
|
||||||
let domain = parts.splice(-2, 2).join(".")
|
let domain = parts.splice(-2, 2).join(".")
|
||||||
let hostname = parts.join(".");
|
let hostname = parts.join(".");
|
||||||
@ -100,7 +100,7 @@ class TestQuestionPlugin implements QuestionPlugin {
|
|||||||
|
|
||||||
class TestListenerPlugin implements ListenerPlugin {
|
class TestListenerPlugin implements ListenerPlugin {
|
||||||
async init(core) { }
|
async init(core) { }
|
||||||
Priority = 0;
|
priority = 0;
|
||||||
callback: (data: Buffer, sender: string, max_size?: number) => Promise<Buffer>;
|
callback: (data: Buffer, sender: string, max_size?: number) => Promise<Buffer>;
|
||||||
registerCallback(callback) {
|
registerCallback(callback) {
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
@ -120,9 +120,9 @@ class TestStoragePlugin implements StoragePlugin {
|
|||||||
this.re = record;
|
this.re = record;
|
||||||
}
|
}
|
||||||
|
|
||||||
Priority = 0
|
priority = 0
|
||||||
NoCache = false
|
no_cache = false
|
||||||
RecordTypes = [RecordTypes.A]
|
record_types = [RecordTypes.A]
|
||||||
isResponsible(domain: string) {
|
isResponsible(domain: string) {
|
||||||
// console.log("Is responsible")
|
// console.log("Is responsible")
|
||||||
return true
|
return true
|
||||||
|
30
src/test.ts
30
src/test.ts
@ -351,20 +351,20 @@ describe("DNS Core", function () {
|
|||||||
|
|
||||||
core.addListener({
|
core.addListener({
|
||||||
init: async (c) => { assert.exists(c, "Core not defined on Plugin init") },
|
init: async (c) => { assert.exists(c, "Core not defined on Plugin init") },
|
||||||
Priority: 0,
|
priority: 0,
|
||||||
registerCallback: () => { }
|
registerCallback: () => { }
|
||||||
})
|
})
|
||||||
|
|
||||||
core.addMonitoring({
|
core.addMonitoring({
|
||||||
init: async (c) => { assert.exists(c, "Core not defined on Plugin init") },
|
init: async (c) => { assert.exists(c, "Core not defined on Plugin init") },
|
||||||
Priority: 0,
|
priority: 0,
|
||||||
onRequest: () => { }
|
onRequest: () => { }
|
||||||
})
|
})
|
||||||
|
|
||||||
core.addQuestion({
|
core.addQuestion({
|
||||||
init: async (c) => { assert.exists(c, "Core not defined on Plugin init") },
|
init: async (c) => { assert.exists(c, "Core not defined on Plugin init") },
|
||||||
QuestionTypes: [RecordTypes.A],
|
question_types: [RecordTypes.A],
|
||||||
Priority: 0,
|
priority: 0,
|
||||||
handleQuestion: async () => { },
|
handleQuestion: async () => { },
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -373,9 +373,9 @@ describe("DNS Core", function () {
|
|||||||
getRecords: async () => undefined,
|
getRecords: async () => undefined,
|
||||||
init: async (c) => { assert.exists(c, "Core not defined on Plugin init") },
|
init: async (c) => { assert.exists(c, "Core not defined on Plugin init") },
|
||||||
isResponsible: () => true,
|
isResponsible: () => true,
|
||||||
NoCache: false,
|
no_cache: false,
|
||||||
Priority: 0,
|
priority: 0,
|
||||||
RecordTypes: [RecordTypes.A]
|
record_types: [RecordTypes.A]
|
||||||
})
|
})
|
||||||
|
|
||||||
return core.start();
|
return core.start();
|
||||||
@ -425,9 +425,9 @@ class TestStoragePlugin implements StoragePlugin {
|
|||||||
this.re = record;
|
this.re = record;
|
||||||
}
|
}
|
||||||
|
|
||||||
Priority = 0
|
priority = 0
|
||||||
NoCache = false
|
no_cache = false
|
||||||
RecordTypes = [RecordTypes.A]
|
record_types = [RecordTypes.A]
|
||||||
isResponsible(domain: string) {
|
isResponsible(domain: string) {
|
||||||
// console.log("Is responsible")
|
// console.log("Is responsible")
|
||||||
return true
|
return true
|
||||||
@ -450,7 +450,7 @@ class TestMonitoringPlugin implements MonitoringPlugin {
|
|||||||
constructor(private should: { domain: string, hostname: string, type: string }) { }
|
constructor(private should: { domain: string, hostname: string, type: string }) { }
|
||||||
|
|
||||||
async init(core) { assert.exists(core, "TestMonitoringPlugin init no core object") }
|
async init(core) { assert.exists(core, "TestMonitoringPlugin init no core object") }
|
||||||
Priority = 0
|
priority = 0
|
||||||
onRequest(domain, hostname, type) {
|
onRequest(domain, hostname, type) {
|
||||||
assert.equal(this.should.domain, domain, "Domain value wrong")
|
assert.equal(this.should.domain, domain, "Domain value wrong")
|
||||||
assert.equal(this.should.hostname, hostname, "Domain value wrong")
|
assert.equal(this.should.hostname, hostname, "Domain value wrong")
|
||||||
@ -486,15 +486,15 @@ class ARR extends RecourceRecord {
|
|||||||
|
|
||||||
class TestQuestionPlugin implements QuestionPlugin {
|
class TestQuestionPlugin implements QuestionPlugin {
|
||||||
private Core: DnsCore
|
private Core: DnsCore
|
||||||
QuestionTypes = [RecordTypes.A]
|
question_types = [RecordTypes.A]
|
||||||
Priority = 0
|
priority = 0
|
||||||
async init(core) {
|
async init(core) {
|
||||||
assert.exists(core, "TestQuestionPlugin init no core object")
|
assert.exists(core, "TestQuestionPlugin init no core object")
|
||||||
this.Core = core;
|
this.Core = core;
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleQuestion(question: Question, request: AnswerHandler, next: () => void) {
|
async handleQuestion(question: Question, request: AnswerHandler, next: () => void) {
|
||||||
assert(this.QuestionTypes.find(e => e === <any>question.QTYPE), "Handler was called with not supported questin type")
|
assert(this.question_types.find(e => e === <any>question.QTYPE), "Handler was called with not supported questin type")
|
||||||
let parts = question.QNAME.split(".")
|
let parts = question.QNAME.split(".")
|
||||||
let domain = parts.splice(-2, 2).join(".")
|
let domain = parts.splice(-2, 2).join(".")
|
||||||
let hostname = parts.join(".");
|
let hostname = parts.join(".");
|
||||||
@ -506,7 +506,7 @@ class TestQuestionPlugin implements QuestionPlugin {
|
|||||||
|
|
||||||
class TestListenerPlugin implements ListenerPlugin {
|
class TestListenerPlugin implements ListenerPlugin {
|
||||||
async init(core) { assert.exists(core, "TestListenerPlugin init no core object") }
|
async init(core) { assert.exists(core, "TestListenerPlugin init no core object") }
|
||||||
Priority = 0;
|
priority = 0;
|
||||||
callback: (data: Buffer, sender: string, max_size?: number) => Promise<Buffer>;
|
callback: (data: Buffer, sender: string, max_size?: number) => Promise<Buffer>;
|
||||||
registerCallback(callback) {
|
registerCallback(callback) {
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
|
Loading…
Reference in New Issue
Block a user