Exemplo n.º 1
0
func addNode(n *node.Node) bool {

	splitted := false

	for i, b := range buckets {

		if !b.match(n.ID()) {
			continue
		}

		if !b.isFull() {
			b.addNode(n)
			return true
		}

		if b.match(goDHT.OwnNode().ID()) {
			/* When a bucket is full of known good nodes,
			no more nodes may be added unless our own node ID
			falls within the range of the bucket. */
			newB1, newB2 := b.split()
			buckets[i] = newB1
			buckets = append(buckets, newB2)
			splitted = true
		}
	}

	if splitted {
		return addNode(n)
	}

	return false
}
Exemplo n.º 2
0
func (b bucket) addNode(n *node.Node) bool {

	if b.match(n.ID()) {
		b.nodes[n.ID().String()] = n
		return true
	}

	return false
}