peer improvment
This commit is contained in:
@@ -8,14 +8,11 @@ import (
|
||||
)
|
||||
|
||||
// now write a go enum for the state partner with self, blacklist, partner
|
||||
|
||||
type PeerState int
|
||||
|
||||
const (
|
||||
NONE PeerState = iota
|
||||
SELF
|
||||
PARTNER
|
||||
BLACKLIST
|
||||
OFFLINE PeerState = iota
|
||||
ONLINE
|
||||
)
|
||||
|
||||
func (m PeerState) String() string {
|
||||
@@ -26,6 +23,24 @@ func (m PeerState) EnumIndex() int {
|
||||
return int(m)
|
||||
}
|
||||
|
||||
type PeerRelation int
|
||||
|
||||
const (
|
||||
NONE PeerRelation = iota
|
||||
SELF
|
||||
PARTNER
|
||||
BLACKLIST
|
||||
UNKNOWN
|
||||
)
|
||||
|
||||
func (m PeerRelation) String() string {
|
||||
return [...]string{"NONE", "SELF", "PARTNER", "BLACKLIST"}[m]
|
||||
}
|
||||
|
||||
func (m PeerRelation) EnumIndex() int {
|
||||
return int(m)
|
||||
}
|
||||
|
||||
func GetSelf() (utils.ShallowDBObject, string) {
|
||||
d, code, err := NewAccessor(nil).Search(nil, SELF.String(), false)
|
||||
if code != 200 || err != nil || len(d) == 0 {
|
||||
@@ -47,10 +62,12 @@ func IsMySelf(peerID string) (bool, string) {
|
||||
// Peer is a struct that represents a peer
|
||||
type Peer struct {
|
||||
utils.AbstractObject
|
||||
PeerID string `json:"peer_id" bson:"peer_id" validate:"required"`
|
||||
Url string `json:"url" bson:"url" validate:"required"` // Url is the URL of the peer (base64url)
|
||||
WalletAddress string `json:"wallet_address" bson:"wallet_address" validate:"required"` // WalletAddress is the wallet address of the peer
|
||||
PublicKey string `json:"public_key" bson:"public_key" validate:"required"` // PublicKey is the public key of the peer
|
||||
State PeerState `json:"state" bson:"state" default:"0"`
|
||||
Relation PeerRelation `json:"relation" bson:"state" default:"0"`
|
||||
ServicesState map[string]int `json:"services_state,omitempty" bson:"services_state,omitempty"`
|
||||
FailedExecution []PeerExecution `json:"failed_execution" bson:"failed_execution"` // FailedExecution is the list of failed executions, to be retried
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user