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

feat: messagebox #1926

Merged
merged 1 commit into from
Jul 2, 2020
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ require (
github.com/onsi/ginkgo v1.10.1 // indirect
github.com/onsi/gomega v1.7.0 // indirect
github.com/piprate/json-gold v0.3.0
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/errors v0.9.1
github.com/rs/cors v1.7.0
github.com/square/go-jose/v3 v3.0.0-20191119004800-96c717272387
github.com/stretchr/testify v1.4.0
Expand Down
16 changes: 16 additions & 0 deletions pkg/didcomm/protocol/messagepickup/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
Copyright Scoir Inc. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
*/

package messagepickup

import (
"github.com/hyperledger/aries-framework-go/pkg/didcomm/common/model"
)

// ProtocolService fix
type ProtocolService interface {
AddMessage(message *model.Envelope, theirDID string) error
}
42 changes: 42 additions & 0 deletions pkg/didcomm/protocol/messagepickup/lockbox.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Reference implementation of kmutex from github.com/im7mortal/kmutex

SPDX-License-Identifier: Apache-2.0
*/

package messagepickup

import "sync"

type lockbox struct {
c *sync.Cond
l sync.Locker
s map[interface{}]struct{}
}

func newLockBox() *lockbox {
l := sync.Mutex{}
return &lockbox{c: sync.NewCond(&l), l: &l, s: make(map[interface{}]struct{})}
}

func (km *lockbox) locked(key interface{}) (ok bool) { _, ok = km.s[key]; return }

// Unlock lockbox by unique ID
func (km *lockbox) Unlock(key interface{}) {
km.l.Lock()
defer km.l.Unlock()
delete(km.s, key)
km.c.Broadcast()
}

// Lock lockbox by unique ID
func (km *lockbox) Lock(key interface{}) {
km.l.Lock()
defer km.l.Unlock()

for km.locked(key) {
km.c.Wait()
}

km.s[key] = struct{}{}
}
68 changes: 68 additions & 0 deletions pkg/didcomm/protocol/messagepickup/models.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
Copyright Scoir Inc. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
*/

package messagepickup

import (
"time"

"github.com/hyperledger/aries-framework-go/pkg/didcomm/common/model"
"github.com/hyperledger/aries-framework-go/pkg/didcomm/protocol/decorator"
)

// StatusRequest sent by the recipient to the message_holder to request a status message./0212-pickup#statusrequest
// https://github.com/hyperledger/aries-rfcs/tree/master/features/0212-pickup#statusrequest
type StatusRequest struct {
Type string `json:"@type,omitempty"`
ID string `json:"@id,omitempty"`
Thread *decorator.Thread `json:"~thread,omitempty"`
}

// Status details about pending messages
// https://github.com/hyperledger/aries-rfcs/tree/master/features/0212-pickup#status
type Status struct {
Type string `json:"@type,omitempty"`
ID string `json:"@id,omitempty"`
MessageCount int `json:"message_count"`
DurationWaited int `json:"duration_waited,omitempty"`
LastAddedTime time.Time `json:"last_added_time,omitempty"`
LastDeliveredTime time.Time `json:"last_delivered_time,omitempty"`
LastRemovedTime time.Time `json:"last_removed_time,omitempty"`
TotalSize int `json:"total_size,omitempty"`
Thread *decorator.Thread `json:"~thread,omitempty"`
}

// BatchPickup a request to have multiple waiting messages sent inside a batch message.
// https://github.com/hyperledger/aries-rfcs/tree/master/features/0212-pickup#batch-pickup
type BatchPickup struct {
Type string `json:"@type,omitempty"`
ID string `json:"@id,omitempty"`
BatchSize int `json:"batch_size"`
Thread *decorator.Thread `json:"~thread,omitempty"`
}

// Batch a message that contains multiple waiting messages.
// https://github.com/hyperledger/aries-rfcs/tree/master/features/0212-pickup#batch
type Batch struct {
Type string `json:"@type,omitempty"`
ID string `json:"@id,omitempty"`
Messages []*Message `json:"messages~attach"`
Thread *decorator.Thread `json:"~thread,omitempty"`
}

// Message messagepickup wrapper
type Message struct {
ID string `json:"id"`
AddedTime time.Time `json:"added_time"`
Message *model.Envelope `json:"msg,omitempty"`
}

// Noop message
// https://github.com/hyperledger/aries-rfcs/tree/master/features/0212-pickup#noop
type Noop struct {
Type string `json:"@type,omitempty"`
ID string `json:"@id,omitempty"`
}
Loading