github.com/hyperledger/aries-framework-go@v0.3.2/pkg/didcomm/common/service/messenger.go (about) 1 /* 2 Copyright SecureKey Technologies Inc. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package service 8 9 // DIDCommMsg describes message interface. 10 type DIDCommMsg interface { 11 ID() string 12 SetID(id string, opts ...Opt) 13 SetThread(thid, pthid string, opts ...Opt) 14 UnsetThread() 15 Type() string 16 ThreadID() (string, error) 17 ParentThreadID() string 18 Clone() DIDCommMsgMap 19 Metadata() map[string]interface{} 20 Decode(v interface{}) error 21 } 22 23 // DIDCommContext holds information on the context in which a DIDCommMsg is being processed. 24 type DIDCommContext interface { 25 MyDID() string 26 TheirDID() string 27 EventProperties 28 } 29 30 // NewDIDCommContext returns a new DIDCommContext with the given DIDs and properties. 31 func NewDIDCommContext(myDID, theirDID string, props map[string]interface{}) DIDCommContext { 32 return &context{ 33 myDID: myDID, 34 theirDID: theirDID, 35 props: props, 36 } 37 } 38 39 // EmptyDIDCommContext returns a DIDCommContext with no DIDs nor properties. 40 func EmptyDIDCommContext() DIDCommContext { 41 return &context{props: make(map[string]interface{})} 42 } 43 44 type context struct { 45 myDID string 46 theirDID string 47 props map[string]interface{} 48 } 49 50 func (c *context) MyDID() string { 51 return c.myDID 52 } 53 54 func (c *context) TheirDID() string { 55 return c.theirDID 56 } 57 58 func (c *context) All() map[string]interface{} { 59 return c.props 60 } 61 62 // The messenger package is responsible for the handling of communication between agents. 63 // It takes care of threading, timing, etc. 64 // Each message that we are going to send should be DIDCommMsg type. 65 // e.g we have type model.Ack{Type: "type", ID: "id"} 66 // it should be converted to: map[@id:id @type:type] 67 // NOTE: The package modifies message data by JSON tag name according to aries-rfcs. 68 // Fields like @id, ~thread , etc. are redundant and may be rewritten. 69 70 // Messenger provides methods for the communication. 71 type Messenger interface { 72 // ReplyTo replies to the message by given msgID. 73 // Keeps threadID in the *decorator.Thread. 74 // Using this function means that communication will be on the same thread. 75 // 76 // Deprecated: Please do not use it anymore. The function can be removed in future release. 77 ReplyTo(msgID string, msg DIDCommMsgMap, opts ...Opt) error 78 79 // ReplyToMsg replies to the given message. 80 // Keeps threadID in the *decorator.Thread. 81 // Using this function means that communication will be on the same thread. 82 ReplyToMsg(in, out DIDCommMsgMap, myDID, theirDID string, opts ...Opt) error 83 84 // Send sends the message by starting a new thread. 85 Send(msg DIDCommMsgMap, myDID, theirDID string, opts ...Opt) error 86 87 // SendToDestination sends the message to given destination by starting a new thread. 88 SendToDestination(msg DIDCommMsgMap, sender string, destination *Destination, opts ...Opt) error 89 90 // ReplyToNested sends the message by starting a new thread. 91 // Keeps parent threadID in the *decorator.Thread 92 ReplyToNested(msg DIDCommMsgMap, opts *NestedReplyOpts) error 93 } 94 95 // MessengerHandler includes Messenger interface and Handle function to handle inbound messages. 96 type MessengerHandler interface { 97 Messenger 98 InboundMessenger 99 } 100 101 // InboundMessenger contains Handle function to handle inbound messages. 102 type InboundMessenger interface { 103 // HandleInbound handles all inbound messages 104 HandleInbound(msg DIDCommMsgMap, ctx DIDCommContext) error 105 } 106 107 // NestedReplyOpts options for performing `ReplyToNested` operation. 108 type NestedReplyOpts struct { 109 // ThreadID is parent thread ID for nested reply, 110 // if not provided then 'ThreadID' from message record will be used 111 ThreadID string 112 // MyDID for nested reply message, 113 // if not provided then 'MyDID' from message record will be used 114 MyDID string 115 // TheirDID for nested reply message, 116 // if not provided then 'TheirDID' from message record will be used 117 TheirDID string 118 // MsgID to which nested reply to be sent, 119 // optional when all the above parameters are provided. 120 // 121 // Deprecated: Please do not use it anymore. The field can be removed in future release. 122 MsgID string 123 V Version 124 }