-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathp2pCore.go
84 lines (71 loc) · 2.24 KB
/
p2pCore.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
package core
// P2PPeerType defines the type of a p2p peer
type P2PPeerType int
// String returns the string-ified version of P2PPeerType
func (pt P2PPeerType) String() string {
switch pt {
case ValidatorPeer:
return "validator"
case ObserverPeer:
return "observer"
default:
return "unknown"
}
}
const (
// UnknownPeer defines a peer that is unknown (did not advertise data in any way)
UnknownPeer P2PPeerType = iota
// ValidatorPeer means that the peer is a validator
ValidatorPeer
// ObserverPeer means that the peer is an observer
ObserverPeer
)
// P2PPeerSubType defines the subtype of peer (e.g. FullArchive)
type P2PPeerSubType uint32
const (
// RegularPeer
RegularPeer P2PPeerSubType = iota
// FullHistoryObserver is a node that syncs the entire history of its shard
FullHistoryObserver
)
// String returns the string-ified version of P2PPeerSubType
func (pst P2PPeerSubType) String() string {
switch pst {
case RegularPeer:
return "regular"
case FullHistoryObserver:
return "fullArchive"
default:
return "unknown"
}
}
// P2PPeerInfo represents a peer info structure
type P2PPeerInfo struct {
PeerType P2PPeerType
PeerSubType P2PPeerSubType
ShardID uint32
PkBytes []byte
}
// QueryP2PPeerInfo represents a DTO used in exporting p2p peer info after a query
type QueryP2PPeerInfo struct {
IsBlacklisted bool `json:"isblacklisted"`
Pid string `json:"pid"`
Pk string `json:"pk"`
PeerType string `json:"peertype"`
PeerSubType string `json:"peersubtype"`
Addresses []string `json:"addresses"`
}
// PeerTopicType represents the type of a peer in regards to the topic it is used
type PeerTopicType string
// String returns a string version of the peer topic type
func (pt PeerTopicType) String() string {
return string(pt)
}
const (
// IntraShardPeer represents the identifier for intra shard peers to be used in intra shard topics
IntraShardPeer PeerTopicType = "intra peer"
// CrossShardPeer represents the identifier for intra shard peers to be used in cross shard topics
CrossShardPeer PeerTopicType = "cross peer"
// FullHistoryPeer represents the identifier for intra shard peers to be used in full history topics
FullHistoryPeer PeerTopicType = "full history peer"
)