void MeerkatChunkHandler::get(std::tr1::shared_ptr<Chunk> chunk, ChunkCallback callback) { std::tr1::shared_ptr<DenseData> bad; if (!chunk) { SILOG(transfer, error, "HttpChunkHandler get called with null chunk parameter"); callback(bad); return; } //Check to see if it's in the cache first SharedChunkCache::getSingleton().getCache()->getData(chunk->getHash(), chunk->getRange(), std::tr1::bind( &MeerkatChunkHandler::cache_check_callback, this, _1, URI("meerkat:///"), chunk, callback)); }
void MeerkatChunkHandler::cache_check_callback(const SparseData* data, const URI& uri, std::tr1::shared_ptr<Chunk> chunk, ChunkCallback callback) { if (data) { mStats.downloaded++; std::tr1::shared_ptr<const DenseData> flattened = data->flatten(); callback(flattened); } else { URL url(uri); assert(!url.empty()); std::string download_uri_prefix = CDN_DOWNLOAD_URI_PREFIX; std::string host_name = CDN_HOST_NAME; Network::Address cdn_addr = mCdnAddr; if (url.host() != "") { host_name = url.context().hostname(); std::string service = url.context().service(); if (service == "") { service = CDN_SERVICE; } Network::Address given_addr(host_name, service); cdn_addr = given_addr; } HttpManager::Headers headers; headers["Host"] = host_name; headers["Accept-Encoding"] = "deflate, gzip"; bool chunkReq = false; if(!chunk->getRange().goesToEndOfFile() || chunk->getRange().startbyte() != 0) { chunkReq = true; headers["Range"] = "bytes=" + boost::lexical_cast<String>(chunk->getRange().startbyte()) + "-" + boost::lexical_cast<String>(chunk->getRange().endbyte()); } HttpManager::getSingleton().get( cdn_addr, download_uri_prefix + "/" + chunk->getHash().convertToHexString(), std::tr1::bind(&MeerkatChunkHandler::request_finished, this, _1, _2, _3, uri, chunk, chunkReq, callback), headers ); } }