forked from berty/berty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
group_context.go
70 lines (55 loc) · 1.67 KB
/
group_context.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package bertyprotocol
import (
"encoding/base64"
"fmt"
"github.com/libp2p/go-libp2p-core/crypto"
"go.uber.org/zap"
"berty.tech/berty/v2/go/pkg/protocoltypes"
)
type groupContext struct {
group *protocoltypes.Group
metadataStore *metadataStore
messageStore *messageStore
messageKeystore *messageKeystore
memberDevice *ownMemberDevice
logger *zap.Logger
}
func (gc *groupContext) MessageKeystore() *messageKeystore {
return gc.messageKeystore
}
func (gc *groupContext) getMemberPrivKey() crypto.PrivKey {
return gc.memberDevice.member
}
func (gc *groupContext) MessageStore() *messageStore {
return gc.messageStore
}
func (gc *groupContext) MetadataStore() *metadataStore {
return gc.metadataStore
}
func (gc *groupContext) Group() *protocoltypes.Group {
return gc.group
}
func (gc *groupContext) MemberPubKey() crypto.PubKey {
return gc.memberDevice.member.GetPublic()
}
func (gc *groupContext) DevicePubKey() crypto.PubKey {
return gc.memberDevice.device.GetPublic()
}
func (gc *groupContext) Close() error {
gc.metadataStore.Close()
gc.messageStore.Close()
return nil
}
func newContextGroup(group *protocoltypes.Group, metadataStore *metadataStore, messageStore *messageStore, messageKeystore *messageKeystore, memberDevice *ownMemberDevice, logger *zap.Logger) *groupContext {
if logger == nil {
logger = zap.NewNop()
}
return &groupContext{
group: group,
metadataStore: metadataStore,
messageStore: messageStore,
messageKeystore: messageKeystore,
memberDevice: memberDevice,
logger: logger.With(zap.String("group-id", fmt.Sprintf("%.6s", base64.StdEncoding.EncodeToString(group.PublicKey)))),
}
}