예제 #1
0
        public void TwoConnections()
        {
            using var hub0 = new Hub("hub 0");
            var hub0EndPoint = new IPEndPoint(IPAddress.Loopback, 4500);

            hub0.StartListening(hub0EndPoint);

            using var hub1 = new Hub("hub 1");

            Task.WaitAll(hub1.Connect(hub0EndPoint),
                         hub1.Connect(hub0EndPoint));

            var hub0KnownHubs = hub0.KnownHubs.ToArray();

            Assert.AreEqual(1, hub0KnownHubs.Length);
            Assert.IsTrue(hub0KnownHubs.Any(x => x.Name == "hub 1"));

            var hub1KnownHubs = hub1.KnownHubs.ToArray();

            Assert.AreEqual(1, hub1KnownHubs.Length);
            Assert.IsTrue(hub1KnownHubs.Any(x => x.Name == "hub 0"));

            var connections0 = hub0.Connections.ToArray();

            Assert.AreEqual(2, connections0.Length);
            Assert.IsTrue(connections0.All(x => x.State == HubConnectionState.Active));

            var connections1 = hub1.Connections.ToArray();

            Assert.AreEqual(2, connections1.Length);
            Assert.IsTrue(connections1.All(x => x.State == HubConnectionState.Active));
        }
예제 #2
0
        public void TwoConnectionsAndYetAnthorHubThenOneDisconnect()
        {
            using var hub0   = new Hub("hub 0");
            hub0.PathThrough = true;
            var hub0EndPoint = new IPEndPoint(IPAddress.Loopback, 4500);

            hub0.StartListening(hub0EndPoint);

            using var hub1   = new Hub("hub 1");
            hub1.PathThrough = true;

            Task.WaitAll(hub1.Connect(hub0EndPoint),
                         hub1.Connect(hub0EndPoint));

            using var hub2   = new Hub("hub 2");
            hub0.PathThrough = true;
            hub2.Connect(hub0EndPoint).Wait();

            hub1.Connections.First().Disconnect();

            Thread.Sleep(10);

            var hub0KnownHubs = hub0.KnownHubs.ToArray();

            Assert.AreEqual(2, hub0KnownHubs.Length);
            Assert.IsTrue(hub0KnownHubs.Any(x => x.Name == "hub 1"));
            Assert.IsTrue(hub0KnownHubs.Any(x => x.Name == "hub 2"));

            var hub1KnownHubs = hub1.KnownHubs.ToArray();

            Assert.AreEqual(2, hub1KnownHubs.Length);
            Assert.IsTrue(hub1KnownHubs.Any(x => x.Name == "hub 0"));
            Assert.IsTrue(hub1KnownHubs.Any(x => x.Name == "hub 2"));

            var hub2KnownHubs = hub2.KnownHubs.ToArray();

            Assert.AreEqual(2, hub2KnownHubs.Length);
            Assert.IsTrue(hub2KnownHubs.Any(x => x.Name == "hub 0"));
            Assert.IsTrue(hub2KnownHubs.Any(x => x.Name == "hub 1"));

            var connections0 = hub0.Connections.ToArray();

            Assert.AreEqual(2, connections0.Length);
            Assert.IsTrue(connections0.All(x => x.State == HubConnectionState.Active));

            var connections1 = hub1.Connections.ToArray();

            Assert.AreEqual(1, connections1.Length);
            Assert.IsTrue(connections1.All(x => x.State == HubConnectionState.Active));

            var connections2 = hub2.Connections.ToArray();

            Assert.AreEqual(1, connections2.Length);
            Assert.IsTrue(connections2.All(x => x.State == HubConnectionState.Active));
        }
        public PassiveDownloadFilelistFromUserUsingTLS()
        {
            UpdateBase = new FmdcEventHandler(PassiveConnectToUser_UpdateBase);

            // Creates a empty share
            Share share = new Share("Testing");

            // Adds common filelist to share
            AddFilelistsToShare(share);

            HubSetting setting = new HubSetting();

            setting.Address     = "127.0.0.1";
            setting.Port        = 411;
            setting.DisplayName = "FlowLibPassiveTLS";
            setting.Protocol    = "Auto";

            Hub hubConnection = new Hub(setting, this);

            hubConnection.ProtocolChange += new FmdcEventHandler(hubConnection_ProtocolChange);
            // Adds share to hub
            hubConnection.Share = share;
            hubConnection.Me.Set(UserInfo.SECURE, "");
            hubConnection.Connect();
        }
예제 #4
0
        public void CloseRemoteStream()
        {
            using var hub0   = new Hub("hub 0");
            hub0.PathThrough = true;
            var hub0EndPoint = new IPEndPoint(IPAddress.Loopback, 4500);

            hub0.StartListening(hub0EndPoint);

            using var hub1   = new Hub("hub 1");
            hub1.PathThrough = true;
            var hub1EndPoint = new IPEndPoint(IPAddress.Loopback, 4501);

            hub1.StartListening(hub1EndPoint);

            hub0.Connect(hub1EndPoint).Wait();

            var stream = new MemoryStream();

            var streamId = hub0.RegisterStream(stream);

            var remoteStreamTask = hub1.GetRemoteStream(hub0.Id, streamId);

            remoteStreamTask.Wait();
            var remoteStream = remoteStreamTask.Result;

            remoteStream.Close();

            Assert.ThrowsException <AggregateException>(() => hub1.GetRemoteStream(hub0.Id, streamId).Wait(), "Unknown stream");
        }
예제 #5
0
        public void GetStreamInfo()
        {
            using var hub0   = new Hub("hub 0");
            hub0.PathThrough = true;
            var hub0EndPoint = new IPEndPoint(IPAddress.Loopback, 4500);

            hub0.StartListening(hub0EndPoint);

            using var hub1   = new Hub("hub 1");
            hub1.PathThrough = true;
            var hub1EndPoint = new IPEndPoint(IPAddress.Loopback, 4501);

            hub1.StartListening(hub1EndPoint);

            hub0.Connect(hub1EndPoint).Wait();

            var stream = new MemoryStream(Encoding.UTF8.GetBytes("Hello, world!"));

            var streamId = hub0.RegisterStream(stream);

            var remoteStream = hub1.GetRemoteStream(hub0.Id, streamId);

            remoteStream.Wait();

            Assert.AreEqual(stream.Length, remoteStream.Result.Length);
            Assert.AreEqual(stream.Position, remoteStream.Result.Position);
            Assert.AreEqual(stream.CanRead, remoteStream.Result.CanRead);
            Assert.AreEqual(stream.CanSeek, remoteStream.Result.CanSeek);
            Assert.AreEqual(stream.CanWrite, remoteStream.Result.CanWrite);
        }
예제 #6
0
        public void SetLengthOfRemoteStream()
        {
            using var hub0   = new Hub("hub 0");
            hub0.PathThrough = true;
            var hub0EndPoint = new IPEndPoint(IPAddress.Loopback, 4500);

            hub0.StartListening(hub0EndPoint);

            using var hub1   = new Hub("hub 1");
            hub1.PathThrough = true;
            var hub1EndPoint = new IPEndPoint(IPAddress.Loopback, 4501);

            hub1.StartListening(hub1EndPoint);

            hub0.Connect(hub1EndPoint).Wait();

            var stream = new MemoryStream();

            var streamId = hub0.RegisterStream(stream);

            var remoteStreamTask = hub1.GetRemoteStream(hub0.Id, streamId);

            remoteStreamTask.Wait();
            var remoteStream = remoteStreamTask.Result;

            remoteStream.SetLength(100);

            Assert.AreEqual(100, remoteStream.Length);
            Assert.AreEqual(100, stream.Length);
        }
예제 #7
0
        public async Task Connect(Guid userId, Guid connectionId)
        {
            EnsureGameIsNotStarted();

            if (!_playerListEditor.Contains(userId))
            {
                var player       = _playerListEditor.Add(userId);
                var playerJoined = new PlayerJoined(_state.RoomId, player);
                if (_playerListEditor.Count == 1)
                {
                    _mapEditor.Generate();
                }
                if (!_mapEditor.CanPlacePlanet)
                {
                    var options = new GameOptionsData
                    {
                        MapWidth            = _mapEditor.MapWidth + 1,
                        MapHeight           = _mapEditor.MapHeigth + 1,
                        NeutralPlanetsCount = _mapEditor.NeutralPlanetsCount
                    };
                    _mapEditor.Generate(options);
                }
                _mapEditor.PlacePlanet(userId);
                var mapUpdated = new MapUpdated(_state.RoomId, _state.MapEditor.Map);
                await _hub.NotifyEverybodyExcept(userId, playerJoined, mapUpdated);
            }
            await _hub.Connect(userId, connectionId);
        }
예제 #8
0
        public ActiveEmptySharing()
        {
            // Creates a empty share
            Share share = new Share("Testing");

            // Port to listen for incomming connections on
            share.Port = 12345;
            AddFilelistsToShare(share);

            incomingConnectionListener         = new TcpConnectionListener(share.Port);
            incomingConnectionListener.Update += new FmdcEventHandler(Connection_Update);
            incomingConnectionListener.Start();

            HubSetting setting = new HubSetting();

            setting.Address     = "127.0.0.1";
            setting.Port        = 411;
            setting.DisplayName = "FlowLib";
            setting.Protocol    = "Auto";

            Hub hubConnection = new Hub(setting);

            hubConnection.ProtocolChange += new FmdcEventHandler(hubConnection_ProtocolChange);
            hubConnection.Share           = share;
            hubConnection.Me.Mode         = FlowLib.Enums.ConnectionTypes.Direct;
            hubConnection.Connect();
        }
예제 #9
0
        public SendMainChatOrPMToHub()
        {
            UpdateBase = new FlowLib.Events.FmdcEventHandler(SendMainChatOrPMToHub_UpdateBase);

            HubSetting settings = new HubSetting();

            settings.Address     = "127.0.0.1";
            settings.Port        = 411;
            settings.DisplayName = "FlowLib";
            settings.Protocol    = "Auto";

            Hub hubConnection = new Hub(settings, this);

            hubConnection.Connect();
            // YOU should really listen for regmode change here.
            // Im not doing it here to make example more easy to understand.
            // Wait 10 seconds and hope we are connected.
            System.Threading.Thread.Sleep(10 * 1000);

            // Create mainchat message.
            MainMessage msg = new MainMessage(hubConnection.Me.ID, "Testing");

            // message will here be converted to right format and then be sent.
            UpdateBase(this, new FlowLib.Events.FmdcEventArgs(FlowLib.Events.Actions.MainMessage, msg));

            // Create private message.
            PrivateMessage privMsg = new PrivateMessage("DCpp706", hubConnection.Me.ID, "Testing");

            // message will here be converted to right format and then be sent.
            UpdateBase(this, new FlowLib.Events.FmdcEventArgs(FlowLib.Events.Actions.PrivateMessage, privMsg));
        }
예제 #10
0
        public void RemoteCall()
        {
            using var hub1 = new Hub(777003, "hub 1");
            using var hub2 = new Hub(777004, "hub 2");
            var endpoint = new IPEndPoint(IPAddress.Loopback, 4500);

            hub1.StartListening(endpoint);
            hub2.Connect(endpoint).Wait();

            hub1.RegisterInterface <ITestInterface>(new TestImplementation()).Wait();

            while (!hub2.TryGet <ITestInterface>(out _))
            {
                Thread.Sleep(1);
            }

            var a = 1;
            var b = 2;
            var remoteInterface = hub2.Get <ITestInterface>();
            var result          = remoteInterface.Call(_ => _.Sum(a, b));

            GC.Collect(2);

            result.Wait();

            Assert.AreEqual(3, result.Result);
        }
예제 #11
0
        public void TryToCallDeniedMethodWithNonVoidResult()
        {
            using var hub1 = new Hub(777008, "hub 1");

            var endpoint2 = new IPEndPoint(IPAddress.Loopback, 4501);

            using var hub2 = new Hub(777009, "hub 2");
            hub2.StartListening(endpoint2);

            hub1.Connect(endpoint2).Wait();

            var called = false;

            hub1.RegisterInterface <ITestInterface>(new TestImplementation(() => called = true)).Wait();

            var value = hub2.Get <ITestInterface>().Call(x => x.DeniedFunction());

            try
            {
                value.Wait();
            }
            catch (AggregateException e)
            {
                Assert.IsInstanceOfType(e.InnerException, typeof(RemoteException));
            }

            Assert.IsFalse(called, nameof(called));
        }
예제 #12
0
        public ActiveSearch()
        {
            UpdateBase = new FmdcEventHandler(ActiveSearch_UpdateBase);

            HubSetting settings = new HubSetting();

            settings.Address     = "127.0.0.1";
            settings.Port        = 411;
            settings.DisplayName = "FlowLib";
            settings.Protocol    = "Auto";

            hubConnection = new Hub(settings, this);
            hubConnection.ProtocolChange += new FmdcEventHandler(hubConnection_ProtocolChange);
            hubConnection.Connect();

            Share share = new Share("Test");

            share.Port = 1000;

            // Telling that we are listening on port 1000 for incomming search results (Any means from everyone)
            UdpConnection udp = new UdpConnection(new IPEndPoint(IPAddress.Any, share.Port));

            udp.Protocol = new FlowLib.Protocols.UdpNmdcProtocol();
            udp.Protocol.MessageReceived += new FmdcEventHandler(Protocol_MessageReceived);
            // Enable Active searching
            hubConnection.Me.Mode = FlowLib.Enums.ConnectionTypes.Direct;
            hubConnection.Share   = share;
        }
예제 #13
0
        public PassiveSearch()
        {
            UpdateBase = new FlowLib.Events.FmdcEventHandler(PassiveSearch_UpdateBase);

            HubSetting settings = new HubSetting();

            settings.Address     = "127.0.0.1";
            settings.Port        = 411;
            settings.DisplayName = "FlowLib";
            settings.Protocol    = "Auto";

            Hub hubConnection = new Hub(settings, this);

            hubConnection.ProtocolChange += new FmdcEventHandler(hubConnection_ProtocolChange);
            hubConnection.Connect();

            // Wait 5 seconds (We should really listen on ConnectionStatusChange instead.
            System.Threading.Thread.Sleep(5 * 1000);

            // Send Search
            SearchInfo searchInfo = new SearchInfo();

            searchInfo.Set(SearchInfo.SEARCH, "Ubuntu");

            UpdateBase(this, new FlowLib.Events.FmdcEventArgs(Actions.Search, searchInfo));
        }
예제 #14
0
        private void HubTest(string protocol, ConnectionTypes connectionType)
        {
            _settings.Protocol = protocol;

            _hubConnection = new Hub(_settings, this);
            _hubConnection.ProtocolChange += new FmdcEventHandler(hubConnection_ProtocolChange);

            // We need to have a share
            _hubConnection.Share = new Share("temp");

            _hubConnection.Me.TagInfo.Mode = connectionType;

            _hubConnection.Connect();

            //Thread thread = new Thread(new ThreadStart(AutoDownloadNewStuff));
            //thread.IsBackground = true;
            //thread.Start();

            int i = 0;

            while (!_isFinished && i++ < _testTimeoutLength)
            {
                Thread.Sleep(500);
            }

            // Close all open threads
            //thread.Abort();
            _hubConnection.Disconnect("Test time exceeded");
            _hubConnection.Dispose();
        }
예제 #15
0
        private SixBot(Okno gui)
        {
            gui.Bot = this;

            m_Gui      = gui;
            m_Hostname = "sazavahub.vscht.cz";

            CekejNaPripojeni();

            m_TransferManager = new TransferManager();
            m_DownloadManager = new DownloadManager();

            m_Share = new Share("Share");
            //m_Share.ErrorOccured += new FmdcEventHandler(m_Share_ErrorOccured);
            //m_Share.HashAllowDuplicate = false;
            //m_Share.HashAutoSaveCount = 1;
            //m_Share.AddVirtualDir("Test", AppDomain.CurrentDomain.BaseDirectory+"\\Test");
            //m_Share.AddVirtualDir("Test2", @"F:\Hry\EasyUO");
            //General.AddCommonFilelistsToShare(m_Share, AppDomain.CurrentDomain.BaseDirectory);

            /* m_Share.HashContent();
             *
             * m_Gui.VypisRadek(m_Share.TotalCount.ToString());
             * m_Gui.VypisRadek(m_Share.IsHashing.ToString());
             * m_Gui.VypisRadek(m_Share.HashedCount.ToString());*/

            HubSetting nastaveni = new HubSetting();

            nastaveni.Address = m_Hostname;
            nastaveni.Port    = 411;

#if DEBUG
            nastaveni.DisplayName = "Sixbot_Test";
#else
            nastaveni.DisplayName = "Sixbot";
#endif

            nastaveni.Protocol = "Nmdc";
            nastaveni.Password = "******";

            m_Hub       = new Hub(nastaveni, this);
            m_Hub.Share = m_Share;
            m_Hub.Me.TagInfo.Version = "SixBot";
            m_Hub.Me.Description     = "http://sixbot.googlecode.com";
            m_Hub.Me.Mode            = ConnectionTypes.Direct;

            m_Hub.ConnectionStatusChange += new FmdcEventHandler(m_Hub_ConnectionStatusChange);

            HandlerPrikazu.Inicialiazce(this);

            m_Hub.Connect();

            m_Hub.Protocol.Encoding = Encoding.Default; //je to nutnй od verze 4
        }
예제 #16
0
        public void ConnectInTheMiddleOfChain()
        {
            using var hub0   = new Hub("hub 0");
            hub0.PathThrough = true;
            var hub0EndPoint = new IPEndPoint(IPAddress.Loopback, 4500);

            hub0.StartListening(hub0EndPoint);

            using var hub1   = new Hub("hub 1");
            hub1.PathThrough = true;
            var hub1EndPoint = new IPEndPoint(IPAddress.Loopback, 4501);

            hub1.StartListening(hub1EndPoint);

            using var hub2   = new Hub("hub 2");
            hub2.PathThrough = true;

            Task.WaitAll(hub1.Connect(hub0EndPoint),
                         hub2.Connect(hub1EndPoint));

            using var hub3 = new Hub("hub 3");
            hub3.Connect(hub1EndPoint).Wait();

            var hub0KnownHubs = hub0.KnownHubs.ToArray();

            Assert.AreEqual(3, hub0KnownHubs.Length);
            Assert.IsTrue(hub0KnownHubs.Any(x => x.Name == "hub 1"));
            Assert.IsTrue(hub0KnownHubs.Any(x => x.Name == "hub 2"));
            Assert.IsTrue(hub0KnownHubs.Any(x => x.Name == "hub 3"));

            var hub1KnownHubs = hub1.KnownHubs.ToArray();

            Assert.AreEqual(3, hub1KnownHubs.Length);
            Assert.IsTrue(hub1KnownHubs.Any(x => x.Name == "hub 0"));
            Assert.IsTrue(hub1KnownHubs.Any(x => x.Name == "hub 2"));
            Assert.IsTrue(hub1KnownHubs.Any(x => x.Name == "hub 3"));

            var hub2KnownHubs = hub2.KnownHubs.ToArray();

            Assert.AreEqual(3, hub2KnownHubs.Length);
            Assert.IsTrue(hub2KnownHubs.Any(x => x.Name == "hub 0"));
            Assert.IsTrue(hub2KnownHubs.Any(x => x.Name == "hub 1"));
            Assert.IsTrue(hub2KnownHubs.Any(x => x.Name == "hub 3"));

            var hub3KnownHubs = hub3.KnownHubs.ToArray();

            Assert.AreEqual(3, hub3KnownHubs.Length);
            Assert.IsTrue(hub3KnownHubs.Any(x => x.Name == "hub 0"));
            Assert.IsTrue(hub3KnownHubs.Any(x => x.Name == "hub 1"));
            Assert.IsTrue(hub3KnownHubs.Any(x => x.Name == "hub 2"));
        }
        public ReceiveMainChatOrPMFromHub()
        {
            HubSetting settings = new HubSetting();

            settings.Address     = "127.0.0.1";
            settings.Port        = 411;
            settings.DisplayName = "FlowLib";
            settings.Protocol    = "Auto";

            Hub hubConnection = new Hub(settings);

            hubConnection.ProtocolChange += new FmdcEventHandler(hubConnection_ProtocolChange);
            hubConnection.Connect();
        }
예제 #18
0
        public DisplayRawMessages()
        {
            HubSetting settings = new HubSetting();

            settings.Address     = "127.0.0.1";
            settings.Port        = 411;
            settings.DisplayName = "FlowLib";
            settings.Protocol    = "Auto";

            Hub hubConnection = new Hub(settings);

            hubConnection.ProtocolChange += new FlowLib.Events.FmdcEventHandler(hubConnection_ProtocolChange);
            hubConnection.Connect();
        }
예제 #19
0
        public bool ConnectToHub(string ip)
        {
            HubSetting settings = new HubSetting();

            settings.Address     = ip;
            settings.Protocol    = "Zpoc";
            settings.DisplayName = prefs.Nick;

            Hub hub = new Hub(settings);

            hub.Me.TagInfo.Version = "ZPoc V:3.00a";
            hub.ProtocolChange    += new FmdcEventHandler(protUpdate);
            hub.Connect();

            return(true);
        }
        public RetrievingUserInfoWhenReceivingPrivateMessage()
        {
            UpdateBase = new FlowLib.Events.FmdcEventHandler(OnUpdateBase);

            HubSetting settings = new HubSetting();

            settings.Address     = "127.0.0.1";
            settings.Port        = 411;
            settings.DisplayName = "FlowLib";
            settings.Protocol    = "Nmdc";

            Hub hubConnection = new Hub(settings, this);

            hubConnection.ProtocolChange += new FlowLib.Events.FmdcEventHandler(hubConnection_ProtocolChange);
            hubConnection.Connect();
        }
예제 #21
0
        protected async Task SubmitFrom()
        {
            var vm = new TokenViewModel
            {
                Email    = Email,
                Password = Password
            };

            var response = await Http.PostJsonAsync <TokenResponse>("api/Token/Login", vm);

            await AuthStore.Login(response.Token);

            await Hub.Connect();

            UriHelper.NavigateTo("/");
        }
예제 #22
0
        private static void hubsTest()
        {
            var hub0         = new Hub("hub 0");
            var hub0EndPoint = new IPEndPoint(IPAddress.Loopback, 4500);

            hub0.StartListening(hub0EndPoint);

            var hub1 = new Hub("hub 1")
            {
                PathThrough = true
            };
            var hub1EndPoint = new IPEndPoint(IPAddress.Loopback, 4501);

            hub1.StartListening(hub1EndPoint);

            var hub2 = new Hub("hub 2")
            {
                PathThrough = true
            };
            var hub2EndPoint = new IPEndPoint(IPAddress.Loopback, 4502);

            hub2.StartListening(hub2EndPoint);

            Task.WaitAll(hub1.Connect(hub0EndPoint),
                         hub2.Connect(hub1EndPoint));

            Thread.Sleep(100);

            var hub3 = new Hub("hub 3")
            {
                PathThrough = true
            };
            var hub3EndPoint = new IPEndPoint(IPAddress.Loopback, 4503);

            //hub3.Listen(hub3EndPoint);

            Task.WaitAll(hub3.Connect(hub1EndPoint));

            Task.WaitAll(
                hub1.RegisterInterface <ITest>(new ClassV1(), 1),
                hub2.RegisterInterface <ITest>(new ClassV2(), 2));

            var v = hub0.Get <ITest>().Call(x => x.GetValue(), 2).Result;

            Console.WriteLine(v);
        }
예제 #23
0
        public void SendLambda()
        {
            using var hub1 = new Hub(777008, "hub 1");

            var endpoint2 = new IPEndPoint(IPAddress.Loopback, 4501);

            using var hub2 = new Hub(777009, "hub 2");
            hub2.StartListening(endpoint2);

            hub1.Connect(endpoint2).Wait();

            hub1.RegisterInterface <ITestInterface>(new TestImplementation()).Wait();

            var value = hub2.Get <ITestInterface>().Call(x => x.MethodWithCallback((y, s) => s + y));

            value.Wait();

            Assert.AreEqual("str1", value.Result);
        }
예제 #24
0
        public void CallWithTaskAsResult()
        {
            using var hub1 = new Hub(777008, "hub 1");

            var endpoint2 = new IPEndPoint(IPAddress.Loopback, 4501);

            using var hub2 = new Hub(777009, "hub 2");
            hub2.StartListening(endpoint2);

            hub1.Connect(endpoint2).Wait();

            hub1.RegisterInterface <ITestInterface>(new TestImplementation()).Wait();

            var value = hub2.Get <ITestInterface>().Call(x => x.GetDelayedValue(123));

            value.Wait();

            Assert.AreEqual(123, value.Result);
        }
예제 #25
0
        public ConnectToHub()
        {
            HubSetting settings = new HubSetting();

            settings.Address     = "127.0.0.1";
            settings.Port        = 411;
            settings.DisplayName = "FlowLib";
            // The below is one way to say what protocol we should use when connecting to hub.
            //settings.Protocol = "Nmdc";   // Here we are saying we know it is a Nmdc hub
            //settings.Protocol = "Adc";   // Here we are saying we know it is a Adc hub
            //settings.Protocol = "Auto";   // Here we tell it we dont care what protocol it uses (Adc or Nmdc). Just try to connect.

            Hub hubConnection = new Hub(settings);

            // This is a other way to say what protocol we should use when connecting
            hubConnection.Protocol = new FlowLib.Protocols.HubNmdcProtocol(hubConnection);

            hubConnection.Connect();
        }
예제 #26
0
        public void InterfacePropagation()
        {
            using var hub1 = new Hub(777001, "hub 1");
            using var hub2 = new Hub(777002, "hub 2");
            var endpoint = new IPEndPoint(IPAddress.Loopback, 4500);

            hub1.StartListening(endpoint);
            hub2.Connect(endpoint).Wait();

            hub1.RegisterInterface <ITestInterface>(new TestImplementation()).Wait();

            while (!hub2.TryGet <ITestInterface>(out _))
            {
                Thread.Sleep(1);
            }

            var remoteInterface = hub2.Get <ITestInterface>();

            Assert.IsNotNull(remoteInterface);
            Assert.AreEqual(typeof(ITestInterface).FullName, remoteInterface.Name);
        }
예제 #27
0
        public void CallMethodWithVoidResult()
        {
            using var hub1 = new Hub(777008, "hub 1");

            var endpoint2 = new IPEndPoint(IPAddress.Loopback, 4501);

            using var hub2 = new Hub(777009, "hub 2");
            hub2.StartListening(endpoint2);

            hub1.Connect(endpoint2).Wait();

            var called = false;

            hub1.RegisterInterface <ITestInterface>(new TestImplementation(() => called = true)).Wait();

            var value = hub2.Get <ITestInterface>().Call(x => x.SomeMethod());

            value.Wait();

            Assert.IsTrue(called, nameof(called));
        }
예제 #28
0
        public ChangeBotUserInfo()
        {
            HubSetting settings = new HubSetting();

            settings.Address     = "127.0.0.1";
            settings.Port        = 411;
            settings.DisplayName = "FlowLib";
            settings.Protocol    = "Auto";

            Hub hubConnection = new Hub(settings);

            // Connection mode in UserInfo. Direct/Passive/Socket5
            hubConnection.Me.Mode = FlowLib.Enums.ConnectionTypes.Direct;
            // Client/Bot name and version in UserInfo.
            hubConnection.Me.TagInfo.Version = "SpeedBot V:2.0";
            // Connection in UserInfo
            hubConnection.Me.Connection = "104KiB/s";
            // User Description in UserInfo
            hubConnection.Me.Description = "Testing you for a better feature";
            hubConnection.Connect();
        }
예제 #29
0
        private void HubTest(string protocol)
        {
            _settings.Protocol = protocol;

            Hub hubConnection = new Hub(_settings, this);

            hubConnection.SecureUpdate   += new FmdcEventHandler(hubConnection_SecureUpdate);
            hubConnection.ProtocolChange += new FmdcEventHandler(hubConnection_ProtocolChange);

            hubConnection.Connect();

            int i = 0;

            while (!_isFinished && i++ < 20)
            {
                Thread.Sleep(500);
            }

            hubConnection.Disconnect("Test time exceeded");
            hubConnection.Dispose();
        }
예제 #30
0
        public PassiveEmptySharing()
        {
            // Creates a empty share
            Share share = new Share("Testing");

            // Adds common filelist to share
            AddFilelistsToShare(share);

            HubSetting setting = new HubSetting();

            setting.Address     = "127.0.0.1";
            setting.Port        = 411;
            setting.DisplayName = "FlowLib";
            setting.Protocol    = "Auto";

            Hub hubConnection = new Hub(setting);

            hubConnection.ProtocolChange += new FmdcEventHandler(hubConnection_ProtocolChange);
            // Adds share to hub
            hubConnection.Share = share;
            hubConnection.Connect();
        }