public MoleClientSenderTests(ClientFixture fixture)
 {
     PServSenderFromClientA = fixture.PServSenderFromClientA;
     PServSenderFromClientB = fixture.PServSenderFromClientB;
     SenderClientA          = fixture.SenderToClientA;
     SenderClientB          = fixture.SenderToClientB;
     CoreClientA            = fixture.CoreClientAF;
     CoreClientB            = fixture.CoreClientBF;
 }
Example #2
0
        public ClientFixture()
        {
            try
            {
                PushServerFixture.PrepareProtoBufSerrializer();
                PrepareProtoBuf();
                ServerListnerF = new PushServerListner();
                var users = ServerListnerF.DbContext.Users.ToArray();
                ServerListnerF.DbContext.RemoveRange(users);
                ServerListnerF.DbContext.SaveChanges();

                while (ServerListnerF.CryptoFactories == null || ServerListnerF.PossibleCrypto == null)
                {
                }
                IPAddress[] localIPs    = Dns.GetHostAddressesAsync(Dns.GetHostName()).Result;
                var         ip          = localIPs.First(address => address.AddressFamily == AddressFamily.InterNetwork);
                var         rand        = new Random();
                var         clientATupl = PushServerFixture.CreateForm("Frodo1", true, ip, rand);
                clientATupl.Item1.Accessibility = new AccessibilityInfo(100, 5);
                clientATupl.Item1.Accessibility.AddToConst("Frodo2");

                CoreClientAF = new MoleClientCore(new ProtoBufSerializer(), @"C:\MoleFileSavingA",
                                                  ServerListnerF.CryptoFactories, clientATupl.Item1, (ISign)clientATupl.Item3);
                var clientBTupl = PushServerFixture.CreateForm("Frodo2", true, ip, rand);
                clientBTupl.Item1.Accessibility = new AccessibilityInfo(100, 5);
                clientBTupl.Item1.Accessibility.AddToConst("Frodo1");
                CoreClientBF = new MoleClientCore(new ProtoBufSerializer(), @"C:\MoleFileSavingB",
                                                  ServerListnerF.CryptoFactories, clientBTupl.Item1, (ISign)clientBTupl.Item3);

                PServSenderFromClientA = new MolePushServerSender(ServerListnerF.CryptoFactories, ServerListnerF.PossibleCrypto);
                PServSenderFromClientA.InitializeConnectionAsync(ServerListnerF.EndPoint.Address,
                                                                 ServerListnerF.EndPoint.Port).Wait();
                PServSenderFromClientA.RegisterNewUserAsync(CoreClientAF.MyUserForm).Wait();
                PServSenderFromClientB = new MolePushServerSender(ServerListnerF.CryptoFactories, ServerListnerF.PossibleCrypto);
                PServSenderFromClientB.InitializeConnectionAsync(ServerListnerF.EndPoint.Address,
                                                                 ServerListnerF.EndPoint.Port).Wait();
                PServSenderFromClientB.RegisterNewUserAsync(CoreClientBF.MyUserForm).Wait();

                ListnerClientAF = new ClientListner(clientATupl, CoreClientAF.DirForFileSaving, PServSenderFromClientA,
                                                    new IPEndPoint(ip, rand.Next(20000, 60000)), ServerListnerF.CryptoFactories, CoreClientAF);
                ListnerClientBF = new ClientListner(clientBTupl, CoreClientBF.DirForFileSaving, PServSenderFromClientB,
                                                    new IPEndPoint(ip, rand.Next(20000, 60000)), ServerListnerF.CryptoFactories, CoreClientBF);
                SenderToClientA = new MoleClientSender(CoreClientAF.MyUserForm, ServerListnerF.PossibleCrypto, CoreClientBF);
                SenderToClientA.Inicialize(ListnerClientAF.EndPoint).Wait();
                SenderToClientB = new MoleClientSender(CoreClientBF.MyUserForm, ServerListnerF.PossibleCrypto, CoreClientAF);
                SenderToClientB.Inicialize(ListnerClientBF.EndPoint).Wait();
                //SetFuncOnEvents(CoreClientAF);
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #3
0
 private void SetFuncOnEvents(MoleClientCore core)
 {
     //core.RegisterNewContactEvent += (o, args) =>
     //{
     //    args.AllowContinueRegistration(true);
     //    return Task.CompletedTask;
     //};
     //core.TextMessageRecievedEvent += (o, args) =>
     //{
     //    Debug.WriteLine($"From: [{args.Contact.Login}], Message: [{args.Message}]");
     //    return Task.CompletedTask;
     //};
     //core.RecieveOfFileTransferRequestEvent += (o, args) =>
     //{
     //    args.AllowContinueRegistration(true);
     //    return Task.CompletedTask;
     //};
     //core.FileRecievingPreparedEvent += (o, args) => args.
 }
Example #4
0
        protected async Task Listen(TcpListener listener)
        {
            try
            {
                MoleClientCore core = CreateCore();
                while (true)
                {
                    if (CancellationTokenSource.IsCancellationRequested)
                    {
                        return;
                    }
                    ReadyToAcceptClient = true;
                    var client = await listener.AcceptTcpClientAsync().ConfigureAwait(false);

                    var reciever = new MoleClientReceiver(client, core, ServerSender);
                    Recievers.Add(reciever);
                    reciever.RunAsync(CancellationTokenSource.Token);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Example #5
0
        public ClientListner(Tuple <UserForm, IEnumerable <TcpListener>, IAsymmetricKeysExchange> clientTupl, string dirForFileSaving,
                             MolePushServerSender serverSender, IPEndPoint endPoint, IEnumerable <CryptoFactoryBase> factories, MoleClientCore core)
        {
            if (clientTupl == null)
            {
                throw new ArgumentNullException(nameof(clientTupl))
                      {
                          Source = GetType().AssemblyQualifiedName
                      }
            }
            ;
            if (!Directory.Exists(dirForFileSaving))
            {
                throw new ArgumentException("Указанной директории для сохранения файлов не существует.", nameof(dirForFileSaving))
                      {
                          Source = GetType().AssemblyQualifiedName
                      }
            }
            ;
            if (serverSender == null)
            {
                throw new ArgumentNullException(nameof(serverSender))
                      {
                          Source = GetType().AssemblyQualifiedName
                      }
            }
            ;
            if (!serverSender.IsReg || !serverSender.IsAuth)
            {
                throw new ArgumentException(
                          $"{nameof(serverSender)} не зарегистрировал или не авторизовал клиента на сервере.")
                      {
                          Source = GetType().AssemblyQualifiedName
                      }
            }
            ;
            if (endPoint == null)
            {
                throw new ArgumentNullException(nameof(endPoint))
                      {
                          Source = GetType().AssemblyQualifiedName
                      }
            }
            ;
            if (factories == null)
            {
                throw new ArgumentNullException(nameof(factories))
                      {
                          Source = GetType().AssemblyQualifiedName
                      }
            }
            ;
            if (!factories.Any())
            {
                throw new ArgumentException("factories.Any() == false.")
                      {
                          Source = GetType().AssemblyQualifiedName
                      }
            }
            ;

            Core                = core;
            ClientFormTupl      = clientTupl;
            FileSavingDirectory = dirForFileSaving;
            ServerSender        = serverSender;
            EndPoint            = endPoint;
            Factories           = factories.ToList();
            var listner = new TcpListener(EndPoint);

            listner.Start();
            ListenTaskF = Task.Run(async() => await Listen(listner).ConfigureAwait(false));
            while (Core == null)
            {
            }
            PossibleCrypto = Core.PossibleAlgs;
            while (!ReadyToAcceptClient)
            {
            }
        }