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 ¶
- func NewUnlockedUser(wb perun.WalletBackend, cfg UserConfig) (perun.User, error)
- type ChProposalResponder
- type ChUpdateResponder
- type Channel
- func (ch *Channel) ChallengeDurSecs() uint64
- func (ch *Channel) Close(pctx context.Context) (perun.ChInfo, error)
- func (ch *Channel) Currency() string
- func (ch *Channel) GetChInfo() perun.ChInfo
- func (ch *Channel) HandleUpdate(chUpdate pclient.ChannelUpdate, responder ChUpdateResponder)
- func (ch *Channel) HandleWatcherReturned(err error)
- func (ch *Channel) ID() string
- func (ch *Channel) Parts() []string
- func (ch *Channel) RespondChUpdate(pctx context.Context, updateID string, accept bool) (perun.ChInfo, error)
- func (ch *Channel) SendChUpdate(pctx context.Context, updater perun.StateUpdater) (perun.ChInfo, error)
- func (ch *Channel) SubChUpdates(notifier perun.ChUpdateNotifier) error
- func (ch *Channel) UnsubChUpdates() error
- type Config
- type Session
- func (s *Session) AddPeerID(peerID perun.PeerID) error
- func (s *Session) Close(force bool) ([]perun.ChInfo, error)
- func (s *Session) GetCh(chID string) (perun.ChAPI, error)
- func (s *Session) GetChsInfo() []perun.ChInfo
- func (s *Session) GetPeerID(alias string) (perun.PeerID, error)
- func (s *Session) HandleProposal(chProposal pclient.ChannelProposal, responder *pclient.ProposalResponder)
- func (s *Session) HandleProposalWInterface(chProposal pclient.ChannelProposal, responder ChProposalResponder)
- func (s *Session) HandleUpdate(chUpdate pclient.ChannelUpdate, responder *pclient.UpdateResponder)
- func (s *Session) HandleUpdateWInterface(chUpdate pclient.ChannelUpdate, responder ChUpdateResponder)
- func (s *Session) ID() string
- func (s *Session) OpenCh(pctx context.Context, openingBalInfo perun.BalInfo, app perun.App, ...) (perun.ChInfo, error)
- func (s *Session) RespondChProposal(pctx context.Context, chProposalID string, accept bool) (perun.ChInfo, error)
- func (s *Session) SubChProposals(notifier perun.ChProposalNotifier) error
- func (s *Session) UnsubChProposals() error
- type UserConfig
- type WalletConfig
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
Channel implements perun.ChAPI.
func (*Channel) ChallengeDurSecs ¶ added in v0.5.0
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) Currency ¶ added in v0.5.0
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) 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
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
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
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
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 ¶
ParseConfig parses the session configuration from a file.
type Session ¶ added in v0.5.0
Session implements perun.SessionAPI.
func New ¶
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) GetChsInfo ¶ added in v0.5.0
GetChsInfo implements sessionAPI.GetChsInfo.
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) 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
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 ¶
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. |