Skip to content
Snippets Groups Projects
Commit 634c209f authored by Josh Brooks's avatar Josh Brooks
Browse files

Add field RoundUrl to all send reporters in bindings

parent 6c1ccd50
No related branches found
No related tags found
2 merge requests!510Release,!368Add field RoundUrl to all send reporters in bindings
...@@ -44,9 +44,11 @@ type ChannelDef struct { ...@@ -44,9 +44,11 @@ type ChannelDef struct {
// BroadcastMessage is the bindings representation of a broadcast message. // BroadcastMessage is the bindings representation of a broadcast message.
// //
// Example JSON: // BroadcastMessage Example JSON:
// {"RoundID":42, // {
// "RoundID":42,
// "EphID":[0,0,0,0,0,0,24,61], // "EphID":[0,0,0,0,0,0,24,61],
// "RoundURL":"https://dashboard.xx.network/rounds/25?xxmessenger=true",
// "Payload":"SGVsbG8sIGJyb2FkY2FzdCBmcmllbmRzIQ==" // "Payload":"SGVsbG8sIGJyb2FkY2FzdCBmcmllbmRzIQ=="
// } // }
type BroadcastMessage struct { type BroadcastMessage struct {
...@@ -57,12 +59,15 @@ type BroadcastMessage struct { ...@@ -57,12 +59,15 @@ type BroadcastMessage struct {
// BroadcastReport is the bindings representation of the info on how a broadcast // BroadcastReport is the bindings representation of the info on how a broadcast
// message was sent // message was sent
// //
// Example JSON: // BroadcastReport Example JSON:
// {"RoundID":42, // {
// "EphID":[0,0,0,0,0,0,24,61] // "Rounds": [25, 26, 29],
// "EphID":[0,0,0,0,0,0,24,61],
// "RoundURL":"https://dashboard.xx.network/rounds/25?xxmessenger=true"
// } // }
type BroadcastReport struct { type BroadcastReport struct {
RoundsList RoundsList
RoundURL string
EphID ephemeral.Id EphID ephemeral.Id
} }
...@@ -131,6 +136,7 @@ func (c *Channel) Listen(l BroadcastListener, method int) error { ...@@ -131,6 +136,7 @@ func (c *Channel) Listen(l BroadcastListener, method int) error {
l.Callback(json.Marshal(&BroadcastMessage{ l.Callback(json.Marshal(&BroadcastMessage{
BroadcastReport: BroadcastReport{ BroadcastReport: BroadcastReport{
RoundsList: makeRoundsList(round.ID), RoundsList: makeRoundsList(round.ID),
RoundURL: getRoundURL(round.ID),
EphID: receptionID.EphId, EphID: receptionID.EphId,
}, },
Payload: payload, Payload: payload,
...@@ -153,6 +159,7 @@ func (c *Channel) Broadcast(payload []byte) ([]byte, error) { ...@@ -153,6 +159,7 @@ func (c *Channel) Broadcast(payload []byte) ([]byte, error) {
} }
return json.Marshal(BroadcastReport{ return json.Marshal(BroadcastReport{
RoundsList: makeRoundsList(rid), RoundsList: makeRoundsList(rid),
RoundURL: getRoundURL(rid),
EphID: eid, EphID: eid,
}) })
} }
...@@ -174,6 +181,7 @@ func (c *Channel) BroadcastAsymmetric(payload, pk []byte) ([]byte, error) { ...@@ -174,6 +181,7 @@ func (c *Channel) BroadcastAsymmetric(payload, pk []byte) ([]byte, error) {
} }
return json.Marshal(BroadcastReport{ return json.Marshal(BroadcastReport{
RoundsList: makeRoundsList(rid), RoundsList: makeRoundsList(rid),
RoundURL: getRoundURL(rid),
EphID: eid, EphID: eid,
}) })
} }
......
...@@ -94,6 +94,7 @@ func (c *Connection) SendE2E(mt int, payload []byte) ([]byte, error) { ...@@ -94,6 +94,7 @@ func (c *Connection) SendE2E(mt int, payload []byte) ([]byte, error) {
sr := E2ESendReport{ sr := E2ESendReport{
RoundsList: makeRoundsList(sendReport.RoundList...), RoundsList: makeRoundsList(sendReport.RoundList...),
RoundURL: getRoundURL(sendReport.RoundList[0]),
MessageID: sendReport.MessageId.Marshal(), MessageID: sendReport.MessageId.Marshal(),
Timestamp: sendReport.SentTime.UnixNano(), Timestamp: sendReport.SentTime.UnixNano(),
KeyResidue: sendReport.KeyResidue.Marshal(), KeyResidue: sendReport.KeyResidue.Marshal(),
......
...@@ -9,6 +9,7 @@ package bindings ...@@ -9,6 +9,7 @@ package bindings
import ( import (
"encoding/json" "encoding/json"
"fmt"
"time" "time"
"github.com/pkg/errors" "github.com/pkg/errors"
...@@ -17,9 +18,20 @@ import ( ...@@ -17,9 +18,20 @@ import (
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
) )
// dashboardBaseURL is the base of the xx network's round dashboard URL.
// This should be used by any type of send report's GetRoundURL method.
const dashboardBaseURL = "https://dashboard.xx.network"
// getRoundURL is a helper function which returns the specific round
// within any type of send report, if they have a round in their RoundsList.
// This helper function is messenger specific.
func getRoundURL(round id.Round) string {
return fmt.Sprintf("%s/rounds/%d?xxmessenger=true", dashboardBaseURL, round)
}
// RoundsList contains a list of round IDs. // RoundsList contains a list of round IDs.
// //
// Example marshalled roundList object: // JSON Example:
// [1001,1003,1006] // [1001,1003,1006]
type RoundsList struct { type RoundsList struct {
Rounds []uint64 Rounds []uint64
......
...@@ -23,15 +23,17 @@ import ( ...@@ -23,15 +23,17 @@ import (
// E2ESendReport is the bindings' representation of the return values of // E2ESendReport is the bindings' representation of the return values of
// SendE2E. // SendE2E.
// //
// Example E2ESendReport: // E2ESendReport Example JSON:
// { // {
// "Rounds": [ 1, 4, 9], // "Rounds": [ 1, 4, 9],
// "RoundURL":"https://dashboard.xx.network/rounds/25?xxmessenger=true",
// "MessageID": "iM34yCIr4Je8ZIzL9iAAG1UWAeDiHybxMTioMAaezvs=", // "MessageID": "iM34yCIr4Je8ZIzL9iAAG1UWAeDiHybxMTioMAaezvs=",
// "Timestamp": 1661532254302612000, // "Timestamp": 1661532254302612000,
// "KeyResidue": "9q2/A69EAuFM1hFAT7Bzy5uGOQ4T6bPFF72h5PlgCWE=" // "KeyResidue": "9q2/A69EAuFM1hFAT7Bzy5uGOQ4T6bPFF72h5PlgCWE="
// } // }
type E2ESendReport struct { type E2ESendReport struct {
RoundsList RoundsList
RoundURL string
MessageID []byte MessageID []byte
Timestamp int64 Timestamp int64
KeyResidue []byte KeyResidue []byte
...@@ -147,6 +149,7 @@ func (e *E2e) SendE2E(messageType int, recipientId, payload, ...@@ -147,6 +149,7 @@ func (e *E2e) SendE2E(messageType int, recipientId, payload,
result := E2ESendReport{ result := E2ESendReport{
RoundsList: makeRoundsList(sendReport.RoundList...), RoundsList: makeRoundsList(sendReport.RoundList...),
RoundURL: getRoundURL(sendReport.RoundList[0]),
MessageID: sendReport.MessageId.Marshal(), MessageID: sendReport.MessageId.Marshal(),
Timestamp: sendReport.SentTime.UnixNano(), Timestamp: sendReport.SentTime.UnixNano(),
KeyResidue: sendReport.KeyResidue.Marshal(), KeyResidue: sendReport.KeyResidue.Marshal(),
......
...@@ -157,6 +157,7 @@ func (g *GroupChat) MakeGroup( ...@@ -157,6 +157,7 @@ func (g *GroupChat) MakeGroup(
report := GroupReport{ report := GroupReport{
Id: grp.ID.Bytes(), Id: grp.ID.Bytes(),
RoundsList: makeRoundsList(roundIDs...), RoundsList: makeRoundsList(roundIDs...),
RoundURL: getRoundURL(roundIDs[0]),
Status: int(status), Status: int(status),
} }
...@@ -199,6 +200,7 @@ func (g *GroupChat) ResendRequest(groupId []byte) ([]byte, error) { ...@@ -199,6 +200,7 @@ func (g *GroupChat) ResendRequest(groupId []byte) ([]byte, error) {
report := &GroupReport{ report := &GroupReport{
Id: grp.ID.Bytes(), Id: grp.ID.Bytes(),
RoundsList: makeRoundsList(rnds...), RoundsList: makeRoundsList(rnds...),
RoundURL: getRoundURL(rnds[0]),
Status: int(status), Status: int(status),
} }
...@@ -270,6 +272,7 @@ func (g *GroupChat) Send(groupId, message []byte, tag string) ([]byte, error) { ...@@ -270,6 +272,7 @@ func (g *GroupChat) Send(groupId, message []byte, tag string) ([]byte, error) {
// Construct send report // Construct send report
sendReport := &GroupSendReport{ sendReport := &GroupSendReport{
RoundsList: makeRoundsList(round), RoundsList: makeRoundsList(round),
RoundURL: getRoundURL(round),
Timestamp: timestamp.UnixNano(), Timestamp: timestamp.UnixNano(),
MessageID: msgID.Bytes(), MessageID: msgID.Bytes(),
} }
...@@ -451,16 +454,34 @@ func (gcp *groupChatProcessor) String() string { ...@@ -451,16 +454,34 @@ func (gcp *groupChatProcessor) String() string {
// GroupReport is returned when creating a new group and contains the ID of // GroupReport is returned when creating a new group and contains the ID of
// the group, a list of rounds that the group requests were sent on, and the // the group, a list of rounds that the group requests were sent on, and the
// status of the send operation. // status of the send operation.
//
// Example GroupReport JSON:
// {
// "Id": "AAAAAAAAAM0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAE",
// "Rounds": [25, 64],
// "RoundURL": "https://dashboard.xx.network/rounds/25?xxmessenger=true",
// "Status": 1
// }
type GroupReport struct { type GroupReport struct {
Id []byte Id []byte
RoundsList RoundsList
RoundURL string
Status int Status int
} }
// GroupSendReport is returned when sending a group message. It contains the // GroupSendReport is returned when sending a group message. It contains the
// round ID sent on and the timestamp of the send operation. // round ID sent on and the timestamp of the send operation.
//
// Example GroupSendReport JSON:
// {
// "Rounds": [25, 64],
// "RoundURL": "https://dashboard.xx.network/rounds/25?xxmessenger=true",
// "Timestamp": 1662577352813112000,
// "MessageID": "69ug6FA50UT2q6MWH3hne9PkHQ+H9DnEDsBhc0m0Aww="
// }
type GroupSendReport struct { type GroupSendReport struct {
RoundsList RoundsList
RoundURL string
Timestamp int64 Timestamp int64
MessageID []byte MessageID []byte
} }
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2022 xx foundation //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file. //
////////////////////////////////////////////////////////////////////////////////
package bindings
import (
"encoding/json"
"gitlab.com/elixxir/crypto/e2e"
"math/rand"
"testing"
"time"
)
func TestName(t *testing.T) {
rl := []uint64{1, 4, 9}
prng := rand.New(rand.NewSource(42))
rfp := make([]byte, 32)
prng.Read(rfp)
mid := e2e.NewMessageID(rfp, prng.Uint64())
randData := make([]byte, 32)
prng.Read(randData)
k := e2e.Key{}
copy(k[:], randData)
kr := e2e.NewKeyResidue(k)
report := E2ESendReport{
RoundsList: RoundsList{rl},
MessageID: mid.Marshal(),
Timestamp: time.Now().UnixNano(),
KeyResidue: kr.Marshal(),
}
marshal, _ := json.Marshal(report)
t.Logf("%s", marshal)
}
...@@ -64,6 +64,7 @@ func TransmitSingleUse(e2eID int, recipient []byte, tag string, payload, ...@@ -64,6 +64,7 @@ func TransmitSingleUse(e2eID int, recipient []byte, tag string, payload,
EphID: eid.EphId.Int64(), EphID: eid.EphId.Int64(),
ReceptionID: eid.Source, ReceptionID: eid.Source,
RoundsList: makeRoundsList(rids...), RoundsList: makeRoundsList(rids...),
RoundURL: getRoundURL(rids[0]),
} }
return json.Marshal(sr) return json.Marshal(sr)
} }
...@@ -99,14 +100,16 @@ func Listen(e2eID int, tag string, cb SingleUseCallback) (Stopper, error) { ...@@ -99,14 +100,16 @@ func Listen(e2eID int, tag string, cb SingleUseCallback) (Stopper, error) {
// SingleUseSendReport is the bindings-layer struct used to represent // SingleUseSendReport is the bindings-layer struct used to represent
// information returned by single.TransmitRequest. // information returned by single.TransmitRequest.
// //
// JSON example: // SingleUseSendReport JSON example:
// { // {
// "Rounds":[1,5,9], // "Rounds":[1,5,9],
// "RoundURL": "https://dashboard.xx.network/rounds/25?xxmessenger=true",
// "EphID":1655533, // "EphID":1655533,
// "ReceptionID":"emV6aW1hAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD"} // "ReceptionID":"emV6aW1hAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD"}
// } // }
type SingleUseSendReport struct { type SingleUseSendReport struct {
RoundsList RoundsList
RoundURL string
ReceptionID *id.ID ReceptionID *id.ID
EphID int64 EphID int64
} }
...@@ -115,9 +118,10 @@ type SingleUseSendReport struct { ...@@ -115,9 +118,10 @@ type SingleUseSendReport struct {
// information passed to the single.Response callback interface in response to // information passed to the single.Response callback interface in response to
// single.TransmitRequest. // single.TransmitRequest.
// //
// JSON example: // SingleUseResponseReport JSON example:
// { // {
// "Rounds":[1,5,9], // "Rounds":[1,5,9],
// "RoundURL": "https://dashboard.xx.network/rounds/25?xxmessenger=true",
// "Payload":"rSuPD35ELWwm5KTR9ViKIz/r1YGRgXIl5792SF8o8piZzN6sT4Liq4rUU/nfOPvQEjbfWNh/NYxdJ72VctDnWw==", // "Payload":"rSuPD35ELWwm5KTR9ViKIz/r1YGRgXIl5792SF8o8piZzN6sT4Liq4rUU/nfOPvQEjbfWNh/NYxdJ72VctDnWw==",
// "EphID":1655533, // "EphID":1655533,
// "ReceptionID":"emV6aW1hAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD"}, // "ReceptionID":"emV6aW1hAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD"},
...@@ -125,6 +129,7 @@ type SingleUseSendReport struct { ...@@ -125,6 +129,7 @@ type SingleUseSendReport struct {
// } // }
type SingleUseResponseReport struct { type SingleUseResponseReport struct {
RoundsList RoundsList
RoundURL string
Payload []byte Payload []byte
ReceptionID *id.ID ReceptionID *id.ID
EphID int64 EphID int64
...@@ -134,9 +139,10 @@ type SingleUseResponseReport struct { ...@@ -134,9 +139,10 @@ type SingleUseResponseReport struct {
// SingleUseCallbackReport is the bindings-layer struct used to represent // SingleUseCallbackReport is the bindings-layer struct used to represent
// single -use messages received by a callback passed into single.Listen. // single -use messages received by a callback passed into single.Listen.
// //
// JSON example: // SingleUseCallbackReport JSON example:
// { // {
// "Rounds":[1,5,9], // "Rounds":[1,5,9],
// "RoundURL": "https://dashboard.xx.network/rounds/25?xxmessenger=true",
// "Payload":"rSuPD35ELWwm5KTR9ViKIz/r1YGRgXIl5792SF8o8piZzN6sT4Liq4rUU/nfOPvQEjbfWNh/NYxdJ72VctDnWw==", // "Payload":"rSuPD35ELWwm5KTR9ViKIz/r1YGRgXIl5792SF8o8piZzN6sT4Liq4rUU/nfOPvQEjbfWNh/NYxdJ72VctDnWw==",
// "Partner":"emV6aW1hAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD", // "Partner":"emV6aW1hAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD",
// "EphID":1655533, // "EphID":1655533,
...@@ -144,6 +150,7 @@ type SingleUseResponseReport struct { ...@@ -144,6 +150,7 @@ type SingleUseResponseReport struct {
// } // }
type SingleUseCallbackReport struct { type SingleUseCallbackReport struct {
RoundsList RoundsList
RoundURL string
Payload []byte Payload []byte
Partner *id.ID Partner *id.ID
EphID int64 EphID int64
...@@ -208,6 +215,7 @@ func (sl singleUseListener) Callback( ...@@ -208,6 +215,7 @@ func (sl singleUseListener) Callback(
scr := SingleUseCallbackReport{ scr := SingleUseCallbackReport{
Payload: req.GetPayload(), Payload: req.GetPayload(),
RoundsList: makeRoundsList(rids...), RoundsList: makeRoundsList(rids...),
RoundURL: getRoundURL(rids[0]),
Partner: req.GetPartner(), Partner: req.GetPartner(),
EphID: eid.EphId.Int64(), EphID: eid.EphId.Int64(),
ReceptionID: eid.Source, ReceptionID: eid.Source,
...@@ -246,6 +254,7 @@ func (sr singleUseResponse) Callback(payload []byte, ...@@ -246,6 +254,7 @@ func (sr singleUseResponse) Callback(payload []byte,
} }
sendReport := SingleUseResponseReport{ sendReport := SingleUseResponseReport{
RoundsList: makeRoundsList(rids...), RoundsList: makeRoundsList(rids...),
RoundURL: getRoundURL(rids[0]),
ReceptionID: receptionID.Source, ReceptionID: receptionID.Source,
EphID: receptionID.EphId.Int64(), EphID: receptionID.EphId.Int64(),
Payload: payload, Payload: payload,
......
...@@ -414,6 +414,7 @@ func LookupUD(e2eID int, udContact []byte, cb UdLookupCallback, ...@@ -414,6 +414,7 @@ func LookupUD(e2eID int, udContact []byte, cb UdLookupCallback,
EphID: eid.EphId.Int64(), EphID: eid.EphId.Int64(),
ReceptionID: eid.Source, ReceptionID: eid.Source,
RoundsList: makeRoundsList(rids...), RoundsList: makeRoundsList(rids...),
RoundURL: getRoundURL(rids[0]),
} }
return json.Marshal(sr) return json.Marshal(sr)
...@@ -517,6 +518,7 @@ func SearchUD(e2eID int, udContact []byte, cb UdSearchCallback, ...@@ -517,6 +518,7 @@ func SearchUD(e2eID int, udContact []byte, cb UdSearchCallback,
EphID: eid.EphId.Int64(), EphID: eid.EphId.Int64(),
ReceptionID: eid.Source, ReceptionID: eid.Source,
RoundsList: makeRoundsList(rids...), RoundsList: makeRoundsList(rids...),
RoundURL: getRoundURL(rids[0]),
} }
return json.Marshal(sr) return json.Marshal(sr)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment