Пример #1
0
 public override void up(Event evt)
 {
     Console.WriteLine(name.PadRight(5) + " [UP]  : " + Event.type2String(evt.Type));
     switch(evt.Type)
     {
         case(Event.GET_DIGEST):
         {
             Thread.Sleep(10000);
             Digest d = new Digest(1);
             d.add(localAddr,0,0,0);
             evt = new Event(Event.GET_DIGEST_OK,d);
             passDown(evt);
             break;
         }
         case(Event.SET_LOCAL_ADDRESS):
         {
             localAddr = (Address)evt.Arg;
             return;
         }
     }
 }
Пример #2
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();
        }
Пример #3
0
 /// <summary>
 /// Returns a deep-copy of the digest.
 /// </summary>
 /// <returns>A deep-copy of the digest</returns>
 public Digest copy()
 {
     Digest ret=new Digest(senders.Length);
     ret.senders=(Address[])senders.Clone();
     ret.low_seqnos=(long[])low_seqnos.Clone();
     ret.high_seqnos=(long[])high_seqnos.Clone();
     ret.high_seqnos_seen=(long[])high_seqnos_seen.Clone();
     return ret;
 }
Пример #4
0
        /// <remarks>
        /// For each member in the new digest the <c>merge()</c> method will be called. The digest must
        /// have enough space to merge the new digest.
        /// </remarks>
        /// <summary>
        /// Merge two digest together.
        /// </summary>
        /// <param name="d">Digest to merge into this Digest</param>
        public void merge(Digest d)
        {
            Address sender;
            long    low_seqno, high_seqno, high_seqno_seen;

            if(d == null)
            {
                if(Trace.trace)
                    Trace.error("Digest.merge()", "digest to be merged with is null");
                return;
            }
            for(int i=0; i < d.size(); i++)
            {
                sender=d.senderAt(i);
                low_seqno=d.lowSeqnoAt(i);
                high_seqno=d.highSeqnoAt(i);
                high_seqno_seen=d.highSeqnoSeenAt(i);
                merge(sender, low_seqno, high_seqno, high_seqno_seen);
            }
        }
Пример #5
0
        /// <summary>
        /// Adds a number of members into the Digest.
        /// </summary>
        /// <param name="d">Digest to add into this Digest</param>
        public void add(Digest d)
        {
            Address sender;
            long    low_seqno, high_seqno, high_seqno_seen;

            if(d != null)
            {
                for(int i=0; i < d.size(); i++)
                {
                    sender=d.senderAt(i);
                    low_seqno=d.lowSeqnoAt(i);
                    high_seqno=d.highSeqnoAt(i);
                    high_seqno_seen=d.highSeqnoSeenAt(i);
                    add(sender, low_seqno, high_seqno, high_seqno_seen);
                }
            }
        }