public void Flood() { foreach (MessageIdentifier m in recent_messages.Keys) { PeerAddress[] pas = recent_messages[m].neighbors.Keys.ToArray(); foreach (PeerAddress pa in pas) { if (!peers.IsSymetricNeighbor(pa)) { recent_messages[m].neighbors.Remove(pa); } else { NeighborFloodInfo nfi = recent_messages[m].neighbors[pa]; if (nfi.lastAttempt.ElapsedMilliseconds >= nfi.nextAttemptMillisecond) { nfi.numberAttempts++; nfi.lastAttempt = Stopwatch.StartNew(); nfi.nextAttemptMillisecond = ComputeNextFloodAttempt(nfi.numberAttempts); com.SendMessage(pa, messages.PackTLV(tlv_utils.data(m.sender, m.nonce, recent_messages[m].msg))); if (nfi.numberAttempts >= max_flood_tries_number) { recent_messages[m].neighbors.Remove(pa); peers.Goodbye(pa, 2); } } } } } }
MessageFloodInfo InitNewFloodInfo(string msg) { Dictionary <PeerAddress, NeighborFloodInfo> neighbors = new Dictionary <PeerAddress, NeighborFloodInfo>(); foreach (PeerAddress p in peers.GetSymetricsNeighbors()) { NeighborFloodInfo nii = new NeighborFloodInfo(); nii.numberAttempts = 0; nii.nextAttemptMillisecond = ComputeNextFloodAttempt(nii.numberAttempts); nii.lastAttempt = Stopwatch.StartNew(); neighbors[p] = nii; } MessageFloodInfo mii = new MessageFloodInfo(); mii.neighbors = neighbors; mii.timeElapsed = Stopwatch.StartNew(); mii.msg = msg; return(mii); }