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

Commit

Permalink
Merge pull request #1926 from m00sey/issue-811
Browse files Browse the repository at this point in the history
feat:  messagebox
  • Loading branch information
George Aristy authored Jul 2, 2020
2 parents 849aad6 + 5fe6569 commit e07d38e
Show file tree
Hide file tree
Showing 6 changed files with 1,604 additions and 1 deletion.
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

0 comments on commit e07d38e

Please sign in to comment.