-
Notifications
You must be signed in to change notification settings - Fork 9
/
topology.go
100 lines (86 loc) · 2.96 KB
/
topology.go
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Package topology exposes abstractions needed in
// topology-aware components.
package topology
import (
"errors"
"io"
"time"
"github.com/gauss-project/aurorafs/pkg/boson"
"github.com/gauss-project/aurorafs/pkg/p2p"
"github.com/gauss-project/aurorafs/pkg/subscribe"
"github.com/gauss-project/aurorafs/pkg/topology/model"
)
var (
ErrNotFound = errors.New("no peer found")
ErrWantSelf = errors.New("node wants self")
ErrOversaturated = errors.New("oversaturated")
)
type Driver interface {
p2p.Notifier
PeerAdder
ClosestPeerer
EachPeerer
EachNeighbor
NeighborhoodDepther
SubscribePeersChange(notifier subscribe.INotifier)
SubscribePeerState(notifier subscribe.INotifier)
io.Closer
Halter
Snapshot() *model.KadParams
SnapshotConnected() (connected int, peers map[string]*model.PeerInfo)
SnapshotAddr(addr boson.Address) *model.Snapshot
GetPeersWithLatencyEWMA(list []boson.Address) (now []boson.Address)
RecordPeerLatency(add boson.Address, t time.Duration)
DisconnectForce(addr boson.Address, reason string) error
Outbound(peer p2p.Peer)
NotifyPeerState(peer p2p.PeerInfo)
EachKnownPeerer
ProtectPeer
}
type ProtectPeer interface {
RefreshProtectPeer(peer []boson.Address)
}
type PeerAdder interface {
// AddPeers is called when peers are added to the topology backlog
AddPeers(addr ...boson.Address)
}
type ClosestPeerer interface {
// ClosestPeer returns the closest connected peer we have in relation to a
// given chunk address.
// This function will ignore peers with addresses provided in skipPeers.
// Returns topology.ErrWantSelf in case base is the closest to the address.
ClosestPeer(addr boson.Address, includeSelf bool, f Filter, skipPeers ...boson.Address) (peerAddr boson.Address, err error)
ClosestPeers(addr boson.Address, limit int, f Filter, skipPeers ...boson.Address) ([]boson.Address, error)
}
type EachPeerer interface {
// EachPeer iterates from closest bin to farthest
EachPeer(model.EachPeerFunc, Filter) error
// EachPeerRev iterates from farthest bin to closest
EachPeerRev(model.EachPeerFunc, Filter) error
}
// Filter defines the different filters that can be used with the Peer iterators
type Filter struct {
Reachable bool
}
type EachKnownPeerer interface {
// EachKnownPeer iterates from closest bin to farthest
EachKnownPeer(model.EachPeerFunc) error
// EachKnownPeerRev iterates from farthest bin to closest
EachKnownPeerRev(model.EachPeerFunc) error
}
type EachNeighbor interface {
// EachNeighbor iterates from closest bin to farthest within the neighborhood.
EachNeighbor(model.EachPeerFunc) error
// EachNeighborRev iterates from farthest bin to closest within the neighborhood.
EachNeighborRev(model.EachPeerFunc) error
// IsWithinDepth checks if an address is the within neighborhood.
IsWithinDepth(boson.Address) bool
}
type Halter interface {
// Halt the topology from initiating new connections
// while allowing it to still run.
Halt()
}
type NeighborhoodDepther interface {
NeighborhoodDepth() uint8
}