void WriteToLog_deepDetail(string msg) { if (WriteToLog_deepDetail_enabled) { _visionChannel?.Emit(_visionChannelSourceId, VisionChannelModuleName, AttentionLevel.deepDetail, msg); } }
internal void Log_deepDetail(string message) { if (_visionChannel?.GetAttentionTo(_visionChannelSourceId, VisionChannelModuleName) <= AttentionLevel.deepDetail) { _visionChannel?.Emit(_visionChannelSourceId, VisionChannelModuleName, AttentionLevel.deepDetail, message); } }
public async Task SendInvite_AtoX_Async() { _xUser.ContactBookUsersByRegId.Add(_aLocalDrpPeer.Configuration.LocalPeerRegistrationId, _aUser.UserId); var aUserCertificate = UserCertificate.GenerateKeyPairsAndSignAtSingleDevice(_a.CryptoLibrary, _aUser.UserId, _aUser.UserRootPrivateKeys, DateTime.UtcNow.AddHours(-1), DateTime.UtcNow.AddHours(1)); var message = $"test Dcomms message {new Random().Next()}"; _a.Configuration.VisionChannel.Emit(_a.Configuration.VisionChannelSourceId, DrpTesterVisionChannelModuleName, AttentionLevel.guiActivity, $"sending message: {message}"); _aLocalDrpPeer.BeginSendShortSingleMessage(aUserCertificate, _xLocalDrpPeer.Configuration.LocalPeerRegistrationId, _xUser.UserId, message, null, (exc) => { if (exc == null) { _visionChannel.Emit(_a.Configuration.VisionChannelSourceId, DrpTesterVisionChannelModuleName, AttentionLevel.guiActivity, $"message was sent successfully"); } else { _visionChannel.Emit(_a.Configuration.VisionChannelSourceId, DrpTesterVisionChannelModuleName, AttentionLevel.mediumPain, $"message was not sent successfully"); } }); }
void BeginTestInvites(InvitesTest test, Action cb = null) { var peer1 = test.Peers[_inviteTestsCounter++ % test.Peers.Count]; _retry: var peer2 = test.Peers[_rnd.Next(test.Peers.Count)]; if (peer1 == peer2) { goto _retry; } EmitAllPeers(AttentionLevel.guiActivity, $"testing message from {peer1} to {peer2} ({test.counter}/{test.MaxCount}) {DateTime.Now}"); var userCertificate1 = UserCertificate.GenerateKeyPairsAndSignAtSingleDevice(peer1.DrpPeerEngine.CryptoLibrary, peer1.UserId, peer1.UserRootPrivateKeys, DateTime.UtcNow.AddHours(-1), DateTime.UtcNow.AddHours(1)); var text = $"test{_rnd.Next()}-{_rnd.Next()}_from_{peer1}_to_{peer2}"; peer1.LocalDrpPeer.BeginSendShortSingleMessage(userCertificate1, peer2.LocalDrpPeer.Configuration.LocalPeerRegistrationId, peer2.UserId, text, null, (exc) => { test.counter++; if (peer2.LatestReceivedTextMessage == text) { test.successfulCount++; _visionChannel.Emit(peer1.DrpPeerEngine.Configuration.VisionChannelSourceId, DrpTesterVisionChannelModuleName, AttentionLevel.guiActivity, $"successfully tested message from {peer1} to {peer2}. success rate = {(double)test.successfulCount * 100 / test.counter}% ({test.successfulCount}/{test.counter})"); } else { EmitAllPeers(AttentionLevel.mediumPain, $"test message failed from {peer1} to {peer2}: received '{peer2.LatestReceivedTextMessage}', expected '{text}"); } if (test.counter < test.MaxCount) { BeginTestInvites(test, cb); } else { var successRatePercents = (double)test.successfulCount * 100 / test.counter; var level = successRatePercents == 100 ? AttentionLevel.guiActivity : (successRatePercents > 99 ? AttentionLevel.lightPain : AttentionLevel.mediumPain); _visionChannel.Emit(peer1.DrpPeerEngine.Configuration.VisionChannelSourceId, DrpTesterVisionChannelModuleName, level, $"messages test is complete: success rate = {successRatePercents}%"); cb?.Invoke(); } }); }
void AfterEpRegistration_ContinueIfConnectedToEnoughNeighbors(Stopwatch waitForNeighborsSw) { if (_userApp.LocalDrpPeer.ConnectedNeighbors.Count >= _userApp.LocalDrpPeer.Configuration.MinDesiredNumberOfNeighbors) { waitForNeighborsSw.Stop(); var level = waitForNeighborsSw.Elapsed.TotalMilliseconds < 10000 ? AttentionLevel.guiActivity : AttentionLevel.lightPain; _visionChannel.EmitListOfPeers(_userApp.DrpPeerEngine.Configuration.VisionChannelSourceId, DrpTesterVisionChannelModuleName, AttentionLevel.guiActivity, $"{_userApp} is connected with {_userApp.LocalDrpPeer.ConnectedNeighbors.Count} neighbors (in {waitForNeighborsSw.Elapsed.TotalMilliseconds}ms), enough to continue"); SendMessage(); } else { _visionChannel.Emit(_userApp.DrpPeerEngine.Configuration.VisionChannelSourceId, DrpTesterVisionChannelModuleName, AttentionLevel.higherLevelDetail, $"{_userApp} is connected with {_userApp.LocalDrpPeer.ConnectedNeighbors.Count} neighbors, not enough to continue with more users"); _userApp.DrpPeerEngine.EngineThreadQueue.EnqueueDelayed(TimeSpan.FromSeconds(1), () => { AfterEpRegistration_ContinueIfConnectedToEnoughNeighbors(waitForNeighborsSw); }, "userEngine_AfterEpRegistration_ContinueIfConnectedToEnoughNeighbors53809"); } }
void BeginCreateLocalEpOrContinue(int localEpIndex) { if (localEpIndex >= NumberOfLocalInterconnectedEpEngines) { // continue _visionChannel.EmitListOfPeers("", DrpTesterVisionChannelModuleName, AttentionLevel.guiActivity, $"connected all EPs"); foreach (var ep2 in _localEpApps) { ep2.DrpPeerRegistrationConfiguration.MinDesiredNumberOfNeighborsSatisfied_WorstNeighborDestroyIntervalS = null; ep2.DrpPeerRegistrationConfiguration.AbsoluteMaxNumberOfNeighbors = EpAbsoluteMaxDesiredNumberOfNeighbors; ep2.DrpPeerRegistrationConfiguration.SoftMaxNumberOfNeighbors = EpSoftMaxDesiredNumberOfNeighbors; ep2.DrpPeerRegistrationConfiguration.MinDesiredNumberOfNeighbors = EpMinDesiredNumberOfNeighbors; } BeginCreateUserAppOrContinue(0); return; } var epEngine = new DrpPeerEngine(new DrpPeerEngineConfiguration { InsecureRandomSeed = _insecureRandom.Next(), LocalPort = (ushort)(LocalInterconnectedEpEnginesBasePort + localEpIndex), VisionChannel = _visionChannel, VisionChannelSourceId = $"{VisionChannelSourceIdPrefix}EP{localEpIndex}", SandboxModeOnly_NumberOfDimensions = NumberOfDimensions });; var epLocalDrpPeerConfig = LocalDrpPeerConfiguration.Create(epEngine.CryptoLibrary, NumberOfDimensions); epLocalDrpPeerConfig.MinDesiredNumberOfNeighbors = null; epLocalDrpPeerConfig.AbsoluteMaxNumberOfNeighbors = null; epLocalDrpPeerConfig.SoftMaxNumberOfNeighbors = null; epLocalDrpPeerConfig.MinDesiredNumberOfNeighborsSatisfied_WorstNeighborDestroyIntervalS = null; var epApp = new DrpTesterPeerApp(epEngine, epLocalDrpPeerConfig); epEngine.BeginCreateLocalPeer(epLocalDrpPeerConfig, epApp, (localDrpPeer) => { var connectToEpsList = _localEpApps.Select(x => x.LocalDrpPeerEndpoint).ToList(); // make a list of EPs WITHOUT this new EP epApp.LocalDrpPeer = localDrpPeer; _localEpApps.Add(epApp); _visionChannel.Emit(epEngine.Configuration.VisionChannelSourceId, DrpTesterVisionChannelModuleName, AttentionLevel.guiActivity, $"created local EP #{localEpIndex}/{NumberOfLocalInterconnectedEpEngines}"); if (RemoteEpEndPoints != null) { connectToEpsList.AddRange(RemoteEpEndPoints.Where(x => !connectToEpsList.Contains(x) && !x.Equals(epApp.LocalDrpPeerEndpoint))); } if (connectToEpsList.Count != 0) { _visionChannel.Emit(epEngine.Configuration.VisionChannelSourceId, DrpTesterVisionChannelModuleName, AttentionLevel.guiActivity, $"connecting with {connectToEpsList.Count} other EPs..."); epApp.LocalDrpPeer.BeginConnectToEPs(connectToEpsList.ToArray(), () => { BeginCreateLocalEpOrContinue(localEpIndex + 1); }); } else { BeginCreateLocalEpOrContinue(localEpIndex + 1); } }); }
public DrpTester1(VisionChannel visionChannel, Action cb = null) { _visionChannel = visionChannel; _ep = new DrpPeerEngine(new DrpPeerEngineConfiguration { InsecureRandomSeed = _insecureRandom.Next(), LocalPort = EpLocalPort, VisionChannel = visionChannel, VisionChannelSourceId = "EP", ForcedPublicIpApiProviderResponse = IPAddress.Loopback, SandboxModeOnly_NumberOfDimensions = NumberOfDimensions }); var epLocalDrpPeerConfig = LocalDrpPeerConfiguration.Create(_ep.CryptoLibrary, NumberOfDimensions); _ep.BeginCreateLocalPeer(epLocalDrpPeerConfig, new DrpTesterPeerApp(_ep, epLocalDrpPeerConfig), (rpLocalPeer) => { _a = new DrpPeerEngine(new DrpPeerEngineConfiguration { InsecureRandomSeed = _insecureRandom.Next(), VisionChannel = visionChannel, ForcedPublicIpApiProviderResponse = IPAddress.Loopback, VisionChannelSourceId = "A", SandboxModeOnly_NumberOfDimensions = NumberOfDimensions }); var aLocalDrpPeerConfig = LocalDrpPeerConfiguration.Create(_a.CryptoLibrary, NumberOfDimensions); aLocalDrpPeerConfig.EntryPeerEndpoints = new[] { new IPEndPoint(IPAddress.Loopback, EpLocalPort) }; _x = new DrpPeerEngine(new DrpPeerEngineConfiguration { InsecureRandomSeed = _insecureRandom.Next(), VisionChannel = visionChannel, ForcedPublicIpApiProviderResponse = IPAddress.Loopback, VisionChannelSourceId = "X", SandboxModeOnly_NumberOfDimensions = NumberOfDimensions }); _retryx: var xLocalDrpPeerConfig = LocalDrpPeerConfiguration.Create(_x.CryptoLibrary, NumberOfDimensions); var distance_eptoa = epLocalDrpPeerConfig.LocalPeerRegistrationId.GetDistanceTo(_x.CryptoLibrary, aLocalDrpPeerConfig.LocalPeerRegistrationId, NumberOfDimensions); var distance_xtoa = xLocalDrpPeerConfig.LocalPeerRegistrationId.GetDistanceTo(_x.CryptoLibrary, aLocalDrpPeerConfig.LocalPeerRegistrationId, NumberOfDimensions); if (distance_xtoa.IsGreaterThan(distance_eptoa)) { goto _retryx; } xLocalDrpPeerConfig.EntryPeerEndpoints = new[] { new IPEndPoint(IPAddress.Loopback, EpLocalPort) }; _n = new DrpPeerEngine(new DrpPeerEngineConfiguration { InsecureRandomSeed = _insecureRandom.Next(), VisionChannel = visionChannel, ForcedPublicIpApiProviderResponse = IPAddress.Loopback, VisionChannelSourceId = "N", SandboxModeOnly_NumberOfDimensions = NumberOfDimensions }); _retryn: var nLocalDrpPeerConfig = LocalDrpPeerConfiguration.Create(_n.CryptoLibrary, NumberOfDimensions); var distance_ntoa = nLocalDrpPeerConfig.LocalPeerRegistrationId.GetDistanceTo(_n.CryptoLibrary, aLocalDrpPeerConfig.LocalPeerRegistrationId, NumberOfDimensions); if (distance_ntoa.IsGreaterThan(distance_xtoa)) { goto _retryn; } nLocalDrpPeerConfig.EntryPeerEndpoints = new[] { new IPEndPoint(IPAddress.Loopback, EpLocalPort) }; var distance_xton = xLocalDrpPeerConfig.LocalPeerRegistrationId.GetDistanceTo(_n.CryptoLibrary, nLocalDrpPeerConfig.LocalPeerRegistrationId, NumberOfDimensions); var distance_epton = epLocalDrpPeerConfig.LocalPeerRegistrationId.GetDistanceTo(_n.CryptoLibrary, nLocalDrpPeerConfig.LocalPeerRegistrationId, NumberOfDimensions); if (distance_xton.IsGreaterThan(distance_epton)) { goto _retryn; } _xUser = new DrpTesterPeerApp(_x, xLocalDrpPeerConfig); var swX = Stopwatch.StartNew(); _x.BeginRegister(xLocalDrpPeerConfig, _xUser, (xLocalPeer) => { _visionChannel.Emit(_x.Configuration.VisionChannelSourceId, DrpTesterVisionChannelModuleName, AttentionLevel.guiActivity, $"registration complete in {(int)swX.Elapsed.TotalMilliseconds}ms"); _xLocalDrpPeer = xLocalPeer; var swN = Stopwatch.StartNew(); _n.BeginRegister(nLocalDrpPeerConfig, new DrpTesterPeerApp(_n, nLocalDrpPeerConfig), (nLocalPeer) => { _visionChannel.Emit(_n.Configuration.VisionChannelSourceId, DrpTesterVisionChannelModuleName, AttentionLevel.guiActivity, $"registration complete in {(int)swN.Elapsed.TotalMilliseconds}ms"); _nLocalDrpPeer = nLocalPeer; _aUser = new DrpTesterPeerApp(_a, aLocalDrpPeerConfig); var swA = Stopwatch.StartNew(); _a.BeginRegister(aLocalDrpPeerConfig, _aUser, (aLocalPeer) => { _visionChannel.Emit(_a.Configuration.VisionChannelSourceId, DrpTesterVisionChannelModuleName, AttentionLevel.guiActivity, $"registration complete in {(int)swA.Elapsed.TotalMilliseconds}ms"); _aLocalDrpPeer = aLocalPeer; if (cb != null) { cb(); } }); }); }); }); }
internal void WriteToLog_deepDetail(string module, string message) { VisionChannel.Emit(VisionChannelSourceId, module, AttentionLevel.deepDetail, message); }