diff --git a/bindings/broadcast.go b/bindings/broadcast.go index d2773904333e46902c85166f66ec5a05a4e3ee91..aa29611d44bd815803b2691884fb7ce5c10910dc 100644 --- a/bindings/broadcast.go +++ b/bindings/broadcast.go @@ -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, }) } diff --git a/bindings/broadcast_test.go b/bindings/broadcast_test.go index 48fa0bed595de2664f5b5f011d129ed53c3a97e6..5c12dff82a86193ab99cc839d57dc5d94ce93c1a 100644 --- a/bindings/broadcast_test.go +++ b/bindings/broadcast_test.go @@ -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) diff --git a/bindings/connect.go b/bindings/connect.go index 57cb090bd9d551558011e57abedc58b8f64d5abb..a384ff464c520efd12c391610373043309ddcff9 100644 --- a/bindings/connect.go +++ b/bindings/connect.go @@ -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) } diff --git a/bindings/connect_test.go b/bindings/connect_test.go index c23027b103f3261023fff389b458562047e2da04..e0f8b38cd106e79c430a5e0b3a56484e87423d7d 100644 --- a/bindings/connect_test.go +++ b/bindings/connect_test.go @@ -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, diff --git a/bindings/delivery.go b/bindings/delivery.go index a160813bf10f9f4483a0d7f75db287f1784fc070..62647578dac8b2bd98bfb1c76f3faa72e7c73900 100644 --- a/bindings/delivery.go +++ b/bindings/delivery.go @@ -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 "+ diff --git a/bindings/e2eHandler.go b/bindings/e2eHandler.go index 52e0c830f385d760e83d792b490e2c7acb0a07f4..5cac142e364055e8dfefc3bf257a5d7661a34cab 100644 --- a/bindings/e2eHandler.go +++ b/bindings/e2eHandler.go @@ -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(), } diff --git a/bindings/group.go b/bindings/group.go index 4bae7053464b4cec8683641c9940cc0b8c0717cd..fa1fcc78d8aedb44f4f006017b46d4f36734d759 100644 --- a/bindings/group.go +++ b/bindings/group.go @@ -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 } diff --git a/bindings/single.go b/bindings/single.go index ee1ea6fb74fd7f67df1105f62d6b3af4a59f7c07..f246f920fc23d988355e255c3d451908e855602c 100644 --- a/bindings/single.go +++ b/bindings/single.go @@ -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, diff --git a/bindings/single_test.go b/bindings/single_test.go index 863ff7c71a5671fd983c70ec1ead3d04acb35c70..a262a40738afe4ce73fc565ddaf259663f9d3a2e 100644 --- a/bindings/single_test.go +++ b/bindings/single_test.go @@ -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 { diff --git a/bindings/ud.go b/bindings/ud.go index c5d8fc2e75019557ef5d2199a044b4a395c9b141..dffd1ed43eeafee882b893d74421f7de6bae348a 100644 --- a/bindings/ud.go +++ b/bindings/ud.go @@ -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)