Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            TestAckSenderWindow test = new TestAckSenderWindow();
            test.ackSender.setWindowSize(3,2);

            Console.WriteLine("-=-=-=-=- Sending 5 messages -=-=-=-=-");
            Message msg = new Message(null,null,"Sending message 0");
            test.ackSender.add(0,msg);

            msg = new Message(null,null,"Sending message 1");
            test.ackSender.add(1,msg);

            msg = new Message(null,null,"Sending message 2");
            test.ackSender.add(2,msg);
            msg = new Message(null,null,"Sending message 3");
            test.ackSender.add(3,msg);
            msg = new Message(null,null,"Sending message 4");
            test.ackSender.add(4,msg);

            Thread.Sleep(10000);

            Console.WriteLine("-=-=-=-=- Ack msg 1 -=-=-=-=-");
            test.ackSender.ack(1);
            Thread.Sleep(10000);

            Console.WriteLine("-=-=-=-=- Ack msg 0 -=-=-=-=-");
            test.ackSender.ack(0);

            Console.ReadLine();
        }
Ejemplo n.º 2
0
        // -=-=-=-=-=-=-=- MessageListener Interface -=-=-=-=-=-=-=-
        public void receive(GCT.Message msg)
        {
            try
            {
                Object obj = msg.getObject();
                if (obj != null && (obj is String))
                {
                    String str         = (String)obj;
                    String userHandler = "???";
                    int    pos         = str.IndexOf("|:|");
                    if (pos != -1)
                    {
                        userHandler = str.Substring(0, pos);
                        str         = str.Substring((pos + 3), str.Length - (pos + 3));
                    }
                    if (members.Contains(msg.Source))
                    {
                        members[msg.Source] = userHandler;
                        updateMembers();
                        txtMsgsReceived.AppendText(userHandler + ":   " + (String)str + "\n");

                        txtMsgsReceived.SelectionStart = txtMsgsReceived.TextLength;
                        txtMsgsReceived.Focus();
                        txtMsgsReceived.ScrollToCaret();
                    }
                }
            }
            catch (Exception e)
            {
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            TestAckReceiverWindow test = new TestAckReceiverWindow();

            Console.WriteLine("-=-=-=-=- Receive msgs 0-2 -=-=-=-=-");
            Message msg = new Message(null,null,"Sending message 0");
            test.ackRecv.add(0,msg);
            msg = new Message(null,null,"Sending message 1");
            test.ackRecv.add(1,msg);
            msg = new Message(null,null,"Sending message 2");
            test.ackRecv.add(2,msg);

            Console.WriteLine("-=-=-=-=-=- Remove -=-=-=-=-=-");
            test.remove();

            Console.WriteLine("-=-=-=-=- Receive msgs 4-5 -=-=-=-=-");
            msg = new Message(null,null,"Sending message 4");
            test.ackRecv.add(4,msg);
            msg = new Message(null,null,"Sending message 5");
            test.ackRecv.add(5,msg);

            Console.WriteLine("-=-=-=-=-=- Remove -=-=-=-=-=-");
            test.remove();

            Console.WriteLine("-=-=-=-=- Receive msgs 3 -=-=-=-=-");
            msg = new Message(null,null,"Sending message 3");
            test.ackRecv.add(3,msg);

            Console.WriteLine("-=-=-=-=-=- Remove -=-=-=-=-=-");
            test.remove();
            Console.ReadLine();
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            int msgNo = 10;

            TestNakReceiverWindow test = new TestNakReceiverWindow();
            test.init();
            Message[] msgs = new Message[msgNo];
            for(int i= 0;i<msgNo;i++)
                msgs[i] = new Message(test.localAddr,test.remoteAddr, i + ": Test Message");

            Console.WriteLine("-=-=-=-=-=- Adding msgs 0-2 -=-=-=-=-=-");
            for(int i= 0;i < 3;i++)
                test.nak.add(i,msgs[i]);

            Console.WriteLine("-=-=-=-=-=- Remove -=-=-=-=-=-");
            Console.WriteLine(test.nak.toString());
            test.remove();
            Console.WriteLine(test.nak.toString());

            Console.WriteLine("-=-=-=-=-=- Adding msg 2 again -=-=-=-=-=-");
            test.nak.add(2,msgs[2]);
            Console.WriteLine(test.nak.toString());

            Console.WriteLine("-=-=-=-=-=- Adding msgs 3-4 -=-=-=-=-=-");
            test.nak.add(3,msgs[3]);
            test.nak.add(4,msgs[4]);

            Console.WriteLine("-=-=-=-=-=- Adding msgs 6-7 -=-=-=-=-=-");
            test.nak.add(6,msgs[6]);
            test.nak.add(7,msgs[7]);

            Thread.Sleep(10000);

            Console.WriteLine("-=-=-=-=-=- Remove -=-=-=-=-=-");
            test.remove();
            Console.WriteLine(test.nak.toString());

            Thread.Sleep(20000);

            Console.WriteLine("-=-=-=-=-=- Adding msg 5 -=-=-=-=-=-");
            test.nak.add(5,msgs[5]);

            Console.WriteLine("-=-=-=-=-=- Remove -=-=-=-=-=-");
            Console.WriteLine(test.nak.toString());
            test.remove();
            Console.WriteLine(test.nak.toString());

            Console.WriteLine("-=-=-=-=-=- Stable up to 5 -=-=-=-=-=-");
            test.nak.stable(5);
            Console.WriteLine(test.nak.toString());
            Console.WriteLine("-=-=-=-=-=- Stable up to 7 -=-=-=-=-=-");
            test.nak.stable(7);
            Console.WriteLine(test.nak.toString());

            Console.ReadLine();
        }
Ejemplo n.º 5
0
        private void sendMessage()
        {
            if (String.Compare(txtHandle.Text.Trim(), "") == 0 || String.Compare(txtHandle.Text.Trim(), "|:|") == 0)
            {
                txtHandle.Text = "DefaultName";
            }

            if (String.Compare(txtToSend.Text.Trim(), "") != 0)
            {
                GCT.Message msg = null;
                if (lstMembers.SelectedIndex != -1)
                {
                    foreach (DictionaryEntry dic in members)
                    {
                        if ((String.Compare((String)dic.Value, (String)lstMembers.SelectedItem) == 0))
                        {
                            if (!dic.Key.Equals(chan.getLocalAddress()))
                            {
                                msg = new GCT.Message((Address)dic.Key, chan.getLocalAddress(), txtHandle.Text + "|:|" + txtToSend.Text);
                            }
                            else
                            {
                                MessageBox.Show("Can't send message to yourself!!", "Private Message Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                        }
                    }
                }
                else
                {
                    msg = new GCT.Message(null, null, txtHandle.Text + "|:|" + txtToSend.Text);
                }

                if (msg != null)
                {
                    chan.send(msg);
                }
                txtToSend.Text = "";
            }
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            Tester.SetupDebug();
            NAKACK nak = new NAKACK();
            Protocol bottom = null;
            Protocol top = Tester.createStack(nak, out bottom);
            Address remote1 = new Address("1.1.1.1",8005);
            Address remote2 = new Address("1.1.1.2",8005);
            Address remote3 = new Address("1.1.1.3",8005);

            ArrayList members = new ArrayList();
            members.Add(Tester.localAddr);
            members.Add(remote1);
            members.Add(remote2);
            members.Add(remote3);

            View newView = new View(new ViewId(Tester.localAddr,0),members);
            evt = new Event(Event.VIEW_CHANGE,newView);
            top.down(evt);

            evt = new Event(Event.MSG,new Message(null,null,"Message 1"));
            top.down(evt);
            evt = new Event(Event.MSG,new Message(null,null,"Message 2"));
            top.down(evt);
            evt = new Event(Event.MSG,new Message(null,null,"Message 3"));
            top.down(evt);

            Console.WriteLine("-=-=-=-=- Received Msg 0 from Remote 1 -=-=-=-=-=-");
            Message msg = new Message(null,remote1,"Incoming Message 0");
            msg.Headers.Add("NAKACK",new NakAckHeader(NakAckHeader.MSG, 0));
            evt = new Event(Event.MSG,msg);
            bottom.up(evt);

            Console.WriteLine("-=-=-=-=- Received Msg 0 from Remote 2 -=-=-=-=-=-");
            msg = new Message(null,remote2,"Incoming Message 0");
            msg.Headers.Add("NAKACK",new NakAckHeader(NakAckHeader.MSG, 0));
            evt = new Event(Event.MSG,msg);
            bottom.up(evt);

            Console.WriteLine("-=-=-=-=- Received Msg 1 from Remote 1 -=-=-=-=-=-");
            msg = new Message(null,remote1,"Incoming Message 1");
            msg.Headers.Add("NAKACK",new NakAckHeader(NakAckHeader.MSG, 1));
            evt = new Event(Event.MSG,msg);
            bottom.up(evt);

            Console.WriteLine("-=-=-=-=- Received Msg 2 from Remote 2 -=-=-=-=-=-");
            msg = new Message(null,remote2,"Incoming Message 2");
            msg.Headers.Add("NAKACK",new NakAckHeader(NakAckHeader.MSG, 2));
            evt = new Event(Event.MSG,msg);
            bottom.up(evt);

            Thread.Sleep(20000);

            Console.WriteLine("-=-=-=-=- Received Msg 1 from Remote 2 -=-=-=-=-=-");
            msg = new Message(null,remote2,"Incoming Message 1");
            msg.Headers.Add("NAKACK",new NakAckHeader(NakAckHeader.MSG, 1));
            evt = new Event(Event.MSG,msg);
            bottom.up(evt);

            Thread.Sleep(3000);

            Console.WriteLine("-=-=-=-=- Receiving STABLE event -=-=-=-=-=-");
            Digest digest = new Digest(4); // 4 members
            digest.add(Tester.localAddr, 0, 2, 2);
            digest.add(remote1, 0, 1, 1);
            digest.add(remote2, 0, 2, 2);
            digest.add(remote3, 0, 0, 0);

            evt = new Event(Event.STABLE,digest);
            bottom.up(evt);

            Console.ReadLine();
            Tester.stopProtocols(top);

            Console.ReadLine();
        }
Ejemplo n.º 7
0
        // -=-=-=-=-=-=-=- MessageListener Interface -=-=-=-=-=-=-=-
        /// <summary>
        /// Message Listener Implementation. Receives messages from the channel and
        /// updates the hashtable accordingly.
        /// </summary>
        /// <param name="msg">The received message</param>
        public void receive(GCT.Message msg)
        {
            if (msg == null)
            {
                return;
            }
            object obj = msg.getObject();

            if (obj == null)
            {
                return;
            }
            if (!(obj is HTUpdate))
            {
                return;
            }
            HTUpdate update = (HTUpdate)obj;

            switch (update.Type)
            {
            case HTUpdate.ADD:
                if (update.Key != null && update.Value != null)
                {
                    _Add(update.Key, update.Value);
                }
                break;

            case HTUpdate.UPDATE:
                if (update.Key != null && update.Value != null)
                {
                    _Update(update.Key, update.Value);
                }
                break;

            case HTUpdate.REMOVE:
                if (update.Key != null)
                {
                    _Remove(update.Key);
                }
                break;

            case HTUpdate.CLEAR:
                _Clear();
                break;

            case HTUpdate.SET_STATE:
                if (update.Value != null && update.Value is Hashtable)
                {
                    lock (state_mutex)
                    {
                        _State((Hashtable)update.Value);
                        Monitor.Pulse(state_mutex);
                    }
                }
                break;

            case HTUpdate.GET_STATE:
                if (channel.getView().getMembers()[0].Equals(channel.getLocalAddress()))
                {
                    channel.send(new Message(msg.Source, channel.getLocalAddress(), new HTUpdate(HTUpdate.SET_STATE, null, base.Clone())));
                }
                break;
            }
        }
Ejemplo n.º 8
0
 public void retransmit(long seqno, Message msg)
 {
     Console.WriteLine("RETRANSMIT: ("  + seqno + ")" +"\t" + DateTime.Now.ToLongTimeString());
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Updates an entry in the hashtable. Called from "hashtable[key] = value". 
 /// </summary>
 /// <param name="key">Key of hashtable entry</param>
 /// <param name="val">Value of hashtable entry</param>
 private void Update(object key, object val)
 {
     //shouldnt override existing members
     Message msg;
     msg = new Message(null,null,new HTUpdate(HTUpdate.UPDATE,key,val));
     channel.send(msg);
 }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            Tester.SetupDebug();
            Event evt = null;
            UNICAST uni = new UNICAST();
            Protocol bottom = null;
            Protocol top = Tester.createStack(uni, out bottom);
            Address remote1 = new Address("1.1.1.1",8005);
            Address remote2 = new Address("1.1.1.2",8005);
            Address remote3 = new Address("1.1.1.3",8005);

            Console.WriteLine("-=-=-=-=- Send msgs 0-2 to Remote 1 -=-=-=-=-=-");
            evt = new Event(Event.MSG,new Message(remote1,null,"Message 1"));
            top.down(evt);
            evt = new Event(Event.MSG,new Message(remote1,null,"Message 2"));
            top.down(evt);
            evt = new Event(Event.MSG,new Message(remote1,null,"Message 3"));
            top.down(evt);

            Thread.Sleep(7000);

            Console.WriteLine("-=-=-=-=- Ack 0 from Remote 1 -=-=-=-=-=-");
            Message msg = new Message(Tester.localAddr,remote1,"Incoming Message 0");
            msg.Headers.Add("UNICAST",new UnicastHeader(UnicastHeader.DATA_ACK, 0));
            evt = new Event(Event.MSG,msg);
            bottom.up(evt);

            Console.WriteLine("-=-=-=-=- Ack 1 from Remote 1 -=-=-=-=-=-");
            msg = new Message(Tester.localAddr,remote1,"Incoming Message 0");
            msg.Headers.Add("UNICAST",new UnicastHeader(UnicastHeader.DATA_ACK, 1));
            evt = new Event(Event.MSG,msg);
            bottom.up(evt);

            Thread.Sleep(7000);

            Console.WriteLine("-=-=-=-=- Ack 2 from Remote 1 -=-=-=-=-=-");
            msg = new Message(Tester.localAddr,remote1,"Incoming Message 0");
            msg.Headers.Add("UNICAST",new UnicastHeader(UnicastHeader.DATA_ACK, 2));
            evt = new Event(Event.MSG,msg);
            bottom.up(evt);

            Thread.Sleep(2000);

            Console.WriteLine("-=-=-=-=- Recv msg 0 from Remote 1 -=-=-=-=-=-");
            msg = new Message(Tester.localAddr,remote1,"Incoming Message 0");
            msg.Headers.Add("UNICAST",new UnicastHeader(UnicastHeader.DATA, 0));
            evt = new Event(Event.MSG,msg);
            bottom.up(evt);

            Console.WriteLine("-=-=-=-=- Recv msg 1 from Remote 1 -=-=-=-=-=-");
            msg = new Message(Tester.localAddr,remote1,"Incoming Message 1");
            msg.Headers.Add("UNICAST",new UnicastHeader(UnicastHeader.DATA, 1));
            evt = new Event(Event.MSG,msg);
            bottom.up(evt);

            Console.WriteLine("-=-=-=-=- Recv msg 3 from Remote 1 -=-=-=-=-=-");
            msg = new Message(Tester.localAddr,remote1,"Incoming Message 1");
            msg.Headers.Add("UNICAST",new UnicastHeader(UnicastHeader.DATA, 3));
            evt = new Event(Event.MSG,msg);
            bottom.up(evt);

            Thread.Sleep(10000);

            Console.WriteLine("-=-=-=-=- Recv msg 2 from Remote 1 -=-=-=-=-=-");
            msg = new Message(Tester.localAddr,remote1,"Incoming Message 1");
            msg.Headers.Add("UNICAST",new UnicastHeader(UnicastHeader.DATA, 2));
            evt = new Event(Event.MSG,msg);
            bottom.up(evt);

            Thread.Sleep(10000);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Removes the specified key from the hashtable.
 /// </summary>
 /// <param name="key">Key of hashtable entry</param>
 public override void Remove(object key)
 {
     Message msg;
     msg = new Message(null,null,new HTUpdate(HTUpdate.REMOVE,key,null));
     channel.send(msg);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Clears the hashtable.
 /// </summary>
 public override void Clear()
 {
     Message msg;
     msg = new Message(null,null,new HTUpdate(HTUpdate.CLEAR,null,null));
     channel.send(msg);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Adds a value into the Hashtable. This does not update an existing entry.
 /// </summary>
 /// <param name="key">Key of hashtable entry</param>
 /// <param name="val">Value of hashtable entry</param>
 public override void Add(object key, object val)
 {
     //shouldnt override existing members
     Message msg;
     msg = new Message(null,null,new HTUpdate(HTUpdate.ADD,key,val));
     channel.send(msg);
 }
Ejemplo n.º 14
0
        private void sendMessage()
        {
            if(String.Compare(txtHandle.Text.Trim(),"")==0 || String.Compare(txtHandle.Text.Trim(),"|:|")==0)
            {
                txtHandle.Text = "DefaultName";
            }

            if(String.Compare(txtToSend.Text.Trim(),"")!=0)
            {
                GCT.Message msg = null;
                if(lstMembers.SelectedIndex!=-1)
                {
                    foreach(DictionaryEntry dic in members)
                    {
                        if((String.Compare((String)dic.Value,(String)lstMembers.SelectedItem)==0))
                        {
                            if(!dic.Key.Equals(chan.getLocalAddress()))
                            {
                                msg = new GCT.Message((Address)dic.Key,chan.getLocalAddress(),txtHandle.Text + "|:|" + txtToSend.Text);
                            }
                            else
                            {
                                MessageBox.Show("Can't send message to yourself!!", "Private Message Error", MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
                            }
                        }
                    }
                }
                else
                {
                    msg = new GCT.Message(null,null,txtHandle.Text + "|:|" + txtToSend.Text);
                }

                if(msg!=null)
                    chan.send(msg);
                txtToSend.Text = "";
            }
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Sends a request for the current state. Method returns once response is received.
 /// </summary>
 private void getState()
 {
     int stateTimeout= 15000;
     Message msg;
     msg = new Message(null,null,new HTUpdate(HTUpdate.GET_STATE,null,null));
     bool stateReturned = false;
     lock(state_mutex)
     {
         channel.send(msg);
         stateReturned = Monitor.Wait(state_mutex,stateTimeout,true);
     }
     // if stateReturned = false then no coordinator present.
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Sends a message through the Channel
 /// </summary>
 /// <param name="msg">Message to be sent</param>
 public abstract void send(Message msg);
Ejemplo n.º 17
0
        /// <summary>
        /// Copy the Message
        /// </summary>
        /// <returns>A copy of the current Message</returns>
        public Message copy()
        {
            Message retval = new Message(null,null,null);
            retval.dest_addr = dest_addr;
            retval.src_addr = src_addr;
            if(buf != null)
                retval.buf=buf;

            if(headers != null)
            {
                retval.headers = new PropertyCollection();
                foreach(DictionaryEntry h in headers)
                {
                    retval.headers.Add(h.Key,h.Value);
                }
            }
            return retval;
        }