Documentation
¶
Overview ¶
Package node defines RPC client structures to facilitate RPC interactions with 0g storage nodes and 0g key-value (KV) nodes.
Index ¶
- type AdminClient
- func (c *AdminClient) FindFile(ctx context.Context, txSeq uint64) (int, error)
- func (c *AdminClient) GetFileLocation(ctx context.Context, txSeq uint64, allShards bool) ([]LocationInfo, error)
- func (c *AdminClient) GetNetworkInfo(ctx context.Context) (NetworkInfo, error)
- func (c *AdminClient) GetPeers(ctx context.Context) (map[string]*PeerInfo, error)
- func (c *AdminClient) GetSyncInfo(ctx context.Context, tx_seq ...uint64) (map[uint64]FileSyncInfo, error)
- func (c *AdminClient) GetSyncStatus(ctx context.Context, txSeq uint64) (string, error)
- func (c *AdminClient) Shutdown(ctx context.Context) (int, error)
- func (c *AdminClient) StartSyncChunks(ctx context.Context, txSeq, startIndex, endIndex uint64) (int, error)
- func (c *AdminClient) StartSyncFile(ctx context.Context, txSeq uint64) (int, error)
- func (c *AdminClient) TerminateSync(ctx context.Context, txSeq uint64) (bool, error)
- type ClientInfo
- type FileInfo
- type FileSyncGoal
- type FileSyncInfo
- type FlowProof
- type KeyValue
- type KvClient
- func (c *KvClient) GetFirst(ctx context.Context, streamId common.Hash, startIndex, length uint64, ...) (*KeyValue, error)
- func (c *KvClient) GetHoldingStreamIds(ctx context.Context) ([]common.Hash, error)
- func (c *KvClient) GetLast(ctx context.Context, streamId common.Hash, startIndex, length uint64, ...) (*KeyValue, error)
- func (c *KvClient) GetNext(ctx context.Context, streamId common.Hash, key []byte, ...) (*KeyValue, error)
- func (c *KvClient) GetPrev(ctx context.Context, streamId common.Hash, key []byte, ...) (*KeyValue, error)
- func (c *KvClient) GetTransactionResult(ctx context.Context, txSeq uint64) (string, error)
- func (c *KvClient) GetValue(ctx context.Context, streamId common.Hash, key []byte, ...) (*Value, error)
- func (c *KvClient) HasWritePermission(ctx context.Context, account common.Address, streamId common.Hash, key []byte, ...) (bool, error)
- func (c *KvClient) IsAdmin(ctx context.Context, account common.Address, streamId common.Hash, ...) (bool, error)
- func (c *KvClient) IsSpecialKey(ctx context.Context, streamId common.Hash, key []byte, version ...uint64) (bool, error)
- func (c *KvClient) IsWriterOfKey(ctx context.Context, account common.Address, streamId common.Hash, key []byte, ...) (bool, error)
- func (c *KvClient) IsWriterOfStream(ctx context.Context, account common.Address, streamId common.Hash, ...) (bool, error)
- type LocationInfo
- type NetworkIdentity
- type NetworkInfo
- type NetworkProtocolVersion
- type PeerConnectionStatus
- type PeerInfo
- type PeerState
- type RPCError
- type SegmentWithProof
- type Status
- type Transaction
- type TxSeqOrRoot
- type Value
- type ZgsClient
- func (c *ZgsClient) CheckFileFinalized(ctx context.Context, txSeqOrRoot TxSeqOrRoot) (*bool, error)
- func (c *ZgsClient) DownloadSegment(ctx context.Context, root common.Hash, startIndex, endIndex uint64) ([]byte, error)
- func (c *ZgsClient) DownloadSegmentByTxSeq(ctx context.Context, txSeq uint64, startIndex, endIndex uint64) ([]byte, error)
- func (c *ZgsClient) DownloadSegmentWithProof(ctx context.Context, root common.Hash, index uint64) (*SegmentWithProof, error)
- func (c *ZgsClient) DownloadSegmentWithProofByTxSeq(ctx context.Context, txSeq uint64, index uint64) (*SegmentWithProof, error)
- func (c *ZgsClient) GetFileInfo(ctx context.Context, root common.Hash, needAvailable bool) (*FileInfo, error)
- func (c *ZgsClient) GetFileInfoByTxSeq(ctx context.Context, txSeq uint64) (*FileInfo, error)
- func (c *ZgsClient) GetSectorProof(ctx context.Context, sectorIndex uint64, root *common.Hash) (FlowProof, error)
- func (c *ZgsClient) GetShardConfig(ctx context.Context) (shard.ShardConfig, error)
- func (c *ZgsClient) GetStatus(ctx context.Context) (Status, error)
- func (c *ZgsClient) UploadSegment(ctx context.Context, segment SegmentWithProof) (int, error)
- func (c *ZgsClient) UploadSegmentByTxSeq(ctx context.Context, segment SegmentWithProof, txSeq uint64) (int, error)
- func (c *ZgsClient) UploadSegments(ctx context.Context, segments []SegmentWithProof) (int, error)
- func (c *ZgsClient) UploadSegmentsByTxSeq(ctx context.Context, segments []SegmentWithProof, txSeq uint64) (int, error)
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
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
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 ¶
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 ¶
StartSyncFile Call admin_startSyncFile to request synchronization of a file.
func (*AdminClient) TerminateSync ¶ added in v0.3.1
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
Pruned bool `json:"pruned"` // whether the file has been pruned, and mutually exclusive with Finalized
}
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
MustNewKvClient initalize a kv client and panic on failure.
func NewKvClient ¶ added in v0.3.1
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 ¶
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 ¶
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.
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 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
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
MustNewZgsClient Initalize a zgs client and panic on failure.
func MustNewZgsClients ¶ added in v0.3.1
MustNewZgsClients Initialize a list of zgs clients and panic on failure.
func NewZgsClient ¶ added in v0.3.1
NewZgsClient Initalize a zgs client.
func (*ZgsClient) CheckFileFinalized ¶ added in v0.6.1
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, needAvailable bool) (*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
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
GetShardConfig Call zgs_getShardConfig RPC to get the current shard configuration of the node.
func (*ZgsClient) GetStatus ¶ added in v0.3.1
GetStatus Call zgs_getStatus RPC to get sync status of the node.
func (*ZgsClient) UploadSegment ¶ added in v0.3.1
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
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.