forked from berty/berty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_app.go
109 lines (99 loc) · 3.27 KB
/
api_app.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package bertyprotocol
import (
"context"
"encoding/hex"
"fmt"
"berty.tech/berty/v2/go/pkg/errcode"
"berty.tech/berty/v2/go/pkg/protocoltypes"
"berty.tech/berty/v2/go/pkg/tyber"
)
func (s *service) AppMetadataSend(ctx context.Context, req *protocoltypes.AppMetadataSend_Request) (*protocoltypes.AppMetadataSend_Reply, error) {
ctx = tyber.ContextWithTraceID(ctx)
s.logger.Info(
fmt.Sprintf("Sending metadata to group %s", hex.EncodeToString(req.GroupPK)),
tyber.FormatTraceLogFields(ctx)...,
)
gc, err := s.getContextGroupForID(req.GroupPK)
if err != nil {
s.logger.Error(
"Getting Group Context failed",
tyber.FormatStepLogFields(ctx, []tyber.Detail{{Name: "Error", Description: err.Error()}}, tyber.Failed, true)...,
)
return nil, errcode.ErrGroupMissing.Wrap(err)
}
s.logger.Debug(
"Getting Group Context succeeded",
tyber.FormatStepLogFields(
ctx,
[]tyber.Detail{{Name: "Group Type", Description: gc.Group().GetGroupType().String()}},
tyber.Succeeded,
false,
)...,
)
if _, err := gc.MetadataStore().SendAppMetadata(ctx, req.Payload, req.GetAttachmentCIDs()); err != nil {
s.logger.Error(
"Writing metadata on metadata store failed",
tyber.FormatStepLogFields(
ctx,
[]tyber.Detail{{Name: "Error", Description: err.Error()}},
tyber.Failed,
true,
)...,
)
return nil, errcode.ErrOrbitDBAppend.Wrap(err)
}
s.logger.Debug(
"ToDo: catch Tinder event to display related connected peers",
tyber.FormatStepLogFields(ctx, []tyber.Detail{}, tyber.Succeeded, false)...,
)
s.logger.Debug(
"ToDo: catch acknowledge event to confirm message reception",
tyber.FormatStepLogFields(ctx, []tyber.Detail{}, tyber.Succeeded, true)...,
)
return &protocoltypes.AppMetadataSend_Reply{}, nil
}
func (s *service) AppMessageSend(ctx context.Context, req *protocoltypes.AppMessageSend_Request) (*protocoltypes.AppMessageSend_Reply, error) {
ctx = tyber.ContextWithTraceID(ctx)
s.logger.Info(
fmt.Sprintf("Sending message to group %s", hex.EncodeToString(req.GroupPK)),
tyber.FormatTraceLogFields(ctx)...,
)
gc, err := s.getContextGroupForID(req.GroupPK)
if err != nil {
s.logger.Error(
"Getting Group Context failed",
tyber.FormatStepLogFields(ctx, []tyber.Detail{{Name: "Error", Description: err.Error()}}, tyber.Failed, true)...,
)
return nil, errcode.ErrGroupMissing.Wrap(err)
}
s.logger.Debug(
"Getting Group Context succeeded",
tyber.FormatStepLogFields(
ctx,
[]tyber.Detail{{Name: "Group Type", Description: gc.Group().GetGroupType().String()}},
tyber.Succeeded,
false,
)...,
)
if _, err := gc.MessageStore().AddMessage(ctx, req.Payload, req.GetAttachmentCIDs()); err != nil {
s.logger.Error(
"Writing metadata on metadata store failed",
tyber.FormatStepLogFields(
ctx,
[]tyber.Detail{{Name: "Error", Description: err.Error()}},
tyber.Failed,
true,
)...,
)
return nil, errcode.ErrOrbitDBAppend.Wrap(err)
}
s.logger.Debug(
"ToDo: catch Tinder event to display related connected peers",
tyber.FormatStepLogFields(ctx, []tyber.Detail{}, tyber.Succeeded, false)...,
)
s.logger.Debug(
"ToDo: catch acknowledge event to confirm message reception",
tyber.FormatStepLogFields(ctx, []tyber.Detail{}, tyber.Succeeded, true)...,
)
return &protocoltypes.AppMessageSend_Reply{}, nil
}