Example #1
0
//DEPRECATED
struct metadata* zht_unparse_meta(const char* text) {

	Package package;
	package.ParseFromString(text);
	
	struct metadata* meta = (struct metadata*)malloc(sizeof(struct metadata));
	meta->loc = (struct comLocations *) malloc(sizeof(struct comLocations));
	
	meta->key = package.virtualpath().c_str();
	meta->k = package.k();
	meta->m = package.m();
	meta->bufsize = package.bufsize();
	meta->fileSize = package.filesize();
	meta->encodingLib = package.encodinglib();
	
	return meta;
}
Example #2
0
struct metadata * zht_lookup_meta(ZHTClient_c zhtClient, const char * key){

	//1. Lookup in ZHT
	ZHTClient * zhtcppClient = (ZHTClient *) zhtClient;

	string keyStr(key);
	string resSerializedPackage;
	
	Package keyPackage;
	keyPackage.set_virtualpath(keyStr); //as key
	keyPackage.set_isdir(false);
	keyPackage.set_replicano(1);
	keyPackage.set_operation(1); //1 for look up, 2 for remove, 3 for insert
	
	int res = zhtcppClient->lookup(keyPackage.SerializeAsString(),resSerializedPackage);

	dbgprintf("Package Length:%i\n",resSerializedPackage.size());

	
	//2. Parse Package and fill meta
	Package package;
	package.ParseFromString(resSerializedPackage);
	
	struct metadata* meta = (struct metadata*)malloc(sizeof(struct metadata));
	
	//2.1 General file infos
	meta->key = package.virtualpath().c_str();
	meta->k = package.k();
	meta->m = package.m();
	meta->bufsize = package.bufsize();
	meta->fileSize = package.filesize();
	meta->encodingLib = package.encodinglib();
	
	//2.2 Locations
	meta->loc = (struct comLocations *) malloc(sizeof(struct comLocations));

	struct comTransfer * current;
	struct comTransfer * prev = NULL;

	for (int j = package.location_size() -1 ; j >= 0; j--) {
		current = (struct comTransfer *) malloc(sizeof(struct comTransfer));
	
		const Package_Location& location = package.location(j);
	
		//const std::string host = location.hostname();
		current->hostName = (char *) malloc((location.hostname()).size()+1);
		strcpy(current->hostName,location.hostname().c_str());
		
		current->port = location.port();
		
		current->distantChunkName = (char *) malloc((location.distantchunkname()).size()+1);
		strcpy(current->distantChunkName,location.distantchunkname().c_str());
		
		dbgprintf("Host (%i):%s - port: %i - chunkname: %s\n",j,location.hostname().c_str(),location.port(), location.distantchunkname().c_str());
		
		current->next = prev;
		prev = current;
	}
	meta->loc->transfers = current;
	
	
	return meta;
}