Пример #1
0
        public void SendMessage(string msg)
        {
            MessageIdentifier mid = new MessageIdentifier();

            mid.sender = tlv_utils.getSelfID();
            mid.nonce  = tlv_utils.nextDataNonce();
            // Send the message only if it is not too big
            if (messages.PackTLV(tlv_utils.data(mid.sender, mid.nonce, msg)) != null)
            {
                MessageFloodInfo mii = InitNewFloodInfo(msg);
                recent_messages[mid] = mii;
                new_message_action(mid.sender, msg);
            }
        }
Пример #2
0
 bool IsRecentMessage(MessageIdentifier m)
 {
     try
     {
         if (recent_messages[m].timeElapsed != null)
         {
             if (recent_messages[m].timeElapsed.ElapsedMilliseconds <= recentMessageDelay * 1000)
             {
                 return(true);
             }
         }
         return(false);
     }
     catch { return(false); }
 }
Пример #3
0
        public void TreatTLV(PeerAddress a, TLV tlv)
        {
            try
            {
                TLV_utils.DataMessage dm;
                switch (tlv.type)
                {
                case TLV.Type.Data:
                    dm = tlv_utils.getDataMessage(tlv);
                    if (dm != null && peers.IsSymetricNeighbor(a))
                    {
                        MessageIdentifier mid = new MessageIdentifier();
                        mid.nonce  = dm.nonce;
                        mid.sender = dm.sender;

                        // Adding message to the flooding list...
                        if (!recent_messages.ContainsKey(mid))
                        {
                            MessageFloodInfo mii = InitNewFloodInfo(dm.msg);
                            recent_messages[mid] = mii;
                            new_message_action(mid.sender, dm.msg);
                        }
                        // Ack & Remove from flooding list
                        com.SendMessage(a, messages.PackTLV(tlv_utils.ack(mid.sender, mid.nonce)));
                        try { recent_messages[mid].neighbors.Remove(a); } catch { }
                    }
                    break;

                case TLV.Type.Ack:
                    dm = tlv_utils.getAckMessage(tlv);
                    if (dm != null && peers.IsSymetricNeighbor(a))
                    {
                        MessageIdentifier mid = new MessageIdentifier();
                        mid.nonce  = dm.nonce;
                        mid.sender = dm.sender;
                        try { recent_messages[mid].neighbors.Remove(a); } catch { }
                    }
                    break;
                }
            }
            catch { }
        }