Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
feat: Update Protocol Service API with Event handling functions (Regi…
Browse files Browse the repository at this point in the history
…ster/Unregister)

- Add Register/Unregister Action/Msg event APIs to Protocol Services

Signed-off-by: Rolson Quadras <[email protected]>
  • Loading branch information
rolsonquadras committed Sep 24, 2019
1 parent bd040c0 commit 2479754
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pkg/didcomm/dispatcher/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ type Service interface {
Handle(msg DIDCommMsg) error
Accept(msgType string) bool
Name() string

// 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<- DIDCommMsg) error

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

// DIDCommMsg did comm msg
Expand Down
16 changes: 16 additions & 0 deletions pkg/framework/aries/framework_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,22 @@ func (m mockProtocolSvc) Name() string {
return "mockProtocolSvc"
}

func (m mockProtocolSvc) RegisterActionEvent(ch chan<- dispatcher.DIDCommAction) error {
return nil
}

func (m mockProtocolSvc) UnregisterActionEvent(ch chan<- dispatcher.DIDCommAction) error {
return nil
}

func (m mockProtocolSvc) RegisterMsgEvent(ch chan<- dispatcher.DIDCommMsg) error {
return nil
}

func (m mockProtocolSvc) UnregisterMsgEvent(ch chan<- dispatcher.DIDCommMsg) error {
return nil
}

type mockTransportProviderFactory struct {
err error
}
Expand Down
16 changes: 16 additions & 0 deletions pkg/framework/context/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,19 @@ func (m mockProtocolSvc) Accept(msgType string) bool {
func (m mockProtocolSvc) Name() string {
return "mockProtocolSvc"
}

func (m mockProtocolSvc) RegisterActionEvent(ch chan<- dispatcher.DIDCommAction) error {
return nil
}

func (m mockProtocolSvc) UnregisterActionEvent(ch chan<- dispatcher.DIDCommAction) error {
return nil
}

func (m mockProtocolSvc) RegisterMsgEvent(ch chan<- dispatcher.DIDCommMsg) error {
return nil
}

func (m mockProtocolSvc) UnregisterMsgEvent(ch chan<- dispatcher.DIDCommMsg) error {
return nil
}
16 changes: 16 additions & 0 deletions pkg/internal/mock/didcomm/protocol/mock_didexchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,19 @@ func (m *MockDIDExchangeSvc) Accept(msgType string) bool {
func (m *MockDIDExchangeSvc) Name() string {
return "didexchange"
}

func (m *MockDIDExchangeSvc) RegisterActionEvent(ch chan<- dispatcher.DIDCommAction) error {
return nil
}

func (m *MockDIDExchangeSvc) UnregisterActionEvent(ch chan<- dispatcher.DIDCommAction) error {
return nil
}

func (m *MockDIDExchangeSvc) RegisterMsgEvent(ch chan<- dispatcher.DIDCommMsg) error {
return nil
}

func (m *MockDIDExchangeSvc) UnregisterMsgEvent(ch chan<- dispatcher.DIDCommMsg) error {
return nil
}
16 changes: 16 additions & 0 deletions pkg/restapi/operation/didexchange/didexchange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,22 @@ func (m mockProtocolSvc) Name() string {
return "mockProtocolSvc"
}

func (m mockProtocolSvc) RegisterActionEvent(ch chan<- dispatcher.DIDCommAction) error {
return nil
}

func (m mockProtocolSvc) UnregisterActionEvent(ch chan<- dispatcher.DIDCommAction) error {
return nil
}

func (m mockProtocolSvc) RegisterMsgEvent(ch chan<- dispatcher.DIDCommMsg) error {
return nil
}

func (m mockProtocolSvc) UnregisterMsgEvent(ch chan<- dispatcher.DIDCommMsg) error {
return nil
}

type mockWriter struct {
failure error
}
Expand Down

0 comments on commit 2479754

Please sign in to comment.