コード例 #1
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);
	}
}
コード例 #2
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);
		}
	}
コード例 #3
0
	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));
	}
コード例 #4
0
ファイル: TransferManager.hpp プロジェクト: danx0r/sirikata
		/// @returns the URI of the hashed file (mhash:///...), NOT the named file.
		inline const URI &uri() const {
			return mFileId.uri();
		}
コード例 #5
0
ファイル: TransferManager.hpp プロジェクト: danx0r/sirikata
		/// @returns fingerprint of the downloaded file.
		inline const Fingerprint &fingerprint() const {
			return mFileId.fingerprint();
		}
コード例 #6
0
ファイル: TransferManager.hpp プロジェクト: danx0r/sirikata
		/** 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());
		}
コード例 #7
0
ファイル: TransferManager.hpp プロジェクト: danx0r/sirikata
	/**
	 * 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)));
	}