Esempio n. 1
0
        public Nod()
        {
            Id          = string.Empty;
            IsSuperPeer = false;
            Chain       = -1;
            Ring        = -1;
            Status      = new Neighbour();

            Content = CreateContnt();
        }
Esempio n. 2
0
        public Nod(int chain, int ring, bool flag)
        {
            Chain = chain;
            Ring  = ring;
            Id    = chain.ToString() + "-" + ring.ToString() + " ";

            Content = CreateContnt();

            if (flag == true)
            {
                IsSuperPeer = true;
            }
            else
            {
                IsSuperPeer = false;
            }

            Status = new Neighbour();
        }
Esempio n. 3
0
        public void JoinOverlay(Nod existingNode)
        {
            Nod newNode = new Nod();

            if (this.Peers.Count == 1)
            {
                // join with the SP
                newNode.Chain  = 1;
                newNode.Ring   = 1;
                newNode.Id     = newNode.Chain.ToString() + "-" + newNode.Ring.ToString() + " ";
                newNode.Status = new Neighbour(false, true, false, false);
                if (!IsNodeInOverlay(newNode))
                {
                    Peers.Add(newNode);
                }
            }
            else
            {
                //rest of the cases
                Neighbour status = existingNode.GetStatus();
                if (!status.left)
                {
                    if (existingNode.Chain + 1 > NrChains)
                    {
                        newNode.Chain = existingNode.Chain + 1 - NrChains;
                    }
                    else
                    {
                        newNode.Chain = existingNode.Chain + 1;
                    }

                    newNode.Ring = existingNode.Ring;
                    newNode.Id   = newNode.Chain.ToString() + "-" + newNode.Ring.ToString() + " ";
                    if (newNode.Chain == NrChains)
                    {
                        newNode.Status = new Neighbour(false, true, true, true);
                    }
                    else
                    {
                        newNode.Status = new Neighbour(false, true, false, true);
                    }

                    //existingNode.status.left = true;
                    Peers.Where(item => item.Id == existingNode.Id).ToList().ForEach(s => s.Status.left = true);
                    if (!IsNodeInOverlay(newNode))
                    {
                        Peers.Add(newNode);
                    }
                }
                else
                {
                    if (!status.right)
                    {
                        if (existingNode.Chain - 1 == 0)
                        {
                            newNode.Chain = NrChains;
                        }
                        else
                        {
                            newNode.Chain = existingNode.Chain - 1;
                        }

                        newNode.Ring = existingNode.Ring;
                        newNode.Id   = newNode.Chain.ToString() + "-" + newNode.Ring.ToString() + " ";
                        if (newNode.Chain == NrChains)
                        {
                            newNode.Status = new Neighbour(false, true, true, true);
                        }
                        else
                        {
                            newNode.Status = new Neighbour(false, true, false, true);
                        }
                        Peers.Where(item => item.Id == existingNode.Id).ToList().ForEach(s => s.Status.right = true);
                        //existingNode.status.right = true;
                        if (!IsNodeInOverlay(newNode))
                        {
                            Peers.Add(newNode);
                        }
                    }
                    else
                    {
                        if (!status.up)
                        {
                            newNode.Chain  = existingNode.Chain;
                            newNode.Ring   = existingNode.Ring + 1;
                            newNode.Id     = newNode.Chain.ToString() + "-" + newNode.Ring.ToString() + " ";
                            newNode.Status = new Neighbour(false, true, false, false);
                            Peers.Where(item => item.Id == existingNode.Id).ToList().ForEach(s => s.Status.up = true);
                            //existingNode.status.up = true;
                            if (!IsNodeInOverlay(newNode))
                            {
                                Peers.Add(newNode);
                            }
                        }
                    }
                }
            }
            LastNode = newNode;
        }