private void initialize()
        {
            //if file already exists do nothing
            //else create new file
            String      ownIPAddress = "127.0.0.1";
            IPHostEntry host;

            host = Dns.GetHostEntry(Dns.GetHostName());
            foreach (IPAddress ip in host.AddressList)
            {
                if (ip.AddressFamily == AddressFamily.InterNetwork)
                {
                    ownIPAddress = ip.ToString();
                    break;
                }
            }
            thisMachineIpnPort = new HostIPnPort(ownIPAddress, port);
            string curFile = System.Environment.CurrentDirectory + "\\Calendar.txt";

            if (File.Exists(curFile))
            {
                //do nothing
            }
            else
            {
                File.Create(curFile).Dispose();
            }
        }
 public int compare(HostIPnPort obj2)
 {
     if(this.getHostId()<obj2.getHostId())
     return -1;
     if(this.getHostId()==obj2.getHostId())
     return 0;
     else
     return 1;
 }
 public bool addNode(string IpnPort)
 {
     Console.WriteLine("New node has joined the network.");
     //Client.activeNodes.Add(ipAddress);
     HostIPnPort newObj = new HostIPnPort(IpnPort);
     int k = 0;
     while (k < Client.activeNodes.Count && Client.activeNodes[k].compare(newObj) < 0) k++;
     Client.activeNodes.Insert(k, newObj);
     return true;
 }
        public bool addNode(string IpnPort)
        {
            Console.WriteLine("New node has joined the network.");
            //Client.activeNodes.Add(ipAddress);
            HostIPnPort newObj = new HostIPnPort(IpnPort);
            int         k      = 0;

            while (k < Client.activeNodes.Count && Client.activeNodes[k].compare(newObj) < 0)
            {
                k++;
            }
            Client.activeNodes.Insert(k, newObj);
            return(true);
        }
Exemple #5
0
 public int compare(HostIPnPort obj2)
 {
     if (this.getHostId() < obj2.getHostId())
     {
         return(-1);
     }
     if (this.getHostId() == obj2.getHostId())
     {
         return(0);
     }
     else
     {
         return(1);
     }
 }
        public bool deleteNode(string IpnPort)
        {
            Console.WriteLine("Node has signed off the network.");
            //Client.activeNodes.Remove(ipAddress);
            int k = 0;

            while (k < Client.activeNodes.Count && !Client.activeNodes[k].getIPnPort().Equals(IpnPort))
            {
                k++;
            }
            if (k < Client.activeNodes.Count)
            {
                HostIPnPort obj = Client.activeNodes[k];
                Client.activeNodes.Remove(obj);
            }
            if (Client.activeNodes.Count == 1)
            {
                TokenRing.stopTokenRingAlgorithm(); //If you are alone you must stop Token Ring
            }
            return(true);
        }
Exemple #7
0
 public TokenSender(HostIPnPort nextNodeOnRing)
 {
     this.nextNodeOnRing = nextNodeOnRing;
 }
 public TokenSender(HostIPnPort nextNodeOnRing)
 {
     this.nextNodeOnRing = nextNodeOnRing;
 }
        private void join()
        {
            //if offline
            //make it online
            //input ip of active node, if it is first onlinenode input 17.0.0.1
            //if 127.0.0.1 then isOnline = true
            //else
            //get list of all events
            //ip to url
            //config xmlrpc
            //get list of active nodes
            //for all active nodes - joinoverrpc
            //else node is already online
            if (!isOnline)
            {
                isOnline = true;
                Console.WriteLine("Input IP-address of active node");
                Console.WriteLine("If it is the first online node input 127.0.0.1");
                String ipAddress = Console.ReadLine();
                if (!ipAddress.Equals("127.0.0.1"))
                {
                    //TODO set port
                    Console.WriteLine("Enter the port for this machine : ");
                    int port = int.Parse(Console.ReadLine());
                    firstActiveNode = new HostIPnPort(ipAddress, port);

                    getListOfEvents(true);
                    IServiceContract proxy = XmlRpcProxyGen.Create <IServiceContract>();
                    proxy.Url = firstActiveNode.getFullUrl();
                    Object[] listOfNodes = proxy.getListOfActiveNodes();
                    for (int i = 0; i < listOfNodes.Length; i++)
                    {
                        HostIPnPort newObj = new HostIPnPort(listOfNodes[i].ToString());
                        int         k      = 0;
                        while (k < activeNodes.Count && activeNodes[k].compare(newObj) < 0)
                        {
                            k++;
                        }
                        activeNodes.Insert(k, newObj);
                        //activeNodes.Add(list[i].ToString());
                    }
                    bool tokenRingStarter = false;
                    if (activeNodes.Count == 2)
                    {
                        tokenRingStarter = true;
                    }
                    foreach (HostIPnPort h in activeNodes)
                    {
                        if (!h.Equals(thisMachineIpnPort))
                        {
                            joinOverRPC(h.getFullUrl());
                        }
                    }
                    //config xnlrpc with firstactivenode to url
                    //call Node.getListOfActive Nodes
                    //add all nodes to the list of active nodes
                    //for all activenodes - joinoverRPC(s)
                    if (tokenRingStarter)
                    {
                        TokenRing.startTokenRingAlgorithm(); //for the time that you are starter of the token ring
                    }
                    if (activeNodes.Count > 2)
                    {
                        TokenRing.initiateTokenRing(); //for the time that token does not rotating in the Network Ring and it need to be monitored by this client
                    }
                }
                else
                {
                    isOnline = true;
                }
            }
            else
            {
                Console.WriteLine("Node is already online!");
            }
        }
Exemple #10
0
        private void join()
        {
            //if offline
            //make it online
            //input ip of active node, if it is first onlinenode input 17.0.0.1
            //if 127.0.0.1 then isOnline = true
            //else
            //get list of all events
            //ip to url
            //config xmlrpc
            //get list of active nodes
            //for all active nodes - joinoverrpc
            //else node is already online
            if (!isOnline)
            {
                isOnline = true;
                Console.WriteLine("Input IP-address of active node");
                Console.WriteLine("If it is the first online node input 127.0.0.1");
                String ipAddress = Console.ReadLine();
                if (!ipAddress.Equals("127.0.0.1"))
                {
                    //TODO set port
                    Console.WriteLine("Enter the port for this machine : ");
                    int port = int.Parse(Console.ReadLine());
                    firstActiveNode = new HostIPnPort(ipAddress, port);

                    getListOfEvents(true);
                    IServiceContract proxy = XmlRpcProxyGen.Create<IServiceContract>();
                    proxy.Url = firstActiveNode.getFullUrl();
                    Object[] listOfNodes = proxy.getListOfActiveNodes();
                    for (int i = 0; i < listOfNodes.Length; i++)
                    {
                        HostIPnPort newObj = new HostIPnPort(listOfNodes[i].ToString());
                        int k = 0;
                        while (k < activeNodes.Count && activeNodes[k].compare(newObj) < 0) k++;
                        activeNodes.Insert(k, newObj);
                        //activeNodes.Add(list[i].ToString());
                    }
                    bool tokenRingStarter = false;
                    if (activeNodes.Count == 2)
                        tokenRingStarter = true;
                    foreach (HostIPnPort h in activeNodes)
                    {
                        if (!h.Equals(thisMachineIpnPort))
                            joinOverRPC(h.getFullUrl());
                    }
                    //config xnlrpc with firstactivenode to url
                    //call Node.getListOfActive Nodes
                    //add all nodes to the list of active nodes
                    //for all activenodes - joinoverRPC(s)
                    if (tokenRingStarter)
                        TokenRing.startTokenRingAlgorithm(); //for the time that you are starter of the token ring
                    if (activeNodes.Count > 2)
                        TokenRing.initiateTokenRing(); //for the time that token does not rotating in the Network Ring and it need to be monitored by this client
                }
                else
                {
                    isOnline = true;
                }
            }
            else
            {
                Console.WriteLine("Node is already online!");
            }
        }
Exemple #11
0
        private void initialize()
        {
            //if file already exists do nothing
            //else create new file
            String ownIPAddress = "127.0.0.1";
            IPHostEntry host;
            host = Dns.GetHostEntry(Dns.GetHostName());
            foreach (IPAddress ip in host.AddressList)
            {
                if (ip.AddressFamily == AddressFamily.InterNetwork)
                {
                    ownIPAddress = ip.ToString();
                    break;
                }
            }
            thisMachineIpnPort = new HostIPnPort(ownIPAddress, port);
            string curFile = System.Environment.CurrentDirectory + "\\Calendar.txt";
            if (File.Exists(curFile))
            {
                //do nothing
            }
            else
            {
                File.Create(curFile).Dispose();

            }
        }