node

package
v0.1.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2023 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	// common api
	api.Common
	api.Device
	api.Validation
	api.DataSync
	api.Asset
	WaitQuiet func(ctx context.Context) error
	// edge api
	ExternalServiceAddress func(ctx context.Context, candidateURL string) (string, error)
	UserNATPunch           func(ctx context.Context, sourceURL string, req *types.NatPunchReq) error
	// candidate api
	GetBlocksOfAsset         func(ctx context.Context, assetCID string, randomSeed int64, randomCount int) ([]string, error)
	CheckNetworkConnectivity func(ctx context.Context, network, targetURL string) error
}

API represents the node API

func APIFromCandidate

func APIFromCandidate(api api.Candidate) *API

APIFromCandidate creates a new API from a Candidate API

func APIFromEdge

func APIFromEdge(api api.Edge) *API

APIFromEdge creates a new API from an Edge API

type Manager

type Manager struct {
	Edges      int // online edge node count
	Candidates int // online candidate node count

	*db.SQLDB
	*rsa.PrivateKey // scheduler privateKey
	dtypes.ServerID // scheduler server id
	// contains filtered or unexported fields
}

Manager is the node manager responsible for managing the online nodes

func NewManager

func NewManager(sdb *db.SQLDB, serverID dtypes.ServerID, pk *rsa.PrivateKey, pb *pubsub.PubSub, ec *etcdcli.Client) *Manager

NewManager creates a new instance of the node manager

func (*Manager) GetAllCandidateNodes

func (m *Manager) GetAllCandidateNodes() []string

GetAllCandidateNodes returns a list of all candidate nodes

func (*Manager) GetCandidateNode

func (m *Manager) GetCandidateNode(nodeID string) *Node

GetCandidateNode retrieves a candidate node with the given node ID

func (*Manager) GetCandidateNodes

func (m *Manager) GetCandidateNodes(n int) []*Node

GetCandidateNodes return n candidate node

func (*Manager) GetEdgeNode

func (m *Manager) GetEdgeNode(nodeID string) *Node

GetEdgeNode retrieves an edge node with the given node ID

func (*Manager) GetNode

func (m *Manager) GetNode(nodeID string) *Node

GetNode retrieves a node with the given node ID

func (*Manager) GetOnlineNodeCount

func (m *Manager) GetOnlineNodeCount(nodeType types.NodeType) int

GetOnlineNodeCount returns online node count of the given type

func (*Manager) GetRandomCandidate

func (m *Manager) GetRandomCandidate() (*Node, int)

GetRandomCandidate returns a random candidate node

func (*Manager) GetRandomEdge

func (m *Manager) GetRandomEdge() (*Node, int)

GetRandomEdge returns a random edge node

func (*Manager) NewNodeID

func (m *Manager) NewNodeID(nType types.NodeType) (string, error)

NewNodeID create a node id

func (*Manager) NodeOnline

func (m *Manager) NodeOnline(node *Node) error

NodeOnline registers a node as online

type Node

type Node struct {
	*API
	jsonrpc.ClientCloser

	*types.NodeInfo
	// contains filtered or unexported fields
}

Node represents an Edge or Candidate node

func New

func New() *Node

New creates a new node

func (*Node) ConnectRPC

func (n *Node) ConnectRPC(addr string, nodeType types.NodeType) error

ConnectRPC connects to the node RPC

func (*Node) CurPullingCount

func (n *Node) CurPullingCount() int

CurPullingCount returns the number of assets being pulled by the node

func (*Node) DownloadAddr

func (n *Node) DownloadAddr() string

DownloadAddr returns the download address of the node

func (*Node) IncrCurPullingCount

func (n *Node) IncrCurPullingCount(v int)

IncrCurPullingCount increments the number of assets being pulled by the node

func (*Node) LastRequestTime

func (n *Node) LastRequestTime() time.Time

LastRequestTime returns the last request time of the node

func (*Node) PublicKey

func (n *Node) PublicKey() *rsa.PublicKey

PublicKey returns the publicKey of the node

func (*Node) RPCURL

func (n *Node) RPCURL() string

RPCURL returns the rpc url of the node

func (*Node) RemoteAddr

func (n *Node) RemoteAddr() string

RemoteAddr returns the rpc address of the node

func (*Node) SetCurPullingCount

func (n *Node) SetCurPullingCount(t int)

SetCurPullingCount sets the number of assets being pulled by the node

func (*Node) SetLastRequestTime

func (n *Node) SetLastRequestTime(t time.Time)

SetLastRequestTime sets the last request time of the node

func (*Node) SetPublicKey

func (n *Node) SetPublicKey(pKey *rsa.PublicKey)

SetPublicKey sets the publicKey of the node

func (*Node) SetRemoteAddr

func (n *Node) SetRemoteAddr(addr string)

SetRemoteAddr sets the remoteAddr of the node

func (*Node) SetTCPPort

func (n *Node) SetTCPPort(port int)

SetTCPPort sets the tcpPort of the node

func (*Node) SetToken

func (n *Node) SetToken(t string)

SetToken sets the token of the node

func (*Node) TCPAddr

func (n *Node) TCPAddr() string

TCPAddr returns the tcp address of the node

func (*Node) Token

func (n *Node) Token(cid string, titanRsa *titanrsa.Rsa, privateKey *rsa.PrivateKey) (*types.Token, *types.TokenPayload, error)

Token returns the token of the node

func (*Node) UpdateNodePort

func (n *Node) UpdateNodePort(port string)

UpdateNodePort updates the node port

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL