Documentation ¶
Overview ¶
Package local contains an implementation of ID provider, where the peer IDs are stored in a YAML file stored locally on the disk.
The complete list of peer IDs are loaded into an in-memory cache during initialization. The entries in the cache are indexed by both alias and off-chain address of the peer and can be using either of these as reference.
Read, Write and Delete operations act only on the cache and do not affect the contents of the file.
Latest state of cache can be updated to the file by explicitly calling UpdateStorage method. Normally this should be called before shutting down the node.
Index ¶
- func PeerIDEqual(p1, p2 perun.PeerID) bool
- type IDProvider
- func (c IDProvider) Delete(alias string) error
- func (c IDProvider) ReadByAlias(alias string) (_ perun.PeerID, isPresent bool)
- func (c IDProvider) ReadByOffChainAddr(offChainAddr pwire.Address) (_ perun.PeerID, isPresent bool)
- func (c *IDProvider) UpdateStorage() error
- func (c IDProvider) Write(alias string, p perun.PeerID) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PeerIDEqual ¶
func PeerIDEqual(p1, p2 perun.PeerID) bool
PeerIDEqual returns true if all fields in the Peer ID except OffChainAddr are equal.
Types ¶
type IDProvider ¶
type IDProvider struct {
// contains filtered or unexported fields
}
IDProvider represents an ID provider that provides access to peer IDs stored locally in a file on the file system.
It generates a cache of all peer IDs in the ID provider file during initialization. Read, Write and Delete operations act only on the cached list of peer IDs and do not update the ID provider file. The changes in cache can be updated to the ID provider file by explicitly calling UpdateStorage method.
It also stores an instance of wallet backend that will be used or decoding address strings.
func NewIDprovider ¶
func NewIDprovider(filePath string, backend perun.WalletBackend) (*IDProvider, error)
NewIDprovider returns an instance of ID provider to access the peer IDs in the given ID provider file.
All the peer IDs are cached in memory during initialization and Read, Write, Delete operations affect only the cache. The changes are updated to the ID provider file only when UpdateStorage method is explicitly called. There is no mechanism to reload the cache if the ID provider file is updated.
Backend is used for decoding the address strings during initialization.
func (IDProvider) Delete ¶
Delete deletes the peer from ID Provider cache. Returns an error if peer corresponding to given alias is not found.
func (IDProvider) ReadByAlias ¶
ReadByAlias returns the peer ID corresponding to given alias from the cache.
func (IDProvider) ReadByOffChainAddr ¶
ReadByOffChainAddr returns the peer ID corresponding to given off-chain address from the cache.
func (*IDProvider) UpdateStorage ¶
func (c *IDProvider) UpdateStorage() error
UpdateStorage writes the latest state of ID provider cache to the file on the disk.