-
Notifications
You must be signed in to change notification settings - Fork 0
/
nodenetwork.go
101 lines (90 loc) · 3.46 KB
/
nodenetwork.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
101
/*
* Copyright 2019 Insolar Technologies
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package core
import (
"crypto"
)
// ShortNodeID is the shortened ID of node that is unique inside the globe
type ShortNodeID uint32
// GlobuleID is the ID of the globe
type GlobuleID uint32
// NodeState is the state of the node
type NodeState uint8
//go:generate stringer -type=NodeState
const (
NodeDiscovery NodeState = iota
NodeJoining
NodeReady
)
//go:generate minimock -i github.com/insolar/insolar/core.Node -o ../testutils/network -s _mock.go
type Node interface {
// ID is the unique identifier of the node
ID() RecordRef
// ShortID get short ID of node
ShortID() ShortNodeID
// Role is the candidate Role for the node
Role() StaticRole
// PublicKey is the public key of the node
PublicKey() crypto.PublicKey
// Address is the network address of the node
Address() string
// ConsensusAddress is the network address of the node for consensus packets exchange
ConsensusAddress() string
// GetGlobuleID returns node current globule id
GetGlobuleID() GlobuleID
// Version of node software
Version() string
// Leaving indicates, that node preparing for graceful shutdown
Leaving() bool
// LeavingETA is pulse number, after which node leave
LeavingETA() PulseNumber
// IsWorking true if node is in working node list
IsWorking() bool
// GetState get state of the node
GetState() NodeState
}
type NodeNetworkState uint8
//go:generate stringer -type=NodeNetworkState
const (
// UndefinedNodeNetworkState is state of NodeKeeper while it is not valid
UndefinedNodeNetworkState NodeNetworkState = iota + 1
// WaitingNodeNetworkState is state of NodeKeeper while it is not part of consensus yet (waits for its join claim to pass)
WaitingNodeNetworkState
// ReadyNodeNetworkState is state of NodeKeeper when it is ready for consensus
ReadyNodeNetworkState
)
//go:generate minimock -i github.com/insolar/insolar/core.NodeNetwork -o ../testutils/network -s _mock.go
type NodeNetwork interface {
// GetState get state of the NodeKeeper
GetState() NodeNetworkState
// GetOrigin get origin node for the current insolard. Returns nil if the current insolard is not a working node.
GetOrigin() Node
// GetWorkingNode get working node by its reference. Returns nil if node is not found.
GetWorkingNode(ref RecordRef) Node
// GetWorkingNodes get working nodes.
GetWorkingNodes() []Node
// GetWorkingNodesByRole get working nodes by role
GetWorkingNodesByRole(role DynamicRole) []RecordRef
}
// TODO: remove this interface when bootstrap mechanism completed
// SwitcherWorkAround temp interface for NetworkSwitcher interaction
//go:generate minimock -i github.com/insolar/insolar/core.SwitcherWorkAround -o ../testutils/network -s _mock.go
type SwitcherWorkAround interface {
// IsBootstrapped method shows that all DiscoveryNodes finds each other
IsBootstrapped() bool
// SetIsBootstrapped method set is bootstrap completed
SetIsBootstrapped(isBootstrap bool)
}