Ejemplo n.º 1
0
        public Section GetRandomSection()
        {
            var x = new XorName();
            var p = GetPrefixForXorname(x);
            var s = Sections[p.Key];

            return(s);
        }
Ejemplo n.º 2
0
        public bool Matches(XorName x)
        {
            if (Bits.Count > x.Bits.Count)
            {
                return(false);
            }

            for (int i = 0; i < Bits.Count; i++)
            {
                if (Bits[i] != x.Bits[i])
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 3
0
        // @mav:
        // There should never be a prefix longer than the vault name length (vault name length is constant at 256 bits).
        // This would mean there’s approx 2^256 sections in the network which is pretty massive.
        public void RenameWithPrefix(Prefix p)
        {
            if (p.Bits.Count > Name.Bits.Count)
            {
                Console.WriteLine("Warning: prefix bit count longer than name bit count!");
            }

            var newBits = Name.Bits.Count >= p.Bits.Count ?
                          new BitArray(Name.Bits) : new BitArray(p.Bits);

            for (int i = 0; i < p.Bits.Count; i++)
            {
                newBits.Set(i, p.Bits[i]);
            }

            Name = new XorName(newBits);
        }
Ejemplo n.º 4
0
        Prefix GetPrefixForXorname(XorName x)
        {
            var prefix = new Prefix();

            while (!Sections.ContainsKey(prefix.Key) && prefix.Bits.Count < x.Bits.Count)
            {
                // get the next bit of the xorname prefix
                // extend the prefix depending on the bit of the xorname
                if (!x.Bits[prefix.Bits.Count])
                {
                    prefix = prefix.ExtendLeft();
                }
                else
                {
                    prefix = prefix.ExtendRight();
                }
            }
            if (!Sections.ContainsKey(prefix.Key) && HasMoreThanOneVault())
            {
                Debug.WriteLine("Warning: No prefix for xorname");
                return(new Prefix());
            }
            return(prefix);
        }
Ejemplo n.º 5
0
 public Vault()
 {
     Name = new XorName();
     Age  = 1;
 }