예제 #1
0
	virtual void getData(const RemoteFileId &uri, const Range &requestedRange,
			const TransferCallback&callback) {
		bool haveData = false;
		SparseData foundData;
		{
			MemoryMap::read_iterator iter(mData);
			if (iter.find(uri.fingerprint())) {
				const SparseData &sparseData = static_cast<const CacheData*>(*iter)->mSparse;
                if (SILOGP(transfer,debug)) {
                    SILOGNOCR(transfer,debug,"Found " << uri.fingerprint() << "; ranges=");
                    std::stringstream sparsePrintStream;
                    sparseData.debugPrint(sparsePrintStream);
                    SILOG(transfer,debug,sparsePrintStream.str());
                }
				if (sparseData.contains(requestedRange)) {
					haveData = true;
					foundData = sparseData;
				}
			}
		}
		if (haveData) {
			for (DenseDataList::iterator iter = foundData.DenseDataList::begin();
					iter != foundData.DenseDataList::end();
					++iter) {
				CacheLayer::populateParentCaches(uri.fingerprint(), iter.getPtr());
			}
			callback(&foundData);
		} else {
			CacheLayer::getData(uri, requestedRange, callback);
		}
	}
예제 #2
0
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);
	}
}
예제 #3
0
		/// @returns fingerprint of the downloaded file.
		inline const Fingerprint &fingerprint() const {
			return mFileId.fingerprint();
		}
예제 #4
0
		/** Gets the event ID that this event will be subscribed to.
		 *
		 * @returns IdPair(DownloadEventId, fileid.fingerprint().convertToHexString())
		 */
		static Task::IdPair getIdPair(const RemoteFileId &fileId) {
			return Task::IdPair(DownloadEventId, fileId.fingerprint().convertToHexString());
		}