fsm

package
v0.2.18 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2023 License: Apache-2.0 Imports: 20 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// monitors how our proof/issue protocol goes
	TriggerTypeOurMessage = "OUR_STATUS"

	// used just for echo/forward
	TriggerTypeUseInput = "INPUT"

	// saves input data to event that we can use it, data tells the name of
	// memory slot
	TriggerTypeUseInputSave = "INPUT_SAVE"

	// formates input data with then format string which is in send data
	TriggerTypeFormat = "FORMAT"

	// formates send event where data is themplate and every memory map value
	// are available. See exmaples for more information.
	TriggerTypeFormatFromMem = "FORMAT_MEM"

	// helps to generate a PIN code to send e.g. email (endpoint not yet
	// supported).
	TriggerTypePIN = "GEN_PIN"

	// quides to use send events `data` as is.
	TriggerTypeData = ""

	// these three validate 'operations' compare input data to send data
	TriggerTypeValidateInputEqual    = "INPUT_VALIDATE_EQUAL"
	TriggerTypeValidateInputNotEqual = "INPUT_VALIDATE_NOT_EQUAL"
	TriggerTypeInputEqual            = "INPUT_EQUAL"

	// these two need other states to help them (in production). The previous
	// states decide to which of these the FSM transits.
	// accept and stores present proof values and stores them to FSM memory map
	TriggerTypeAcceptAndInputValues = "ACCEPT_AND_INPUT_VALUES"
	// not accept present proof protocol
	TriggerTypeNotAcceptValues = "NOT_ACCEPT_VALUES"
)
View Source
const (
	// these are Aries DIDComm protocols
	MessageNone         = ""
	MessageBasicMessage = "basic_message"
	MessageIssueCred    = "issue_cred"
	MessageTrustPing    = "trust_ping"
	MessagePresentProof = "present_proof"
	MessageConnection   = "connection"

	MessageAnswer = "answer"

	MessageEmail = "email" // not supported yet
	MessageHook  = "hook"  // internal program call back
)
View Source
const (
	EmailProtocol = 100
	QAProtocol    = 101
	HookProtocol  = 102
)

Variables

View Source
var QuestionTypeID = map[string]agency.Question_Type{
	"ANSWER_NEEDED_PING":          agency.Question_PING_WAITS,
	"ANSWER_NEEDED_ISSUE_PROPOSE": agency.Question_ISSUE_PROPOSE_WAITS,
	"ANSWER_NEEDED_PROOF_PROPOSE": agency.Question_PROOF_PROPOSE_WAITS,
	"ANSWER_NEEDED_PROOF_VERIFY":  agency.Question_PROOF_VERIFY_WAITS,
}

Functions

func GenerateURL

func GenerateURL(subPath string, m *Machine) (URL *url.URL, err error)

Types

type BasicMessage

type BasicMessage struct {
	Content string
}

type Email

type Email struct {
	To      string `json:"to,omitempty"`
	From    string `json:"from,omitempty"`
	Subject string `json:"subject,omitempty"`
	Body    string `json:"body,omitempty"`
}

type Event

type Event struct {

	// These both are string versions to make writing the yaml fsm easier.
	// There parser methdod, Initialize() that must be call to make the machine
	// to work. It also make other syntax checks.
	Protocol string `json:"protocol"` // Note! See ProtocolType below
	TypeID   string `json:"type_id"`  // Note! See NotificationType below

	Rule string `json:"rule"`
	Data string `json:"data,omitempty"`
	// Used for sending: we don't want status update, aka echo
	NoStatus bool `json:"no_status,omitempty"`

	*EventData `json:"event_data,omitempty"`

	ProtocolType     agency.Protocol_Type `json:"-"`
	NotificationType NotificationType     `json:"-"`

	*agency.ProtocolStatus `json:"-"`
	*Transition            `json:"-"`
}

func (Event) Answers

func (e Event) Answers(status *agency.Question) bool

func (Event) String

func (e Event) String() string

func (Event) Triggers

func (e Event) Triggers(status *agency.ProtocolStatus) bool

func (Event) TriggersByHook

func (e Event) TriggersByHook() bool

type EventData

type EventData struct {
	BasicMessage *BasicMessage `json:"basic_message,omitempty"`
	Issuing      *Issuing      `json:"issuing,omitempty"`
	Email        *Email        `json:"email,omitempty"`
	Proof        *Proof        `json:"proof,omitempty"`
	Hook         *Hook         `json:"hook,omitempty"`
}

type Hook

type Hook struct {
	Data map[string]string
}

type Issuing

type Issuing struct {
	CredDefID string
	AttrsJSON string
}

type Machine

type Machine struct {
	Name string `json:"name,omitempty"`

	// marks the start state: there can be only one for the Machine, but there
	// can be 0..n termination states. See State.Terminate field.
	Initial *Transition `json:"initial"`

	States map[string]*State `json:"states"`

	Current     string `json:"-"`
	Initialized bool   `json:"-"`

	Memory map[string]string `json:"-"`
	// contains filtered or unexported fields
}

func NewMachine

func NewMachine(data MachineData) *Machine

func (*Machine) Answers

func (m *Machine) Answers(q *agency.Question) *Transition

func (*Machine) CurrentState

func (m *Machine) CurrentState() *State

func (*Machine) Initialize

func (m *Machine) Initialize() (err error)

Initialize initializes and optimizes the state machine because the JSON is meant for humans to write and machines to read. Initialize also moves machine to the initial state. It returns error if machine has them.

func (*Machine) Start

func (m *Machine) Start(termChan TerminateOutChan) []*Event

Start starts the FSM. It takes termination channel as an argument to be able to signaling outside when machine is stoped. It accept nil as a channel value when signaling isn't done.

func (*Machine) Step

func (m *Machine) Step(t *Transition)

func (*Machine) String

func (m *Machine) String() string

func (*Machine) Triggers

func (m *Machine) Triggers(status *agency.ProtocolStatus) *Transition

Triggers returns a transition if machine has it in its current state. If not it returns nil.

func (*Machine) TriggersByHook

func (m *Machine) TriggersByHook() *Transition

TriggersByHook returns a transition if machine has it in its current state. If not it returns nil.

type MachineData

type MachineData struct {
	FType string
	Data  []byte
}

type NotificationType

type NotificationType int32

func NotificationTypeID

func NotificationTypeID(typeName string) NotificationType

type Proof

type Proof struct {
	ProofJSON string `json:"proof_json"`
}

type ProofAttr

type ProofAttr struct {
	ID        string `json:"-"`
	Name      string `json:"name,omitempty"`
	CredDefID string `json:"credDefId,omitempty"`
	Predicate string `json:"predicate,omitempty"`
	// contains filtered or unexported fields
}

type State

type State struct {
	Transitions []*Transition `json:"transitions"`

	Terminate bool `json:"terminate,omitempty"`
}

type TerminateChan added in v0.2.5

type TerminateChan = chan bool

type TerminateInChan added in v0.2.5

type TerminateInChan = <-chan bool

type TerminateOutChan added in v0.2.5

type TerminateOutChan = chan<- bool

type Transition

type Transition struct {
	Trigger *Event `json:"trigger,omitempty"`

	Sends []*Event `json:"sends,omitempty"`

	Target string `json:"target"`

	Machine *Machine `json:"-"`
}

func (*Transition) BuildSendAnswers

func (t *Transition) BuildSendAnswers(status *agency.AgentStatus) []*Event

func (*Transition) BuildSendEvents

func (t *Transition) BuildSendEvents(status *agency.ProtocolStatus) []*Event

func (*Transition) BuildSendEventsFromHook

func (t *Transition) BuildSendEventsFromHook(hookData map[string]string) []*Event

func (*Transition) FmtFromMem

func (t *Transition) FmtFromMem(send *Event) string

func (*Transition) GenPIN

func (t *Transition) GenPIN(_ *Event)

Jump to

Keyboard shortcuts

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