Example #1
0
        private void CheckConnectivity()
        {
            List <RemotePeer> RemotePeerListCopy = RemotePeerList;
            var itr = RemotePeerListCopy.GetEnumerator();

            while (itr.MoveNext())
            {
                //if (itr.Current.RemotePeerType == RemotePeer.RemotePeerTypes.Master)
                //{
                RemotePeer tmp = itr.Current;
                if (tmp.GetConnectionStatus() == RemotePeer.ConnectonStaus.Disconnected)
                {
                    if (tmp.RemotePeerType == RemotePeer.RemotePeerTypes.Master)
                    {
                        Console.WriteLine("Disc 1");
                        // TODO Reconnect
                        tmp.ConnectionStatusChange(RemotePeer.ConnectonStaus.Disconnected);
                        Disconnect();
                        Connect(tmp.ipEndPoint.Address.ToString(), tmp.ipEndPoint.Port);
                        Console.WriteLine("Disc 2");
                    }
                    else
                    {
                        //TODO delete the peer
                        Console.WriteLine("Disc 3");
                        tmp.ConnectionStatusChange(RemotePeer.ConnectonStaus.Disconnected);
                        // TODO: Why?!
                        //RemotePeerList.Remove(tmp);
                        itr.Current.shouldberemoved = true;
                        Console.WriteLine("Disc 4");
                    }
                }
                else
                {
                    if ((tmp.RemotePeerType == RemotePeer.RemotePeerTypes.Master) && (tmp.GetConnectionStatus() == RemotePeer.ConnectonStaus.Connected))
                    {
                        tmp.Ping();
                    }
                }
                //}
            }
            List <RemotePeer> RemotePeerListCopys = RemotePeerList;
            var itrremove = RemotePeerListCopys.ToArray().GetEnumerator();

            while (itrremove.MoveNext())
            {
                RemotePeer tmp = (RemotePeer)itrremove.Current;
                if (tmp.shouldberemoved)
                {
                    RemotePeerList.Remove(tmp);
                }
            }
        }
Example #2
0
 private void DispatchInternal(RemotePeer senderpeer, Protocol message)
 {
     if (message.Data.Data == "Hello")
     {
         Protocol msg = new Protocol();
         msg.Header.SendType = ProtocolHeader.MessageSendType.Internal;
         msg.Data.Data       = "HandShake";
         Send(senderpeer, msg);
         senderpeer.ConnectionStatusChange(RemotePeer.ConnectonStaus.Connected);
     }
     if (message.Data.Data == "HandShake")
     {
         senderpeer.ConnectionStatusChange(RemotePeer.ConnectonStaus.Connected);
     }
 }
Example #3
0
        public RemotePeer Connect(string IPV4IP, int port)
        {
            socket.Connect(IPV4IP, port);
            //TODO is it reqired to check for the connect result?

            System.Net.IPAddress  RemotePeerIPAddress = System.Net.IPAddress.Parse(IPV4IP);
            System.Net.IPEndPoint RemotePeerEndPoint  = new System.Net.IPEndPoint(RemotePeerIPAddress, port);

            RemotePeer remotepeer = TouchPeer(RemotePeerEndPoint);

            if (remotepeer.RemotePeerType == RemotePeer.RemotePeerTypes.NotDeterminedYet)
            {
                remotepeer.RemotePeerType = RemotePeer.RemotePeerTypes.Master;
            }

            remotepeer.ResetReceives();
            remotepeer.ResetSends();

            Protocol message = new Protocol();

            message.Header.SendType = ProtocolHeader.MessageSendType.Internal;
            message.Data.Data       = "Hello";

            Send(remotepeer, message);

            //ConnectionStatusChange(ConnectonStaus.Connecting, remotepeer);
            remotepeer.ConnectionStatusChange(RemotePeer.ConnectonStaus.Connecting);

            return(remotepeer);
        }
Example #4
0
        public RemotePeer Connect(string IPV4IP, int port)
        {
            socket.Connect(IPV4IP, port);

            Console.WriteLine("RUDPPeer: socket Connected to: " + IPV4IP + ":" + port);

            System.Net.IPAddress  RemotePeerIPAddress = System.Net.IPAddress.Parse(IPV4IP);
            System.Net.IPEndPoint RemotePeerEndPoint  = new System.Net.IPEndPoint(RemotePeerIPAddress, port);

            RemotePeer remotepeer = TouchPeer(RemotePeerEndPoint);

            remotepeer.RemotePeerType = RemotePeerTypes.Master;
            //SortedDictionary<int, Protocol > outgoingtmp = remotepeer.OutGoingMessageList;
            //remotepeer.Reset();

            Protocol message = new Protocol();

            message.Header.SendType = ProtocolHeader.MessageSendType.Internal;
            message.Data.Data       = "Hello";
            remotepeer.Send(message);
            // TDOO this line should be moved to ManageRemoteConnections to reconnect and stuff
            //remotepeer.ResendAllOutgoingMessages(outgoingtmp);

            remotepeer.ConnectionStatusChange(ConnectonStaus.Connecting);


            Console.WriteLine($"RUDPPeer: <<< Number of RemotePeerList connections: {RemotePeerList.Count}");
            return(remotepeer);
        }