From 0fd7548ba402e57fade886c6e66bdb8957e5877c Mon Sep 17 00:00:00 2001 From: ycc Date: Sat, 10 Feb 2024 22:36:25 +0100 Subject: [PATCH] Contact struct removed from peer --- client/identity.go | 28 +++++++++++++++++++++------- client/identity_test.go | 10 +++++----- client/peer.go | 30 +++++++++++++++--------------- client/peer_test.go | 2 +- client/peerlist.go | 4 ++-- 5 files changed, 44 insertions(+), 30 deletions(-) diff --git a/client/identity.go b/client/identity.go index 0c2e5cd..fbbf80d 100644 --- a/client/identity.go +++ b/client/identity.go @@ -98,7 +98,14 @@ func (id *Identity) AnswerInvitation(MyName string, ContactName string, MessageS } else { peer.Name = ReceivedContact.Name } - peer.Contact = *ReceivedContact + peer.ContactEncryption = ReceivedContact.EncryptionPublicKey + peer.ContactLookupKey = ReceivedContact.LookupPublicKey + peer.ContactPublicKey = ReceivedContact.ContactPublicKey + peer.InvitationId = ReceivedContact.InvitationId + peer.InvitationMessage = ReceivedContact.InvitationMessage + for srv := range ReceivedContact.PullServers { + peer.ContactPullServers = append(peer.ContactPullServers, ReceivedContact.PullServers[srv].GetUid()) + } /* for _, i := range MessageServerIdxs { srv := id.MessageServers.Servers[i].GetServerCard() peer.MyContact.PullServers = append(peer.MyContact.PullServers, srv) @@ -119,7 +126,14 @@ func (id *Identity) AnswerInvitation(MyName string, ContactName string, MessageS func (id *Identity) FinalizeInvitation(ReceivedContact *meowlib.ContactCard) error { for i, p := range id.Peers { if p.InvitationId == ReceivedContact.InvitationId { - id.Peers[i].Contact = *ReceivedContact + //id.Peers[i].Name = ReceivedContact.Name + id.Peers[i].ContactEncryption = ReceivedContact.EncryptionPublicKey + id.Peers[i].ContactLookupKey = ReceivedContact.LookupPublicKey + id.Peers[i].ContactPublicKey = ReceivedContact.ContactPublicKey + for srv := range ReceivedContact.PullServers { + id.Peers[i].ContactPullServers = append(id.Peers[i].ContactPullServers, ReceivedContact.PullServers[srv].GetUid()) + } + return nil } } @@ -206,11 +220,11 @@ func (id *Identity) generateRandomHiddenStuff() { p.MyEncryptionKp = meowlib.NewKeyPair() p.MyIdentity = meowlib.NewKeyPair() p.MyLookupKp = meowlib.NewKeyPair() - p.Contact.Name = randomLenString(4, 20) - p.Contact.ContactPublicKey = p.MyLookupKp.Public - p.Contact.EncryptionPublicKey = p.MyIdentity.Public - p.Contact.LookupPublicKey = p.MyEncryptionKp.Public - p.Contact.AddUrls([]string{randomLenString(14, 60), randomLenString(14, 60)}) + p.Name = randomLenString(4, 20) + p.ContactPublicKey = p.MyLookupKp.Public + 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.HidePeer(0, randomLenString(8, 14)) // TODO Add random conversations diff --git a/client/identity_test.go b/client/identity_test.go index 046dcef..f01aa0d 100644 --- a/client/identity_test.go +++ b/client/identity_test.go @@ -33,11 +33,11 @@ func createId() *Identity { p.MyEncryptionKp = meowlib.NewKeyPair() p.MyIdentity = meowlib.NewKeyPair() p.MyLookupKp = meowlib.NewKeyPair() - p.Contact.Name = "foo" - p.Contact.ContactPublicKey = p.MyLookupKp.Public - p.Contact.EncryptionPublicKey = p.MyIdentity.Public - p.Contact.LookupPublicKey = p.MyEncryptionKp.Public - p.Contact.AddUrls([]string{"http:/127.0.0.1/meow", "tcp://localhost:1234"}) + p.Name = "foo" + p.ContactPublicKey = p.MyLookupKp.Public + 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) return id } diff --git a/client/peer.go b/client/peer.go index 76e4c1d..aa0c183 100644 --- a/client/peer.go +++ b/client/peer.go @@ -26,15 +26,15 @@ type Peer struct { MyLookupKp meowlib.KeyPair `json:"my_lookup_kp,omitempty"` MyPullServers []string `json:"my_pull_servers,omitempty"` // Peer keys and infos - Contact meowlib.ContactCard `json:"contact,omitempty"` // todo : remove - ContactPublicKey string `json:"contact_public_key,omitempty"` - ContactLookupKey string `json:"contact_lookup_key,omitempty"` - ContactEncryption string `json:"contact_encryption,omitempty"` - ContactPullServers []string `json:"contact_pull_servers,omitempty"` - InvitationId string `json:"invitation_id,omitempty"` - InvitationUrl string `json:"invitation_url,omitempty"` - InvitationMessage string `json:"invitation_message,omitempty"` - InvitationExpiry time.Time `json:"invitation_expiry,omitempty"` + //Contact meowlib.ContactCard `json:"contact,omitempty"` // todo : remove + ContactPublicKey string `json:"contact_public_key,omitempty"` + ContactLookupKey string `json:"contact_lookup_key,omitempty"` + ContactEncryption string `json:"contact_encryption,omitempty"` + ContactPullServers []string `json:"contact_pull_servers,omitempty"` + InvitationId string `json:"invitation_id,omitempty"` + InvitationUrl string `json:"invitation_url,omitempty"` + InvitationMessage string `json:"invitation_message,omitempty"` + InvitationExpiry time.Time `json:"invitation_expiry,omitempty"` // Internal management attributes Visible bool `json:"visible,omitempty"` VisiblePassword string `json:"visible_password,omitempty"` @@ -86,7 +86,7 @@ func (p *Peer) GetContact() *meowlib.ContactCard { func (p *Peer) BuildSimpleUserMessage(message []byte) (*meowlib.UserMessage, error) { var msg meowlib.UserMessage - msg.Destination = p.Contact.LookupPublicKey + msg.Destination = p.ContactLookupKey msg.From = p.MyIdentity.Public msg.Data = message msg.Type = "1" @@ -122,7 +122,7 @@ func (p *Peer) BuildSingleFileMessage(filename string, message []byte) ([]meowli } var msg meowlib.UserMessage var file meowlib.File - msg.Destination = p.Contact.LookupPublicKey + msg.Destination = p.ContactLookupKey msg.From = p.MyIdentity.Public file.Filename = fi.Name() file.Chunk = uint32(chunk) @@ -151,7 +151,7 @@ func (p *Peer) BuildInvitationAnswerMessage(myContactCard *meowlib.ContactCard) return nil, err } invitation.Payload = out - msg.Destination = p.Contact.LookupPublicKey + msg.Destination = p.ContactLookupKey msg.From = p.MyIdentity.Public msg.Type = "1" return &msg, nil @@ -181,7 +181,7 @@ func (p *Peer) DeserializeUserMessage(data []byte) (*meowlib.UserMessage, error) // AsymEncryptMessage prepares a message to send to a specific peer contact func (p *Peer) AsymEncryptMessage(Message []byte) (*meowlib.EncryptedMessage, error) { var enc *meowlib.EncryptedMessage - enc, err := meowlib.AsymEncryptAndSign(p.Contact.EncryptionPublicKey, p.MyIdentity.Private, Message) + enc, err := meowlib.AsymEncryptAndSign(p.ContactEncryption, p.MyIdentity.Private, Message) if err != nil { fmt.Println(err.Error()) return enc, err @@ -191,7 +191,7 @@ func (p *Peer) AsymEncryptMessage(Message []byte) (*meowlib.EncryptedMessage, er // AsymDecryptMessage reads a message from a specific peer contact func (p *Peer) AsymDecryptMessage(Message []byte, Signature []byte) (DecryptedMessage []byte, err error) { - DecryptedMessage, err = meowlib.AsymDecryptAndCheck(p.MyEncryptionKp.Private, p.Contact.ContactPublicKey, Message, Signature) + DecryptedMessage, err = meowlib.AsymDecryptAndCheck(p.MyEncryptionKp.Private, p.ContactPublicKey, Message, Signature) if err != nil { fmt.Println(err.Error()) return nil, err @@ -202,7 +202,7 @@ func (p *Peer) AsymDecryptMessage(Message []byte, Signature []byte) (DecryptedMe // PackUserMessage will package the previously encrypted message func (p *Peer) PackUserMessage(message []byte, signature []byte) *meowlib.PackedUserMessage { var msg meowlib.PackedUserMessage - msg.Destination = p.Contact.LookupPublicKey + msg.Destination = p.ContactLookupKey msg.Payload = message msg.Signature = signature return &msg diff --git a/client/peer_test.go b/client/peer_test.go index 5a247d5..eaec421 100644 --- a/client/peer_test.go +++ b/client/peer_test.go @@ -13,7 +13,7 @@ func TestGetFromPublicKey(t *testing.T) { for i := 1; i < 10; i++ { var p Peer p.Name = "test" + strconv.Itoa(i) - p.Contact.ContactPublicKey = "stringToFind" + strconv.Itoa(i) + p.ContactPublicKey = "stringToFind" + strconv.Itoa(i) id.Peers = append(id.Peers, p) } p5 := id.Peers.GetFromPublicKey("stringToFind5") diff --git a/client/peerlist.go b/client/peerlist.go index f64f3a9..fde0ef5 100644 --- a/client/peerlist.go +++ b/client/peerlist.go @@ -8,7 +8,7 @@ type PeerList []Peer func (pl *PeerList) GetFromPublicKey(publickey string) *Peer { for _, peer := range *pl { - if peer.Contact.ContactPublicKey == publickey { + if peer.ContactPublicKey == publickey { return &peer } } @@ -26,7 +26,7 @@ func (pl *PeerList) GetFromMyLookupKey(publickey string) *Peer { func (pl *PeerList) GetFromName(name string) *Peer { for _, peer := range *pl { - if peer.Contact.Name == name { + if peer.Name == name { return &peer } }