Skip to content
Snippets Groups Projects
Commit 1708cd1a authored by Jake Taylor's avatar Jake Taylor :lips:
Browse files

Merge branch 'XX-4013/bindingsRoundList' into 'release'

XX-4013 / Bindings RoundList

See merge request !321
parents d5347ea1 9bbff0f6
No related branches found
No related tags found
2 merge requests!510Release,!321XX-4013 / Bindings RoundList
......@@ -58,8 +58,8 @@ type BroadcastMessage struct {
// "EphID":[0,0,0,0,0,0,24,61]
// }
type BroadcastReport struct {
RoundID int
EphID ephemeral.Id
RoundsList
EphID ephemeral.Id
}
// BroadcastListener is the public function type bindings can use to listen for broadcast messages.
......@@ -120,8 +120,8 @@ func (c *Channel) Listen(l BroadcastListener, method int) error {
receptionID receptionID.EphemeralIdentity, round rounds.Round) {
l.Callback(json.Marshal(&BroadcastMessage{
BroadcastReport: BroadcastReport{
RoundID: int(round.ID),
EphID: receptionID.EphId,
RoundsList: makeRoundsList(round.ID),
EphID: receptionID.EphId,
},
Payload: payload,
}))
......@@ -136,8 +136,8 @@ func (c *Channel) Broadcast(payload []byte) ([]byte, error) {
return nil, err
}
return json.Marshal(BroadcastReport{
RoundID: int(rid),
EphID: eid,
RoundsList: makeRoundsList(rid),
EphID: eid,
})
}
......@@ -153,8 +153,8 @@ func (c *Channel) BroadcastAsymmetric(payload, pk []byte) ([]byte, error) {
return nil, err
}
return json.Marshal(BroadcastReport{
RoundID: int(rid),
EphID: eid,
RoundsList: makeRoundsList(rid),
EphID: eid,
})
}
......
......@@ -37,8 +37,8 @@ func TestBroadcastMessage_JSON(t *testing.T) {
}
bm := BroadcastMessage{
BroadcastReport: BroadcastReport{
RoundID: 42,
EphID: eid,
RoundsList: makeRoundsList(42),
EphID: eid,
},
Payload: []byte("Hello, broadcast friends!"),
}
......@@ -56,8 +56,8 @@ func TestBroadcastReport_JSON(t *testing.T) {
t.Errorf("Failed to form ephemeral ID: %+v", err)
}
br := BroadcastReport{
RoundID: 42,
EphID: eid,
RoundsList: makeRoundsList(42),
EphID: eid,
}
brJson, err := json.Marshal(br)
......
......@@ -93,7 +93,7 @@ func (c *Connection) SendE2E(mt int, payload []byte) ([]byte, error) {
Timestamp: ts.UnixNano(),
}
sr.RoundsList = makeRoundsList(rounds)
sr.RoundsList = makeRoundsList(rounds...)
return json.Marshal(&sr)
}
......
......@@ -23,7 +23,7 @@ func TestE2ESendReport_JSON(t *testing.T) {
mid := e2e.MessageID{}
_, _ = rng.Read(mid[:])
origRL := []id.Round{1, 5, 9}
rl := makeRoundsList(origRL)
rl := makeRoundsList(origRL...)
mrl, _ := json.Marshal(&rl)
sr := E2ESendReport{
RoundsList: rl,
......
......@@ -22,7 +22,17 @@ import (
// Example marshalled roundList object:
// [1001,1003,1006]
type RoundsList struct {
Rounds []int
Rounds []uint64
}
// makeRoundsList converts a list of id.Round into a binding-compatable
// RoundsList.
func makeRoundsList(rounds ...id.Round) RoundsList {
rl := RoundsList{make([]uint64, len(rounds))}
for i, rid := range rounds {
rl.Rounds[i] = uint64(rid)
}
return rl
}
// Marshal JSON marshals the RoundsList.
......@@ -46,15 +56,6 @@ func unmarshalRoundsList(marshaled []byte) ([]id.Round, error) {
}
return realRl, nil
}
func makeRoundsList(rounds []id.Round) RoundsList {
rl := RoundsList{}
for _, rid := range rounds {
rl.Rounds = append(rl.Rounds, int(rid))
}
return rl
}
// MessageDeliveryCallback gets called on the determination if all events
......@@ -79,9 +80,12 @@ type MessageDeliveryCallback interface {
// This function takes the marshaled send report to ensure a memory leak does
// not occur as a result of both sides of the bindings holding a reference to
// the same pointer.
//
// roundList is a JSON marshalled RoundsList or any JSON marshalled send report
// that inherits a RoundsList object.
func (c *Cmix) WaitForMessageDelivery(
roundList []byte, mdc MessageDeliveryCallback, timeoutMS int) error {
jww.INFO.Printf("WaitForMessageDelivery(%v, _, %v)", roundList, timeoutMS)
jww.INFO.Printf("WaitForMessageDelivery(%s, _, %d)", roundList, timeoutMS)
rl, err := unmarshalRoundsList(roundList)
if err != nil {
return errors.Errorf("Failed to WaitForMessageDelivery callback due "+
......
......@@ -138,7 +138,7 @@ func (e *E2e) SendE2E(messageType int, recipientId, payload,
}
result := E2ESendReport{
RoundsList: makeRoundsList(roundIds),
RoundsList: makeRoundsList(roundIds...),
MessageID: messageId.Marshal(),
Timestamp: ts.UnixNano(),
}
......
......@@ -150,9 +150,9 @@ func (g *GroupChat) MakeGroup(membership IdList, message, name []byte) (
// Construct the group report
report := GroupReport{
Id: grp.ID.Bytes(),
Rounds: makeRoundsList(rounds).Rounds,
Status: int(status),
Id: grp.ID.Bytes(),
RoundsList: makeRoundsList(rounds...),
Status: int(status),
}
// Marshal the report
......@@ -190,9 +190,9 @@ func (g *GroupChat) ResendRequest(groupId []byte) ([]byte, error) {
// Construct the group report on resent request
report := &GroupReport{
Id: grp.ID.Bytes(),
Rounds: makeRoundsList(rnds).Rounds,
Status: int(status),
Id: grp.ID.Bytes(),
RoundsList: makeRoundsList(rnds...),
Status: int(status),
}
// Marshal the report
......@@ -261,9 +261,9 @@ func (g *GroupChat) Send(groupId,
// Construct send report
sendReport := &GroupSendReport{
RoundID: uint64(round),
Timestamp: timestamp.UnixNano(),
MessageID: msgID.Bytes(),
RoundsList: makeRoundsList(round),
Timestamp: timestamp.UnixNano(),
MessageID: msgID.Bytes(),
}
return json.Marshal(sendReport)
......@@ -426,15 +426,15 @@ func (gcp *groupChatProcessor) String() string {
// the group, a list of rounds that the group requests were sent on, and the
// status of the send operation.
type GroupReport struct {
Id []byte
Rounds []int
Id []byte
RoundsList
Status int
}
// GroupSendReport is returned when sending a group message. It contains the
// round ID sent on and the timestamp of the send operation.
type GroupSendReport struct {
RoundID uint64
RoundsList
Timestamp int64
MessageID []byte
}
......@@ -62,7 +62,7 @@ func TransmitSingleUse(e2eID int, recipient []byte, tag string, payload,
sr := SingleUseSendReport{
EphID: eid.EphId.Int64(),
ReceptionID: eid.Source.Marshal(),
RoundsList: makeRoundsList(rids),
RoundsList: makeRoundsList(rids...),
}
return json.Marshal(sr)
}
......@@ -201,7 +201,7 @@ func (sl singleUseListener) Callback(
// Todo: what other info from req needs to get to bindings
scr := SingleUseCallbackReport{
Payload: req.GetPayload(),
RoundsList: makeRoundsList(rids),
RoundsList: makeRoundsList(rids...),
Partner: req.GetPartner(),
EphID: eid.EphId.Int64(),
ReceptionID: eid.Source.Marshal(),
......@@ -239,7 +239,7 @@ func (sr singleUseResponse) Callback(payload []byte,
rids = append(rids, r.ID)
}
sendReport := SingleUseResponseReport{
RoundsList: makeRoundsList(rids),
RoundsList: makeRoundsList(rids...),
ReceptionID: receptionID.Source.Marshal(),
EphID: receptionID.EphId.Int64(),
Payload: payload,
......
......@@ -20,7 +20,7 @@ import (
func TestSingleUseJsonMarshals(t *testing.T) {
rids := []id.Round{1, 5, 9}
rl := makeRoundsList(rids)
rl := makeRoundsList(rids...)
rid := id.NewIdFromString("zezima", id.User, t)
eid, _, _, err := ephemeral.GetId(rid, 16, time.Now().UnixNano())
if err != nil {
......
......@@ -343,7 +343,7 @@ func LookupUD(e2eID int, udContact []byte, cb UdLookupCallback,
sr := SingleUseSendReport{
EphID: eid.EphId.Int64(),
ReceptionID: eid.Source.Marshal(),
RoundsList: makeRoundsList(rids),
RoundsList: makeRoundsList(rids...),
}
return json.Marshal(sr)
......@@ -424,7 +424,7 @@ func SearchUD(e2eID int, udContact []byte, cb UdSearchCallback,
sr := SingleUseSendReport{
EphID: eid.EphId.Int64(),
ReceptionID: eid.Source.Marshal(),
RoundsList: makeRoundsList(rids),
RoundsList: makeRoundsList(rids...),
}
return json.Marshal(sr)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment