Skip to content
Snippets Groups Projects
Commit 725b4c4d authored by Richard T. Carback III's avatar Richard T. Carback III
Browse files

Syntax and compilation error fixes

parent c333478f
No related branches found
No related tags found
4 merge requests!60Revert "Fail a test to be sure it works",!48Finalize DM,!36project/DM,!32Admin Commands
......@@ -13,11 +13,12 @@ import (
"crypto/ed25519"
"encoding/base64"
"encoding/json"
"gitlab.com/elixxir/xxdk-wasm/indexedDb"
"sync"
"syscall/js"
"time"
"gitlab.com/elixxir/xxdk-wasm/indexedDb"
"github.com/hack-pad/go-indexeddb/idb"
"github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman"
......@@ -26,6 +27,7 @@ import (
"gitlab.com/elixxir/client/v4/cmix/rounds"
cryptoBroadcast "gitlab.com/elixxir/crypto/broadcast"
cryptoChannel "gitlab.com/elixxir/crypto/channel"
"gitlab.com/elixxir/crypto/message"
"gitlab.com/elixxir/xxdk-wasm/utils"
"gitlab.com/xx_network/primitives/id"
)
......@@ -166,7 +168,7 @@ func (w *wasmModel) deleteMsgByChannel(channelID *id.ID) error {
// It may be called multiple times on the same message; it is incumbent on the
// user of the API to filter such called by message ID.
func (w *wasmModel) ReceiveMessage(channelID *id.ID,
messageID cryptoChannel.MessageID, nickname, text string,
messageID message.ID, nickname, text string,
pubKey ed25519.PublicKey, dmToken uint32, codeset uint8,
timestamp time.Time, lease time.Duration, round rounds.Round,
mType channels.MessageType, status channels.SentStatus) uint64 {
......@@ -202,7 +204,7 @@ func (w *wasmModel) ReceiveMessage(channelID *id.ID,
// Messages may arrive our of order, so a reply, in theory, can arrive before
// the initial message. As a result, it may be important to buffer replies.
func (w *wasmModel) ReceiveReply(channelID *id.ID,
messageID cryptoChannel.MessageID, replyTo cryptoChannel.MessageID,
messageID message.ID, replyTo message.ID,
nickname, text string, pubKey ed25519.PublicKey, dmToken uint32, codeset uint8,
timestamp time.Time, lease time.Duration, round rounds.Round,
mType channels.MessageType, status channels.SentStatus) uint64 {
......@@ -238,7 +240,7 @@ func (w *wasmModel) ReceiveReply(channelID *id.ID,
// Messages may arrive our of order, so a reply, in theory, can arrive before
// the initial message. As a result, it may be important to buffer reactions.
func (w *wasmModel) ReceiveReaction(channelID *id.ID,
messageID cryptoChannel.MessageID, reactionTo cryptoChannel.MessageID,
messageID message.ID, reactionTo message.ID,
nickname, reaction string, pubKey ed25519.PublicKey, dmToken uint32, codeset uint8,
timestamp time.Time, lease time.Duration, round rounds.Round,
mType channels.MessageType, status channels.SentStatus) uint64 {
......@@ -272,7 +274,7 @@ func (w *wasmModel) ReceiveReaction(channelID *id.ID,
//
// TODO: Potential race condition due to separate get/update operations.
func (w *wasmModel) UpdateSentStatus(uuid uint64,
messageID cryptoChannel.MessageID, timestamp time.Time, round rounds.Round,
messageID message.ID, timestamp time.Time, round rounds.Round,
status channels.SentStatus) {
parentErr := errors.New("failed to UpdateSentStatus")
......@@ -303,7 +305,7 @@ func (w *wasmModel) UpdateSentStatus(uuid uint64,
}
newMessage.Status = uint8(status)
if !messageID.Equals(cryptoChannel.MessageID{}) {
if !messageID.Equals(message.ID{}) {
newMessage.MessageID = messageID.Bytes()
}
......@@ -387,7 +389,7 @@ func (w *wasmModel) receiveHelper(newMessage *Message, isUpdate bool) (uint64,
// NOTE: Sometimes the insert fails to return an error but hits a duplicate
// insert, so this fallthrough returns the UUID entry in that case.
if res.IsUndefined() {
msgID := cryptoChannel.MessageID{}
msgID := message.ID{}
copy(msgID[:], newMessage.MessageID)
uuid, errLookup := w.msgIDLookup(msgID)
if uuid != 0 && errLookup == nil {
......@@ -402,7 +404,7 @@ func (w *wasmModel) receiveHelper(newMessage *Message, isUpdate bool) (uint64,
}
// msgIDLookup gets the UUID of the Message with the given messageID.
func (w *wasmModel) msgIDLookup(messageID cryptoChannel.MessageID) (uint64,
func (w *wasmModel) msgIDLookup(messageID message.ID) (uint64,
error) {
msgIDStr := js.ValueOf(base64.StdEncoding.EncodeToString(messageID.Bytes()))
resultObj, err := indexedDb.GetIndex(w.db, messageStoreName,
......
......@@ -12,20 +12,21 @@ package channels
import (
"encoding/json"
"fmt"
"github.com/hack-pad/go-indexeddb/idb"
"gitlab.com/elixxir/xxdk-wasm/indexedDb"
"gitlab.com/elixxir/xxdk-wasm/storage"
"gitlab.com/xx_network/primitives/netTime"
"os"
"strconv"
"testing"
"time"
"github.com/hack-pad/go-indexeddb/idb"
"gitlab.com/elixxir/xxdk-wasm/indexedDb"
"gitlab.com/elixxir/xxdk-wasm/storage"
"gitlab.com/xx_network/primitives/netTime"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/v4/channels"
"gitlab.com/elixxir/client/v4/cmix/rounds"
cryptoBroadcast "gitlab.com/elixxir/crypto/broadcast"
"gitlab.com/elixxir/crypto/channel"
"gitlab.com/elixxir/crypto/message"
"gitlab.com/xx_network/primitives/id"
)
......@@ -40,14 +41,15 @@ func dummyCallback(uint64, *id.ID, bool) {}
func TestWasmModel_msgIDLookup(t *testing.T) {
storage.GetLocalStorage().Clear()
testString := "test"
testMsgId := channel.MakeMessageID([]byte(testString), &id.ID{1})
testMsgId := message.DeriveChannelMessageID(&id.ID{1}, 0,
[]byte(testString))
eventModel, err := newWASMModel(testString, nil, dummyCallback)
if err != nil {
t.Fatalf("%+v", err)
}
testMsg := buildMessage([]byte(testString), testMsgId.Bytes(), nil,
testString, []byte(testString), []byte{8, 6, 7, 5}, 0, netTime.Now(),
testString, []byte(testString), []byte{8, 6, 7, 5}, 0, 0, netTime.Now(),
time.Second, 0, 0, channels.Sent)
_, err = eventModel.receiveHelper(testMsg, false)
if err != nil {
......@@ -67,7 +69,8 @@ func TestWasmModel_msgIDLookup(t *testing.T) {
func Test_wasmModel_UpdateSentStatus(t *testing.T) {
storage.GetLocalStorage().Clear()
testString := "test"
testMsgId := channel.MakeMessageID([]byte(testString), &id.ID{1})
testMsgId := message.DeriveChannelMessageID(&id.ID{1}, 0,
[]byte(testString))
eventModel, err := newWASMModel(testString, nil, dummyCallback)
if err != nil {
t.Fatalf("%+v", err)
......@@ -172,7 +175,7 @@ func Test_wasmModel_UUIDTest(t *testing.T) {
for i := 0; i < 10; i++ {
// Store a test message
channelID := id.NewIdFromBytes([]byte(testString), t)
msgID := channel.MessageID{}
msgID := message.ID{}
copy(msgID[:], testString+fmt.Sprintf("%d", i))
rnd := rounds.Round{ID: id.Round(42)}
uuid := eventModel.ReceiveMessage(channelID, msgID, "test",
......@@ -202,7 +205,7 @@ func Test_wasmModel_DuplicateReceives(t *testing.T) {
uuids := make([]uint64, 10)
msgID := channel.MessageID{}
msgID := message.ID{}
copy(msgID[:], testString)
for i := 0; i < 10; i++ {
// Store a test message
......@@ -250,7 +253,7 @@ func Test_wasmModel_deleteMsgByChannel(t *testing.T) {
thisChannel = keepChannel
}
testMsgId := channel.MakeMessageID([]byte(testStr), &id.ID{1})
testMsgId := message.DeriveChannelMessageID(&id.ID{1}, 0, []byte(testStr))
eventModel.ReceiveMessage(thisChannel, testMsgId, testStr, testStr,
[]byte{8, 6, 7, 5}, 0, 0, netTime.Now(), time.Second,
rounds.Round{ID: id.Round(0)}, 0, channels.Sent)
......@@ -312,7 +315,8 @@ func TestWasmModel_receiveHelper_UniqueIndex(t *testing.T) {
}
// First message insert should succeed
testMsgId := channel.MakeMessageID([]byte(testString), &id.ID{1})
testMsgId := message.DeriveChannelMessageID(&id.ID{1}, 0,
[]byte(testString))
testMsg := buildMessage([]byte(testString), testMsgId.Bytes(), nil,
testString, []byte(testString), []byte{8, 6, 7, 5}, 0, 0, netTime.Now(),
time.Second, 0, 0, channels.Sent)
......@@ -335,7 +339,8 @@ func TestWasmModel_receiveHelper_UniqueIndex(t *testing.T) {
}
// Now insert a message with a different message ID from the first
testMsgId2 := channel.MakeMessageID([]byte(testString), &id.ID{2})
testMsgId2 := message.DeriveChannelMessageID(&id.ID{2}, 0,
[]byte(testString))
testMsg = buildMessage([]byte(testString), testMsgId2.Bytes(), nil,
testString, []byte(testString), []byte{8, 6, 7, 5}, 0, 0, netTime.Now(),
time.Second, 0, 0, channels.Sent)
......
......@@ -12,6 +12,10 @@ package channelEventModel
import (
"crypto/ed25519"
"encoding/json"
"sync"
"syscall/js"
"time"
"github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/v4/cmix/rounds"
......@@ -19,12 +23,10 @@ import (
"gitlab.com/elixxir/xxdk-wasm/indexedDb"
"gitlab.com/elixxir/xxdk-wasm/utils"
"gitlab.com/xx_network/primitives/id"
"sync"
"syscall/js"
"time"
"github.com/hack-pad/go-indexeddb/idb"
cryptoChannel "gitlab.com/elixxir/crypto/channel"
"gitlab.com/elixxir/crypto/message"
)
// wasmModel implements [dm.Receiver] interface, which uses the channels
......@@ -92,7 +94,7 @@ func buildMessage(messageID, parentID []byte, text []byte,
}
}
func (w *wasmModel) Receive(messageID dm.MessageID, nickname string, text []byte,
func (w *wasmModel) Receive(messageID message.ID, nickname string, text []byte,
pubKey ed25519.PublicKey, dmToken uint32, codeset uint8, timestamp time.Time,
round rounds.Round, mType dm.MessageType, status dm.Status) uint64 {
parentErr := errors.New("failed to Receive")
......@@ -104,7 +106,7 @@ func (w *wasmModel) Receive(messageID dm.MessageID, nickname string, text []byte
jww.ERROR.Printf("%+v", errors.WithMessagef(parentErr,
"Unable to get Conversation: %+v", err))
return 0
} else if len(result) == 0 {
} else if len(result.String()) == 0 {
err = w.joinConversation(nickname, pubKey, dmToken, codeset)
jww.ERROR.Printf("%+v", err)
return 0
......@@ -132,7 +134,7 @@ func (w *wasmModel) Receive(messageID dm.MessageID, nickname string, text []byte
return uuid
}
func (w *wasmModel) ReceiveText(messageID dm.MessageID, nickname, text string,
func (w *wasmModel) ReceiveText(messageID message.ID, nickname, text string,
pubKey ed25519.PublicKey, dmToken uint32, codeset uint8, timestamp time.Time,
round rounds.Round, status dm.Status) uint64 {
parentErr := errors.New("failed to ReceiveText")
......@@ -144,7 +146,7 @@ func (w *wasmModel) ReceiveText(messageID dm.MessageID, nickname, text string,
jww.ERROR.Printf("%+v", errors.WithMessagef(parentErr,
"Unable to get Conversation: %+v", err))
return 0
} else if len(result) == 0 {
} else if len(result.String()) == 0 {
err = w.joinConversation(nickname, pubKey, dmToken, codeset)
jww.ERROR.Printf("%+v", err)
return 0
......@@ -174,7 +176,7 @@ func (w *wasmModel) ReceiveText(messageID dm.MessageID, nickname, text string,
return uuid
}
func (w *wasmModel) ReceiveReply(messageID dm.MessageID, reactionTo dm.MessageID,
func (w *wasmModel) ReceiveReply(messageID message.ID, reactionTo message.ID,
nickname, text string, pubKey ed25519.PublicKey, dmToken uint32, codeset uint8,
timestamp time.Time, round rounds.Round, status dm.Status) uint64 {
parentErr := errors.New("failed to ReceiveReply")
......@@ -186,7 +188,7 @@ func (w *wasmModel) ReceiveReply(messageID dm.MessageID, reactionTo dm.MessageID
jww.ERROR.Printf("%+v", errors.WithMessagef(parentErr,
"Unable to get Conversation: %+v", err))
return 0
} else if len(result) == 0 {
} else if len(result.String()) == 0 {
err = w.joinConversation(nickname, pubKey, dmToken, codeset)
jww.ERROR.Printf("%+v", err)
return 0
......@@ -216,7 +218,7 @@ func (w *wasmModel) ReceiveReply(messageID dm.MessageID, reactionTo dm.MessageID
return uuid
}
func (w *wasmModel) ReceiveReaction(messageID dm.MessageID, reactionTo dm.MessageID,
func (w *wasmModel) ReceiveReaction(messageID message.ID, reactionTo message.ID,
nickname, reaction string, pubKey ed25519.PublicKey, dmToken uint32,
codeset uint8, timestamp time.Time, round rounds.Round, status dm.Status) uint64 {
parentErr := errors.New("failed to ReceiveText")
......@@ -228,7 +230,7 @@ func (w *wasmModel) ReceiveReaction(messageID dm.MessageID, reactionTo dm.Messag
jww.ERROR.Printf("%+v", errors.WithMessagef(parentErr,
"Unable to get Conversation: %+v", err))
return 0
} else if len(result) == 0 {
} else if len(result.String()) == 0 {
err = w.joinConversation(nickname, pubKey, dmToken, codeset)
jww.ERROR.Printf("%+v", err)
return 0
......@@ -258,7 +260,7 @@ func (w *wasmModel) ReceiveReaction(messageID dm.MessageID, reactionTo dm.Messag
return uuid
}
func (w *wasmModel) UpdateSentStatus(uuid uint64, messageID dm.MessageID,
func (w *wasmModel) UpdateSentStatus(uuid uint64, messageID message.ID,
timestamp time.Time, round rounds.Round, status dm.Status) {
parentErr := errors.New("failed to UpdateSentStatus")
......@@ -279,12 +281,12 @@ func (w *wasmModel) UpdateSentStatus(uuid uint64, messageID dm.MessageID,
// Extract the existing Message and update the Status
newMessage := &Message{}
err = json.Unmarshal([]byte(currentMsg), newMessage)
err = json.Unmarshal([]byte(currentMsg.String()), newMessage)
if err != nil {
return
}
newMessage.Status = uint8(status)
if !messageID.Equals(dm.MessageID{}) {
if !messageID.Equals(message.ID{}) {
newMessage.MessageID = messageID.Bytes()
}
......@@ -336,7 +338,7 @@ func (w *wasmModel) receiveHelper(newMessage *Message, isUpdate bool) (uint64,
// NOTE: Sometimes the insert fails to return an error but hits a duplicate
// insert, so this fallthrough returns the UUID entry in that case.
if res.IsUndefined() {
msgID := cryptoChannel.MessageID{}
msgID := message.ID{}
copy(msgID[:], newMessage.MessageID)
uuid, errLookup := w.msgIDLookup(msgID)
if uuid != 0 && errLookup == nil {
......@@ -351,7 +353,7 @@ func (w *wasmModel) receiveHelper(newMessage *Message, isUpdate bool) (uint64,
}
// msgIDLookup gets the UUID of the Message with the given messageID.
func (w *wasmModel) msgIDLookup(messageID cryptoChannel.MessageID) (uint64,
func (w *wasmModel) msgIDLookup(messageID message.ID) (uint64,
error) {
resultObj, err := indexedDb.GetIndex(w.db, messageStoreName,
messageStoreMessageIndex, utils.CopyBytesToJS(messageID.Marshal()))
......
......@@ -23,11 +23,11 @@ import (
"gitlab.com/elixxir/client/v4/restlike"
"gitlab.com/elixxir/client/v4/single"
"gitlab.com/elixxir/crypto/broadcast"
"gitlab.com/elixxir/crypto/channel"
"gitlab.com/elixxir/crypto/contact"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/fileTransfer"
"gitlab.com/elixxir/crypto/group"
cryptoMessage "gitlab.com/elixxir/crypto/message"
"gitlab.com/elixxir/primitives/fact"
"gitlab.com/elixxir/primitives/format"
"gitlab.com/xx_network/primitives/id"
......@@ -50,7 +50,7 @@ var (
_ = connect.Callback(nil)
_ = partner.Manager(nil)
_ = ndf.NetworkDefinition{}
_ = channel.MessageID{}
_ = cryptoMessage.ID{}
_ = channels.SentStatus(0)
_ = ftE2e.Params{}
_ = fileTransfer.TransferID{}
......
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