node

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2024 License: MIT Imports: 10 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) FindFile added in v0.4.0

func (c *AdminClient) FindFile(ctx context.Context, txSeq uint64) (int, 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) ([]LocationInfo, error)

GetFileLocation Get file location

func (*AdminClient) GetNetworkInfo added in v0.3.1

func (c *AdminClient) GetNetworkInfo(ctx context.Context) (NetworkInfo, 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) (map[string]*PeerInfo, 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) (map[uint64]FileSyncInfo, 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) (string, error)

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

func (*AdminClient) Shutdown

func (c *AdminClient) Shutdown(ctx context.Context) (int, 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) (int, error)

StartSyncChunks Call admin_startSyncChunks to request synchronization of specified chunks.

func (*AdminClient) StartSyncFile

func (c *AdminClient) StartSyncFile(ctx context.Context, txSeq uint64) (int, 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) (bool, error)

TerminateSync Call admin_terminateSync to terminate a file sync.

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 FlowProof added in v0.6.1

type FlowProof struct {
	Lemma []common.Hash `json:"lemma"`
	Path  []bool        `json:"path"`
}

FlowProof proof of a sector in flow

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) GetFirst

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

GetFirst Call kv_getFirst RPC to query the first key.

func (*KvClient) GetHoldingStreamIds

func (c *KvClient) GetHoldingStreamIds(ctx context.Context) ([]common.Hash, 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) (*KeyValue, 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) (*KeyValue, 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) (*KeyValue, 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) (string, 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) (*Value, 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) (bool, 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) (bool, 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) (bool, 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) (bool, 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) (bool, error)

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

type LocationInfo added in v0.4.0

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

LocationInfo file location information

type NetworkIdentity added in v0.6.0

type NetworkIdentity struct {
	ChainId                uint64                 `json:"chainId"`
	FlowContractAddress    common.Address         `json:"flowAddress"`
	NetworkProtocolVersion NetworkProtocolVersion `json:"p2pProtocolVersion"`
}

NetworkIdentity network identity of 0g storage node to distinguish different networks.

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 NetworkProtocolVersion added in v0.6.0

type NetworkProtocolVersion struct {
	Major uint8 `json:"major"`
	Minor uint8 `json:"minor"`
	Build uint8 `json:"build"`
}

NetworkProtocolVersion P2P network protocol version.

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"`
	NextTxSeq       uint64          `json:"nextTxSeq"`
	NetworkIdentity NetworkIdentity `json:"networkIdentity"`
}

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 TxSeqOrRoot added in v0.6.1

type TxSeqOrRoot struct {
	TxSeq uint64
	Root  common.Hash
}

TxSeqOrRoot represents a tx seq or data root.

func (TxSeqOrRoot) MarshalJSON added in v0.6.1

func (t TxSeqOrRoot) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface.

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) CheckFileFinalized added in v0.6.1

func (c *ZgsClient) CheckFileFinalized(ctx context.Context, txSeqOrRoot TxSeqOrRoot) (*bool, error)

CheckFileFinalized Call zgs_checkFileFinalized to check if specified file is finalized. Returns nil if file not available on storage node.

func (*ZgsClient) DownloadSegment added in v0.3.1

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

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

func (*ZgsClient) DownloadSegmentByTxSeq added in v0.6.1

func (c *ZgsClient) DownloadSegmentByTxSeq(ctx context.Context, txSeq uint64, startIndex, endIndex uint64) ([]byte, error)

DownloadSegmentByTxSeq Call zgs_downloadSegmentByTxSeq 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) (*SegmentWithProof, error)

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

func (*ZgsClient) DownloadSegmentWithProofByTxSeq added in v0.6.1

func (c *ZgsClient) DownloadSegmentWithProofByTxSeq(ctx context.Context, txSeq uint64, index uint64) (*SegmentWithProof, error)

DownloadSegmentWithProofByTxSeq Call zgs_downloadSegmentWithProofByTxSeq 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) (*FileInfo, 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) (*FileInfo, error)

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

func (*ZgsClient) GetSectorProof added in v0.6.1

func (c *ZgsClient) GetSectorProof(ctx context.Context, sectorIndex uint64, root *common.Hash) (FlowProof, error)

GetSectorProof Call zgs_getSectorProof RPC to get the proof of a sector.

func (*ZgsClient) GetShardConfig added in v0.3.1

func (c *ZgsClient) GetShardConfig(ctx context.Context) (shard.ShardConfig, 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, error)

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

func (*ZgsClient) UploadSegment added in v0.3.1

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

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

func (*ZgsClient) UploadSegmentByTxSeq added in v0.6.1

func (c *ZgsClient) UploadSegmentByTxSeq(ctx context.Context, segment SegmentWithProof, txSeq uint64) (int, error)

UploadSegmentByTxSeq Call zgs_uploadSegmentByTxSeq 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) (int, error)

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

func (*ZgsClient) UploadSegmentsByTxSeq added in v0.6.1

func (c *ZgsClient) UploadSegmentsByTxSeq(ctx context.Context, segments []SegmentWithProof, txSeq uint64) (int, error)

UploadSegmentsByTxSeq Call zgs_uploadSegmentsByTxSeq 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