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

feat: Update Protocol Service API with Event handling functions (Register/Unregister) #335

Merged
merged 1 commit into from
Sep 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions pkg/didcomm/dispatcher/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ SPDX-License-Identifier: Apache-2.0

package dispatcher

// TODO https://github.com/hyperledger/aries-framework-go/issues/342 - refactor the pkg, currently contains dispatcher,
// messages and events fuctionalities. (need to avoid cyclical dependecy)
import (
"github.com/hyperledger/aries-framework-go/pkg/didcomm/transport"
"github.com/hyperledger/aries-framework-go/pkg/wallet"
Expand Down Expand Up @@ -67,3 +69,31 @@ type DIDCommCallback struct {

// Callback type to pass service callbacks.
type Callback func(DIDCommCallback)

// Event related apis.
type Event interface {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I wasn't clear before about the embedding: I think this new interface (whatever it will be named) should embed the existing dispatcher.Service interface, not the other way around. The dispatchers have no use for these new methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@llorllale Created a new interface for DIDComm Services.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened #344 to consider moving this interface to a different package in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@llorllale I had already raised one for that. May be we can close #344

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

// DIDCommService defines service APIs.
type DIDCommService interface {
// dispatcher service
Service

// event service
Event
}
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 @@ -173,3 +173,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
}
20 changes: 20 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,23 @@ func (m *MockDIDExchangeSvc) Accept(msgType string) bool {
func (m *MockDIDExchangeSvc) Name() string {
return "didexchange"
}

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

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

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

// UnregisterMsgEvent unregister message event.
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 @@ -297,6 +297,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