Exemple #1
0
        public static PingHeader ReadPingHeader(CompactReader reader)
        {
            byte isNull = reader.ReadByte();

            if (isNull == 1)
            {
                return(null);
            }
            PingHeader newHdr = new PingHeader();

            newHdr.Deserialize(reader);
            return(newHdr);
        }
Exemple #2
0
        public static void WritePingHeader(CompactWriter writer, PingHeader hdr)
        {
            byte isNull = 1;

            if (hdr == null)
            {
                writer.Write(isNull);
            }
            else
            {
                isNull = 0;
                writer.Write(isNull);
                hdr.Serialize(writer);
            }
            return;
        }
Exemple #3
0
 public static PingHeader ReadPingHeader(CompactReader reader)
 {
     byte isNull = reader.ReadByte();
     if (isNull == 1)
         return null;
     PingHeader newHdr = new PingHeader();
     newHdr.Deserialize(reader);
     return newHdr;
 }
Exemple #4
0
 public static void WritePingHeader(CompactWriter writer, PingHeader hdr)
 {
     byte isNull = 1;
     if (hdr == null)
         writer.Write(isNull);
     else
     {
         isNull = 0;
         writer.Write(isNull);
         hdr.Serialize(writer);
     }
     return;
 }  		    
Exemple #5
0
        public override void  up(Event evt)
        {
            Message msg, rsp_msg;

            System.Object obj;
            PingHeader    hdr, rsp_hdr;
            PingRsp       rsp;
            Address       coord;


            switch (evt.Type)
            {
            case Event.MSG:
                msg = (Message)evt.Arg;

                obj = msg.getHeader(HeaderType.TCPPING);
                if (obj == null || !(obj is PingHeader))
                {
                    passUp(evt);
                    return;
                }

                hdr = (PingHeader)msg.removeHeader(HeaderType.TCPPING);

                switch (hdr.type)
                {
                case PingHeader.GET_MBRS_REQ:


                    if (!hdr.group_addr.Equals(group_addr))
                    {
                        if (Stack.NCacheLog.IsInfoEnabled)
                        {
                            Stack.NCacheLog.Info("TcpPing.up()", "GET_MBRS_REQ from different group , so discarded");
                        }
                        return;
                    }
                    Address src = (Address)hdr.arg;
                    msg.Src = src;

                    if (Stack.NCacheLog.IsInfoEnabled)
                    {
                        Stack.NCacheLog.Info("TCPPING.up()", "GET_MBRS_REQ from " + msg.Src.ToString());
                    }


                    lock (members.SyncRoot)
                    {
                        coord = members.Count > 0 ? (Address)members[0] : local_addr;
                    }
                    if (Stack.NCacheLog.IsInfoEnabled)
                    {
                        Stack.NCacheLog.Info("TCPPING.up()", "my coordinator is " + coord.ToString());
                    }

                    rsp_msg = new Message(msg.Src, null, null);
                    rsp_hdr = new PingHeader(PingHeader.GET_MBRS_RSP, new PingRsp(local_addr, coord, Stack.IsOperational, Stack.IsOperational));
                    rsp_msg.putHeader(HeaderType.TCPPING, rsp_hdr);
                    if (Stack.NCacheLog.IsInfoEnabled)
                    {
                        Stack.NCacheLog.Info("TCPPING.up()", "responding to GET_MBRS_REQ back to " + msg.Src.ToString());
                    }

                    if (Stack.NCacheLog.IsInfoEnabled)
                    {
                        Stack.NCacheLog.Info(local_addr + " - [FIND_INITIAL_MBRS] replying PING request to " + rsp_msg.Dest);
                    }


                    passDown(new Event(Event.MSG, rsp_msg, Priority.Critical));

                    return;


                case PingHeader.GET_MBRS_RSP:                          // add response to vector and notify waiting thread


                    if (Stack.NCacheLog.IsInfoEnabled)
                    {
                        Stack.NCacheLog.Info("TCPPING.up()", "GET_MBRS_RSP from " + msg.Src.ToString());
                    }
                    rsp = (PingRsp)hdr.arg;


                    //muds:
                    //check if the received response is valid i.e. successful security authorization
                    //at other end.
                    if (rsp.OwnAddress == null && rsp.CoordAddress == null && rsp.HasJoined == false)
                    {
                        lock (initial_members.SyncRoot)
                        {
                            if (Stack.NCacheLog.IsInfoEnabled)
                            {
                                Stack.NCacheLog.Info("TCPPING.up()", "I am not authorized to join to " + msg.Src.ToString());
                            }
                            System.Threading.Monitor.PulseAll(initial_members.SyncRoot);
                        }
                    }
                    else
                    {
                        if (Stack.NCacheLog.IsInfoEnabled)
                        {
                            Stack.NCacheLog.Info("TCPPING.up()", "Before Adding initial members response");
                        }
                        lock (initial_members.SyncRoot)
                        {
                            if (Stack.NCacheLog.IsInfoEnabled)
                            {
                                Stack.NCacheLog.Info("TCPPING.up()", "Adding initial members response");
                            }
                            if (!initial_members.Contains(rsp))
                            {
                                initial_members.Add(rsp);
                                if (Stack.NCacheLog.IsInfoEnabled)
                                {
                                    Stack.NCacheLog.Info("TCPPING.up()", "Adding initial members response for " + rsp.OwnAddress);
                                }
                            }
                            else
                            if (Stack.NCacheLog.IsInfoEnabled)
                            {
                                Stack.NCacheLog.Info("TcpPing.up()", "response already received");
                            }

                            System.Threading.Monitor.PulseAll(initial_members.SyncRoot);
                        }
                    }


                    return;


                default:
                    Stack.NCacheLog.Warn("got TCPPING header with unknown type (" + hdr.type + ')');
                    return;
                }
            //goto case Event.SET_LOCAL_ADDRESS;



            case Event.SET_LOCAL_ADDRESS:
                passUp(evt);
                local_addr = (Address)evt.Arg;
                // Add own address to initial_hosts if not present: we must always be able to ping ourself !
                if (initial_hosts != null && local_addr != null)
                {
                    if (!initial_hosts.Contains(local_addr))
                    {
                        Stack.NCacheLog.Debug("[SET_LOCAL_ADDRESS]: adding my own address (" + local_addr + ") to initial_hosts; initial_hosts=" + Global.CollectionToString(initial_hosts));
                        initial_hosts.Add(local_addr);
                    }
                }
                break;

            case Event.CONNECT_OK:
                obj = evt.Arg;

                if (obj != null && obj is Address)
                {
                    tcpServerPort = ((Address)obj).Port;
                }
                passUp(evt);
                break;

            case Event.CONNECTION_NOT_OPENED:
                if (mbrDiscoveryInProcess)
                {
                    Address node     = evt.Arg as Address;
                    PingRsp response = new PingRsp(node, node, true, false);
                    lock (initial_members.SyncRoot)
                    {
                        initial_members.Add(response);
                        System.Threading.Monitor.PulseAll(initial_members.SyncRoot);
                    }
                    Stack.NCacheLog.CriticalInfo(Name + ".up", "connection failure with " + node);
                }

                break;

            // end services
            default:
                passUp(evt);                         // Pass up to the layer above us
                break;
            }
        }
Exemple #6
0
		public override void  up(Event evt)
		{
			Message msg, rsp_msg;
			System.Object obj;
			PingHeader hdr, rsp_hdr;
			PingRsp rsp;
			Address coord;
			
			
			switch (evt.Type)
			{
				 
				case Event.MSG: 
					msg = (Message) evt.Arg;
                   
                    obj = msg.getHeader(HeaderType.TCPPING);
					if (obj == null || !(obj is PingHeader))
					{
						passUp(evt);
						return ;
					}
                    
                    hdr = (PingHeader)msg.removeHeader(HeaderType.TCPPING);
					
				switch (hdr.type)
				{
											
					case PingHeader.GET_MBRS_REQ:  

                       
						if( !hdr.group_addr.Equals(group_addr))
						{
                            if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("TcpPing.up()",   "GET_MBRS_REQ from different group , so discarded");
							return;
						}
						Address src = (Address) hdr.arg;
						msg.Src = src;

						if(Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("TCPPING.up()",  "GET_MBRS_REQ from " + msg.Src.ToString());

						
						lock (members.SyncRoot)
						{
							coord = members.Count > 0 ? (Address)members[0] : local_addr;
						}
						if(Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("TCPPING.up()",   "my coordinator is " + coord.ToString());

						rsp_msg = new Message(msg.Src, null, null);
						rsp_hdr = new PingHeader(PingHeader.GET_MBRS_RSP, new PingRsp(local_addr, coord, Stack.IsOperational,Stack.IsOperational));
						rsp_msg.putHeader(HeaderType.TCPPING, rsp_hdr);
						if(Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("TCPPING.up()",   "responding to GET_MBRS_REQ back to " + msg.Src.ToString());

                       if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info(local_addr + " - [FIND_INITIAL_MBRS] replying PING request to " + rsp_msg.Dest);

                        
						passDown(new Event(Event.MSG, rsp_msg, Priority.Critical));

return ;
						
						
					case PingHeader.GET_MBRS_RSP:  // add response to vector and notify waiting thread
                       

						if(Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("TCPPING.up()",  "GET_MBRS_RSP from " + msg.Src.ToString());
						rsp = (PingRsp) hdr.arg;


                        //muds:
                        //check if the received response is valid i.e. successful security authorization
                        //at other end.
                        if (rsp.OwnAddress == null && rsp.CoordAddress == null && rsp.HasJoined == false)
                        {
                            lock (initial_members.SyncRoot)
                            {
                                if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("TCPPING.up()", "I am not authorized to join to " + msg.Src.ToString());
                                System.Threading.Monitor.PulseAll(initial_members.SyncRoot);
                            }
                        }
                        else
                        {
                            if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("TCPPING.up()", "Before Adding initial members response");
                            lock (initial_members.SyncRoot)
                            {
                                if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("TCPPING.up()", "Adding initial members response");
                                if (!initial_members.Contains(rsp))
                                {
                                    initial_members.Add(rsp);
                                    if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("TCPPING.up()", "Adding initial members response for " + rsp.OwnAddress);
                                }
                                else
                                    if (Stack.NCacheLog.IsInfoEnabled) Stack.NCacheLog.Info("TcpPing.up()", "response already received");

                                System.Threading.Monitor.PulseAll(initial_members.SyncRoot);
                            }
                        }

                       
						return ;
						
						
					default:
                        Stack.NCacheLog.Warn("got TCPPING header with unknown type (" + hdr.type + ')');
						return ;
						
				}
					//goto case Event.SET_LOCAL_ADDRESS;
				
				
				
				case Event.SET_LOCAL_ADDRESS: 
					passUp(evt);
					local_addr = (Address) evt.Arg;
					// Add own address to initial_hosts if not present: we must always be able to ping ourself !
					if (initial_hosts != null && local_addr != null)
					{
						if (!initial_hosts.Contains(local_addr))
						{
                            Stack.NCacheLog.Debug("[SET_LOCAL_ADDRESS]: adding my own address (" + local_addr + ") to initial_hosts; initial_hosts=" + Global.CollectionToString(initial_hosts));
							initial_hosts.Add(local_addr);
						}
					}
					break;
				case Event.CONNECT_OK: 
					obj = evt.Arg;

					if(obj != null && obj is Address)
					{
						tcpServerPort = ((Address)obj).Port;
					}
					passUp(evt);
					break;
                case Event.CONNECTION_NOT_OPENED:
                    if (mbrDiscoveryInProcess)
                    {
                        Address node = evt.Arg as Address;
                        PingRsp response = new PingRsp(node, node, true, false);
                        lock (initial_members.SyncRoot)
                        {
                            initial_members.Add(response);
                            System.Threading.Monitor.PulseAll(initial_members.SyncRoot);
                        }
                        Stack.NCacheLog.CriticalInfo(Name + ".up", "connection failure with " + node);
                    }

                    break;
				// end services
				default: 
					passUp(evt); // Pass up to the layer above us
					break;
				
			}
		}