static void StorePackets(IList <Server> servers) { var splitSize = G.FileSize / G.RequestCount; for (var i = 0; i < G.MachineCount; ++i) { for (var j = 0; j < G.MachineCount; ++j) { if (i == j) { continue; } var cp = new CodePacket(i, j, splitSize); servers[j].StoreCodePacket(cp); } } }
LinkedList <CodePacket> ReconstructPackets() { var visited = new HashSet <int>(); var usedServers = new HashSet <int>(); var unusedFrames = new LinkedList <UdpPacket>(); var codePackets = new LinkedList <CodePacket>(); foreach (var f in _arrivedFrames) { if (visited.Contains(f.Src)) { if (!usedServers.Contains(f.Src)) { unusedFrames.AddLast(f); } continue; } visited.Add(f.Src); var frameCount = f.Count; var actualCount = _arrivedFrames.Count(p => p.Src == f.Src); // If there are enough UDP packets to make a code packet, // then we put the new code packet into array. if (actualCount >= frameCount) { usedServers.Add(f.Src); var cp = new CodePacket(Id, f.Src, f.Len); codePackets.AddLast(cp); } else { unusedFrames.AddLast(f); } } _arrivedFrames.Clear(); foreach (var f in unusedFrames) { _arrivedFrames.Add(f); } return(codePackets); }
public AnswerInfo(CodePacket cp, object sessionId) { Packet = cp; SessionId = sessionId; }
public void Send(CodePacket cp, object sessionId) { _sendRequests.Put(new AnswerInfo(cp, sessionId)); }
public void StoreCodePacket(CodePacket cp) { _packets.Add(cp.Owner, cp); }