local

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

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

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

func (c IDProvider) Delete(alias string) error

Delete deletes the peer from ID Provider cache. Returns an error if peer corresponding to given alias is not found.

func (IDProvider) ReadByAlias

func (c IDProvider) ReadByAlias(alias string) (_ perun.PeerID, isPresent bool)

ReadByAlias returns the peer ID corresponding to given alias from the cache.

func (IDProvider) ReadByOffChainAddr

func (c IDProvider) ReadByOffChainAddr(offChainAddr pwire.Address) (_ perun.PeerID, isPresent bool)

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.

func (IDProvider) Write

func (c IDProvider) Write(alias string, p perun.PeerID) error

Write adds the peer ID to ID Provider cache. Returns an error if the alias is already used by same or different peer ID or if the off-chain address of the peer ID cannot be parsed using the wallet backend of this ID Provider.

Jump to

Keyboard shortcuts

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