// import { HostName, HostNameBase, DnsType, HostNameTemplate, HostComponent } from "./HostName.js"; // export type HostType = "child-gateway" | "root-gateway" | "unknown" | "child-vagrant" | "domain" | "root-vagrant"; // /** // * Let gateway X = the gateway of the start host // * Let gateway Y = closest gateway of the deepest known end host component // * Let gateway Z = the common root gateway of X and Y // * Are we at Z? If not, go upstream and repeat // */ // export class Resolve2 { // public component: string; // public dns: DnsType; // constructor( // host: HostNameBase, // public _type: HostType = "unknown", // public kid: Resolve2 | null = null, // public parent: Resolve2 | null = null, // public gateway: string | null = null // ) { // this.component = host.first.name; // this.dns = host.first.dns; // this._init(host); // this.type = _type; // } // _init(host: HostNameBase) { // let p = host.nameTemplate; // let first = true; // let lastKid: Resolve2 = this; // let kid: Resolve2 = this; // while (p) { // if (!first) { // console.log(host.nameTemplate); // let r = new Resolve2(host, "unknown", kid); // lastKid.parent = r; // kid = r; // console.log(p); // } // p = host.parent; // if (p) { // host = new HostNameTemplate(p); // } // first = false; // } // console.log(this.debugStr); // } // get type() { // return this._type; // } // set type(v: HostType) { // this._type = v; // this.infer("root-gateway", "root-gateway", "child-gateway"); // Children of gateways are always gateways // this.infer("root-vagrant", "child-vagrant", "child-vagrant"); // Intentional as a root-gateway can be a child of a root-vagrant // } // infer(root: string, contagious: string, child: HostType) { // let goUp = (x: Resolve2) => { // if (x.type == root) { // let goUpDomain = (x: Resolve2) => { // x.type = "domain"; // if (x.parent) { // goUpDomain(x.parent); // } // } // if (x.parent) { // goUpDomain(x.parent); // } // } // if (x.type == contagious || x.type == child) { // if (x.kid) { // let goDown = (x: Resolve2) => { // x.type = child; // if (x.kid) { // goDown(x.kid); // } // } // goDown(x.kid); // } // } // else { // if (x.parent) { // goUp(x.parent); // } // } // } // goUp(this); // } // get debugStr() { // let r: Resolve2 | null = this; // let str = ""; // while (r) { // str = `${str}${r.component}${r.type == "unknown" ? "?" : ""}${r.parent == null ? "" : ((r.dns == "dashed") ? "-" : ".")}`; // r = r.parent; // } // return str; // } // get isGateway() { // return this.type == "child-gateway" || this.type == "root-gateway" // } // get resolved(): Resolve2 | null { // let x: Resolve2 | null = this; // while (x && x.type == "unknown") { // x = x.parent; // } // return x; // } // } // /** // * Annotate the host as a root gateway. This means that the domains parenting this domain name // * must be network domains without a burpa gateway. // * // * @returns // */ // export function resolveAsRootGateway(name: HostName): Resolve2 { // let resolve = new Resolve2(name, "root-gateway"); // resolve.gateway = name.nameTemplate; // return resolve; // } // /** // * Annotate the host as a root gateway. This means that the domains parenting this domain name // * must be network domains without a burpa gateway. // * // * @returns // */ // export function resolveAsRootVagrant(name: HostNameBase, gateway: string): Resolve2 { // let resolve = new Resolve2(name, "root-vagrant"); // resolve.gateway = gateway; // return resolve; // }