From 258882225811288de7ad3704888e6951155e8616 Mon Sep 17 00:00:00 2001 From: Garrett K Date: Sun, 14 Mar 2021 15:18:48 +0000 Subject: [PATCH] 0.3.14 before crawlPath cleanup --- backend/retrieve_path_full.php | 3 - includes/App.class.php | 128 ++++++++++++++++++--------------- includes/content-path2.php | 3 +- 3 files changed, 71 insertions(+), 63 deletions(-) diff --git a/backend/retrieve_path_full.php b/backend/retrieve_path_full.php index b965ec8..88c00db 100755 --- a/backend/retrieve_path_full.php +++ b/backend/retrieve_path_full.php @@ -25,10 +25,7 @@ if($_SERVER['REQUEST_METHOD'] == 'POST'){ // Create $path include_once $_SERVER['DOCUMENT_ROOT'].'/includes/content-path2.php'; - //include_once $_SERVER['DOCUMENT_ROOT'].'/includes/content-path.php'; - //error_log('Debug (pathArray): '.json_encode($pathArray)); $validate->returnData['success'] = $qls->App->buildPathFull2($pathArray); - //$validate->returnData['success'] = $qls->App->buildPathFull($path, $connectorCode39); } echo json_encode($validate->returnData); } diff --git a/includes/App.class.php b/includes/App.class.php index f5803f7..ef57cce 100755 --- a/includes/App.class.php +++ b/includes/App.class.php @@ -3232,7 +3232,7 @@ var $qls; return str_replace('‑', '-', $string); } - function crawlPath2($objID, $objFace, $objDepth, $objPort, $detectDivergence=false, $selected=true, &$pathArray=array(), &$visitedArray=array(), $newConnection=true, $outerDirection=0, $innerDirection=0, $outerDirectionOffset=0, $initial=true){ + function crawlPath2($objID, $objFace, $objDepth, $objPort, $detectDivergence=false, &$pathArray=array(array(array(),array())), &$visitedArray=array(), $pathArrayIndex=0, $outerDirection=0, $innerDirection=0, $initial=true){ // $outerDirection - 0=up 1=down // $innerDirection - 0=near 1=far @@ -3265,29 +3265,12 @@ var $qls; 'objFace' => $objFace, 'objDepth' => $objDepth, 'objPort' => $objPort, - 'selected' => $selected, + 'selected' => $initial, 'length' => $length, 'mediaTypeID' => $mediaTypeID, 'connectorTypeID' => $connectorTypeID ); - // Clear selected flag - $selected = false; - - // Prepare to add port to pathArray - if($newConnection) { - - // Grow pathArray - if($outerDirection == 0) { - array_unshift($pathArray, array(array(), array())); - } else { - array_push($pathArray, array(array(), array())); - } - } - - // Determine path array index - $pathArrayIndex = ($outerDirection == 0) ? $outerDirectionOffset : ((count($pathArray)-1)-$outerDirectionOffset); - // Determine connection array index if($outerDirection == 0) { $connectionArrayIndex = ($innerDirection == 0) ? 1 : 0; @@ -3295,36 +3278,14 @@ var $qls; $connectionArrayIndex = ($innerDirection == 0) ? 0 : 1; } - // Flip connection array index if propogating backwards - $connectionArrayIndex = ($outerDirectionOffset) ? ($connectionArrayIndex+1)-($connectionArrayIndex*2) : $connectionArrayIndex; - - error_log('Debug (pathArray): '.json_encode($pathArray)); - error_log('Debug (portAddressString): '.$portAddressString); - error_log('Debug (newConnection): '.$newConnection); - error_log('Debug (outerDirection): '.$outerDirection); - error_log('Debug (innerDirection): '.$innerDirection); - error_log('Debug (outerDirectionOffset): '.$outerDirectionOffset); - error_log('Debug (initial): '.$initial); - error_log('Debug (pathArrayIndex): '.$pathArrayIndex); - error_log('Debug (connectionArrayIndex): '.$connectionArrayIndex); - // Add port to pathArray - if(isset($pathArray[$pathArrayIndex][$connectionArrayIndex])) { - array_push($pathArray[$pathArrayIndex][$connectionArrayIndex], $portArray); - } else { - error_log('Debug: array not set'); - } - error_log('Debug (pathArray): '.json_encode($pathArray)); - error_log('----------------------'); + array_push($pathArray[$pathArrayIndex][$connectionArrayIndex], $portArray); // // Crawl connected ports // if(isset($this->inventoryArray[$objID][$objFace][$objDepth][$objPort])) { - // Clear new connection flag - $newConnection = false; - // Flip connection array index $newInnerDirection = ($innerDirection == 0) ? 1 : 0; @@ -3344,15 +3305,12 @@ var $qls; if(!in_array($remotePortAddressMD5, $visitedArray)) { - error_log('Debug: crawl port'); + // Get path array index... it could change during recursion + $pathArrayIndex = $this->getCurrentPathIndex($pathArray, $portAddressMD5); - $this->crawlPath2($remoteObjID, $remoteObjFace, $remoteObjDepth, $remoteObjPort, $detectDivergence, $selected, $pathArray, $visitedArray, $newConnection, $outerDirection, $newInnerDirection, $outerDirectionOffset, false); + $this->crawlPath2($remoteObjID, $remoteObjFace, $remoteObjDepth, $remoteObjPort, $detectDivergence, $pathArray, $visitedArray, $pathArrayIndex, $outerDirection, $newInnerDirection, false); } } - } else if($initial){ - - // Correct innerDirection when processing seed port - $innerDirection = 1; } // @@ -3361,14 +3319,10 @@ var $qls; if(isset($this->peerArray[$objID][$objFace][$objDepth])) { // Set direction for seed port - $outerDirection = ($initial) ? 1 : $outerDirection; - $innerDirection = ($initial) ? 1 : $innerDirection; - - // Adjust direction offset - $newConnection = ($innerDirection == 0) ? false : true; - - // If this is a near port and we are considering trunk peers, then we must be back propagating - $newOuterDirectionOffset = ($innerDirection == 0) ? $outerDirectionOffset + 1 : $outerDirectionOffset; + if($initial) { + $outerDirection = 1; + $innerDirection = 1; + } // Loop over each local port connection $peer = $this->peerArray[$objID][$objFace][$objDepth]; @@ -3384,15 +3338,73 @@ var $qls; $remotePortAddressMD5 = md5($remotePortAddressString); if(!in_array($remotePortAddressMD5, $visitedArray)) { - error_log('Debug: crawl trunk'); + + // Get path array index... it could change during recursion + $pathArrayIndex = $this->getCurrentPathIndex($pathArray, $portAddressMD5); + + // Grow path array + if($outerDirection == 0) { + if($innerDirection == 1) { + if($pathArrayIndex == 0) { + array_unshift($pathArray, array(array(),array())); + } else { + $pathArrayIndex--; + } + } else { + $outerDirection = 1; + $pathArrayIndex++; + if(!isset($pathArray[$pathArrayIndex])) { + array_push($pathArray, array(array(),array())); + } + } + } else { + if($innerDirection == 1) { + $pathArrayIndex++; + if(!isset($pathArray[$pathArrayIndex])) { + array_push($pathArray, array(array(),array())); + } + } else { + $outerDirection = 0; + if($pathArrayIndex == 0) { + array_unshift($pathArray, array(array(),array())); + } + $pathArrayIndex--; + } + } + $innerDirection = 0; - $this->crawlPath2($remoteObjID, $remoteObjFace, $remoteObjDepth, $remoteObjPort, $detectDivergence, $selected, $pathArray, $visitedArray, $newConnection, $outerDirection, $innerDirection, $newOuterDirectionOffset, false); + $this->crawlPath2($remoteObjID, $remoteObjFace, $remoteObjDepth, $remoteObjPort, $detectDivergence, $pathArray, $visitedArray, $pathArrayIndex, $outerDirection, $innerDirection, false); } } return $pathArray; } + function getCurrentPathIndex($pathArray, $currentPortAddressMD5){ + error_log('Debug (current port): '.$currentPortAddressMD5); + foreach($pathArray as $pathArrayIndex => $connection) { + foreach($connection as $connectionSide) { + foreach($connectionSide as $port) { + $objID = $port['objID']; + $objFace = $port['objFace']; + $objDepth = $port['objDepth']; + $objPort = $port['objPort']; + + $portAddressString = $objID.'_'.$objFace.'_'.$objDepth.'_'.$objPort; + $portAddressMD5 = md5($portAddressString); + + error_log('Debug (port): '.$portAddressString.' - '.$portAddressMD5); + + if($currentPortAddressMD5 == $portAddressMD5) { + return $pathArrayIndex; + } + } + } + } + + return false; + } + function crawlPath($objID, $objFace, $objDepth, $objPort, $detectDivergence=false){ // pathArray contains all necessary path data diff --git a/includes/content-path2.php b/includes/content-path2.php index 5567bae..48ebbf1 100755 --- a/includes/content-path2.php +++ b/includes/content-path2.php @@ -16,8 +16,7 @@ $selectedObjDepth = $objDepth; $selectedObjPort = $objPort; $detectDivergence = true; -//$pathArray = $qls->App->crawlPath($selectedObjID, $selectedObjFace, $selectedObjDepth, $selectedObjPort, $detectDivergence); + $pathArray = $qls->App->crawlPath2($selectedObjID, $selectedObjFace, $selectedObjDepth, $selectedObjPort, $detectDivergence); -//error_log('Debug (pathArray2): '.json_encode($pathArray)); ?>