async Task TestDirection(Logger logger, double[] vectorFromThisToDestination, int iteration = 0) { // are all vectors along directionVector? bool neighbor_along_destinationVector_exists = false; foreach (var neighbor in ConnectedNeighborsCanBeUsedForNewRequests) { var thisRegIdVector = RegistrationIdDistance.GetVectorValues(CryptoLibrary, this.Configuration.LocalPeerRegistrationId, vectorFromThisToDestination.Length); var neighborRegIdVector = RegistrationIdDistance.GetVectorValues(CryptoLibrary, neighbor.RemoteRegistrationId, vectorFromThisToDestination.Length); var vectorFromLocalPeerToNeighbor = new double[thisRegIdVector.Length]; for (int i = 0; i < vectorFromLocalPeerToNeighbor.Length; i++) { vectorFromLocalPeerToNeighbor[i] = RegistrationIdDistance.GetDifferenceInLoopedRegistrationIdSpace(thisRegIdVector[i], neighborRegIdVector[i]); } double multProduct = 0; for (int dimensionI = 0; dimensionI < vectorFromThisToDestination.Length; dimensionI++) { multProduct += vectorFromLocalPeerToNeighbor[dimensionI] * vectorFromThisToDestination[dimensionI]; } if (multProduct > 0) { neighbor_along_destinationVector_exists = true; break; } } if (neighbor_along_destinationVector_exists == false) { if (iteration < 8) { if (ConnectedNeighbors.Count < _configuration.AbsoluteMaxNumberOfNeighbors) { logger.WriteToLog_higherLevelDetail_EmitListOfPeers($"no neighbors to destination {MiscProcedures.VectorToString(vectorFromThisToDestination)}, sending REGISTER request... iteration={iteration}", this); // try to fix the pain: connect to neighbors at empty direction await ConnectToNewNeighborAsync(Engine.DateTimeNowUtc, true, vectorFromThisToDestination); if (iteration >= 2) { await Engine.EngineThreadQueue.WaitAsync(TimeSpan.FromSeconds(10), "fixing empty direction 1237"); } await TestDirection(logger, vectorFromThisToDestination, iteration + 1); } else { logger.WriteToLog_lightPain_EmitListOfPeers($"no neighbors to destination {MiscProcedures.VectorToString(vectorFromThisToDestination)} after {iteration} iterations. {ConnectedNeighbors.Count} connected neighbors already", this); } } else { // pain is not fixed logger.WriteToLog_lightPain_EmitListOfPeers($"no neighbors to destination {MiscProcedures.VectorToString(vectorFromThisToDestination)} after {iteration} iterations. {ConnectedNeighbors.Count} connected neighbors", this); } } }