session

package
v0.5.0 Latest Latest
Warning

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

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

Documentation

Overview

Package session implements a session to which a user can attach his or her credentials. He or she can then use the session to open, use, and settle state channels.

Each session runs an instance of state channel network client and is owned by the user of the session. Data within a session is continuously persisted in runtime, allowing the user to close and restore the same session later.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewUnlockedUser

func NewUnlockedUser(wb perun.WalletBackend, cfg UserConfig) (perun.User, error)

NewUnlockedUser initializes a user and unlocks all the accounts, those corresponding to on-chain address, off-chain address and all participant addresses.

Types

type ChProposalResponder added in v0.5.0

type ChProposalResponder interface {
	Accept(context.Context, *pclient.ChannelProposalAcc) (perun.Channel, error)
	Reject(ctx context.Context, reason string) error
}

ChProposalResponder defines the methods on proposal responder that will be used by the perun node.

type ChUpdateResponder added in v0.5.0

type ChUpdateResponder interface {
	Accept(ctx context.Context) error
	Reject(ctx context.Context, reason string) error
}

ChUpdateResponder represents the methods on channel update responder that will be used the perun node.

type Channel added in v0.5.0

type Channel struct {
	log.Logger

	psync.Mutex
	// contains filtered or unexported fields
}

Channel implements perun.ChAPI.

func (*Channel) ChallengeDurSecs added in v0.5.0

func (ch *Channel) ChallengeDurSecs() uint64

ChallengeDurSecs returns the challenge duration for the channel (in seconds) for refuting when an invalid/older state is registered on the blockchain closing the channel.

Does not require a mutex lock, as the data will remain unchanged throughout the lifecycle of the channel.

func (*Channel) Close added in v0.5.0

func (ch *Channel) Close(pctx context.Context) (perun.ChInfo, error)

Close implements chAPI.Close.

func (*Channel) Currency added in v0.5.0

func (ch *Channel) Currency() string

Currency returns the currency interpreter used in the channel.

Does not require a mutex lock, as the data will remain unchanged throughout the lifecycle of the channel.

func (*Channel) GetChInfo added in v0.5.0

func (ch *Channel) GetChInfo() perun.ChInfo

GetChInfo implements chAPI.GetChInfo.

func (*Channel) HandleUpdate added in v0.5.0

func (ch *Channel) HandleUpdate(chUpdate pclient.ChannelUpdate, responder ChUpdateResponder)

HandleUpdate handles the incoming updates on an open channel. All updates are sent to a centralized update handler defined on the session. The centrazlied handler identifies the channel and then invokes this function to process the update.

func (*Channel) HandleWatcherReturned added in v0.5.0

func (ch *Channel) HandleWatcherReturned(err error)

HandleWatcherReturned is invoked when the watcher for this channel has returned. If the channel is open (happens when watcher refuted to a wrong state that was registered on-chain),

it will be marked closed.

Then it sends a channel close notification if the channel is already subscribed. If the channel is not subscribed, notification will not be cached as it not possible for the user to subscribe to channel after it is closed.

func (*Channel) ID added in v0.5.0

func (ch *Channel) ID() string

ID returns the ID of the channel.

Does not require a mutex lock, as the data will remain unchanged throughout the lifecycle of the channel.

func (*Channel) Parts added in v0.5.0

func (ch *Channel) Parts() []string

Parts returns the list of aliases of the channel participants.

Does not require a mutex lock, as the data will remain unchanged throughout the lifecycle of the channel.

func (*Channel) RespondChUpdate added in v0.5.0

func (ch *Channel) RespondChUpdate(pctx context.Context, updateID string, accept bool) (perun.ChInfo, error)

RespondChUpdate implements chAPI.RespondChUpdate.

func (*Channel) SendChUpdate added in v0.5.0

func (ch *Channel) SendChUpdate(pctx context.Context, updater perun.StateUpdater) (perun.ChInfo, error)

SendChUpdate implements chAPI.SendChUpdate.

func (*Channel) SubChUpdates added in v0.5.0

func (ch *Channel) SubChUpdates(notifier perun.ChUpdateNotifier) error

SubChUpdates implements chAPI.SubChUpdates.

func (*Channel) UnsubChUpdates added in v0.5.0

func (ch *Channel) UnsubChUpdates() error

UnsubChUpdates implements chAPI.UnsubChUpdates.

type Config

type Config struct {
	User UserConfig

	IDProviderType     string        // Type of ID provider.
	IDProviderURL      string        // URL for accessing the ID provider.
	ChainURL           string        // URL of the blockchain node.
	Asset, Adjudicator string        // Address of the Asset and Adjudicator contracts.
	ChainConnTimeout   time.Duration // Timeout for connecting to blockchain node.
	OnChainTxTimeout   time.Duration // Timeout to wait for confirmation of on-chain tx.
	ResponseTimeout    time.Duration // Timeout to wait for a response from the peer / user.

	DatabaseDir string // Path to directory containing persistence database.
	// Timeout for re-establishing all open channels (if any) that was persisted during the
	// previous running instance of the node.
	PeerReconnTimeout time.Duration
}

Config defines the parameters required to configure a session.

func ParseConfig

func ParseConfig(configFile string) (Config, error)

ParseConfig parses the session configuration from a file.

type Session added in v0.5.0

type Session struct {
	log.Logger
	psync.Mutex
	// contains filtered or unexported fields
}

Session implements perun.SessionAPI.

func New

func New(cfg Config) (*Session, error)

New initializes a SessionAPI instance for the given configuration and returns an instance of it. All methods on it are safe for concurrent use.

func (*Session) AddPeerID added in v0.5.0

func (s *Session) AddPeerID(peerID perun.PeerID) error

AddPeerID implements sessionAPI.AddPeerID.

func (*Session) Close added in v0.5.0

func (s *Session) Close(force bool) ([]perun.ChInfo, error)

Close implements sessionAPI.Close.

func (*Session) GetCh added in v0.5.0

func (s *Session) GetCh(chID string) (perun.ChAPI, error)

GetCh implements sessionAPI.GetCh.

func (*Session) GetChsInfo added in v0.5.0

func (s *Session) GetChsInfo() []perun.ChInfo

GetChsInfo implements sessionAPI.GetChsInfo.

func (*Session) GetPeerID added in v0.5.0

func (s *Session) GetPeerID(alias string) (perun.PeerID, error)

GetPeerID implements sessionAPI.GetPeerID.

func (*Session) HandleProposal added in v0.5.0

func (s *Session) HandleProposal(chProposal pclient.ChannelProposal, responder *pclient.ProposalResponder)

HandleProposal is a handler to be registered on the channel client for processing incoming channel proposals.

func (*Session) HandleProposalWInterface added in v0.5.0

func (s *Session) HandleProposalWInterface(chProposal pclient.ChannelProposal, responder ChProposalResponder)

HandleProposalWInterface is the actual implemention of HandleProposal that takes arguments as interface types. It is implemented this way to enable easier testing.

func (*Session) HandleUpdate added in v0.5.0

func (s *Session) HandleUpdate(chUpdate pclient.ChannelUpdate, responder *pclient.UpdateResponder)

HandleUpdate is a handler to be registered on the channel client for processing incoming channel updates. This function just identifies the channel to which update is received and invokes the handler for that channel.

func (*Session) HandleUpdateWInterface added in v0.5.0

func (s *Session) HandleUpdateWInterface(chUpdate pclient.ChannelUpdate, responder ChUpdateResponder)

HandleUpdateWInterface is the actual implemention of HandleUpdate that takes arguments as interface types. It is implemented this way to enable easier testing.

func (*Session) ID added in v0.5.0

func (s *Session) ID() string

ID implements sessionAPI.ID.

func (*Session) OpenCh added in v0.5.0

func (s *Session) OpenCh(pctx context.Context, openingBalInfo perun.BalInfo, app perun.App, challengeDurSecs uint64) (
	perun.ChInfo, error)

OpenCh implements sessionAPI.OpenCh.

func (*Session) RespondChProposal added in v0.5.0

func (s *Session) RespondChProposal(pctx context.Context, chProposalID string, accept bool) (perun.ChInfo, error)

RespondChProposal implements sessionAPI.RespondChProposal.

func (*Session) SubChProposals added in v0.5.0

func (s *Session) SubChProposals(notifier perun.ChProposalNotifier) error

SubChProposals implements sessionAPI.SubChProposals.

func (*Session) UnsubChProposals added in v0.5.0

func (s *Session) UnsubChProposals() error

UnsubChProposals implements sessionAPI.UnsubChProposals.

type UserConfig

type UserConfig struct {
	Alias string

	OnChainAddr   string
	OnChainWallet WalletConfig

	PartAddrs      []string
	OffChainAddr   string
	OffChainWallet WalletConfig

	CommAddr string
	CommType string
}

UserConfig defines the parameters required to configure a user. Address strings should be parsed using the wallet backend.

type WalletConfig

type WalletConfig struct {
	KeystorePath string
	Password     string
}

WalletConfig defines the parameters required to configure a wallet.

Directories

Path Synopsis
Package sessiontest implements test helpers for functionalities defined in session.
Package sessiontest implements test helpers for functionalities defined in session.

Jump to

Keyboard shortcuts

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