public static void PushItemToPeer(Connection peerConnection, DistributedItem itemToDistribute, string completedPacketType)
{
try
{
if (peerConnection.ConnectionInfo.ConnectionType != ConnectionType.TCP)
throw new Exception("Only able to push DFS item when the request is made via TCP.");
if (itemToDistribute.ItemClosed)
throw new ArgumentException("Unable to push a closed item.");
ItemAssemblyConfig assemblyConfig;
lock (globalDFSLocker)
{
//First double check to see if it's already in the swarm
if (!ItemAlreadyInLocalCache(itemToDistribute))
swarmedItemsDict.Add(itemToDistribute.Data.CompleteDataCheckSum, itemToDistribute);
else
itemToDistribute = swarmedItemsDict[itemToDistribute.Data.CompleteDataCheckSum];
}
itemToDistribute.IncrementPushCount();
//We add the requester to the item swarm at this point
itemToDistribute.SwarmChunkAvailability.AddOrUpdateCachedPeerChunkFlags(peerConnection.ConnectionInfo, new ChunkFlags(0));
//There is a possibility when we create this assembly config that the peer has been removed again
//We handle this on the peer end
assemblyConfig = new ItemAssemblyConfig(itemToDistribute, completedPacketType);
//Send the config information to the client that wanted the file
peerConnection.SendObject("DFS_IncomingLocalItemBuild", assemblyConfig, nullCompressionSRO);
if (DFS.loggingEnabled) DFS._DFSLogger.Debug("Pushed DFS item " + itemToDistribute.Data.CompleteDataCheckSum + " to peer " + peerConnection + ".");
}
catch (CommsException)
{
//LogTools.LogException(ex, "CommsError_AddItemToSwarm");
}
catch (Exception ex)
{
LogTools.LogException(ex, "Error_AddItemToSwarm");
}
//try { GC.Collect(); }
//catch (Exception) { }
}