node

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2024 License: MIT Imports: 9 Imported by: 8

Documentation

Overview

Package node defines RPC client structures to facilitate RPC interactions with 0g storage nodes and 0g key-value (KV) nodes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AdminClient

type AdminClient struct {
	// contains filtered or unexported fields
}

AdminClient RPC Client connected to a 0g storage node's admin RPC endpoint.

func MustNewAdminClient added in v0.3.1

func MustNewAdminClient(url string, option ...providers.Option) *AdminClient

MustNewAdminClient initalize an admin client and panic on failure.

func NewAdminClient added in v0.3.1

func NewAdminClient(url string, option ...providers.Option) (*AdminClient, error)

NewAdminClient initalize an admin client.

func (AdminClient) Close added in v0.3.1

func (c AdminClient) Close()

Close close the underlying RPC client.

func (*AdminClient) FindFile added in v0.4.0

func (c *AdminClient) FindFile(ctx context.Context, txSeq uint64) (ret int, err error)

FindFile Call find_file to update file location cache

func (*AdminClient) GetFileLocation added in v0.4.0

func (c *AdminClient) GetFileLocation(ctx context.Context, txSeq uint64, allShards bool) (locations []LocationInfo, err error)

getFileLocation Get file location

func (*AdminClient) GetNetworkInfo added in v0.3.1

func (c *AdminClient) GetNetworkInfo(ctx context.Context) (info NetworkInfo, err error)

GetNetworkInfo Call admin_getNetworkInfo to retrieve the network information.

func (*AdminClient) GetPeers added in v0.3.1

func (c *AdminClient) GetPeers(ctx context.Context) (peers map[string]*PeerInfo, err error)

GetPeers Call admin_getPeers to retrieve all discovered network peers.

func (*AdminClient) GetSyncInfo added in v0.3.1

func (c *AdminClient) GetSyncInfo(ctx context.Context, tx_seq ...uint64) (files map[uint64]FileSyncInfo, err error)

GetSyncInfo Call admin_getSyncInfo to retrieve the sync status of specified file or all files.

func (*AdminClient) GetSyncStatus

func (c *AdminClient) GetSyncStatus(ctx context.Context, txSeq uint64) (status string, err error)

GetSyncStatus Call admin_getSyncStatus to retrieve the sync status of specified file.

func (*AdminClient) Shutdown

func (c *AdminClient) Shutdown(ctx context.Context) (ret int, err error)

Shutdown Call admin_shutdown to shutdown the node.

func (*AdminClient) StartSyncChunks added in v0.3.1

func (c *AdminClient) StartSyncChunks(ctx context.Context, txSeq, startIndex, endIndex uint64) (ret int, err error)

StartSyncChunks Call admin_startSyncChunks to request synchronization of specified chunks.

func (*AdminClient) StartSyncFile

func (c *AdminClient) StartSyncFile(ctx context.Context, txSeq uint64) (ret int, err error)

StartSyncFile Call admin_startSyncFile to request synchronization of a file.

func (*AdminClient) TerminateSync added in v0.3.1

func (c *AdminClient) TerminateSync(ctx context.Context, txSeq uint64) (terminated bool, err error)

TerminateSync Call admin_terminateSync to terminate a file sync.

func (AdminClient) URL added in v0.3.1

func (c AdminClient) URL() string

URL Get the RPC server URL the client connected to.

type ClientInfo added in v0.3.1

type ClientInfo struct {
	Version  string `json:"version"`
	OS       string `json:"os"`
	Protocol string `json:"protocol"`
	Agent    string `json:"agent"`
}

ClientInfo client information of remote peer

type FileInfo

type FileInfo struct {
	Tx             Transaction `json:"tx"`             // on-chain transaction
	Finalized      bool        `json:"finalized"`      // whether the file has been finalized in the storage node
	IsCached       bool        `json:"isCached"`       // whether the file is cached in the storage node
	UploadedSegNum uint64      `json:"uploadedSegNum"` // the number of uploaded segments
}

FileInfo information about a file responded from 0g storage node

type FileSyncGoal added in v0.3.1

type FileSyncGoal struct {
	NumChunks  uint64 `json:"numChunks"`
	IndexStart uint64 `json:"indexStart"`
	IndexEnd   uint64 `json:"indexEnd"`
}

FileSyncGoal File sync goal

type FileSyncInfo added in v0.3.1

type FileSyncInfo struct {
	ElapsedSecs uint64               `json:"elapsedSecs"`
	Peers       map[PeerState]uint64 `json:"peers"`
	Goal        FileSyncGoal         `json:"goal"`
	NextChunks  uint64               `json:"next_chunks"`
	State       string               `json:"state"`
}

FileSyncInfo file sync information

type KeyValue

type KeyValue struct {
	Version uint64 `json:"version"` // key version
	Key     []byte `json:"key"`     // value key
	Data    []byte `json:"data"`    // value data
	Size    uint64 `json:"size"`    // value total size
}

KeyValue KV key and value

type KvClient

type KvClient struct {
	// contains filtered or unexported fields
}

KvClient RPC client connected to 0g kv node.

func MustNewKvClient added in v0.3.1

func MustNewKvClient(url string, option ...providers.Option) *KvClient

MustNewKvClient initalize a kv client and panic on failure.

func NewKvClient added in v0.3.1

func NewKvClient(url string, option ...providers.Option) (*KvClient, error)

NewKvClient initalize a kv client.

func (KvClient) Close added in v0.3.1

func (c KvClient) Close()

Close close the underlying RPC client.

func (*KvClient) GetFirst

func (c *KvClient) GetFirst(ctx context.Context, streamId common.Hash, startIndex, length uint64, version ...uint64) (val *KeyValue, err error)

GetFirst Call kv_getFirst RPC to query the first key.

func (*KvClient) GetHoldingStreamIds

func (c *KvClient) GetHoldingStreamIds(ctx context.Context) (streamIds []common.Hash, err error)

GetHoldingStreamIds Call kv_getHoldingStreamIds RPC to query the stream ids monitered by the kv node.

func (*KvClient) GetLast

func (c *KvClient) GetLast(ctx context.Context, streamId common.Hash, startIndex, length uint64, version ...uint64) (val *KeyValue, err error)

GetLast Call kv_getLast RPC to query the last key.

func (*KvClient) GetNext

func (c *KvClient) GetNext(ctx context.Context, streamId common.Hash, key []byte, startIndex, length uint64, inclusive bool, version ...uint64) (val *KeyValue, err error)

GetNext Call kv_getNext RPC to query the next key of a given key.

func (*KvClient) GetPrev

func (c *KvClient) GetPrev(ctx context.Context, streamId common.Hash, key []byte, startIndex, length uint64, inclusive bool, version ...uint64) (val *KeyValue, err error)

GetPrev Call kv_getNext RPC to query the prev key of a given key.

func (*KvClient) GetTransactionResult

func (c *KvClient) GetTransactionResult(ctx context.Context, txSeq uint64) (result string, err error)

GetTransactionResult Call kv_getTransactionResult RPC to query the kv replay status of a given file.

func (*KvClient) GetValue

func (c *KvClient) GetValue(ctx context.Context, streamId common.Hash, key []byte, startIndex, length uint64, version ...uint64) (val *Value, err error)

GetValue Call kv_getValue RPC to query the value of a key.

func (*KvClient) HasWritePermission

func (c *KvClient) HasWritePermission(ctx context.Context, account common.Address, streamId common.Hash, key []byte, version ...uint64) (hasPermission bool, err error)

HasWritePermission Call kv_hasWritePermission RPC to check if the account is able to write the stream.

func (*KvClient) IsAdmin

func (c *KvClient) IsAdmin(ctx context.Context, account common.Address, streamId common.Hash, version ...uint64) (isAdmin bool, err error)

IsAdmin Call kv_isAdmin RPC to check if the account is the admin of the stream.

func (*KvClient) IsSpecialKey

func (c *KvClient) IsSpecialKey(ctx context.Context, streamId common.Hash, key []byte, version ...uint64) (isSpecialKey bool, err error)

IsSpecialKey Call kv_isSpecialKey RPC to check if the key has unique access control.

func (*KvClient) IsWriterOfKey

func (c *KvClient) IsWriterOfKey(ctx context.Context, account common.Address, streamId common.Hash, key []byte, version ...uint64) (isWriter bool, err error)

IsWriterOfKey Call kv_isWriterOfKey RPC to check if the account can write the special key.

func (*KvClient) IsWriterOfStream

func (c *KvClient) IsWriterOfStream(ctx context.Context, account common.Address, streamId common.Hash, version ...uint64) (isWriter bool, err error)

IsWriterOfStream Call kv_isWriterOfStream RPC to check if the account is the writer of the stream.

func (KvClient) URL added in v0.3.1

func (c KvClient) URL() string

URL Get the RPC server URL the client connected to.

type LocationInfo added in v0.4.0

type LocationInfo struct {
	Ip          string            `json:"ip"`
	ShardConfig shard.ShardConfig `json:"shardConfig"`
}

LocationInfo file location information

type NetworkInfo added in v0.3.1

type NetworkInfo struct {
	PeerId                 string   `json:"peerId"`
	ListenAddresses        []string `json:"listenAddresses"`
	TotalPeers             uint64   `json:"totalPeers"`
	BannedPeers            uint64   `json:"bannedPeers"`
	DisconnectedPeers      uint64   `json:"disconnectedPeers"`
	ConnectedPeers         uint64   `json:"connectedPeers"`
	ConnectedOutgoingPeers uint64   `json:"connectedOutgoingPeers"`
	ConnectedIncomingPeers uint64   `json:"connectedIncomingPeers"`
}

NetworkInfo network information

type PeerConnectionStatus added in v0.3.1

type PeerConnectionStatus struct {
	Status         string `json:"status"` // connected, disconnecting, disconnected, banned, dialing, unknown
	ConnectionsIn  uint8  `json:"connectionsIn"`
	ConnectionsOut uint8  `json:"connectionsOut"`
	LastSeenSecs   uint64 `json:"lastSeenSecs"`
}

PeerConnectionStatus network connection status of remote peer

type PeerInfo added in v0.3.1

type PeerInfo struct {
	Client              ClientInfo           `json:"client"`
	ConnectionStatus    PeerConnectionStatus `json:"connectionStatus"`
	ListeningAddresses  []string             `json:"listeningAddresses"`
	SeenIps             []string             `json:"seenIps"`
	IsTrusted           bool                 `json:"isTrusted"`
	ConnectionDirection string               `json:"connectionDirection"` // Incoming/Outgoing/empty
	Enr                 string               `json:"enr"`                 // maybe empty
}

PeerInfo remote peer information

type PeerState added in v0.3.1

type PeerState string

PeerState network peer status

const (
	PeerStateFound         PeerState = "Found"
	PeerStateConnecting    PeerState = "Connecting"
	PeerStateConnected     PeerState = "Connected"
	PeerStateDisconnecting PeerState = "Disconnecting"
	PeerStateDisconnected  PeerState = "Disconnected"
)

type RPCError added in v0.4.3

type RPCError struct {
	Message string
	Method  string
	URL     string
}

func (*RPCError) Error added in v0.4.3

func (e *RPCError) Error() string

type SegmentWithProof

type SegmentWithProof struct {
	Root     common.Hash  `json:"root"`     // file merkle root
	Data     []byte       `json:"data"`     // segment data
	Index    uint64       `json:"index"`    // segment index
	Proof    merkle.Proof `json:"proof"`    // segment merkle proof
	FileSize uint64       `json:"fileSize"` // file size
}

SegmentWithProof data segment with merkle proof

type Status

type Status struct {
	ConnectedPeers uint        `json:"connectedPeers"`
	LogSyncHeight  uint64      `json:"logSyncHeight"`
	LogSyncBlock   common.Hash `json:"logSyncBlock"`
}

Status sync status of 0g storage node

type Transaction

type Transaction struct {
	StreamIds       []*hexutil.Big `json:"streamIds"`       // transaction related stream id, used for KV operations
	Data            []byte         `json:"data"`            // in-place data
	DataMerkleRoot  common.Hash    `json:"dataMerkleRoot"`  // data merkle root
	StartEntryIndex uint64         `json:"startEntryIndex"` // start entry index in on-chain flow contract
	Size            uint64         `json:"size"`            // file size in bytes
	Seq             uint64         `json:"seq"`             // sequence id in on-chain flow contract
}

Transaction on-chain transaction about a file

type Value

type Value struct {
	Version uint64 `json:"version"` // key version
	Data    []byte `json:"data"`    // value data
	Size    uint64 `json:"size"`    // value total size
}

Value KV value

type ZgsClient added in v0.3.1

type ZgsClient struct {
	// contains filtered or unexported fields
}

ZgsClient RPC Client connected to a 0g storage node's zgs RPC endpoint.

func MustNewZgsClient added in v0.3.1

func MustNewZgsClient(url string, option ...providers.Option) *ZgsClient

MustNewZgsClient Initalize a zgs client and panic on failure.

func MustNewZgsClients added in v0.3.1

func MustNewZgsClients(urls []string, option ...providers.Option) []*ZgsClient

MustNewZgsClients Initialize a list of zgs clients and panic on failure.

func NewZgsClient added in v0.3.1

func NewZgsClient(url string, option ...providers.Option) (*ZgsClient, error)

NewZgsClient Initalize a zgs client.

func (ZgsClient) Close added in v0.3.1

func (c ZgsClient) Close()

Close close the underlying RPC client.

func (*ZgsClient) DownloadSegment added in v0.3.1

func (c *ZgsClient) DownloadSegment(ctx context.Context, root common.Hash, startIndex, endIndex uint64) (data []byte, err error)

DownloadSegment Call zgs_downloadSegment RPC to download a segment from the node.

func (*ZgsClient) DownloadSegmentWithProof added in v0.3.1

func (c *ZgsClient) DownloadSegmentWithProof(ctx context.Context, root common.Hash, index uint64) (segment *SegmentWithProof, err error)

DownloadSegmentWithProof Call zgs_downloadSegmentWithProof RPC to download a segment along with its merkle proof from the node.

func (*ZgsClient) GetFileInfo added in v0.3.1

func (c *ZgsClient) GetFileInfo(ctx context.Context, root common.Hash) (file *FileInfo, err error)

GetFileInfo Call zgs_getFileInfo RPC to get the information of a file by file data root from the node.

func (*ZgsClient) GetFileInfoByTxSeq added in v0.3.1

func (c *ZgsClient) GetFileInfoByTxSeq(ctx context.Context, txSeq uint64) (file *FileInfo, err error)

GetFileInfoByTxSeq Call zgs_getFileInfoByTxSeq RPC to get the information of a file by file sequence id from the node.

func (*ZgsClient) GetShardConfig added in v0.3.1

func (c *ZgsClient) GetShardConfig(ctx context.Context) (shardConfig shard.ShardConfig, err error)

GetShardConfig Call zgs_getShardConfig RPC to get the current shard configuration of the node.

func (*ZgsClient) GetStatus added in v0.3.1

func (c *ZgsClient) GetStatus(ctx context.Context) (status Status, err error)

GetStatus Call zgs_getStatus RPC to get sync status of the node.

func (ZgsClient) URL added in v0.3.1

func (c ZgsClient) URL() string

URL Get the RPC server URL the client connected to.

func (*ZgsClient) UploadSegment added in v0.3.1

func (c *ZgsClient) UploadSegment(ctx context.Context, segment SegmentWithProof) (ret int, err error)

UploadSegment Call zgs_uploadSegment RPC to upload a segment to the node.

func (*ZgsClient) UploadSegments added in v0.3.1

func (c *ZgsClient) UploadSegments(ctx context.Context, segments []SegmentWithProof) (ret int, err error)

UploadSegments Call zgs_uploadSegments RPC to upload a slice of segments to the node.

Jump to

Keyboard shortcuts

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