public void ReceiveJoinDataPacket(JoinData packet) { if (!MessageCache.Contains(new MessagePrint(packet.SourceIp, packet.SequenceNumber))) { MessageCache.Add(new MessagePrint(packet.SourceIp, packet.SequenceNumber)); RoutingTable.Add(new RoutingTableElement(packet.SourceIp, packet.PreviousHopIp)); if (packet.MulticastGroupIp == NodeId) { JoinTable newJoinTablePacket = new JoinTable(packet.PreviousHopIp, packet.SequenceNumber, packet.SourceIp, NodeId, NodeId); SendJoinTable(newJoinTablePacket); } else { JoinData newPacket = new JoinData(packet.TTL, packet.SequenceNumber, packet.SourceIp, NodeId, packet.MulticastGroupIp); if (newPacket.SourceIp != NodeId) { newPacket.HopCount = packet.HopCount + 1; newPacket.TTL--; } if (newPacket.TTL > 0) { SendJoinData(newPacket); } } } }
public void ReceiveJoinTablePacket(JoinTable packet) { if (NodeId == packet.NextHopIp) { ForwardingTable.Add(new ForwardingTableElement(packet.MulticastGroupIp)); if (NodeId == packet.SourceIp) { SendMessage(packet.MulticastGroupIp); } else { int nextHop = 0; foreach (var a in RoutingTable) { if (a.SourceIp == packet.SourceIp) { nextHop = a.NextHop; } } JoinTable newJoinTable = new JoinTable(nextHop, packet.SequenceNumber, packet.SourceIp, NodeId, packet.MulticastGroupIp); SendJoinTable(newJoinTable); } } }
private void SendJoinTable(JoinTable packet) { foreach (var nnode in NodeScanner.GetNearbyNodes(this, AllNodes)) { new Thread(() => { int timeElapsed = 0; Thread.Sleep((int)(nnode.Key * 10) - timeElapsed); timeElapsed += (int)(nnode.Key * 10); Thread.CurrentThread.IsBackground = true; nnode.Value.ReceiveJoinTablePacket(packet); OnPacketSent(packet, new EventArgs()); }).Start(); } }