Exemplo n.º 1
0
        uint FindFirstMatchingChunk(List <ChunkMetaData> chunksList, long chunk, byte hint)
        {
            uint idx;

            for (idx = 0; idx < chunksList.Count; idx++)
            {
                if ((PackChunking.chunkCode(0, PackChunking.chunkToLen(chunksList[(int)idx].chunk)) == chunk) &&
                    (chunksList[(int)idx].hint == hint))
                {
                    //LogUtility.LogUtility.LogFile(Convert.ToString(m_Id) + "match " + Convert.ToString(idx), ModuleLogLevel);
                    break;
                }
            }
            return(idx);
        }
Exemplo n.º 2
0
        void MatchChain(List <ChunkMetaData> predMsg)
        {
            try
            {
                uint matchLen         = 0;
                uint matchChunkCount  = 0;
                uint firstSenderIdx   = 0;
                uint firstReceiverIdx = 0;
                int  senderChunkIdx   = 0;
                int  receiverChunkIdx = 0;
                bool match            = false;
                int  offset           = 0;
                int  savedOffset      = 0;

                while ((senderChunkIdx < m_SenderChunkList.Count) && (receiverChunkIdx < predMsg.Count))
                {
                    byte senderHint  = PackChunking.GetChunkHint(m_data, (uint)offset, (uint)PackChunking.chunkToLen(m_SenderChunkList[senderChunkIdx]));
                    long senderChunk = PackChunking.chunkCode(0, PackChunking.chunkToLen(m_SenderChunkList[senderChunkIdx]));
                    switch (match)
                    {
                    case false:
                        LogUtility.LogUtility.LogFile(Convert.ToString(m_Id) + " in non-match " + Convert.ToString(PackChunking.chunkToLen(m_SenderChunkList[senderChunkIdx])), ModuleLogLevel);
                        receiverChunkIdx = (int)FindFirstMatchingChunk(predMsg, senderChunk, senderHint);
                        if (receiverChunkIdx != predMsg.Count)
                        {
                            LogUtility.LogUtility.LogFile(Convert.ToString(m_Id) + " match " + Convert.ToString(PackChunking.chunkToLen(predMsg[(int)receiverChunkIdx].chunk)), ModuleLogLevel);
                            match            = true;
                            firstReceiverIdx = (uint)receiverChunkIdx;
                            firstSenderIdx   = (uint)senderChunkIdx;
                            matchLen         = (uint)PackChunking.chunkToLen(m_SenderChunkList[senderChunkIdx]);
                            matchChunkCount  = 1;
                            savedOffset      = offset;
                            receiverChunkIdx++;
                        }
                        else
                        {
                            receiverChunkIdx = 0;
                        }
                        break;

                    case true:
                        LogUtility.LogUtility.LogFile(Convert.ToString(m_Id) + "in match " + Convert.ToString(PackChunking.chunkToLen(m_SenderChunkList[senderChunkIdx])), ModuleLogLevel);
                        if ((senderChunk != PackChunking.chunkCode(0, PackChunking.chunkToLen(predMsg[receiverChunkIdx].chunk))) ||
                            (senderHint != predMsg[receiverChunkIdx].hint))
                        {
                            match = false;
                            LogUtility.LogUtility.LogFile(Convert.ToString(m_Id) + "stopped. matching sha1 ", ModuleLogLevel);
                            OnEndOfMatch(predMsg, matchLen, matchChunkCount, firstSenderIdx, firstReceiverIdx, savedOffset);
                            if (matchLen >= (m_data.Length / 3))
                            {
                                //return;
                            }
                        }
                        else
                        {
                            matchLen += (uint)PackChunking.chunkToLen(m_SenderChunkList[senderChunkIdx]);
                            matchChunkCount++;
                            receiverChunkIdx++;
                            if (senderChunkIdx == (m_SenderChunkList.Count - 1))
                            {
                                LogUtility.LogUtility.LogFile(Convert.ToString(m_Id) + "stopped (end). matching sha1 ", ModuleLogLevel);
                                OnEndOfMatch(predMsg, matchLen, matchChunkCount, firstSenderIdx, firstReceiverIdx, savedOffset);
                                if (matchLen >= (m_data.Length / 3))
                                {
                                    //return;
                                }
                            }
                        }
                        break;
                    }
                    //LogUtility.LogUtility.LogFile("Sender's offset " + Convert.ToString(offset), ModuleLogLevel);
                    offset += (int)PackChunking.chunkToLen(m_SenderChunkList[senderChunkIdx]);
                    senderChunkIdx++;
                }
            }
            catch (Exception exc)
            {
                LogUtility.LogUtility.LogFile("EXCEPTION: " + exc.Message + " " + exc.StackTrace + " " + exc.InnerException, LogUtility.LogLevels.LEVEL_LOG_HIGH);
            }
        }