Example #1
0
CVariant CKadOperation::AddLoadRes(const CVariant& LoadRes, CKadNode* pNode)
{
	SOpProgress* pProgress = GetProgress(pNode);

	CVariant FilteredRes = LoadRes.Clone(false); // Make a Shellow Copy
	const CVariant& LoadedList = LoadRes["RES"];

	CVariant FilteredList;
	for(uint32 i=0; i < LoadedList.Count(); i++)
	{
		CVariant Loaded = LoadedList.At(i).Clone(false); // Make a Shellow Copy
		const CVariant& XID = Loaded["XID"];

		// Counting
		if(pProgress) // might be NULL if we filter our own index response right now
		{
			SOpStatus &Status = pProgress->Loads[XID];
			Status.Results++;
			if(!Loaded.Get("MORE"))
				Status.Done = true; // this marks that no more results are to be expected form this node
		}

		SOpStatus* pStatus = &m_LoadMap[XID].Status;
		pStatus->Results++;
		if(!pStatus->Done)
			pStatus->Done = IsDone(SOpProgress::GetLoads, XID);
		
		if(!pStatus->Done)
			Loaded.Insert("MORE", true);
		else
			Loaded.Remove("MORE");
		//

		if(Loaded.Has("ERR"))
		{
			FilteredList.Append(Loaded);
			continue;
		}

		// Filtering
		CVariant UniquePayloads;
		const CVariant& Payloads = Loaded["PLD"];
		for(uint32 j=0; j < Payloads.Count(); j++)
		{
			const CVariant& Payload = Payloads.At(j);
			if(m_LoadFilter[XID].insert(Payload["DATA"].GetFP()).second)
				UniquePayloads.Append(Payload);
		}

		// Note: we must add this even if UniquePayloads is empty or else we will misscount replys
		CVariant NewLoaded;
		NewLoaded["XID"] = XID;
		NewLoaded["PLD"] = UniquePayloads;
		FilteredList.Append(NewLoaded);
		//
	}

	FilteredRes.Insert("RES", FilteredList);
	return FilteredRes;
}
Example #2
0
CVariant CKadOperation::AddStoreRes(const CVariant& StoreRes, CKadNode* pNode)
{
	SOpProgress* pProgress = GetProgress(pNode);

	CVariant FilteredRes = StoreRes.Clone(false); // Make a Shellow Copy
	const CVariant& StoredList = StoreRes["RES"];

	CVariant FilteredList;
	for(uint32 i=0; i < StoredList.Count(); i++)
	{
		CVariant Stored = StoredList.At(i).Clone(false); // Make a Shellow Copy
		const CVariant& XID = Stored["XID"];

		// Counting
		if(pProgress) // might be NULL if we filter our own index response right now
		{
			SOpStatus &Status = pProgress->Stores[XID];
			Status.Results++;
			if(!Stored.Get("MORE"))
				Status.Done = true; // this marks that no more results are to be expected form this node
		}

		SOpStatus* pStatus = &m_StoreMap[XID].Status;
		pStatus->Results++;
		if(!pStatus->Done)
			pStatus->Done = IsDone(SOpProgress::GetStores, XID);

		if(!pStatus->Done)
			Stored.Insert("MORE", true);
		else
			Stored.Remove("MORE");
		//

		//m_StoredCounter[Stored["XID"]].push_back(Stored.Get("EXP", 0)); // on error there is no EXP

		FilteredList.Append(Stored);
	}
	
	FilteredRes.Insert("RES", FilteredList);
	return FilteredRes;
}
Example #3
0
CVariant CKadOperation::AddCallRes(const CVariant& CallRes, CKadNode* pNode)
{
	SOpProgress* pProgress = GetProgress(pNode);

	CVariant FilteredRes = CallRes.Clone(false); // Make a Shellow Copy
	const CVariant& Results = CallRes["RET"];

	CVariant Filtered;
	for(uint32 i=0; i < Results.Count(); i++)
	{
        CVariant Result = Results.At(i).Clone(false); // Make a Shellow Copy
		const CVariant& XID = Result["XID"];

		// this checks if this particular response is the last and and if this node is done
		if(pProgress) // might be NULL if we filter our own index response right now
		{
			SOpStatus &Status = pProgress->Calls[XID];
			Status.Results++;
			if(!Result.Get("MORE"))
				Status.Done = true; // this marks that no more results are to be expected form this node
		}

		SOpStatus* pStatus = NULL;
		TCallOpMap::iterator I = m_CallMap.find(XID);
		if(I != m_CallMap.end())
		{
			pStatus = &I->second.Status;
			pStatus->Results++; // count the response even if it gets filtered lateron
			if(!pStatus->Done)
				pStatus->Done = IsDone(SOpProgress::GetCalls, XID);
		}

		if(m_pOperator)
		{
			CKadOperator::TRequestMap& ResuestMap = m_pOperator->GetRequests();
			CKadOperator::TRequestMap::iterator I = ResuestMap.find(XID);
			if(I != ResuestMap.end()) // this should not fail
			{
				SOpStatus* pAuxStatus = &I->second.Status;
				pAuxStatus->Results++; // count the response even if it gets filtered lateron
				if(!pAuxStatus->Done)
					pAuxStatus->Done = IsDone(SOpProgress::GetCalls, XID);
			}
		}

		if(!Result.Has("ERR"))
		{
			if(m_pOperator && m_pOperator->IsValid())
			{
				try
				{
					if(m_pOperator->AddCallRes(Result["RET"], XID))
						continue; // intercepted response - Note: if we add a response to this request now it wil be marked as no more results if thats so
				}
				catch(const CJSException& Exception)
				{
					LogReport(Exception.GetFlag(), Exception.GetLine(), Exception.GetError());
				}
			}
		}
		//else 
		//	LogLine(LOG_ERROR | LOG_DEBUG, L"Got Execution Error %s", Result["ERR"].To<wstring>().c_str());

		// check if this is a call we issued, that is one not present in the call map, in that case its never to be relayed
		if(pStatus)
		{
			// UpdateMore sets the "MORE" flag on the packet we relay further down to the source, and checks if we considder this request done
			if(!pStatus->Done)
				Result.Insert("MORE", true);
			else
				Result.Remove("MORE");

			Filtered.Append(Result);
		}
	}

	if(m_pOperator) // add new result to the filtered list
		Filtered.Merge(m_pOperator->GetResponses());
	FilteredRes.Insert("RET", Filtered);
	return FilteredRes;
}