virtual void getData(const RemoteFileId &downloadFileId, const Range &requestedRange, const TransferCallback &callback) { RequestInfo info(downloadFileId, requestedRange, callback); SILOG(transfer,error,"NetworkCacheLayer: "<<downloadFileId.uri()<<" range "<<requestedRange); std::list<RequestInfo>::iterator infoIter; { boost::unique_lock<boost::mutex> transfer_lock(mActiveTransferLock); infoIter = mActiveTransfers.insert(mActiveTransfers.end(), info); } mService->lookupService(downloadFileId.uri().context(), std::tr1::bind(&NetworkCacheLayer::gotServices, this, infoIter, _1)); }
void FileNameHandler::finishedDownload(const NameLookupHandler::Callback &cb, const std::string &filename, DenseDataPtr data, bool success) { bool exists = false; RemoteFileId foundURI; if (success) { for (const unsigned char *iter = data->begin(); iter != data->end();) { const unsigned char *newlinepos = std::find(iter, data->end(), '\n'); if (newlinepos == data->end()) { break; } const unsigned char *spacepos = std::find(iter, newlinepos, ' '); if (std::string(iter, spacepos) != filename) { iter = newlinepos + 1; continue; } if (spacepos == newlinepos || spacepos + 1 == newlinepos) { // the name does not exist. exists = false; } else { exists = true; foundURI = RemoteFileId(URI(std::string(spacepos+1, newlinepos))); } iter = newlinepos + 1; } } if (exists) { cb(foundURI.fingerprint(), foundURI.uri().toString(), true); } else { cb(Fingerprint::null(), std::string(), false); } }
/// @returns the URI of the hashed file (mhash:///...), NOT the named file. inline const URI &uri() const { return mFileId.uri(); }
/** * Like upload(), but does not allocate a name for this object. * * Similar to calling: * UploadHandler::upload(NULL, service.lookup(hash.url().proto()), hash.url(), toUpload, listener) * * Note: uploadByHash checks for the existence of the file, and uploads only if it is * missing from at least one service. The forceIfExists option will override this check. * * @param hash The hash of the file upload. * @param toUpload SparseData to upload (can be cast from DenseData). * @param listener A listener to receive the UploadEvent. * @param forceIfExists Upload the data even if the file already exists on all known CDN services. */ virtual void uploadByHash(const RemoteFileId &hash, const DenseDataPtr &toUpload, const EventListener &listener, bool forceIfExists) { listener(UploadEventPtr(new UploadEvent(FAIL_UNIMPLEMENTED, hash.uri(), UploadDataEventId))); }