示例#1
0
文件: rtable.go 项目: zannet/goDHT
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
}
示例#2
0
文件: rtable.go 项目: zannet/goDHT
func (b bucket) addNode(n *node.Node) bool {

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

	return false
}