Ejemplo n.º 1
0
        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);
                }
            }
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
 public AnswerInfo(CodePacket cp, object sessionId)
 {
     Packet    = cp;
     SessionId = sessionId;
 }
Ejemplo n.º 4
0
 public void Send(CodePacket cp, object sessionId)
 {
     _sendRequests.Put(new AnswerInfo(cp, sessionId));
 }
Ejemplo n.º 5
0
 public void StoreCodePacket(CodePacket cp)
 {
     _packets.Add(cp.Owner, cp);
 }