Exemple #1
0
        public override RELOAD_MessageBody FromReader(ReloadMessage rm, BinaryReader reader, long reload_msg_size)
        {

            /* try to read the packet as a UpdateReqAns packet */
            try
            {
                RELOAD_MsgCode = (RELOAD_MessageCode)(UInt16)IPAddress.NetworkToHostOrder(
                  reader.ReadInt16());
                //reload_msg_size -= 2;

                UInt32 message_len = (UInt32)(IPAddress.HostToNetworkOrder(
                  reader.ReadInt32()));

                reload_msg_size -= 4;

                m_successors.Clear();
                m_predecessors.Clear();

                if (RELOAD_MsgCode == RELOAD_MessageCode.Update_Request)
                {
                    m_TotalSeconds = (UInt32)IPAddress.NetworkToHostOrder(
                      reader.ReadInt32());
                    reload_msg_size -= 4;

                    m_type = (ChordUpdateType)reader.ReadByte();
                    reload_msg_size -= 1;

                    int iLengthOfPredecessors = IPAddress.NetworkToHostOrder(
                      reader.ReadInt16());

                    reload_msg_size -= (iLengthOfPredecessors + 2);

                    if (iLengthOfPredecessors > 0)
                    {
                        while (iLengthOfPredecessors > 0)
                        {
                            m_predecessors.Add(new NodeId(reader.ReadBytes(ReloadGlobals.NODE_ID_DIGITS)));
                            iLengthOfPredecessors -= ReloadGlobals.NODE_ID_DIGITS;
                        }
                    }

                    int iLengthOfSuccessors = IPAddress.NetworkToHostOrder(reader.ReadInt16());

                    reload_msg_size -= (iLengthOfSuccessors + 2);

                    if (iLengthOfSuccessors > 0)
                    {
                        while (iLengthOfSuccessors > 0)
                        {
                            m_successors.Add(new NodeId(reader.ReadBytes(ReloadGlobals.NODE_ID_DIGITS)));
                            iLengthOfSuccessors -= ReloadGlobals.NODE_ID_DIGITS;
                        }
                    }
                }
                else
                {
                    UInt16 Result = (UInt16)IPAddress.NetworkToHostOrder(reader.ReadInt16());
                    reload_msg_size -= 2;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return this;
        }
Exemple #2
0
 public ReloadMessage create_update_req(Destination destination,
   TopologyPlugin.RoutingTable rt, ChordUpdateType type)
 {
     return create_reload_message(destination, ++m_ReloadConfig.TransactionID,
       new UpdateReqAns(rt.GetApproved(rt.Successors), rt.GetApproved(rt.Predecessors),
         type, m_ReloadConfig.StartTime));
 }
Exemple #3
0
        public UpdateReqAns(List<NodeId> successors, List<NodeId> predecessors, ChordUpdateType type, DateTime UpTime)
            // call constructor above
            : this()
        {
            RELOAD_MsgCode = RELOAD_MsgCode = RELOAD_MessageCode.Update_Request;

            m_type = type;
            m_successors = successors;
            m_predecessors = predecessors;

            /* Another validation that we send no more than SUCCESSOR_CACHE_SIZE values 
             * as we store more for internal use
             */
            if (m_successors.Count > ReloadGlobals.SUCCESSOR_CACHE_SIZE)
                m_successors.RemoveRange(ReloadGlobals.SUCCESSOR_CACHE_SIZE, m_successors.Count - ReloadGlobals.SUCCESSOR_CACHE_SIZE);
            if (m_predecessors.Count > ReloadGlobals.SUCCESSOR_CACHE_SIZE)
                m_predecessors.RemoveRange(ReloadGlobals.SUCCESSOR_CACHE_SIZE, m_predecessors.Count - ReloadGlobals.SUCCESSOR_CACHE_SIZE);

            m_UpTime = UpTime;
        }