Beispiel #1
0
 public Client(Node info,TcpChannel channel,  IPuppetMaster puppet, ICentralDirectory cd)
 {
     Registers = new string[10];
     Info = info;
     Channel = channel;
     Puppet = puppet;
     CD = cd;
 }
Beispiel #2
0
        static void Main(string[] args)
        {
            TcpChannel channel = new TcpChannel(0);
            ChannelServices.RegisterChannel(channel, true);

            ChannelDataStore channelData = (ChannelDataStore)channel.ChannelData;
            int port = new System.Uri(channelData.ChannelUris[0]).Port;
            string host = new System.Uri(channelData.ChannelUris[0]).Host;
            //string name = args[1];

            Node node = new Node(host, port, "Console", NodeType.Client);

            ICentralDirectory centralDirectory = (ICentralDirectory)Activator.GetObject(
              typeof(ICentralDirectory),
              "tcp://localhost:9090/CentralDirectory");
            centralDirectory.RegisterClient(node);

            RemotingConfiguration.RegisterWellKnownServiceType(typeof(ClientRemoting), "Client", WellKnownObjectMode.Singleton);

            Console.Write("Enter seed: ");
            string seed = Console.ReadLine();

            string[] fIn = { "PUT 1" + seed + " 1", "GET 1" + seed, "PUT 2" + seed + " 2", "PUT Afonso" + seed + " A", "PUT Francisco" + seed + " F", "PUT Jerome" + seed + " J", "PUT JAmbrosio" + seed + " JA", "GET JAmbrosio" + seed, "PUT 3" + seed + " 3", "PUT 4" + seed + " 4", "GET 4" + seed };

            Transaction t = new Transaction();

               if (seed != "clean")
               foreach (string inp in fIn)
               {
                   if (inp.StartsWith("GET"))
                   {
                       char[] delim = { ' ', '\t' };
                       string[] arg = inp.Split(delim);
                       if (t.GetValue(arg[1]) == null)
                       {
                           Console.ReadLine();
                           return;
                       }
                   }
                   else if (inp.StartsWith("PUT"))
                   {
                       char[] delim = { ' ', '\t' };
                       string[] arg = inp.Split(delim);
                       if (!t.PutValue(arg[1], arg[2]))
                       {
                           Console.ReadLine();
                           return;
                       }
                   }
               }
               else Console.WriteLine("No default operations were made.");

            Console.WriteLine("Choose you're operations\n\nPUT <key> <value> for a put\nGET <key> for a GET\nEmpty Line to process");
            string input="";
            do
            {
                input = Console.ReadLine();
                if (input.StartsWith("GET"))
                {
                    char[] delim = {' ','\t'};
                    string val = null;
                    string[] arg = input.Split(delim);
                    val = t.GetValue(arg[1]);
                    if (val ==  null) {
                        Console.ReadLine();
                        return;
                    }
                    Console.WriteLine(val);
                }
                else if(input.StartsWith("PUT")) {
                    char[] delim = {' ','\t'};
                    string[] arg = input.Split(delim);
                    if (!t.PutValue(arg[1], arg[2]))
                    {
                        Console.ReadLine();
                        return;
                    }
                }

            } while (input != "");

            t.Commit();

            Console.ReadLine();
        }
Beispiel #3
0
        public void Restructure(uint semiTable,Node d)
        {
            uint max_aux = 0;
                uint numberofServer = (uint)listServer.Count();

                if (numberofServer == 1)
                {
                    Console.WriteLine("Replicating... ");
                    IServer oldNode = (IServer)Activator.GetObject(typeof(IServer), "tcp://" + Location[0].IP[0].IP + ":" + Location[0].IP[0].Port.ToString() + "/Server");
                    oldNode.CopySemiTables(d);
                    Location[0].IP.Add(d);
                    Location[1].IP.Insert(0, d);
                    return;
                }

                for (int i = 0; i < Location.Count(); i++)
                {

                    if (Location[i].min < semiTable && Location[i].max > semiTable)
                    {
                        Console.WriteLine("Restructuring... " + semiTable);

                        Interval st = new Interval();
                        st.IP = new List<Node>();
                        max_aux = Location[i].max;
                        Location[i].max = semiTable - 1;
                        st.min = semiTable;
                        st.max = max_aux;
                        st.IP.Add(d);
                        st.IP.Add(Location[i].IP[1]);

                        tableOfLocation.Add(st);
                        IServer link1 = (IServer)Activator.GetObject(typeof(IServer), "tcp://" + Location[i].IP[0].IP + ":" + Location[i].IP[0].Port.ToString() + "/Server");
                        link1.CleanSemiTable(semiTable, d);
                        IServer link2 = (IServer)Activator.GetObject(typeof(IServer), "tcp://" + Location[i].IP[1].IP + ":" + Location[i].IP[1].Port.ToString() + "/Server");
                        link2.CopyAndCleanTable(semiTable, d);
                        Location[i].IP[1] = d;
                        break;
                    }
                }

                for (int i = 0; i < Location.Count; i++)
                {
                    Console.WriteLine("min: " + Location[i].min + " max: " + Location[i].max + "   IP1: " + Location[i].IP[0].Port + "  IP2: " + Location[i].IP[1].Port);
                }
                //link.GetNetworkUpdate(listUpDate);
                //CleanSemiTable(uint semiTableToClean);
                //CopyAndCleanTable(uint semiTableToClean);
        }
Beispiel #4
0
        public bool InsertServer(Node node)
        {
            lock (insertLocker)
               {
               List<Dictionary<uint, int>> listAux = new List<Dictionary<uint, int>>();
               if (miss == true)
               {
                   for (int i = 0; i < Location.Count; i++)
                   {
                       if (Location[i].min == semiTablemin1 && Location[i].max == semiTablemax1)
                       {
                           Console.WriteLine("Sending restructure request to: " + Location[i].IP[0]);
                           IServer link = (IServer)Activator.GetObject(typeof(IServer), "tcp://" + Location[i].IP[0].IP + ":" + Location[i].IP[0].Port.ToString() + "/Server");
                           Location[i].IP.Add(node);
                           link.CopySemiTable(Location[i].min, node);
                       }

                       else if (Location[i].min == semiTablemin2 && Location[i].max == semiTablemax2)
                       {
                           Console.WriteLine("Sending restructure request to: " + Location[i].IP[0]);
                           IServer link = (IServer)Activator.GetObject(typeof(IServer), "tcp://" + Location[i].IP[0].IP + ":" + Location[i].IP[0].Port.ToString() + "/Server");
                           Location[i].IP.Add(node);
                           link.CopySemiTable(Location[i].min, node);
                       }
                   }
                   miss = false;
               }

               else if (firstTime == true)
               {
                   listAux = DimensionOfServers(ListServer);
                   Restructure(MaxSemiTable(listAux), node);
               }

               lock (nodesListLocker)
               {
                   Server = node;
               }
               //Send(ListClient, ListServer);
               return true;
               }
        }
Beispiel #5
0
        public void division()
        {
            lock (insertLocker)
               {
               firstTime = true;
               uint numberofServer = (uint)listServer.Count();
               uint result = 0;
               uint aux1 = 0;

               //int aux3 = 0;
               result = max / numberofServer;
               uint aux2 = result;

               List<string> aux4 = new List<string>();

               if (numberofServer == 1)
               {
                   Node srv = new Node(listServer[0].IP, listServer[0].Port, NodeType.Server);
                   Interval st1 = new Interval();
                   st1.IP = new List<Node>();
                   st1.min = UInt32.MinValue;
                   st1.max = UInt32.MaxValue / 2;
                   st1.IP.Add(srv);
                   Interval st2 = new Interval();
                   st2.IP = new List<Node>();
                   st2.min = UInt32.MaxValue / 2 + 1;
                   st2.max = UInt32.MaxValue;
                   st2.IP.Add(srv);

                   IServer link1 = (IServer)Activator.GetObject(typeof(IServer), "tcp://" + srv.IP + ":" + srv.Port.ToString() + "/Server");
                   link1.GetInitialIntervals(st1.min, st1.max, srv);
                   IServer link2 = (IServer)Activator.GetObject(typeof(IServer), "tcp://" + srv.IP + ":" + srv.Port.ToString() + "/Server");
                   link2.GetInitialIntervals(st2.min, st2.max, srv);

                   tableOfLocation.Add(st1);
                   tableOfLocation.Add(st2);

                   return;
               }

               for (int i = 0; i < numberofServer; i++)
               {

                   Interval st = new Interval();
                   st.IP = new List<Node>();
                   st.min = aux1;
                   st.max = aux2;

                   if (i == numberofServer - 1)
                   {
                       Node node1 = new Node(listServer[i].IP, listServer[i].Port, NodeType.Server);
                       Node a = new Node(listServer[0].IP, listServer[0].Port, NodeType.Server);
                       //node1.IP = listServer[i].IP;
                       //node1.Port = listServer[i].Port;
                       //node2.IP = listServer[0].IP;
                       //node2.Port = listServer[0].Port;
                       st.IP.Add(node1);
                       st.IP.Add(a);
                       //st.IP.Add(listServer[i].IP + ":" + listServer[i].Port.ToString());
                       //st.IP.Add(listServer[0].IP + ":" + listServer[0].Port.ToString());

                       IServer link1 = (IServer)Activator.GetObject(typeof(IServer), "tcp://" + listServer[i].IP + ":" + listServer[i].Port.ToString() + "/Server");
                       link1.GetInitialIntervals(aux1, aux2, listServer[0]);

                       IServer link2 = (IServer)Activator.GetObject(typeof(IServer), "tcp://" + listServer[0].IP + ":" + listServer[0].Port.ToString() + "/Server");
                       link2.GetInitialIntervals(aux1, aux2, listServer[i]);

                   }
                   else
                   {
                       Node node1 = new Node(listServer[i].IP, listServer[i].Port, NodeType.Server);
                       Node a = new Node(listServer[i + 1].IP, listServer[i + 1].Port, NodeType.Server);
                       //node1.IP = listServer[i].IP;
                       //node1.Port = listServer[i].Port;
                       //node2.IP = listServer[i + 1].IP;
                       //node2.Port = listServer[i + 1].Port;
                       st.IP.Add(node1);
                       st.IP.Add(a);
                       //st.IP.Add(listServer[i].IP + ":" + listServer[i].Port.ToString());
                       //st.IP.Add(listServer[i + 1].IP + ":" + listServer[i + 1].Port.ToString());

                       IServer link1 = (IServer)Activator.GetObject(typeof(IServer), "tcp://" + listServer[i].IP + ":" + listServer[i].Port.ToString() + "/Server");
                       link1.GetInitialIntervals(aux1, aux2, listServer[i + 1]);

                       IServer link2 = (IServer)Activator.GetObject(typeof(IServer), "tcp://" + listServer[i + 1].IP + ":" + listServer[i + 1].Port.ToString() + "/Server");
                       link2.GetInitialIntervals(aux1, aux2, listServer[i]);
                   }

                   tableOfLocation.Add(st);

                   if (aux1 == 0)
                       aux1 = aux1 + result + 1;
                   else aux1 = aux1 + result;

                   aux2 = aux2 + result;

               }

               }
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            int port = 0;
            if (args.Length > 1) port = Int32.Parse(args[1]);
            TcpChannel channel = new TcpChannel(port);
            ChannelServices.RegisterChannel(channel, true);

            ChannelDataStore channelData = (ChannelDataStore)channel.ChannelData;
            port = new System.Uri(channelData.ChannelUris[0]).Port;
            string host = new System.Uri(channelData.ChannelUris[0]).Host;
            string name = null;
            if (args.Length > 0) name = args[0];
            else name = "Debug" + port.ToString();

            Console.WriteLine("Ciente: " + name);

            RemotingConfiguration.RegisterWellKnownServiceType(typeof(ClientPuppet), "ClientPuppet", WellKnownObjectMode.Singleton);

            IPuppetMaster puppet = (IPuppetMaster)Activator.GetObject(
               typeof(IPuppetMaster),
               "tcp://localhost:8090/PseudoNodeReg");

            ICentralDirectory cd = (ICentralDirectory)Activator.GetObject(
              typeof(ICentralDirectory),
              "tcp://localhost:9090/CentralDirectory");

            Node node = new Node(host, port, name,NodeType.Client);
            //cd.RegisterClient(node);
            Client clt = new Client(node,channel,puppet,cd);
            ClientPuppet.ctx = clt;
            ClientRemoting.ctx = clt;
            try { puppet.RegisterPseudoNode(node); }
            catch { System.Console.WriteLine("We Dont Need No Puppet Master"); }
            System.Console.WriteLine(host + ":" + port.ToString());
            Console.WriteLine("Press Enter to Test...");
            System.Console.ReadLine();
        }
Beispiel #7
0
 public bool Equals(Node node)
 {
     if (IP == node.IP && Port == node.Port) return true;
     else return false;
 }