コード例 #1
0
	virtual void populateCache(const Fingerprint &fileId, const DenseDataPtr &respondData) {
		{
			MemoryMap::write_iterator writer(mData);
			if (mData.alloc(respondData->length(), writer)) {
				bool newentry = writer.insert(fileId, respondData->length());
				if (newentry) {
					SILOG(transfer,debug,fileId << " created " << *respondData);
					CacheData *cdata = new CacheData;
					*writer = cdata;
					cdata->mSparse.addValidData(respondData);
					writer.use();
				} else {
					CacheData *cdata = static_cast<CacheData*>(*writer);
					cdata->mSparse.addValidData(respondData);
                    if (SILOGP(transfer,debug)) {
                        SILOGNOCR(transfer,debug,fileId << " already exists: ");
                        std::stringstream rangeListStream;
                        Range::printRangeList(rangeListStream,cdata->mSparse, (Range)(*respondData));
                        SILOGNOCR(transfer,debug,rangeListStream.str());
                    }
					writer.update(cdata->mSparse.getSpaceUsed());
				}

			}
		}
		CacheLayer::populateParentCaches(fileId, respondData);
	}
コード例 #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
	/** Like the other uploadByHash() function, but computes the hash.
	 *
	 * @param hashContext  The URIContext to upload the hash to (e.g. "mhash:")
	 */
	inline void uploadByHash(const URIContext &hashContext,
			const DenseDataPtr &toUpload,
			const EventListener &listener) {
		RemoteFileId rfid(
			Fingerprint::computeDigest(toUpload->data(), toUpload->length()),
			hashContext);
		uploadByHash(rfid, toUpload, listener);
	}
コード例 #4
0
ファイル: TransferManager.hpp プロジェクト: danx0r/sirikata
	/** Uploads a filename, and if necessary, uploads the data as well.
	 *
	 * @param name         The named file to be uploaded (of the form "meerkat:///somefile.texture")
	 * @param hashContext  The location to upload the data to (usually "mhash:")
	 * @param toUpload     Data to be uploaded. Will only be uploaded if necessary.
	 * @param listener     An EventListener to receive a UploadEventPtr with the retrieved data.
	 * @param forceIfExists Upload the data even if the file already exists on all known CDN services.
	 */
	inline void upload(const URI &name,
			const URIContext &hashContext,
			const DenseDataPtr &toUpload,
			const EventListener &listener,
			bool forceIfExists) {
		RemoteFileId rfid(
			Fingerprint::computeDigest(toUpload->data(), toUpload->length()),
			hashContext);
		upload(name, rfid, toUpload, listener, forceIfExists);
	}