2020-09-22 15:51:34 +01:00
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2020-12-09 16:34:37 +00:00
|
|
|
package nodes
|
2020-09-22 15:51:34 +01:00
|
|
|
|
|
|
|
import (
|
2020-10-02 17:21:58 +01:00
|
|
|
"context"
|
2020-12-26 01:16:43 +00:00
|
|
|
"time"
|
2020-10-02 17:21:58 +01:00
|
|
|
|
2020-11-16 12:46:49 +00:00
|
|
|
"github.com/zeebo/errs"
|
|
|
|
|
2020-09-22 15:51:34 +01:00
|
|
|
"storj.io/common/storj"
|
|
|
|
)
|
|
|
|
|
2020-12-09 16:34:37 +00:00
|
|
|
// DB exposes needed by MND NodesDB functionality.
|
2020-10-02 17:21:58 +01:00
|
|
|
//
|
|
|
|
// architecture: Database
|
2020-12-09 16:34:37 +00:00
|
|
|
type DB interface {
|
2020-12-17 15:05:18 +00:00
|
|
|
// Get return node from NodesDB by its id.
|
|
|
|
Get(ctx context.Context, id storj.NodeID) (Node, error)
|
|
|
|
// List returns all connected nodes.
|
|
|
|
List(ctx context.Context) ([]Node, error)
|
2021-06-01 08:06:53 +01:00
|
|
|
// ListPaged returns paginated nodes list.
|
2021-06-01 08:50:18 +01:00
|
|
|
// TODO: rename to ListPaginated, because pagination is to divide up copy into pages,
|
|
|
|
// because paging doesn't necessarily mean pagination in computing.
|
2021-06-01 08:06:53 +01:00
|
|
|
ListPaged(ctx context.Context, cursor Cursor) (page Page, err error)
|
2020-11-16 12:46:49 +00:00
|
|
|
// Add creates new node in NodesDB.
|
2021-12-07 07:38:25 +00:00
|
|
|
Add(ctx context.Context, node Node) error
|
2020-10-02 17:21:58 +01:00
|
|
|
// Remove removed node from NodesDB.
|
|
|
|
Remove(ctx context.Context, id storj.NodeID) error
|
2020-12-09 16:34:37 +00:00
|
|
|
// UpdateName will update name of the specified node in database.
|
|
|
|
UpdateName(ctx context.Context, id storj.NodeID, name string) error
|
2020-10-02 17:21:58 +01:00
|
|
|
}
|
|
|
|
|
2021-03-26 22:17:34 +00:00
|
|
|
var (
|
|
|
|
// ErrNoNode is a special error type that indicates about absence of node in NodesDB.
|
|
|
|
ErrNoNode = errs.Class("no such node")
|
|
|
|
)
|
2020-11-16 12:46:49 +00:00
|
|
|
|
2020-12-23 17:21:23 +00:00
|
|
|
// Node is a representation of storagenode, that SNO could add to the Multinode Dashboard.
|
2020-09-22 15:51:34 +01:00
|
|
|
type Node struct {
|
2021-01-21 16:52:19 +00:00
|
|
|
ID storj.NodeID `json:"id"`
|
2020-12-23 17:21:23 +00:00
|
|
|
// APISecret is a secret issued by storagenode, that will be main auth mechanism in MND <-> SNO api.
|
2021-01-21 16:52:19 +00:00
|
|
|
APISecret []byte `json:"apiSecret"`
|
|
|
|
PublicAddress string `json:"publicAddress"`
|
|
|
|
Name string `json:"name"`
|
2020-09-22 15:51:34 +01:00
|
|
|
}
|
2020-11-11 22:29:29 +00:00
|
|
|
|
2021-07-05 15:08:14 +01:00
|
|
|
// Status represents node online status.
|
|
|
|
type Status string
|
|
|
|
|
|
|
|
const (
|
|
|
|
// StatusOnline represents online status.
|
|
|
|
StatusOnline Status = "online"
|
|
|
|
// StatusOffline represents offline status.
|
|
|
|
StatusOffline Status = "offline"
|
|
|
|
// StatusNotReachable indicates that we could not reach storagenode via drpc request.
|
|
|
|
StatusNotReachable Status = "not reachable"
|
2021-07-16 14:07:56 +01:00
|
|
|
// StatusUnauthorized indicates that api key is wrong.
|
|
|
|
StatusUnauthorized Status = "unauthorized"
|
|
|
|
// StatusStorageNodeInternalError indicates storagenode internal error.
|
|
|
|
StatusStorageNodeInternalError Status = "storagenode internal error"
|
2021-07-05 15:08:14 +01:00
|
|
|
)
|
|
|
|
|
2020-12-26 01:16:43 +00:00
|
|
|
// NodeInfo contains basic node internal state.
|
|
|
|
type NodeInfo struct {
|
2021-01-21 16:52:19 +00:00
|
|
|
ID storj.NodeID `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Version string `json:"version"`
|
|
|
|
LastContact time.Time `json:"lastContact"`
|
|
|
|
DiskSpaceUsed int64 `json:"diskSpaceUsed"`
|
|
|
|
DiskSpaceLeft int64 `json:"diskSpaceLeft"`
|
|
|
|
BandwidthUsed int64 `json:"bandwidthUsed"`
|
|
|
|
TotalEarned int64 `json:"totalEarned"`
|
2021-07-05 15:08:14 +01:00
|
|
|
Status Status `json:"status"`
|
2020-11-11 22:29:29 +00:00
|
|
|
}
|
2021-01-05 07:59:22 +00:00
|
|
|
|
|
|
|
// NodeInfoSatellite contains satellite specific node internal state.
|
|
|
|
type NodeInfoSatellite struct {
|
2021-01-21 16:52:19 +00:00
|
|
|
ID storj.NodeID `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Version string `json:"version"`
|
|
|
|
LastContact time.Time `json:"lastContact"`
|
|
|
|
OnlineScore float64 `json:"onlineScore"`
|
|
|
|
AuditScore float64 `json:"auditScore"`
|
|
|
|
SuspensionScore float64 `json:"suspensionScore"`
|
|
|
|
TotalEarned int64 `json:"totalEarned"`
|
2021-07-05 15:08:14 +01:00
|
|
|
Status Status `json:"status"`
|
2021-01-05 07:59:22 +00:00
|
|
|
}
|
2021-06-01 08:06:53 +01:00
|
|
|
|
|
|
|
// TODO: separate common types and logic from nodes and operators and place it in private/pkg.
|
|
|
|
|
|
|
|
// Cursor holds cursor entity which is used to create listed page.
|
|
|
|
type Cursor struct {
|
2021-06-01 08:37:48 +01:00
|
|
|
Limit int64
|
|
|
|
Page int64
|
2021-06-01 08:06:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Page holds nodes page entity which is used to show listed page of nodes.
|
|
|
|
type Page struct {
|
|
|
|
Nodes []Node
|
2021-06-01 08:37:48 +01:00
|
|
|
Limit int64
|
|
|
|
Offset int64
|
|
|
|
PageCount int64
|
|
|
|
CurrentPage int64
|
|
|
|
TotalCount int64
|
2021-06-01 08:06:53 +01:00
|
|
|
}
|