Documentation
¶
Overview ¶
Package indexer defines indexer server and client. The indexer server is a service that maintain a trusted storage node list, client can fetch the list from server and select nodes in list to upload data.
Index ¶
- func InitDefaultIPLocationManager(config IPLocationConfig)
- type Client
- func (c *Client) BatchUpload(ctx context.Context, w3Client *web3go.Client, datas []core.IterableData, ...) (eth_common.Hash, []eth_common.Hash, error)
- func (c *Client) Download(ctx context.Context, root, filename string, withProof bool) error
- func (c *Client) DownloadFragments(ctx context.Context, roots []string, filename string, withProof bool) error
- func (c *Client) GetFileLocations(ctx context.Context, root string) ([]*shard.ShardedNode, error)
- func (c *Client) GetNodeLocations(ctx context.Context) (map[string]*IPLocation, error)
- func (c *Client) GetShardedNodes(ctx context.Context) (ShardedNodes, error)
- func (c *Client) NewDownloaderFromIndexerNodes(ctx context.Context, root string) (*transfer.Downloader, error)
- func (c *Client) NewFileSegmentUploaderFromIndexerNodes(ctx context.Context, segNum uint64, expectedReplica uint, dropped []string, ...) ([]*transfer.FileSegmentUploader, error)
- func (c *Client) NewUploaderFromIndexerNodes(ctx context.Context, segNum uint64, w3Client *web3go.Client, ...) (*transfer.Uploader, error)
- func (c *Client) SelectNodes(ctx context.Context, expectedReplica uint, dropped []string, method string, ...) (*transfer.SelectedNodes, error)
- func (c *Client) Upload(ctx context.Context, w3Client *web3go.Client, data core.IterableData, ...) (eth_common.Hash, error)
- func (c *Client) UploadFileSegments(ctx context.Context, fileSeg transfer.FileSegmentsWithProof, ...) error
- type FileLocation
- type FileLocationCache
- type FileLocationCacheConfig
- type IPLocation
- type IPLocationConfig
- type IPLocationManager
- type IndexerApi
- type IndexerClientOption
- type Interface
- type NodeManager
- type NodeManagerConfig
- type ShardedNodes
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InitDefaultIPLocationManager ¶
func InitDefaultIPLocationManager(config IPLocationConfig)
InitDefaultIPLocationManager initializes the default `IPLocationManager`.
Types ¶
type Client ¶
Client indexer client
func NewClient ¶
func NewClient(url string, option ...IndexerClientOption) (*Client, error)
NewClient create new indexer client, url is indexer service url
func (*Client) BatchUpload ¶
func (c *Client) BatchUpload(ctx context.Context, w3Client *web3go.Client, datas []core.IterableData, option ...transfer.BatchUploadOption) (eth_common.Hash, []eth_common.Hash, error)
BatchUpload submit multiple data to 0g storage contract batchly in single on-chain transaction, then transfer the data to the storage nodes selected from indexer service.
func (*Client) DownloadFragments ¶
func (*Client) GetFileLocations ¶
GetFileLocations return locations info of given file.
func (*Client) GetNodeLocations ¶
GetNodeLocations return storage nodes with IP location information.
func (*Client) GetShardedNodes ¶
func (c *Client) GetShardedNodes(ctx context.Context) (ShardedNodes, error)
GetShardedNodes get node list from indexer service
func (*Client) NewDownloaderFromIndexerNodes ¶
func (*Client) NewFileSegmentUploaderFromIndexerNodes ¶
func (c *Client) NewFileSegmentUploaderFromIndexerNodes( ctx context.Context, segNum uint64, expectedReplica uint, dropped []string, method string, fullTrusted bool) ([]*transfer.FileSegmentUploader, error)
NewUploaderFromIndexerNodes return a file segment uploader with selected storage nodes from indexer service.
func (*Client) NewUploaderFromIndexerNodes ¶
func (c *Client) NewUploaderFromIndexerNodes(ctx context.Context, segNum uint64, w3Client *web3go.Client, expectedReplica uint, dropped []string, method string, fullTrusted bool) (*transfer.Uploader, error)
NewUploaderFromIndexerNodes return an uploader with selected storage nodes from indexer service.
func (*Client) SelectNodes ¶
func (c *Client) SelectNodes(ctx context.Context, expectedReplica uint, dropped []string, method string, fullTrusted bool) (*transfer.SelectedNodes, error)
SelectNodes selects nodes from both trusted and discovered, with discovered max 3/5 of expectedReplica. If discovered cannot meet, all from trusted.
func (*Client) Upload ¶
func (c *Client) Upload(ctx context.Context, w3Client *web3go.Client, data core.IterableData, option ...transfer.UploadOption) (eth_common.Hash, error)
Upload submit data to 0g storage contract, then transfer the data to the storage nodes selected from indexer service.
func (*Client) UploadFileSegments ¶
func (c *Client) UploadFileSegments( ctx context.Context, fileSeg transfer.FileSegmentsWithProof, option ...transfer.UploadOption) error
UploadFileSegments transfer segment data of a file, which should has already been submitted to the 0g storage contract, to the storage nodes selected from indexer service.
type FileLocation ¶
type FileLocation struct {
Url string `json:"url"`
ShardConfig shard.ShardConfig `json:"shardConfig"`
}
type FileLocationCache ¶
type FileLocationCache struct {
// contains filtered or unexported fields
}
func InitFileLocationCache ¶
func InitFileLocationCache(config FileLocationCacheConfig) (cache *FileLocationCache, err error)
func (*FileLocationCache) Close ¶
func (c *FileLocationCache) Close()
func (*FileLocationCache) GetFileLocations ¶
func (c *FileLocationCache) GetFileLocations(ctx context.Context, txSeq uint64) ([]*shard.ShardedNode, error)
type FileLocationCacheConfig ¶
type IPLocation ¶
type IPLocationConfig ¶
type IPLocationManager ¶
type IPLocationManager struct {
// contains filtered or unexported fields
}
IPLocationManager manages IP locations.
func (*IPLocationManager) All ¶
func (manager *IPLocationManager) All() map[string]*IPLocation
All returns all cached IP locations.
func (*IPLocationManager) Get ¶
func (manager *IPLocationManager) Get(ip string) (*IPLocation, bool)
func (*IPLocationManager) Query ¶
func (manager *IPLocationManager) Query(ip string) (*IPLocation, error)
Query returns the cached IP location if any. Otherwise, retrieve from web API.
type IndexerApi ¶
type IndexerApi struct {
Namespace string
}
IndexerApi indexer service configuration
func NewIndexerApi ¶
func NewIndexerApi() *IndexerApi
NewIndexerApi creates indexer service configuration
func (*IndexerApi) GetFileLocations ¶
func (api *IndexerApi) GetFileLocations(ctx context.Context, root string) (locations []*shard.ShardedNode, err error)
GetFileLocations return locations info of given file.
func (*IndexerApi) GetNodeLocations ¶
func (api *IndexerApi) GetNodeLocations(ctx context.Context) (map[string]*IPLocation, error)
GetNodeLocations return IP locations of all nodes.
func (*IndexerApi) GetShardedNodes ¶
func (api *IndexerApi) GetShardedNodes(ctx context.Context) (ShardedNodes, error)
GetShardedNodes return storage node list
type IndexerClientOption ¶
type IndexerClientOption struct {
ProviderOption providers.Option
LogOption common.LogOption // log option when uploading data
FullTrusted bool // whether to use full trusted nodes
}
IndexerClientOption indexer client option
type Interface ¶
type Interface interface {
GetShardedNodes(ctx context.Context) (ShardedNodes, error)
GetNodeLocations(ctx context.Context) (map[string]*IPLocation, error)
GetFileLocations(ctx context.Context, root string) ([]*shard.ShardedNode, error)
}
type NodeManager ¶
type NodeManager struct {
// contains filtered or unexported fields
}
NodeManager manages trusted storage nodes and auto discover peers from network.
func InitDefaultNodeManager ¶
func InitDefaultNodeManager(config NodeManagerConfig) (mgr *NodeManager, err error)
InitDefaultNodeManager initializes the default `NodeManager`.
func (*NodeManager) AddTrustedNodes ¶
func (nm *NodeManager) AddTrustedNodes(nodes ...string) error
AddTrustedNodes add trusted storage nodes.
func (*NodeManager) Close ¶
func (nm *NodeManager) Close()
func (*NodeManager) Discovered ¶
func (nm *NodeManager) Discovered() []*shard.ShardedNode
Discovered returns discovered sharded nodes.
func (*NodeManager) Trusted ¶
func (nm *NodeManager) Trusted() ([]*shard.ShardedNode, error)
Trusted returns trusted sharded nodes.
func (*NodeManager) TrustedClients ¶
func (nm *NodeManager) TrustedClients() []*node.ZgsClient
TrustedClients returns trusted clients.
type NodeManagerConfig ¶
type ShardedNodes ¶
type ShardedNodes struct {
Trusted []*shard.ShardedNode `json:"trusted"`
Discovered []*shard.ShardedNode `json:"discovered"`
}