Exemple #1
0
        public async Task SetUp()
        {
            _stream    = new Mock <Stream>();
            _tcpClient = new Mock <ITcpClient>();
            _tcpClient
            .Setup(c => c.GetStream())
            .Returns(() => _stream.Object);

            _envelopeSerializer = new Mock <IEnvelopeSerializer>();
            _traceWriter        = new Mock <ITraceWriter>();

            _cancellationToken = TimeSpan.FromSeconds(10).ToCancellationToken();
            _serverUri         = new Uri($"net.tcp://*****:*****@fakedomain.local");
            _serverCertificate = GetDomainCertificate(_serverIdentity);
            _tcpListener       = new TcpTransportListener(
                _serverUri,
                _serverCertificate,
                _envelopeSerializer.Object,
                clientCertificateValidationCallback:
                (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) =>
            {
                return(true);
            });
            await _tcpListener.StartAsync(_cancellationToken);
        }
 public DummyServer(Uri listenerUri)
 {
     ListenerUri        = listenerUri;
     _cts               = new CancellationTokenSource();
     _transportListener = new TcpTransportListener(ListenerUri, null, new JsonNetSerializer());
     Channels           = new Queue <ServerChannel>();
     Authentications    = new Queue <Authentication>();
     Messages           = new Queue <Message>();
     Notifications      = new Queue <Notification>();
     Commands           = new Queue <Command>();
 }
Exemple #3
0
        public Core(ISettings settings, IPlatform platform)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }
            if (platform == null)
            {
                throw new ArgumentNullException(nameof(platform));
            }

            Settings = settings;
            Platform = platform;

            KeyManager keyManager = new KeyManager(settings);

            rsaProvider = new RSACryptoServiceProvider();
            rsaProvider.ImportParameters(keyManager.EncryptionParameters);
            nodeID = Common.Utils.SHA512Str(rsaProvider.ToXmlString(false));

            FileSystem = new FileSystemProvider(this);

            ShareBuilder = new ShareBuilder(this);
            ShareBuilder.FinishedIndexing += ShareBuilder_FinishedIndexing;

            shareWatcher = new ShareWatcher(this);

            ShareHasher = new ShareHasher();

            transportManager = new TransportManager(this);

            FileTransferManager = new FileTransferManager(this);

            FileSearchManager = new FileSearchManager(this);

            DestinationManager = new DestinationManager(this);

            // XXX: Use reflection to load these:
            DestinationManager.RegisterSource(new TCPIPv4DestinationSource(this));
            DestinationManager.RegisterSource(new TCPIPv6DestinationSource(this));

            TrackerFactory.Register("meshwork", typeof(MeshworkTracker));

            ITransportListener tcpListener = new TcpTransportListener(this, Settings.TcpListenPort);

            transportListeners.Add(tcpListener);

            if (FinishedLoading != null)
            {
                FinishedLoading(null, EventArgs.Empty);
            }
        }
Exemple #4
0
 public DummyServer(Uri listenerUri)
 {
     ListenerUri        = listenerUri;
     _cts               = new CancellationTokenSource();
     _transportListener = new TcpTransportListener(
         ListenerUri,
         null,
         new EnvelopeSerializer(new DocumentTypeResolver().WithMessagingDocuments()));
     Channels        = new Queue <ServerChannel>();
     Authentications = new Queue <Authentication>();
     Messages        = new Queue <Message>();
     Notifications   = new Queue <Notification>();
     Commands        = new Queue <Command>();
 }
Exemple #5
0
        public async Task SetupAsync()
        {
            _uri = new Uri("net.tcp://localhost:55321");
            _cancellationToken    = TimeSpan.FromSeconds(30).ToCancellationToken();
            _envelopeSerializer   = new FakeEnvelopeSerializer(10);
            _tcpTransportListener = new TcpTransportListener(_uri, null, _envelopeSerializer);
            await _tcpTransportListener.StartAsync(_cancellationToken);

            var serverTcpTransportTask = _tcpTransportListener.AcceptTransportAsync(_cancellationToken);

            _clientTcpTransport = new TcpTransport(_envelopeSerializer);
            await _clientTcpTransport.OpenAsync(_uri, _cancellationToken);

            _serverTcpTransport = (TcpTransport)await serverTcpTransportTask;
            await _serverTcpTransport.OpenAsync(_uri, _cancellationToken);
        }
Exemple #6
0
 /// <summary>
 /// Listen for incoming data on the port - creates messages from incoming data and adds it to processing list.
 /// </summary>
 private void ListenForData()
 {
     //start listening the port
     tcpListener = new TcpTransportListener(TcpTransport.LOCALHOST, port);
     tcpListener.Start();
     // Loop checking for data to become available
     while (isRunning)
     {
         try
         {
             // wait for client to connect
             TcpClient client = tcpListener.WaitForConnection();
             Console.WriteLine("Client connected");
             transport = new Transport.TcpTransport(client);
             if (!transport.IsConnected())
             {
                 break;
             }
             if (tcpProtocol == null)
             {
                 break;
             }
             byte[] messageRaw = transport.Read();
             // Add new message to inbound message queue
             lock (rawMessageQ)
             {
                 rawMessageQ.Enqueue(messageRaw);
             }
         }
         catch (Exception e)
         {
             Console.WriteLine("Listen data error:{0}", e.Message);
         }
         processGate.Set(); // wake up the process thread to process new messages
     }
 }
Exemple #7
0
 public DummyServer(Uri listenerUri)
 {
     ListenerUri        = listenerUri;
     _cts               = new CancellationTokenSource();
     _transportListener = new TcpTransportListener(ListenerUri, null, new JsonNetSerializer());
 }
Exemple #8
0
        public static bool Init(ISettings settings)
        {
            if (loaded == true)
            {
                throw new Exception("Please only call this method once.");
            }

            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            Core.Settings = settings;

            string pidFilePath = Path.Combine(Core.Settings.DataPath, "meshwork.pid");

            if (File.Exists(pidFilePath))
            {
                int processId = -1;
                Int32.TryParse(File.ReadAllText(pidFilePath), out processId);
                try
                {
                    Process.GetProcessById(processId);
                    Console.Error.WriteLine("Meshwork is already running (PID {0})!", processId);
                    return(false);
                }
                catch (ArgumentException)
                {
                    File.Delete(pidFilePath);
                }
            }
            File.WriteAllText(pidFilePath, Process.GetCurrentProcess().Id.ToString());

            if (settings.KeyEncrypted)
            {
                PasswordPrompt(null, EventArgs.Empty);
                if (!settings.KeyUnlocked)
                {
                    // Quit!
                    return(false);
                }
            }

            rsaProvider = new RSACryptoServiceProvider();
            rsaProvider.ImportParameters(settings.EncryptionParameters);
            nodeID = Common.SHA512Str(rsaProvider.ToXmlString(false));

            fileSystem = Container.GetExportedValue <IFileSystemProvider>();

            shareBuilder = Container.GetExportedValue <IShareBuilder>();
            shareBuilder.FinishedIndexing += ShareBuilder_FinishedIndexing;

            shareWatcher        = Container.GetExportedValue <IShareWatcher>();
            shareHasher         = Container.GetExportedValue <IShareHasher>();
            transportManager    = Container.GetExportedValue <ITransportManager>();
            fileTransferManager = Container.GetExportedValue <IFileTransferManager>();
            fileSearchManager   = Container.GetExportedValue <IFileSearchManager>();
            destinationManager  = Container.GetExportedValue <IDestinationManager>();

            // XXX: Use reflection to load these:
            destinationManager.RegisterSource(new TCPIPv4DestinationSource());
            destinationManager.RegisterSource(new TCPIPv6DestinationSource());

            MonoTorrent.Client.Tracker.TrackerFactory.Register("meshwork", typeof(MeshworkTracker));

            ITransportListener tcpListener = new TcpTransportListener(Core.Settings.TcpListenPort);

            transportListeners.Add(tcpListener);

            loaded = true;

            if (FinishedLoading != null)
            {
                FinishedLoading(null, EventArgs.Empty);
            }

            return(true);
        }