-
Notifications
You must be signed in to change notification settings - Fork 9
/
model.go
68 lines (54 loc) · 1.12 KB
/
model.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
package aurora
import (
"errors"
"fmt"
"github.com/gauss-project/aurorafs/pkg/bitvector"
)
var ErrInvalidNodeMode = errors.New("invalid node mode")
const (
FullNode = iota
BootNode
)
const bitVictorNodeModeLen = 1
const RelayPrefixHttp = "/group/http"
func NewModel() Model {
bv, _ := bitvector.New(bitVictorNodeModeLen)
return Model{Bv: bv}
}
func NewModelFromBytes(m []byte) (Model, error) {
bv, err := bitvector.NewFromBytes(m, bitVictorNodeModeLen)
if err != nil {
return NewModel(), err
}
return Model{Bv: bv}, nil
}
type Model struct {
Bv *bitvector.BitVector
}
func (m Model) SetMode(md int) Model {
m.Bv.Set(md)
return m
}
func (m Model) IsFull() bool {
return m.Bv.Get(FullNode)
}
func (m Model) IsBootNode() bool {
return m.Bv.Get(BootNode)
}
func (m Model) String() string {
if m.IsBootNode() {
return "boot-node"
}
if !m.IsFull() {
return "light"
}
return "full"
}
// AddressInfo contains the information received from the handshake.
type AddressInfo struct {
Address *Address
NodeMode Model
}
func (i *AddressInfo) LightString() string {
return fmt.Sprintf(" (%s)", i.NodeMode.String())
}