From 3467ea15d922562f82d7ef48ecfa7180d2febff5 Mon Sep 17 00:00:00 2001 From: ycc Date: Sat, 2 Mar 2024 10:07:59 +0100 Subject: [PATCH] Change Peers to * Peers in identity to retrieve pointer to the real peer --- client/identity.go | 8 ++++---- client/identity_test.go | 6 +++--- client/message.go | 20 ++++++++++---------- client/messagestorage_test.go | 8 ++++---- client/peer_test.go | 2 +- client/peerlist.go | 8 ++++---- 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/client/identity.go b/client/identity.go index 5bc38ff..c71ea08 100644 --- a/client/identity.go +++ b/client/identity.go @@ -71,7 +71,7 @@ func (id *Identity) InvitePeer(MyName string, ContactName string, MessageServerU peer.MyPullServers = MessageServerUids peer.MyName = MyName peer.InvitationMessage = InvitationMessage - id.Peers = append(id.Peers, peer) + id.Peers = append(id.Peers, &peer) return &peer, nil } @@ -120,7 +120,7 @@ func (id *Identity) AnswerInvitation(MyName string, ContactName string, MessageS peer.MyPullServers = MessageServerIdxs peer.MyName = MyName peer.InvitationId = ReceivedContact.InvitationId - id.Peers = append(id.Peers, peer) + id.Peers = append(id.Peers, &peer) return &peer } @@ -189,7 +189,7 @@ func (id *Identity) TryUnlockHidden(password string) error { return err } p.dbPassword = password - id.unlockedHiddenPeers = append(id.unlockedHiddenPeers, p) + id.unlockedHiddenPeers = append(id.unlockedHiddenPeers, &p) found = true } } @@ -229,7 +229,7 @@ func (id *Identity) generateRandomHiddenStuff() { p.ContactEncryption = p.MyIdentity.Public p.ContactLookupKey = p.MyEncryptionKp.Public // p.Contact.AddUrls([]string{randomLenString(14, 60), randomLenString(14, 60)}) // todo add servers - id.Peers = append(id.Peers, p) + id.Peers = append(id.Peers, &p) id.HidePeer(0, randomLenString(8, 14)) // TODO Add random conversations } diff --git a/client/identity_test.go b/client/identity_test.go index ec1f39b..3a82bf9 100644 --- a/client/identity_test.go +++ b/client/identity_test.go @@ -39,7 +39,7 @@ func createId() *Identity { p.ContactEncryption = p.MyIdentity.Public p.ContactLookupKey = p.MyEncryptionKp.Public //p.Contact.AddUrls([]string{"http:/127.0.0.1/meow", "tcp://localhost:1234"}) //todo add servers - id.Peers = append(id.Peers, p) + id.Peers = append(id.Peers, &p) return id } @@ -85,7 +85,7 @@ func TestHidePeer(t *testing.T) { func TestGetRequestJobs(t *testing.T) { // Create a mock Identity object id := &Identity{ - Peers: []Peer{ + Peers: []*Peer{ { MyPullServers: []string{"server1", "server2"}, MyLookupKp: meowlib.NewKeyPair(), @@ -95,7 +95,7 @@ func TestGetRequestJobs(t *testing.T) { MyLookupKp: meowlib.NewKeyPair(), }, }, - unlockedHiddenPeers: []Peer{ + unlockedHiddenPeers: []*Peer{ { MyPullServers: []string{"server5", "server6"}, MyLookupKp: meowlib.NewKeyPair(), diff --git a/client/message.go b/client/message.go index 1e563dc..a3b56f0 100644 --- a/client/message.go +++ b/client/message.go @@ -8,17 +8,17 @@ const ( ) type InternalUserMessage struct { - Outbound bool // 0 = inbound, 1 = outbound - Messagetype string - Message string - ConversationStatus *meowlib.ConversationStatus - Contact *meowlib.ContactCard + Outbound bool `json:"outbound,omitempty"` // 0 = inbound, 1 = outbound + Messagetype string `json:"messagetype,omitempty"` + Message string `json:"message,omitempty"` + ConversationStatus *meowlib.ConversationStatus `json:"conversation_status,omitempty"` + Contact *meowlib.ContactCard `json:"contact,omitempty"` //Group group - FilePaths []string - CurrentLocation *meowlib.Location - Appdata []byte - Dbfile string - Dbid int64 + FilePaths []string `json:"file_paths,omitempty"` + CurrentLocation *meowlib.Location `json:"current_location,omitempty"` + Appdata []byte `json:"appdata,omitempty"` + Dbfile string `json:"dbfile,omitempty"` + Dbid int64 `json:"dbid,omitempty"` } // InternalUserMessageFromUserMessage creates an InternalUserMessage from a UserMessage diff --git a/client/messagestorage_test.go b/client/messagestorage_test.go index 439de42..7db6ad8 100644 --- a/client/messagestorage_test.go +++ b/client/messagestorage_test.go @@ -14,11 +14,11 @@ func TestStoreMessage(t *testing.T) { id := createId() var um meowlib.UserMessage um.Data = []byte("blabla") - err := StoreMessage(&id.Peers[0], &um, []string{}, GetConfig().memoryPassword) + err := StoreMessage(id.Peers[0], &um, []string{}, GetConfig().memoryPassword) if err != nil { log.Fatal(err) } - messages, err := GetMessagesHistory(&id.Peers[0], 0, 0, 10, GetConfig().memoryPassword) + messages, err := GetMessagesHistory(id.Peers[0], 0, 0, 10, GetConfig().memoryPassword) if err != nil { log.Fatal(err) } @@ -45,12 +45,12 @@ func TestManyStoreMessage(t *testing.T) { for i := 1; i < 100; i++ { var um meowlib.UserMessage um.Data = []byte(randomLenString(20, 200)) - err := StoreMessage(&id.Peers[0], &um, []string{}, GetConfig().memoryPassword) + err := StoreMessage(id.Peers[0], &um, []string{}, GetConfig().memoryPassword) if err != nil { log.Fatal(err) } } - messages, err := GetMessagesHistory(&id.Peers[0], 0, 0, 10, GetConfig().memoryPassword) + messages, err := GetMessagesHistory(id.Peers[0], 0, 0, 10, GetConfig().memoryPassword) if err != nil { log.Fatal(err) } diff --git a/client/peer_test.go b/client/peer_test.go index eaec421..0cf3f85 100644 --- a/client/peer_test.go +++ b/client/peer_test.go @@ -14,7 +14,7 @@ func TestGetFromPublicKey(t *testing.T) { var p Peer p.Name = "test" + strconv.Itoa(i) p.ContactPublicKey = "stringToFind" + strconv.Itoa(i) - id.Peers = append(id.Peers, p) + id.Peers = append(id.Peers, &p) } p5 := id.Peers.GetFromPublicKey("stringToFind5") assert.Equal(t, p5.Name, "test5") diff --git a/client/peerlist.go b/client/peerlist.go index fde0ef5..8c81532 100644 --- a/client/peerlist.go +++ b/client/peerlist.go @@ -4,12 +4,12 @@ import ( "forge.redroom.link/yves/meowlib" ) -type PeerList []Peer +type PeerList []*Peer func (pl *PeerList) GetFromPublicKey(publickey string) *Peer { for _, peer := range *pl { if peer.ContactPublicKey == publickey { - return &peer + return peer } } return nil @@ -18,7 +18,7 @@ func (pl *PeerList) GetFromPublicKey(publickey string) *Peer { func (pl *PeerList) GetFromMyLookupKey(publickey string) *Peer { for _, peer := range *pl { if peer.MyLookupKp.Public == publickey { - return &peer + return peer } } return nil @@ -27,7 +27,7 @@ func (pl *PeerList) GetFromMyLookupKey(publickey string) *Peer { func (pl *PeerList) GetFromName(name string) *Peer { for _, peer := range *pl { if peer.Name == name { - return &peer + return peer } } return nil