service

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2020 License: Apache-2.0 Imports: 11 Imported by: 99

Documentation

Index

Constants

View Source
const (
	ErrChannelRegistered = serviceError("channel is already registered for the action event")
	ErrNilChannel        = serviceError("cannot pass nil channel")
	ErrInvalidChannel    = serviceError("invalid channel passed to unregister the action event")
	ErrThreadIDNotFound  = serviceError("threadID not found")
	ErrInvalidMessage    = serviceError("invalid message")
)

Service errors

View Source
const ForwardMsgType = "https://didcomm.org/routing/1.0/forward"

ForwardMsgType defines the route forward message type.

Variables

This section is empty.

Functions

func AutoExecuteActionEvent

func AutoExecuteActionEvent(ch chan DIDCommAction)

AutoExecuteActionEvent is a utility function to execute Action events automatically. The function requires a channel to be passed-in to listen to dispatcher.DIDCommAction and triggers the Continue function on the action event. This is a blocking function and use this function with a goroutine.

Usage:

 s := didexchange.New(....)
	actionCh := make(chan dispatcher.DIDCommAction)
	err = s.RegisterActionEvent(actionCh)
	go service.AutoExecuteActionEvent(actionCh)

Types

type Action

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

Action thread-safe action register structure

func (*Action) ActionEvent

func (a *Action) ActionEvent() chan<- DIDCommAction

ActionEvent returns event action channel

func (*Action) RegisterActionEvent

func (a *Action) RegisterActionEvent(ch chan<- DIDCommAction) error

RegisterActionEvent on protocol messages. The consumer need to invoke the callback to resume processing. Only one channel can be registered for the action events. The function will throw error if a channel is already registered.

func (*Action) UnregisterActionEvent

func (a *Action) UnregisterActionEvent(ch chan<- DIDCommAction) error

UnregisterActionEvent on protocol messages. Refer RegisterActionEvent().

type DIDComm

type DIDComm interface {
	// service handler
	Handler
	// event service
	Event
}

DIDComm defines service APIs.

type DIDCommAction

type DIDCommAction struct {
	// Name of the protocol.
	//
	// Supported protocols
	//   - DID Exchange :  didexchange.DIDExchange
	ProtocolName string

	// DIDComm message
	Message DIDCommMsg

	// Continue function to be called by the consumer for further processing the message.
	Continue func(args interface{})

	// Stop invocation notifies the service that the consumer action event processing has failed or the consumer wants
	// to stop the processing.
	Stop func(err error)

	// Properties contains value based on specific protocol. The consumers need to call the protocol client
	// functions to get the data.
	//
	// Clients function to retrieve data based on protocol.
	//   - DID Exchange :  didexchange.EventProperties
	Properties EventProperties
}

DIDCommAction message type to pass events in go channels.

type DIDCommMsg

type DIDCommMsg interface {
	ID() string
	Type() string

	ThreadID() (string, error)
	Decode(v interface{}) error
}

DIDCommMsg describes message interface

type DIDCommMsgMap added in v0.1.1

type DIDCommMsgMap map[string]interface{}

DIDCommMsgMap did comm msg

func NewDIDCommMsgMap added in v0.1.1

func NewDIDCommMsgMap(v interface{}) DIDCommMsgMap

NewDIDCommMsgMap converts structure(model) to DIDCommMsgMap

func ParseDIDCommMsgMap added in v0.1.1

func ParseDIDCommMsgMap(payload []byte) (DIDCommMsgMap, error)

ParseDIDCommMsgMap returns DIDCommMsg with Header

func (DIDCommMsgMap) Decode added in v0.1.1

func (m DIDCommMsgMap) Decode(v interface{}) error

Decode converts message to struct

func (DIDCommMsgMap) ID added in v0.1.1

func (m DIDCommMsgMap) ID() string

ID returns the message id

func (DIDCommMsgMap) ThreadID added in v0.1.1

func (m DIDCommMsgMap) ThreadID() (string, error)

ThreadID returns msg ~thread.thid if there is no ~thread.thid returns msg @id message is invalid if ~thread.thid exist and @id is absent

func (DIDCommMsgMap) Type added in v0.1.1

func (m DIDCommMsgMap) Type() string

Type returns the message type

type Destination

type Destination struct {
	RecipientKeys        []string
	ServiceEndpoint      string
	RoutingKeys          []string
	TransportReturnRoute string
}

Destination provides the recipientKeys, routingKeys, and serviceEndpoint for an outbound message. Can be populated from an Invitation or DIDDoc.

func CreateDestination added in v0.1.1

func CreateDestination(didDoc *diddoc.Doc) (*Destination, error)

CreateDestination makes a DIDComm Destination object from a DID Doc

func GetDestination added in v0.1.1

func GetDestination(did string, vdr vdri.Registry) (*Destination, error)

GetDestination constructs a Destination struct based on the given DID and parameters It resolves the DID using the given VDR, and collects relevant data from the resolved DIDDoc.

type Empty

type Empty struct {
}

Empty is used if there are no arguments to Continue

type Event

type Event interface {
	// RegisterActionEvent on protocol messages. The events are triggered for incoming message types based on
	// the protocol service. The consumer need to invoke the callback to resume processing.
	// Only one channel can be registered for the action events. The function will throw error if a channel is already
	// registered.
	RegisterActionEvent(ch chan<- DIDCommAction) error

	// UnregisterActionEvent on protocol messages. Refer RegisterActionEvent().
	UnregisterActionEvent(ch chan<- DIDCommAction) error

	// RegisterMsgEvent on protocol messages. The message events are triggered for incoming messages. Service
	// will not expect any callback on these events unlike Action event.
	RegisterMsgEvent(ch chan<- StateMsg) error

	// UnregisterMsgEvent on protocol messages. Refer RegisterMsgEvent().
	UnregisterMsgEvent(ch chan<- StateMsg) error
}

Event event related apis.

type EventProperties

type EventProperties interface{}

EventProperties type for event related data.

type Handler

type Handler interface {
	InboundHandler
	OutboundHandler
}

Handler provides protocol service handle api.

type Header struct {
	ID     string           `json:"@id"`
	Thread decorator.Thread `json:"~thread"`
	Type   string           `json:"@type"`
}

Header helper structure which keeps reusable fields Deprecated: Use DIDCommMsg instead of Header TODO: Remove deprecated Header structure https://github.com/hyperledger/aries-framework-go/issues/1075

type InboundHandler added in v0.1.1

type InboundHandler interface {
	// HandleInbound handles inbound messages.
	HandleInbound(msg DIDCommMsg, myDID, theirDID string) (string, error)
}

InboundHandler is handler for inbound messages

type Message

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

Message thread-safe message register structure

func (*Message) MsgEvents

func (m *Message) MsgEvents() []chan<- StateMsg

MsgEvents returns event message channels

func (*Message) RegisterMsgEvent

func (m *Message) RegisterMsgEvent(ch chan<- StateMsg) error

RegisterMsgEvent on protocol messages. The message events are triggered for incoming messages. Event will not expect any callback on these events unlike Action events.

func (*Message) UnregisterMsgEvent

func (m *Message) UnregisterMsgEvent(ch chan<- StateMsg) error

UnregisterMsgEvent on protocol messages. Refer RegisterMsgEvent().

type Messenger added in v0.1.1

type Messenger interface {
	// ReplyTo replies to the message by given msgID.
	// Keeps threadID in the *decorator.Thread.
	// Using this function means that communication will be on the same thread.
	ReplyTo(msgID string, msg DIDCommMsgMap) error

	// Send sends the message by starting a new thread.
	Send(msg DIDCommMsgMap, myDID, theirDID string) error

	// ReplyToNested sends the message by starting a new thread.
	// Keeps parent threadID in the *decorator.Thread
	ReplyToNested(threadID string, msg DIDCommMsgMap, myDID, theirDID string) error
}

Messenger provides methods for the communication

type MessengerHandler added in v0.1.1

type MessengerHandler interface {
	Messenger
	// HandleInbound handles all inbound messages
	HandleInbound(msg DIDCommMsgMap, myDID, theirDID string) error
}

MessengerHandler includes Messenger interface and Handle function to handle inbound messages

type OutboundHandler added in v0.1.1

type OutboundHandler interface {
	// HandleOutbound handles outbound messages.
	HandleOutbound(msg DIDCommMsg, myDID, theirDID string) error
}

OutboundHandler is handler for outbound messages

type StateMsg

type StateMsg struct {
	// Name of the protocol.
	//
	// Supported protocols
	//   - DID Exchange :  didexchange.DIDExchange
	ProtocolName string

	// type of the message (pre or post), refer service.StateMsgType
	Type StateMsgType

	// current state. Refer protocol RFC for possible states.
	StateID string

	// DIDComm message along with message type
	Msg DIDCommMsg

	// Properties contains value based on specific protocol. The consumers need to call the protocol client
	// functions to get the data.
	//
	// Clients function to retrieve data based on protocol.
	//   - DID Exchange :  didexchange.Event
	Properties EventProperties
}

StateMsg is used in MsgEvent to pass the state details to the consumer. Refer service.Event.RegisterMsgEvent for more details.

type StateMsgType

type StateMsgType int

StateMsgType state msg type

const (
	// PreState pre state
	PreState StateMsgType = iota

	// PostState post state
	PostState
)

Jump to

Keyboard shortcuts

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