Contact struct removed from peer
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
ycc 2024-02-10 22:36:25 +01:00
parent 24183ff581
commit 0fd7548ba4
5 changed files with 44 additions and 30 deletions

View File

@ -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

View File

@ -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
}

View File

@ -26,7 +26,7 @@ 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
//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"`
@ -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

View File

@ -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")

View File

@ -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
}
}