2020-03-30 11:44:18 +00:00
|
|
|
export interface AddressTarget {
|
|
|
|
target_ip: string;
|
|
|
|
target_port?: number;
|
|
|
|
}
|
2019-10-24 16:05:11 +00:00
|
|
|
|
2020-03-30 11:44:18 +00:00
|
|
|
export interface ResolveOptions {
|
|
|
|
timeout?: number;
|
2021-03-18 11:55:35 +00:00
|
|
|
allowCache?: boolean;
|
|
|
|
maxDepth?: number;
|
|
|
|
|
|
|
|
allowSrv?: boolean;
|
|
|
|
allowCName?: boolean;
|
|
|
|
allowAny?: boolean;
|
|
|
|
allowA?: boolean;
|
|
|
|
allowAAAA?: boolean;
|
2020-03-30 11:44:18 +00:00
|
|
|
}
|
2019-10-24 16:05:11 +00:00
|
|
|
|
2020-03-30 11:44:18 +00:00
|
|
|
export const default_options: ResolveOptions = {
|
|
|
|
timeout: 5000,
|
2021-03-18 11:55:35 +00:00
|
|
|
allowCache: true,
|
|
|
|
maxDepth: 5
|
|
|
|
};
|
|
|
|
|
|
|
|
export interface DNSResolveOptions {
|
|
|
|
timeout?: number;
|
|
|
|
allowCache?: boolean;
|
|
|
|
maxDepth?: number;
|
|
|
|
|
|
|
|
allowSrv?: boolean;
|
|
|
|
allowCName?: boolean;
|
|
|
|
allowAny?: boolean;
|
|
|
|
allowA?: boolean;
|
|
|
|
allowAAAA?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface DNSAddress {
|
|
|
|
hostname: string,
|
|
|
|
port: number
|
|
|
|
}
|
|
|
|
|
|
|
|
export type DNSResolveResult = {
|
|
|
|
status: "success",
|
|
|
|
originalAddress: DNSAddress,
|
|
|
|
resolvedAddress: DNSAddress
|
|
|
|
} | {
|
|
|
|
status: "error",
|
|
|
|
message: string
|
|
|
|
} | {
|
|
|
|
status: "empty-result"
|
|
|
|
};
|
|
|
|
|
|
|
|
export interface DNSProvider {
|
|
|
|
resolveAddress(address: DNSAddress, options: DNSResolveOptions) : Promise<DNSResolveResult>;
|
|
|
|
resolveAddressIPv4(address: DNSAddress, options: DNSResolveOptions) : Promise<DNSResolveResult>;
|
|
|
|
}
|
|
|
|
|
|
|
|
let provider: DNSProvider;
|
|
|
|
export function getDNSProvider() : DNSProvider {
|
|
|
|
return provider;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setDNSProvider(newProvider: DNSProvider) {
|
|
|
|
provider = newProvider;
|
|
|
|
}
|