fsm

package
v0.2.71 Latest Latest
Warning

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

Go to latest
Published: May 28, 2024 License: Apache-2.0 Imports: 22 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// Executes Lua script that can access to machines memory and which must
	// return true/false if trigger can be executed.
	TriggerTypeLua = "LUA"

	// 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"

	// saves input data to event that we can use it, data tells the end of the
	// name of memory slot. Name is callculated with concat:
	// connID+<given-name>
	TriggerTypeUseInputSaveConnID = "INPUT_SAVE_CONN"

	// saves input data to event as an SESSION_ID that is used solutions that
	// need chat room algorithm. The date goes from f-fsm -> b-fsm -> f-fsm
	// where in the last stage it's filtered by the SESSION_ID that must be the
	// same. Filtering is done in last phase to keep b-fsm simple.
	TriggerTypeUseInputSaveSessionID = "INPUT_SAVE_SESSION_ID"

	// 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"

	// transient state, just executes without any triggering checks
	TriggerTypeTransient = "TRANSIENT"
)

We cannot (atleast yet) to use JSON enum type like MachineType, because we have used different naming like snake_case, etc. maybe refactor later, or migrate old FSM files?

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

	// these are internal messages send between Backend (service) FSM and
	// conversation (pairwise connection) FSM
	MessageBackend = "backend"

	MessageTransient = "transient"
)
View Source
const (
	EmailProtocol = 100
	QAProtocol    = 101
	HookProtocol  = 102

	BackendProtocol   = 103 // see MessageBackend
	TransientProtocol = 104 // see MessageTransient
)
View Source
const (

	// register names for communication thru machine's memory map.
	LUA_CONN_ID = "CONN_ID" // pairwise ID
	LUA_SUBJECT = "SUBJECT" // reserved

	// this is in use generally, not only in lua
	LUA_SESSION_ID = "SESSION_ID"

	LUA_INPUT  = "INPUT"  // current incoming data like basic_message.content
	LUA_OUTPUT = "OUTPUT" // lua scripts output register name
	LUA_TARGET = "TARGET" // lua scripts target register name
	LUA_OK     = "OK"     // lua scripts OK return value
	LUA_ALL_OK = ""       // lua scripts return values are OK
	LUA_ERROR  = "ERR"    // lua scripts key for error message
)
View Source
const (
	REG_MEMORY  = "MEM"
	REG_DB      = "DB"
	REG_PROCESS = "PROC"
)

------ lua stuff ------

View Source
const (
	MachineTypeNone         = 0
	MachineTypeConversation = 1 + iota
	MachineTypeBackend
)

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 BackendChan added in v0.2.19

type BackendChan = chan *BackendData

type BackendData added in v0.2.19

type BackendData struct {
	// these two are the header part
	ConnID   string // same as conversation FSM connID
	Protocol string

	NoEcho bool

	SessionID string // this is filtering part when available

	// for the start we have only string content, but maybe later..
	// see the EventData
	Subject string // this could be used for the chat room,

	Content string
}

BackendData is important value object to transoprt data between f-fsm and b-fsm. If these values are added remember implement their handling and copying to f-fsm's Memory. See Event.copyBackendDataValuesToMemory(), and event building

func (*BackendData) String added in v0.2.65

func (bd *BackendData) String() string

type BackendInChan added in v0.2.19

type BackendInChan = <-chan *BackendData

type BackendOutChan added in v0.2.19

type BackendOutChan = chan<- *BackendData

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.
	// NOTE. Don't use this here at code level, use ProtocolType!
	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"`
	// Deprecated: replaced by WantStatus, left to keep file format
	NoStatus bool `json:"no_status,omitempty"`
	// Tells that we want status updates about our sending, this is calculated
	// automatically
	WantStatus bool `json:"want_status,omitempty"`

	*EventData `json:"event_data,omitempty"`

	NoEcho bool `json:"no_echo,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) ExecLua added in v0.2.19

func (e Event) ExecLua(content string, a ...string) (out, tgt string, ok bool)

func (Event) String

func (e Event) String() string

func (Event) Triggers

func (e Event) Triggers(status *agency.ProtocolStatus) (ok bool, tgt string)

func (Event) TriggersByBackendData added in v0.2.19

func (e Event) TriggersByBackendData(data *BackendData) (ok bool, tgt string)

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"`

	Backend *BackendData `json:"backend,omitempty"`
}

type Hook

type Hook struct {
	Data map[string]string
}

type Issuing

type Issuing struct {
	CredDefID string
	AttrsJSON string
}

type Machine

type Machine struct {
	// Tells do we have a Backend (Service) bot or a connection lvl bot
	Type       MachineType `json:"type,omitempty"`
	Name       string      `json:"name,omitempty"`
	KeepMemory bool        `json:"keep_memory,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:"-"`

	// f-fsm uses these two, b-fsm gets it from the BackendData. Note, the
	// SessionID is kept in Memory[LUA_SESSION_ID].
	ConnID string `json:"-"`

	// log only once, otherwise annoying
	KeepMemoryReported bool `json:"-"`
	// contains filtered or unexported fields
}

func NewBackendMachine added in v0.2.65

func NewBackendMachine(data MachineData) *Machine

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) InitLua added in v0.2.19

func (m *Machine) InitLua()

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) TriggersByBackendData added in v0.2.19

func (m *Machine) TriggersByBackendData(data *BackendData) *Transition

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.

func (*Machine) TriggersByStep added in v0.2.59

func (m *Machine) TriggersByStep() *Transition

type MachineData

type MachineData struct {
	FType string
	Data  []byte
}

func (*MachineData) IsValid added in v0.2.20

func (md *MachineData) IsValid() bool

type MachineType added in v0.2.19

type MachineType int

func ParseMachineType added in v0.2.19

func ParseMachineType(s string) (mt MachineType, err error)

func (*MachineType) MarshalJSON added in v0.2.19

func (mt *MachineType) MarshalJSON() ([]byte, error)

func (MachineType) String added in v0.2.19

func (mt MachineType) String() string

func (*MachineType) UnmarshalJSON added in v0.2.19

func (mt *MachineType) UnmarshalJSON(data []byte) (err error)

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 TransientChan added in v0.2.59

type TransientChan = chan string

type TransientInChan added in v0.2.59

type TransientInChan = <-chan string

type TransientOutChan added in v0.2.59

type TransientOutChan = chan<- string

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) BuildSendEventsFromBackendData added in v0.2.19

func (t *Transition) BuildSendEventsFromBackendData(data *BackendData) []*Event

BuildSendEventsFromBackendData is called from b-fsm and it's combined method to execute two phases. Build input events and then build send event list. The second phase is shared with pw-fsm. TODO: Note that the input RULE handling is minimal and many methods are missing!

func (*Transition) BuildSendEventsFromHook

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

func (*Transition) BuildSendEventsFromStep added in v0.2.59

func (t *Transition) BuildSendEventsFromStep(data 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