Пример #1
0
        public MatchStateMachine(EndPoint Id, LongestMatch longestMatch, StreamChunckingLib.PackChunking packChunking, byte[] data, List <List <ChunkMetaData> > predMsg)
        {
            m_LongestMatch    = longestMatch;
            m_packChunking    = packChunking;
            m_Id              = Id;
            m_data            = data;
            m_PredMsg         = predMsg;
            m_SenderChunkList = new List <long>();

            m_ProcessedBytes          = m_packChunking.getChunks(m_SenderChunkList, m_data, 0, m_data.Length, true, false);
            m_SenderChunkListWithSha1 = new List <long>();
            m_packChunking.getChunks(m_SenderChunkListWithSha1, m_data, (int)0, m_data.Length, true, true);
            LogUtility.LogUtility.LogFile(Convert.ToString(m_Id) + " processedBytes " + Convert.ToString(m_ProcessedBytes) + " chunk count " + Convert.ToString(m_SenderChunkList.Count), ModuleLogLevel);
        }
Пример #2
0
        uint ReceiverOnDataMsg(byte[] packet, int packet_offset, byte flag, out List <ChunkListAndChainId> chainChunkList, out uint chainOffset)
        {
            m_onDataReceived(packet, packet_offset, packet.Length - packet_offset);

            List <long> chunkList = new List <long>();

            Monitor.Enter(m_libMutex);
            /* process the stream (+reminder) to get chunks */
            int  processed_bytes = m_packChunking.getChunks(chunkList, packet, packet_offset, packet.Length, /*is_last*/ true, true);
            uint offset          = (uint)packet_offset;
            List <ChunkMetaData[]> chunkMetaDataList = new List <ChunkMetaData[]>(100);
            int idx = 0;
            int lastNonMatchingChunk        = chunkList.Count;
            int firstNonMatchingChunk       = chunkList.Count;
            int firstNonMatchingChunkOffset = 0;

            chainChunkList = new List <ChunkListAndChainId>(100);
            List <ChunkListAndChainId> dummyChainChunkList = new List <ChunkListAndChainId>();
            int  rc;
            bool foundMatch = false;

            LogUtility.LogUtility.LogFile(Convert.ToString(m_Id) + " processing " + Convert.ToString(chunkList.Count) + " chunks, CurrentOffset " + Convert.ToString(m_CurrentOffset), ModuleLogLevel);
#if true
            if (chunkList.Count > 0)
            {
                rc = m_chunkAndChainManager.ChainMatch(chunkList, chunkList.Count - 1, chainChunkList, m_SentChainList);
                if (rc > 0)
                {
                    m_SentChainList.Add(chainChunkList[0].chainId);
                    foundMatch = true;
                    LogUtility.LogUtility.LogFile(Convert.ToString(m_Id) + " found long chain (fast path) ", ModuleLogLevel);
                }
                else if (rc == 0)
                {
                    foundMatch = true;
                    LogUtility.LogUtility.LogFile(Convert.ToString(m_Id) + " found equal chain (fast path) ", ModuleLogLevel);
                }
            }
            if (foundMatch)
            {
                chainOffset      = (uint)(m_CurrentOffset + processed_bytes);
                m_CurrentOffset += (uint)(packet.Length - packet_offset);
                Monitor.Exit(m_libMutex);
                return(GetChainsListSize(chainChunkList));
            }
#endif
            foreach (long chunk in chunkList)
            {
                rc = m_chunkAndChainManager.ChainMatch(chunkList, idx, chainChunkList, m_SentChainList);

                if (rc < 0)
                {
                    lastNonMatchingChunk = idx;
                    if (firstNonMatchingChunk == chunkList.Count)
                    {
//                        LogUtility.LogUtility.LogFile("starting non-mactching range " + Convert.ToString(idx), ModuleLogLevel);
                        firstNonMatchingChunk       = idx;
                        firstNonMatchingChunkOffset = (int)offset;
                    }
                    else
                    {
//                        LogUtility.LogUtility.LogFile("updating non-matching range " + Convert.ToString(idx), ModuleLogLevel);
                    }
                }
                else if (lastNonMatchingChunk != chunkList.Count)
                {
//                    LogUtility.LogUtility.LogFile("end of non-matching range " + Convert.ToString(lastNonMatchingChunk), ModuleLogLevel);
                    Chains2Save chain2Save = new Chains2Save(chunkList, firstNonMatchingChunk, lastNonMatchingChunk, packet, firstNonMatchingChunkOffset, m_chunkAndChainManager);
                    AddChain2Save(chain2Save, m_Id);
                    firstNonMatchingChunk = chunkList.Count;
                    lastNonMatchingChunk  = chunkList.Count;
                }
                m_ChunksProcessed++;
                offset += (uint)PackChunking.chunkToLen(chunkList[idx]);
                idx++;
                LogUtility.LogUtility.LogFile(Convert.ToString(m_Id) + " AddUpdateChunk: offset=" + Convert.ToString(m_CurrentOffset + offset) + " chainChunkList " + Convert.ToString(chainChunkList.Count), ModuleLogLevel);
                if (rc > 0)
                {
                    m_SentChainList.Add(chainChunkList[0].chainId);
                    break;
                }
                else if (rc == 0)
                {
                    break;
                }
            }
            if (lastNonMatchingChunk != chunkList.Count)
            {
//                LogUtility.LogUtility.LogFile("end of non-matching range (last) " + Convert.ToString(lastNonMatchingChunk), ModuleLogLevel);
                Chains2Save chain2Save = new Chains2Save(chunkList, firstNonMatchingChunk, lastNonMatchingChunk, packet, firstNonMatchingChunkOffset, m_chunkAndChainManager);
                AddChain2Save(chain2Save, m_Id);
            }
            //Vadim 10/01/13 onDataReceived(packet, packet_offset, packet.Length - packet_offset);
            chainOffset      = (uint)(m_CurrentOffset + processed_bytes);
            m_CurrentOffset += (uint)(packet.Length - packet_offset);
            if (chainChunkList.Count == 0)
            {
                Monitor.Exit(m_libMutex);
                return(0);
            }
            Monitor.Exit(m_libMutex);
            return(GetChainsListSize(chainChunkList));
        }