aboutsummaryrefslogtreecommitdiff
path: root/ktable.go
blob: 0d80b936b22a3386e2106c9c51e1ee58fddd7fb0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package dhtsearch

import (
	"sync"
)

// Keep it simple for now
type kTable struct {
	sync.Mutex
	id    string
	nodes []*remoteNode
}

func newKTable(id string) kTable {
	k := kTable{id: id}
	k.refresh()
	return k
}

func (k *kTable) add(rn *remoteNode) {
	k.Lock()
	defer k.Unlock()
	k.nodes = append(k.nodes, rn)
}

func (k *kTable) getNodes() []*remoteNode {
	k.Lock()
	defer k.Unlock()
	return k.nodes
}

func (k *kTable) isEmpty() bool {
	k.Lock()
	defer k.Unlock()
	return len(k.nodes) == 0
}

func (k *kTable) isFull() bool {
	k.Lock()
	defer k.Unlock()
	return len(k.nodes) >= Config.Advanced.RoutingTableSize
}

// For now
func (k *kTable) refresh() {
	k.Lock()
	defer k.Unlock()
	k.nodes = make([]*remoteNode, 0)
}