cluster automatically balances what nodes are announcing what hashes

This commit is contained in:
Alex Grintsvayg 2018-06-19 13:47:13 -04:00
parent b19df481da
commit 5e346cc21a
12 changed files with 227 additions and 75 deletions
dht/bits

View file

@ -23,14 +23,12 @@ const (
// package as a way to handle the unique identifiers of a DHT node.
type Bitmap [NumBytes]byte
func (b Bitmap) String() string {
func (b Bitmap) RawString() string {
return string(b[:])
}
func (b Bitmap) Big() *big.Int {
i := new(big.Int)
i.SetString(b.Hex(), 16)
return i
func (b Bitmap) String() string {
return b.Hex()
}
// BString returns the bitmap as a string of 0s and 1s
@ -61,6 +59,12 @@ func (b Bitmap) HexSimplified() string {
return simple
}
func (b Bitmap) Big() *big.Int {
i := new(big.Int)
i.SetString(b.Hex(), 16)
return i
}
// Equals returns T/F if every byte in bitmap are equal.
func (b Bitmap) Equals(other Bitmap) bool {
for k := range b {
@ -356,7 +360,7 @@ func FromBigP(b *big.Int) Bitmap {
// Max returns a bitmap with all bits set to 1
func MaxP() Bitmap {
return FromHexP(strings.Repeat("1", NumBytes*2))
return FromHexP(strings.Repeat("f", NumBytes*2))
}
// Rand generates a cryptographically random bitmap with the confines of the parameters specified.