Ejemplo n.º 1
0
        public int GetChainAfterChunk(long chunk, List <ChunkListAndChainId> chainsChunksList)
        {
            Chain chain;

            if (!GetChain(chainId4Lookup, out chain))
            {
                LogUtility.LogUtility.LogFile("Cannot get chain!!!! " + Convert.ToString(chainId4Lookup), ModuleLogLevel);
                CannotGetChain++;
                return(-1);
            }
            //LogUtility.LogUtility.LogFile("chain " + Convert.ToString(ch) + " chunks " + Convert.ToString(chain.chunkIds.Length), ModuleLogLevel);
            int chunk_idx;

            if (!FindChunkInChain(chain.chunkIds, chunk, out chunk_idx))
            {
                //                    LogUtility.LogUtility.LogFile("Cannot find chunk!!!! " + Convert.ToString(chunkList[chunkListIdx]) + " in chain " + Convert.ToString(ch), ModuleLogLevel);
                CannotFindChunkInChain++;
                return(-2);
            }
            ChunkListAndChainId chunkListAndChainId = new ChunkListAndChainId();

            chunkListAndChainId.chainId       = chainId4Lookup;
            chunkListAndChainId.chunks        = chain.chunkIds;
            chunkListAndChainId.firstChunkIdx = (uint)chunk_idx + 1;
            chainsChunksList.Add(chunkListAndChainId);
            return(0);
        }
Ejemplo n.º 2
0
        public int ChainMatch(List <long> chunkList, int chunkListIdx, List <ChunkListAndChainId> chainsChunksList, List <long> sentChainsList)
        {
            Chain               chain;
            uint                longest_chain = 0;
            int                 foundChainLength;
            ChunkCB             chunkCB;
            ChunkListAndChainId chunkListAndChainId;
            bool                AtLeastEqualChainFound = false;

#if false
            if (chunkMap.TryGetValue(chunkId, out chunkCB))
#else
            if (!GetChunkCB(chunkList[chunkListIdx], out chunkCB))
#endif
            {
//                LogUtility.LogUtility.LogFile("Cannot get chunk " + Convert.ToString(chunkList[chunkListIdx]), LogUtility.LogLevels.LEVEL_LOG_MEDIUM);
                return(-1);
            }
//            LogUtility.LogUtility.LogFile("****chunk to math found " + Convert.ToString(PackChunking.chunkToLen(chunkList[chunkListIdx])), ModuleLogLevel);
            foreach (long ch in chunkCB.chains)
            {
                if (sentChainsList.Contains(ch))
                {
                    AtLeastEqualChainFound = true;
                    LogUtility.LogUtility.LogFile("Chain already sent " + Convert.ToString(ch), ModuleLogLevel);
                    continue;
                }
                if (!GetChain(ch, out chain))
                {
                    LogUtility.LogUtility.LogFile("Cannot get chain!!!! " + Convert.ToString(ch), ModuleLogLevel);
                    CannotGetChain++;
                    continue;
                }
                //LogUtility.LogUtility.LogFile("chain " + Convert.ToString(ch) + " chunks " + Convert.ToString(chain.chunkIds.Length), ModuleLogLevel);
                int chunk_idx;
                if (!FindChunkInChain(chain.chunkIds, chunkList[chunkListIdx], out chunk_idx))
                {
//                    LogUtility.LogUtility.LogFile("Cannot find chunk!!!! " + Convert.ToString(chunkList[chunkListIdx]) + " in chain " + Convert.ToString(ch), ModuleLogLevel);
                    CannotFindChunkInChain++;
                    continue;
                }
                //LogUtility.LogUtility.LogFile("chunk id in chain " + Convert.ToString(chunk_idx), ModuleLogLevel);
                foundChainLength = CompareChains(chunkList, chunkListIdx + 1, chain.chunkIds, chunk_idx + 1);
                switch (foundChainLength)
                {
                case -1:                /* different */
                    //Vadim 10/01/13 chainId4Lookup = 0;
                    chainId4Lookup = 0; //Vadim 28/01/13
                    DifferentChains++;
                    break;

                case 0:    /* match but no longer */
                    //LogUtility.LogUtility.LogFile("equal chain found " + Convert.ToString(longest_chain) , ModuleLogLevel);
                    FoundEqualChains++;
                    AtLeastEqualChainFound = true;
                    if (chainId4Lookup == 0)
                    {
//                            LogUtility.LogUtility.LogFile("equal chain found " + Convert.ToString(longest_chain), ModuleLogLevel);
                        chainId4Lookup = ch;
                    }
                    break;

                default:
                {
                    LongerChainsFound++;
                    if (foundChainLength > longest_chain)
                    {
                        longest_chain  = (uint)foundChainLength;
                        chainId4Lookup = ch;
                    }
                    AtLeastEqualChainFound = true;
//                            LogUtility.LogUtility.LogFile("****longer chain found " + Convert.ToString(longest_chain), ModuleLogLevel);
                    bool chainFound = false;
                    foreach (ChunkListAndChainId c in chainsChunksList)
                    {
                        if (c.chainId == ch)
                        {
                            //LogUtility.LogUtility.LogFile("****already in list", ModuleLogLevel);
                            chainFound = true;
                        }
                    }
                    if (!chainFound)
                    {
                        chunkListAndChainId               = new ChunkListAndChainId();
                        chunkListAndChainId.chainId       = ch;
                        chunkListAndChainId.chunks        = chain.chunkIds;
                        chunkListAndChainId.firstChunkIdx = (uint)chunk_idx + (uint)(chunkList.Count - chunkListIdx);
                        chainsChunksList.Add(chunkListAndChainId);
//                                LogUtility.LogUtility.LogFile("****added to list, first chunk " + Convert.ToString(chunkListAndChainId.firstChunkIdx), ModuleLogLevel);
                    }
                }
                break;
                }
            }
            if (!AtLeastEqualChainFound)
            {
                return(-1);
            }
            //chainId4Lookup = 0;
            return((int)longest_chain);
        }