psm

package
v0.25.19 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BucketPSM byte = 0 + iota
	BucketRawPL
	BucketPairwise
	BucketBasicMessage
	BucketIssueCred
	BucketPresentProof
)

Variables

View Source
var Creator = &Factor{factors: make(map[byte]CreatorFunc)}

Functions

func AddPSM

func AddPSM(p *PSM) (err error)

func AddRawPL

func AddRawPL(addr *endp.Addr, data []byte) (err error)

func AddRep added in v0.25.13

func AddRep(p Rep) (err error)

func Open

func Open(filename string) (err error)

Open opens the database by name of the file. If it is already open it returns it, but it doesn't check the database name it isn't thread safe!

func RmPSM

func RmPSM(p *PSM) (err error)

func RmRawPL

func RmRawPL(addr *endp.Addr) (err error)

Types

type CreatorFunc added in v0.25.13

type CreatorFunc func(d []byte) (rep Rep)

type Factor added in v0.25.13

type Factor struct {
	// contains filtered or unexported fields
}

func (*Factor) Add added in v0.25.13

func (f *Factor) Add(t byte, factor CreatorFunc)

type PSM

type PSM struct {
	// Key is the primary key of the protocol state machine: it's pointed by
	// CA's DID and the current connection ID
	Key StateKey

	// StartedByUs tells if Our CA is the one who sent the first protocol msg.
	// It' false if we are the receving part. Please note that Role is a
	// protocol specific and not directly correlate with StartedByUs flag.
	StartedByUs bool

	// Role is a protocol role in the current DID protocol
	Role pb.Protocol_Role

	// ConnDID stores our end's pairwise/connection DID. Please note that the
	// connection ID can be found from Key.
	ConnDID string

	// States has all ouf the state history of this PSM in timestamp order
	States []State
}

PSM is Protocol State Machine that works in event sourcing principle, i.e. every state transition is saved to its State field. Other fields are calculated ASAP and kept that way until to the end.

func FindPSM added in v0.25.7

func FindPSM(k StateKey) (m *PSM, err error)

FindPSM doesn't return error if the PSM doesn't exist. Instead the returned PSM is nil.

func GetPSM

func GetPSM(k StateKey) (m *PSM, err error)

GetPSM get existing PSM from DB. If the PSM doesn't exist it returns error. See FindPSM for version which doesn't return error if the PSM doesn't exist.

func NewPSM

func NewPSM(d []byte) *PSM

func (*PSM) Data

func (p *PSM) Data() []byte

func (*PSM) FirstState

func (p *PSM) FirstState() *State

func (*PSM) IsReady

func (p *PSM) IsReady() bool

func (*PSM) LastState

func (p *PSM) LastState() *State

func (*PSM) Next

func (p *PSM) Next() string

Next is for getting the upcoming protocol message type. For example, if we are waiting a certain message from other end, we can check the message type with this function.

func (*PSM) PairwiseName

func (p *PSM) PairwiseName() string

func (*PSM) PendingUserAction

func (p *PSM) PendingUserAction() bool

PendingUserAction returns true if we the PSM is waiting an user action msg.

func (*PSM) PresentTask added in v0.25.8

func (p *PSM) PresentTask() (t comm.Task)

PresentTask returns latest state's Task of the PSM.

func (*PSM) Protocol

func (p *PSM) Protocol() string

func (*PSM) Timestamp

func (p *PSM) Timestamp() int64

type PayloadInfo

type PayloadInfo struct {
	Type string
}

type Rep added in v0.25.13

type Rep interface {
	Key() StateKey
	Data() []byte
	Type() byte
}

func GetRep added in v0.25.13

func GetRep(repType byte, k StateKey) (m Rep, err error)

type State

type State struct {
	Timestamp int64
	T         comm.Task
	PLInfo    PayloadInfo
	Sub       SubState
}

todo: new idea StateEvent, rename atleast T

type StateKey

type StateKey struct {
	DID   string
	Nonce string
}

func NewStateKey

func NewStateKey(agent comm.Receiver, nonce string) StateKey

func (StateKey) Data

func (key StateKey) Data() []byte

func (StateKey) String

func (key StateKey) String() string

type SubState

type SubState uint // TODO: rename State or StateType

SubState is enumeration for the state transitions PSM will have during its execution. The above PUML diagram illustrates what transitions are currently recognized. The Ready state should have 2 internal states: ACK/NACK

const (
	ACK  SubState = 0x01 << iota // Sub sub state of Ready
	NACK                         // Sub sub state of Ready
	Waiting
	Received
	Decrypted
	Sending
	Ready
	Failure
	Archiving
	Archived
)

States of the PSM`s individual state can be.

const (
	ReadyACK  SubState = Ready | ACK
	ReadyNACK SubState = Ready | NACK
)

func (SubState) IsReady

func (ss SubState) IsReady() bool

func (SubState) Pure

func (ss SubState) Pure() SubState

func (SubState) String

func (ss SubState) String() string

Jump to

Keyboard shortcuts

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