/// <summary>
        /// Actualiza la vecindad TCP
        /// </summary>
        private void updateNeighborhood()
        {
            List <Guid> ids = new List <Guid>();

            RemoteMachine[] serverMachines = netHandler.TcpServerList.toObjectArray();
            for (int i = 0; i < serverMachines.Length; i++)
            {
                NetUser serverNetUser = netUserList.getUser(serverMachines[i].Ip);
                if (serverNetUser != null)
                {
                    ids.Add(serverNetUser.Id);
                }
            }
            configuration.NetUser.NeighborhoodIds = ids.ToArray();
            produceEvent(CommunicationEvent.REFRESHLOCALUSER, configuration.NetUser);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Identifica el tipo de mensaje a enviar y lo envia mediante un netHandler
 /// </summary>
 /// <param name="message">El mensaje e enviar</param>
 private void send(Message message)
 {
     if (message.MetaType == MessageMetaType.MULTICAST)
     {
         MulticastMessage multicastMessage = (MulticastMessage)message;
         multicastMessage.send(netHandler);
     }
     else if (message.MetaType == MessageMetaType.SAFEMULTICAST)
     {
         SafeMulticastMessage safeMulticastMessage = (SafeMulticastMessage)message;
         safeMulticastMessage.send(netHandler);
     }
     else if (message.MetaType == MessageMetaType.UNICAST)
     {
         UnicastMessage unicastMessage = (UnicastMessage)message;
         IPAddress      ip             = pathNextIp(unicastMessage.TargetNetUser);
         NetUser        listedNetUSer  = netUserList.getUser(unicastMessage.TargetNetUser.Ip);
         if (ip != null)
         {
             if (!unicastMessage.send(netHandler, ip))
             {
                 unicastMessage.FailReason = MessageFailReason.TCPFAIL;
                 failedMessageQueue.put(unicastMessage);
             }
         }
         else if (listedNetUSer != null && listedNetUSer.Id.Equals(unicastMessage.TargetNetUser.Id))
         {
             unicastMessage.FailReason = MessageFailReason.NOTROUTEBUTHOSTONNET;
             failedMessageQueue.put(unicastMessage);
         }
         else
         {
             unicastMessage.FailReason = MessageFailReason.NOTROUTETOHOST;
             failedMessageQueue.put(unicastMessage);
         }
     }
     else if (message.MetaType == MessageMetaType.SAFEUNICAST)
     {
         SafeUnicastMessage safeMessage   = (SafeUnicastMessage)message;
         IPAddress          ip            = pathNextIp(safeMessage.TargetNetUser);
         NetUser            listedNetUser = netUserList.getUser(safeMessage.TargetNetUser.Ip);
         if (ip != null)
         {
             if (safeMessage.send(netHandler, ip))
             {
                 //statics
                 nMessagesSent++;
                 //si el mensaje enviado fue de este usuario se espera confirmación
                 if (safeMessage.SenderNetUser.Id.Equals(netUser.Id))
                 {
                     safeMessage.WaitTimeOut = waitForAck + 2 * safeMessage.TargetNetUser.JumpsAway;
                     notConfirmedMessageList.add(safeMessage);
                 }
             }
             else
             {
                 //statics
                 nMessagesFailed++;
                 safeMessage.FailReason = MessageFailReason.TCPFAIL;
                 failedMessageQueue.put(safeMessage);
             }
         }
         else if (listedNetUser != null && listedNetUser.Id.Equals(safeMessage.TargetNetUser.Id))
         {
             safeMessage.FailReason = MessageFailReason.NOTROUTEBUTHOSTONNET;
             failedMessageQueue.put(safeMessage);
         }
         else
         {
             safeMessage.FailReason = MessageFailReason.DESTROY;
             failedMessageQueue.put(safeMessage);
         }
     }
     else if (message.MetaType == MessageMetaType.FASTUNICAST)
     {
         FastUnicastMessage fastUnicastMessage = (FastUnicastMessage)message;
         IPAddress          ip            = pathNextIp(fastUnicastMessage.TargetNetUser);
         NetUser            listedNetUSer = netUserList.getUser(fastUnicastMessage.TargetNetUser.Ip);
         if (ip != null)
         {
             fastUnicastMessage.send(netHandler, ip);
         }
     }
 }