Documentation ¶
Overview ¶
Package channel implements node to node (offchain) communication functionality for the node software.
It manages the lifecycle of a channel, functions to send and receive different kinds of message over the channel, adapters to support different transport layer protocols such as websocket. It also includes functions for initializing listeners for handling new incoming connections and to initiate outgoing connections. The primitives sub package defines message formats and other structures (such as state, session) required for offchain communication., message packets & its parsers as well the adapter implementations.
Index ¶
- Variables
- func GetFlagSet() *pflag.FlagSet
- func InitModule(cfg *Config) (err error)
- func NewChannelConn(peerID identity.OffChainID, adapterType adapter.CommunicationProtocol) (conn adapter.ReadWriteCloser, err error)
- func NewSession(selfID identity.OffChainID, adapterType adapter.CommunicationProtocol, ...) (idVerifiedConn chan *Instance, listener adapter.Shutdown, err error)
- func ParseFlags(flagSet *pflag.FlagSet, cfg *Config) (err error)
- func SetLogger(moduleLogger log.LoggerInterface)
- func StartListener(listenerID identity.OffChainID, maxConn uint32, ...) (newIncomingConn chan adapter.ReadWriteCloser, listener adapter.Shutdown, ...)
- type ClosingMode
- type Config
- type Instance
- func (inst *Instance) Close() (err error)
- func (inst *Instance) ClosingMode() ClosingMode
- func (inst *Instance) Connected() bool
- func (inst *Instance) ContractAddrRead() (addr types.Address, id contract.Handler, err error)
- func (inst *Instance) ContractAddrRequest(addr types.Address, id contract.Handler) (status primitives.MessageStatus, err error)
- func (inst *Instance) ContractAddrRespond(addr types.Address, id contract.Handler, status primitives.MessageStatus) (err error)
- func (inst *Instance) ContractStore() contract.StoreType
- func (inst *Instance) CurrentVpcState() primitives.VPCStateSigned
- func (inst *Instance) IdentityRead() (peerID identity.OffChainID, err error)
- func (inst *Instance) IdentityRequest(selfID identity.OffChainID) (peerID identity.OffChainID, err error)
- func (inst *Instance) IdentityRespond(selfID identity.OffChainID) (err error)
- func (inst *Instance) MscBaseState() primitives.MSCBaseStateSigned
- func (inst *Instance) NewChannelRead() (msgProtocolVersion string, contractStoreVersion []byte, err error)
- func (inst *Instance) NewChannelRequest(msgProtocolVersion string, contractStoreVersion []byte) (accept primitives.MessageStatus, reason string, err error)
- func (inst *Instance) NewChannelRespond(msgProtocolVersion string, contractStoreVersion []byte, ...) (err error)
- func (inst *Instance) NewMSCBaseStateRead() (state primitives.MSCBaseStateSigned, err error)
- func (inst *Instance) NewMSCBaseStateRequest(newSignedState primitives.MSCBaseStateSigned) (responseState primitives.MSCBaseStateSigned, status primitives.MessageStatus, ...)
- func (inst *Instance) NewMSCBaseStateRespond(state primitives.MSCBaseStateSigned, status primitives.MessageStatus) (err error)
- func (inst *Instance) NewVPCStateRead() (state primitives.VPCStateSigned, err error)
- func (inst *Instance) NewVPCStateRequest(newStateSigned primitives.VPCStateSigned) (responseState primitives.VPCStateSigned, status primitives.MessageStatus, ...)
- func (inst *Instance) NewVPCStateRespond(state primitives.VPCStateSigned, status primitives.MessageStatus) (err error)
- func (inst *Instance) PeerID() identity.OffChainID
- func (inst *Instance) Read() (message primitives.ChMsgPkt, err error)
- func (inst *Instance) ReceiverID() identity.OffChainID
- func (inst *Instance) RoleChannel() primitives.Role
- func (inst *Instance) RoleClosing() primitives.Role
- func (inst *Instance) SelfID() identity.OffChainID
- func (inst *Instance) SenderID() identity.OffChainID
- func (inst *Instance) SessionID() primitives.SessionID
- func (inst *Instance) SessionIDRead() (sid primitives.SessionID, err error)
- func (inst *Instance) SessionIDRequest(sid primitives.SessionID) (gotSid primitives.SessionID, status primitives.MessageStatus, err error)
- func (inst *Instance) SessionIDRespond(sid primitives.SessionID, status primitives.MessageStatus) (err error)
- func (inst *Instance) SetClosingMode(closingMode ClosingMode)
- func (inst *Instance) SetContractStore(contractStore contract.StoreType)
- func (inst *Instance) SetCurrentVPCState(newState primitives.VPCStateSigned) (err error)
- func (inst *Instance) SetMSCBaseState(newState primitives.MSCBaseStateSigned) (err error)
- func (inst *Instance) SetRoleChannel(role primitives.Role)
- func (inst *Instance) SetRoleClosing(role primitives.Role)
- func (inst *Instance) SetSessionID(sessionID primitives.SessionID) (err error)
- func (inst *Instance) SetStatus(status Status) bool
- func (inst *Instance) Status() Status
- func (inst *Instance) ValidateFullState(newState primitives.VPCStateSigned) (isValid bool, reason string)
- func (inst *Instance) ValidateIncomingState(newState primitives.VPCStateSigned) (isValid bool, reason string)
- func (inst *Instance) Write(message primitives.ChMsgPkt) (err error)
- type Status
Constants ¶
This section is empty.
Variables ¶
var ConfigDefault = Config{ // contains filtered or unexported fields }
ConfigDefault represents the default configuration for this module.
var ReadWriteLogging = false
ReadWriteLogging to configure logging during channel read/write, for demonstration purposes only
Functions ¶
func GetFlagSet ¶
GetFlagSet initializes and returns a flagset with flags for configuring this module.
func InitModule ¶
InitModule initializes this module with provided configuration. The logger is initialized.
func NewChannelConn ¶ added in v0.2.0
func NewChannelConn(peerID identity.OffChainID, adapterType adapter.CommunicationProtocol) (conn adapter.ReadWriteCloser, err error)
NewChannelConn initializes and returns a new channel connection (as ReadWriteCloser interface) with peer using the adapterType.
func NewSession ¶
func NewSession(selfID identity.OffChainID, adapterType adapter.CommunicationProtocol, maxConn uint32) (idVerifiedConn chan *Instance, listener adapter.Shutdown, err error)
NewSession initializes and returns a new channel session. Channel session has a listener running in the background with defined adapterType. All new incoming connections are processed by the session and if successful made available on idVerifiedConn channel. The higher layers of code can listen for new connections on this idVerifiedConn channel and use it for further communications.
func ParseFlags ¶
ParseFlags parses the flags defined in this module.
func SetLogger ¶
func SetLogger(moduleLogger log.LoggerInterface)
SetLogger sets the logger instance for this module.
func StartListener ¶ added in v0.2.0
func StartListener(listenerID identity.OffChainID, maxConn uint32, communicationProtocol adapter.CommunicationProtocol) (newIncomingConn chan adapter.ReadWriteCloser, listener adapter.Shutdown, err error)
StartListener initializes a listener for accepting connections in the protocol specified by adapterType. The listener is started at the endpoint and address of the listenerID and can hold utmost maxConn number of unprocessed connections in the newIncomingConn channel.
Types ¶
type ClosingMode ¶
type ClosingMode string
ClosingMode represents the closing mode for the vpc state channel. It determines what the node software will do when a channel closing notification is received.
const ( // In ClosingModeManual, the information will be passed on to the user via api interface. // This will occur irrespective of the closing state being the latest or not. ClosingModeManual ClosingMode = ClosingMode("manual") // In ClosingModeNormal, if the closing state is the latest state no action will be taken, // so that channel will be closed after timeout. // Else if it is an older state, then node software will refute with latest state. ClosingModeAutoNormal ClosingMode = ClosingMode("auto-normal") // In ClosingModeNormal, if the closing state is the latest state it will also call close, // so that the channel will be immediately closed without waiting until timeout. // If it is an older state, the node software will refute with latest state. ClosingModeAutoImmediate ClosingMode = ClosingMode("auto-immediate") )
Enumeration of allowed values for Closing mode.
type Instance ¶
type Instance struct {
// contains filtered or unexported fields
}
Instance represents an instance of offchain channel. It groups all the properties of the channel such as identity and role of each user, current and all previous values of channel state.
func NewChannel ¶
func NewChannel(selfID, peerID identity.OffChainID, adapterType adapter.CommunicationProtocol) (conn *Instance, err error)
NewChannel initializes a new channel connection with peer using the adapterType. Upon successful connection, identity verification is done.
func (*Instance) ClosingMode ¶
func (inst *Instance) ClosingMode() ClosingMode
ClosingMode returns the current closing mode configuration of the channel.
func (*Instance) ContractAddrRead ¶
ContractAddrRead reads the contract address request sent by the peer node and returns the contract address and handler in the message.
func (*Instance) ContractAddrRequest ¶
func (inst *Instance) ContractAddrRequest(addr types.Address, id contract.Handler) (status primitives.MessageStatus, err error)
ContractAddrRequest sends a contract id request with details of deployed contract and waits for contract address response from the peer node. If response is successfully received, it returns the acceptance status in the response message.
func (*Instance) ContractAddrRespond ¶
func (inst *Instance) ContractAddrRespond(addr types.Address, id contract.Handler, status primitives.MessageStatus) (err error)
ContractAddrRespond sends an contract address response to the peer node with acceptance status in the message.
func (*Instance) ContractStore ¶
ContractStore returns the contract store that is configured in the channel instance.
func (*Instance) CurrentVpcState ¶
func (inst *Instance) CurrentVpcState() primitives.VPCStateSigned
CurrentVpcState returns the current vpc state of the channel.
func (*Instance) IdentityRead ¶
func (inst *Instance) IdentityRead() (peerID identity.OffChainID, err error)
IdentityRead reads the identity request sent by the peer node and returns the peer id in the message.
func (*Instance) IdentityRequest ¶
func (inst *Instance) IdentityRequest(selfID identity.OffChainID) (peerID identity.OffChainID, err error)
IdentityRequest sends an identity request and waits for identity response from the peer node. If response is successfully received, it returns the peer id in the response message.
func (*Instance) IdentityRespond ¶
func (inst *Instance) IdentityRespond(selfID identity.OffChainID) (err error)
IdentityRespond sends an identity response to the peer node with self id in the message.
func (*Instance) MscBaseState ¶
func (inst *Instance) MscBaseState() primitives.MSCBaseStateSigned
MscBaseState returns the msc base state of the channel.
func (*Instance) NewChannelRead ¶
func (inst *Instance) NewChannelRead() (msgProtocolVersion string, contractStoreVersion []byte, err error)
NewChannelRead reads the new channel request sent by the peer node and returns the message protocol version and contract store version in the message.
func (*Instance) NewChannelRequest ¶
func (inst *Instance) NewChannelRequest(msgProtocolVersion string, contractStoreVersion []byte) (accept primitives.MessageStatus, reason string, err error)
NewChannelRequest sends an new channel request and waits for new channel response from the peer node. If response is successfully received, it returns the acceptance status and reason in the response message.
func (*Instance) NewChannelRespond ¶
func (inst *Instance) NewChannelRespond(msgProtocolVersion string, contractStoreVersion []byte, accept primitives.MessageStatus, reason string) (err error)
NewChannelRespond sends an new channel response to the peer node with acceptance status in the message.
func (*Instance) NewMSCBaseStateRead ¶
func (inst *Instance) NewMSCBaseStateRead() (state primitives.MSCBaseStateSigned, err error)
NewMSCBaseStateRead reads the new msc base state request sent by the peer node and returns the msc base state in the message.
func (*Instance) NewMSCBaseStateRequest ¶
func (inst *Instance) NewMSCBaseStateRequest(newSignedState primitives.MSCBaseStateSigned) (responseState primitives.MSCBaseStateSigned, status primitives.MessageStatus, err error)
NewMSCBaseStateRequest sends a new msc base request with partial signature and waits for msc base state response from the peer node. If response is successfully received, it returns the fully signed msc base state and acceptance status in the response message.
func (*Instance) NewMSCBaseStateRespond ¶
func (inst *Instance) NewMSCBaseStateRespond(state primitives.MSCBaseStateSigned, status primitives.MessageStatus) (err error)
NewMSCBaseStateRespond sends an msc base state response to the peer node with fully signed state (optional) and acceptance status in the message.
func (*Instance) NewVPCStateRead ¶
func (inst *Instance) NewVPCStateRead() (state primitives.VPCStateSigned, err error)
NewVPCStateRead reads the new vpc state request sent by the peer node and returns the vpc state in the message.
func (*Instance) NewVPCStateRequest ¶
func (inst *Instance) NewVPCStateRequest(newStateSigned primitives.VPCStateSigned) (responseState primitives.VPCStateSigned, status primitives.MessageStatus, err error)
NewVPCStateRequest sends a new vpc request with partial signature and waits for vpc state response from the peer node. If response is successfully received, it returns the fully signed vpc state and acceptance status in the response message.
func (*Instance) NewVPCStateRespond ¶
func (inst *Instance) NewVPCStateRespond(state primitives.VPCStateSigned, status primitives.MessageStatus) (err error)
NewVPCStateRespond sends an vpc state response to the peer node with fully signed state (optional) and acceptance status in the message.
func (*Instance) PeerID ¶
func (inst *Instance) PeerID() identity.OffChainID
PeerID returns the id of the peer in the channel.
func (*Instance) Read ¶ added in v0.2.0
func (inst *Instance) Read() (message primitives.ChMsgPkt, err error)
func (*Instance) ReceiverID ¶
func (inst *Instance) ReceiverID() identity.OffChainID
ReceiverID returns the id of receiver in the channel. Receiver is the one who received a new channel connection request and accepted it.
func (*Instance) RoleChannel ¶
func (inst *Instance) RoleChannel() primitives.Role
RoleChannel returns the role of the self user in the channel.
func (*Instance) RoleClosing ¶
func (inst *Instance) RoleClosing() primitives.Role
RoleClosing returns the role of the self user in the channel closing procedure. If this user initializes the closing procedure, role is sender else it is receiver.
func (*Instance) SelfID ¶
func (inst *Instance) SelfID() identity.OffChainID
SelfID returns the id of this user as configured in the channel.
func (*Instance) SenderID ¶
func (inst *Instance) SenderID() identity.OffChainID
SenderID returns the id of sender in the channel. Sender is the one who initialized the channel connection.
func (*Instance) SessionID ¶
func (inst *Instance) SessionID() primitives.SessionID
SessionID returns the session id of the channel.
func (*Instance) SessionIDRead ¶
func (inst *Instance) SessionIDRead() (sid primitives.SessionID, err error)
SessionIDRead reads the session id request sent by the peer node and returns the session id in the message.
func (*Instance) SessionIDRequest ¶
func (inst *Instance) SessionIDRequest(sid primitives.SessionID) (gotSid primitives.SessionID, status primitives.MessageStatus, err error)
SessionIDRequest sends an sessiod id request with partial session id and waits for sessiod id response from the peer node. If response is successfully received, it returns the complete sid and acceptance status in the response message.
func (*Instance) SessionIDRespond ¶
func (inst *Instance) SessionIDRespond(sid primitives.SessionID, status primitives.MessageStatus) (err error)
SessionIDRespond sends an session id response to the peer node with complete session id (optional) and acceptance status in the message.
func (*Instance) SetClosingMode ¶
func (inst *Instance) SetClosingMode(closingMode ClosingMode)
SetClosingMode sets the closing mode for the channel. Closing mode will determine what how the node software will act when a vpc closing event is received.
func (*Instance) SetContractStore ¶
SetContractStore sets contract store in the channel instance. ContractStore is set of contracts and its properties according that facilitates this offchain channel.
func (*Instance) SetCurrentVPCState ¶
func (inst *Instance) SetCurrentVPCState(newState primitives.VPCStateSigned) (err error)
SetCurrentVPCState adds newState to vpc state list of the channel. Validation of the state concerning the application logic should be done before adding signatures.
func (*Instance) SetMSCBaseState ¶
func (inst *Instance) SetMSCBaseState(newState primitives.MSCBaseStateSigned) (err error)
SetMSCBaseState validates the integrity of newState and if successful, sets the msc base state of the channel.
func (*Instance) SetRoleChannel ¶
func (inst *Instance) SetRoleChannel(role primitives.Role)
SetRoleChannel sets the role of the self user in the channel.
func (*Instance) SetRoleClosing ¶
func (inst *Instance) SetRoleClosing(role primitives.Role)
SetRoleClosing sets the role of the self user in the channel closing procedure. If this user initializes the closing procedure, role is sender else it is receiver.
func (*Instance) SetSessionID ¶
func (inst *Instance) SetSessionID(sessionID primitives.SessionID) (err error)
SetSessionID validates and sets the session id in channel instance. If validation fails, the values is not set in channel instance and an error is returned.
func (*Instance) SetStatus ¶
SetStatus sets the current status of the channel and returns true if the status was successfully updated.
Only specific status changes are allowed. For example, new status can be set to Setup only when the current status is PreSetup, if not, the status change will not occur and false is returned.
func (*Instance) ValidateFullState ¶
func (inst *Instance) ValidateFullState(newState primitives.VPCStateSigned) (isValid bool, reason string)
ValidateFullState validates the integrity of newState and if unsuccessful, returns the reason. Version number, self and peer signatures are validated.
func (*Instance) ValidateIncomingState ¶
func (inst *Instance) ValidateIncomingState(newState primitives.VPCStateSigned) (isValid bool, reason string)
ValidateIncomingState validates the integrity of incoming state and if unsuccessful, returns the reason. Only version number and peer signature are validated.
type Status ¶
type Status string
Status of the channel.
const ( PreSetup Status = Status("pre-setup") //Channel pre-setup at node in progress Setup Status = Status("setup") //Channel setup at node in progress Init Status = Status("init") //Channel status Init defined in perun api description Open Status = Status("open") //Channel status Open defined in perun api description InConflict Status = Status("in-conflict") //Channel status In-Conflict defined in perun api description Settled Status = Status("settled") //Channel status Settled defined in perun api description WaitingToClose Status = Status("waiting-to-close") //Channel status Waiting-To-Close defined in perun api description VPCClosing Status = Status("vpc-closing") //Channel close invoked by one of the participants VPCClosed Status = Status("vpc-closed") //Channel close invoked by both the participants Closed Status = Status("closed") //Channel is closed. Funds redistributed and mscontract self destructed )
Enumeration of allowed values for Status of the channel.
Directories ¶
Path | Synopsis |
---|---|
Package primitives defines the data types required for offchain communication.
|
Package primitives defines the data types required for offchain communication. |