public JoinQuery(JoinQuery jq) { this.Source = jq.Source; this.LastHop = jq.LastHop; this.HopCount = jq.HopCount; this.Sequence = jq.Sequence; }
public void ReceiveJoinQuery(JoinQuery joinQuery) { foreach (var jq in messageCache) { if (jq.Source == joinQuery.Source && jq.Sequence >= joinQuery.Sequence) { Console.WriteLine(this.Name + " received duplicate JQ from " + joinQuery.LastHop); return; } } Console.WriteLine(this.Name + " received JQ from " + joinQuery.LastHop); messageCache.Add(joinQuery); UpdateTable(joinQuery); if (Receiver) { SendJoinReply(joinQuery); } joinQuery.HopCount++; Task.Delay(sendDelay).ContinueWith(t => ContinueJoinQuery(joinQuery)); }
public void ContinueJoinQuery(JoinQuery receivedJoinQuery) { var jq = new JoinQuery(receivedJoinQuery) { LastHop = this.Name }; foreach (var node in this.ConnectedNodes) { node.ReceiveJoinQuery(jq); } }
public void SendJoinQuery() { Console.WriteLine("---------"); this.Sequence++; Console.WriteLine(this.Name + " transmitting JQ"); foreach (var node in this.ConnectedNodes) { var jq = new JoinQuery(this, this.Sequence); node.ReceiveJoinQuery(jq); this.messageCache.Add(jq); } }
public void SendJoinReply(JoinQuery joinQuery) { var reply = new JoinReply() { Source = joinQuery.Source, NextHop = joinQuery.LastHop }; Console.WriteLine(this.Name + " transmitting JR"); foreach (Node node in ConnectedNodes) { Task.Delay(sendDelay).ContinueWith(t => node.ReceiveJoinReply(reply)); } }
public void UpdateTable(JoinQuery joinQuery) { var previousRoutingEntry = routingTable.Find(x => x.Destination == joinQuery.Source); if (previousRoutingEntry != null) { routingTable.Remove(previousRoutingEntry); } var entry = new RoutingEntry() { Destination = joinQuery.Source, NextNode = joinQuery.LastHop }; routingTable.Add(entry); }