Beispiel #1
0
        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");
                }
            });
        }
Beispiel #2
0
        void SendMessage()
        {
            if (!LocalUser.SendOrEcho)
            {
                return;
            }

            // send msg (with autoRetry=true)   wait for completion
            var userCertificate1 = UserCertificate.GenerateKeyPairsAndSignAtSingleDevice(_userApp.DrpPeerEngine.CryptoLibrary, _userApp.UserId,
                                                                                         _userApp.UserRootPrivateKeys, DateTime.UtcNow.AddHours(-1), DateTime.UtcNow.AddHours(1));
            var sentText = $"echoTest_#{_sentCount}_from_{LocalUser.Name}_to_{RemoteUser.Name}_{_insecureRandom.Next()}";
            var sw       = Stopwatch.StartNew();

            OnSent();
            _userApp.LocalDrpPeer.BeginSendShortSingleMessage(userCertificate1, RemoteUser.RegistrationId, RemoteUser.UserId, sentText, TimeSpan.FromSeconds(60),
                                                              (exc) =>
            {
                if (exc != null)
                {
                    _visionChannel.EmitListOfPeers(_userApp.DrpPeerEngine.Configuration.VisionChannelSourceId, DrpTesterVisionChannelModuleName, AttentionLevel.strongPain,
                                                   $"could not send message: {exc}");

                    if (!ContinueOnFailed())
                    {
                        return;
                    }
                    SendMessage();
                }
                else
                {
                    BeginVerifyReceivedEchoedMessage(sentText, sw, Stopwatch.StartNew());
                }
            });
        }
Beispiel #3
0
        void BeginTestMessage3(MessagesTest test, DrpTesterPeerApp peer1, DrpTesterPeerApp peer2, Stopwatch sw, string text)
        {
            var userCertificate1 = UserCertificate.GenerateKeyPairsAndSignAtSingleDevice(peer1.DrpPeerEngine.CryptoLibrary, peer1.UserId, peer1.UserRootPrivateKeys, DateTime.UtcNow.AddHours(-1), DateTime.UtcNow.AddHours(1));

            peer1.LocalDrpPeer.BeginSendShortSingleMessage(userCertificate1, peer2.LocalDrpPeer.Configuration.LocalPeerRegistrationId, peer2.UserId, text, TimeSpan.FromSeconds(60), (exc) =>
            {
                BeginVerifyReceivedMessage(test, peer1, peer2, text, sw, Stopwatch.StartNew());
            });
        }
Beispiel #4
0
        public void AddLocalUser(string aliasId)
        {
            try
            {
                UserRootPrivateKeys.CreateUserId(1, 1, TimeSpan.FromDays(365 * 3 + 10), _drpPeerEngine.CryptoLibrary, out var userRootPrivateKeys, out var userId);
                var userCertificateWithPrivateKey = UserCertificate.GenerateKeyPairsAndSignAtSingleDevice(_drpPeerEngine.CryptoLibrary, userId, userRootPrivateKeys, DateTime.UtcNow.AddHours(-1), DateTime.UtcNow.AddYears(3));
                userCertificateWithPrivateKey.AssertHasPrivateKey();
                userCertificateWithPrivateKey.AssertIsValidNow(_drpPeerEngine.CryptoLibrary, userId, _drpPeerEngine.DateTimeNowUtc);

                var u = new User
                {
                    AliasID              = aliasId,
                    UserID               = userId,
                    OwnerLocalUserId     = 0,
                    LocalUserCertificate = userCertificateWithPrivateKey,
                };
                _db.InsertUser(u);

                var ruk = new RootUserKeys
                {
                    UserId = u.Id,
                    UserRootPrivateKeys = userRootPrivateKeys
                };
                _db.InsertRootUserKeys(ruk);

                RegistrationId.CreateNew(_drpPeerEngine.CryptoLibrary, out var regPrivateKey, out var registrationId);

                var regId = new UserRegistrationID
                {
                    UserId                 = u.Id,
                    RegistrationId         = registrationId,
                    RegistrationPrivateKey = regPrivateKey
                };
                _db.InsertUserRegistrationID(regId);

                var newLocalUser = new LocalUser
                {
                    User                = u,
                    RootUserKeys        = ruk,
                    UserRegistrationIDs = new List <UserRegistrationID> {
                        regId
                    }
                };
                LocalUsers.Add(u.Id, newLocalUser);
                newLocalUser.CreateLocalDrpPeers(this);
            }
            catch (Exception exc)
            {
                HandleException("error when adding new local user: ", exc);
            }
        }
Beispiel #5
0
 public DrpTesterPeerApp(DrpPeerEngine drpPeerEngine, LocalDrpPeerConfiguration drpPeerRegistrationConfiguration, UserRootPrivateKeys userRootPrivateKeys = null, UserId userId = null)
 {
     DrpPeerRegistrationConfiguration = drpPeerRegistrationConfiguration;
     DrpPeerEngine = drpPeerEngine;
     if (userRootPrivateKeys == null || userId == null)
     {
         UserRootPrivateKeys.CreateUserId(3, 2, TimeSpan.FromDays(367), DrpPeerEngine.CryptoLibrary, out UserRootPrivateKeys, out UserId);
     }
     else
     {
         UserId = userId;
         UserRootPrivateKeys = userRootPrivateKeys;
     }
     UserCertificateWithPrivateKey = UserCertificate.GenerateKeyPairsAndSignAtSingleDevice(DrpPeerEngine.CryptoLibrary, UserId, UserRootPrivateKeys, DateTime.UtcNow.AddHours(-1), DateTime.UtcNow.AddYears(1));
 }
Beispiel #6
0
        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();
                }
            });
        }
Beispiel #7
0
        public void OnReceivedShortSingleMessage(string message, InviteRequestPacket req)
        {
            _receivedMessages++;
            DrpPeerEngine.Configuration.VisionChannel.Emit(DrpPeerEngine.Configuration.VisionChannelSourceId, VisionChannelModuleName, AttentionLevel.guiActivity,
                                                           $"received message: {message}");
            LatestReceivedTextMessage_req = req;
            LatestReceivedTextMessage     = message;

            if (EchoMessages)
            {
                DrpPeerEngine.Configuration.VisionChannel.Emit(DrpPeerEngine.Configuration.VisionChannelSourceId, VisionChannelModuleName, AttentionLevel.guiActivity,
                                                               $"echoing message: {message}");
                DrpPeerEngine.EngineThreadQueue.EnqueueDelayed(TimeSpan.FromMilliseconds(20), () =>
                {
                    var userCertificate1 = UserCertificate.GenerateKeyPairsAndSignAtSingleDevice(DrpPeerEngine.CryptoLibrary, UserId,
                                                                                                 UserRootPrivateKeys, DateTime.UtcNow.AddHours(-1), DateTime.UtcNow.AddHours(1));
                    _echoedMessages_attempts++;
                    LocalDrpPeer.BeginSendShortSingleMessage(userCertificate1, req.RequesterRegistrationId,
                                                             ContactBookUsersByRegId[req.RequesterRegistrationId], message, TimeSpan.FromSeconds(60),
                                                             (exc) =>
                    {
                        if (exc == null)
                        {
                            _echoedMessages_succeeded++;
                            DrpPeerEngine.Configuration.VisionChannel.Emit(DrpPeerEngine.Configuration.VisionChannelSourceId, VisionChannelModuleName, AttentionLevel.guiActivity,
                                                                           $"successfully echoed message: {message}");
                        }
                        else
                        {
                            DrpPeerEngine.Configuration.VisionChannel.EmitListOfPeers(DrpPeerEngine.Configuration.VisionChannelSourceId, VisionChannelModuleName, AttentionLevel.strongPain,
                                                                                      $"could not send echoed message: {message}: {exc}");
                        }
                    });
                }, "echo 5096");
            }
        }