void MeerkatChunkHandler::get(std::tr1::shared_ptr<RemoteFileMetadata> file, std::tr1::shared_ptr<Chunk> chunk, ChunkCallback callback) { //Check for null arguments std::tr1::shared_ptr<DenseData> bad; if (!file) { SILOG(transfer, error, "HttpChunkHandler get called with null file parameter"); callback(bad); return; } if (!chunk) { SILOG(transfer, error, "HttpChunkHandler get called with null chunk parameter"); callback(bad); return; } //Make sure chunk given is part of file bool foundIt = false; const ChunkList & chunks = file->getChunkList(); for (ChunkList::const_iterator it = chunks.begin(); it != chunks.end(); it++) { if(*chunk == *it) { foundIt = true; } } if(!foundIt) { SILOG(transfer, error, "HttpChunkHandler get called with chunk not present in file metadata"); callback(bad); return; } //Check to see if it's in the cache first SharedChunkCache::getSingleton().getCache()->getData(file->getFingerprint(), chunk->getRange(), std::tr1::bind( &MeerkatChunkHandler::cache_check_callback, this, _1, file->getURI(), chunk, callback)); }
void FileChunkHandler::onReadFinished(std::tr1::shared_ptr<DenseData> fileContents, std::tr1::shared_ptr<RemoteFileMetadata> file, std::tr1::shared_ptr<Chunk> chunk, ChunkCallback callback) { mStats.downloaded++; std::tr1::shared_ptr<DenseData> bad; if (!fileContents) { SILOG(transfer, error, "FileChunkHandler couldn't find file '" << file->getURI() << "'"); callback(bad); return; } SharedChunkCache::getSingleton().getCache()->addToCache(file->getFingerprint(), fileContents); callback(fileContents); }