Esempio n. 1
0
 public JoinQuery(JoinQuery jq)
 {
     this.Source   = jq.Source;
     this.LastHop  = jq.LastHop;
     this.HopCount = jq.HopCount;
     this.Sequence = jq.Sequence;
 }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
        public void ContinueJoinQuery(JoinQuery receivedJoinQuery)
        {
            var jq = new JoinQuery(receivedJoinQuery)
            {
                LastHop = this.Name
            };

            foreach (var node in this.ConnectedNodes)
            {
                node.ReceiveJoinQuery(jq);
            }
        }
Esempio n. 4
0
        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);
            }
        }
Esempio n. 5
0
        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));
            }
        }
Esempio n. 6
0
        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);
        }