Ejemplo n.º 1
0
 public JoinQuery(JoinQuery jq)
 {
     this.Source   = jq.Source;
     this.LastHop  = jq.LastHop;
     this.HopCount = jq.HopCount;
     this.Sequence = jq.Sequence;
 }
Ejemplo 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));
        }
Ejemplo 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);
            }
        }
Ejemplo 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);
            }
        }
Ejemplo 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));
            }
        }
Ejemplo 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);
        }