private static Node GetPreviousSubDomainZoneNode(byte[] key, Node currentNode, int baseDepth) { int k; NodeValue currentValue = currentNode.Value; if (currentValue is null) { //key value does not exists if (currentNode.Children is null) { //no children available; move to previous sibling k = currentNode.K - 1; //find previous node from sibling starting at k - 1 currentNode = currentNode.Parent; } else { if (key.Length == currentNode.Depth) { //current node belongs to the key k = currentNode.K - 1; //find previous node from sibling starting at k - 1 currentNode = currentNode.Parent; } else { //find the previous node for the given k in current node's children k = key[currentNode.Depth]; } } } else { int x = DnsNSECRecordData.CanonicalComparison(currentValue.Key, key); if (x == 0) { //current node value matches the key k = currentNode.K - 1; //find previous node from sibling starting at k - 1 currentNode = currentNode.Parent; } else if (x > 0) { //current node value is larger for the key k = currentNode.K - 1; //find previous node from sibling starting at k - 1 currentNode = currentNode.Parent; } else { //current node value is smaller for the key if (currentNode.Children is null) { //the current node is previous node since no children exists and value is smaller for the key return(currentNode); } else { //find the previous node for the given k in current node's children k = key[currentNode.Depth]; } } } //start reverse tree traversal while ((currentNode is not null) && (currentNode.Depth >= baseDepth)) { Node[] children = currentNode.Children; if (children is not null) { //find previous child node Node child = null; for (int i = k; i > -1; i--) { child = Volatile.Read(ref children[i]); if (child is not null) { bool childNodeHasApexZone = false; NodeValue childValue = child.Value; if (childValue is not null) { AuthZoneNode authZoneNode = childValue.Value; if (authZoneNode is not null) { if (authZoneNode.ApexZone is not null) { childNodeHasApexZone = true; //must stop checking children of the apex of the sub zone } } } if (!childNodeHasApexZone && child.Children is not null) { break; //child has further children so check them first } if (childValue is not null) { AuthZoneNode authZoneNode = childValue.Value; if (authZoneNode is not null) { if (authZoneNode.ParentSideZone is not null) { //is sub domain zone return(child); //child has value so return it } if (authZoneNode.ApexZone is not null) { //is apex zone //skip to next child to avoid listing this auth zone's sub domains child = null; //set null to avoid child being set as current after the loop } } } } } if (child is not null) { //make found child as current k = children.Length - 1; currentNode = child; continue; //start over } } //no child node available; check for current node value { NodeValue value = currentNode.Value; if (value is not null) { AuthZoneNode authZoneNode = value.Value; if (authZoneNode is not null) { if ((authZoneNode.ApexZone is not null) && (currentNode.Depth == baseDepth)) { //current node contains apex zone for the base depth i.e. current zone; return it return(currentNode); } if (authZoneNode.ParentSideZone is not null) { //current node contains sub domain zone; return it return(currentNode); } } } } //move up to parent node for previous sibling k = currentNode.K - 1; currentNode = currentNode.Parent; } return(null); }
private static Node GetNextSubDomainZoneNode(byte[] key, Node currentNode, int baseDepth) { int k; NodeValue currentValue = currentNode.Value; if (currentValue is null) { //key value does not exists if (currentNode.Children is null) { //no children available; move to next sibling k = currentNode.K + 1; //find next node from sibling starting at k + 1 currentNode = currentNode.Parent; } else { if (key.Length == currentNode.Depth) { //current node belongs to the key k = 0; //find next node from first child of current node } else { //find next node for the given k in current node's children k = key[currentNode.Depth]; } } } else { //check if node contains apex zone bool foundApexZone = false; if (currentNode.Depth > baseDepth) { AuthZoneNode authZoneNode = currentValue.Value; if (authZoneNode is not null) { ApexZone apexZone = authZoneNode.ApexZone; if (apexZone is not null) { foundApexZone = true; } } } if (foundApexZone) { //current contains apex for a sub zone; move up to parent node k = currentNode.K + 1; //find next node from sibling starting at k + 1 currentNode = currentNode.Parent; } else { int x = DnsNSECRecordData.CanonicalComparison(currentValue.Key, key); if (x == 0) { //current node value matches the key k = 0; //find next node from children starting at k } else if (x > 0) { //current node value is larger for the key thus current is the next node return(currentNode); } else { //current node value is smaller for the key k = key[currentNode.Depth]; //find next node from children starting at k = key[depth] } } } //start tree traversal while ((currentNode is not null) && (currentNode.Depth >= baseDepth)) { Node[] children = currentNode.Children; if (children is not null) { //find next child node Node child = null; for (int i = k; i < children.Length; i++) { child = Volatile.Read(ref children[i]); if (child is not null) { NodeValue childValue = child.Value; if (childValue is not null) { AuthZoneNode authZoneNode = childValue.Value; if (authZoneNode is not null) { if (authZoneNode.ParentSideZone is not null) { //is sub domain zone return(child); //child has value so return it } if (authZoneNode.ApexZone is not null) { //is apex zone //skip to next child to avoid listing this auth zone's sub domains child = null; //set null to avoid child being set as current after the loop continue; } } } if (child.Children is not null) { break; } } } if (child is not null) { //make found child as current k = 0; currentNode = child; continue; //start over } } //no child nodes available; move up to parent node k = currentNode.K + 1; currentNode = currentNode.Parent; } return(null); }