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);
	}
	/** 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);
	}
Exemple #3
0
	/** 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);
	}