From 09988458171de806b58ee072c632d6c366a6c862 Mon Sep 17 00:00:00 2001 From: ycc Date: Sun, 31 Dec 2023 10:24:15 +0100 Subject: [PATCH] Invitation process store my server card+ server invitation fields --- client/identity.go | 23 +++++++++++------------ client/peer.go | 7 +++++-- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/client/identity.go b/client/identity.go index c30bedb..57b9e3d 100644 --- a/client/identity.go +++ b/client/identity.go @@ -43,34 +43,33 @@ func CreateIdentity(nickname string) *Identity { } // Creates an invitation for a peer, returns the peer containing -func (id *Identity) InvitePeer(MyName string, ContactName string, MessageServerIdxs []int) (*Peer, *meowlib.ContactCard, error) { +func (id *Identity) InvitePeer(MyName string, ContactName string, MessageServerIdxs []int) (*Peer, error) { var peer Peer - var myContactCard meowlib.ContactCard peer.MyIdentity = meowlib.NewKeyPair() peer.MyEncryptionKp = meowlib.NewKeyPair() peer.MyLookupKp = meowlib.NewKeyPair() peer.Name = ContactName - peer.InvitationId = uuid.New().String() + peer.InvitationId = uuid.New().String() // todo as param to identify then update url if id.MessageServers.Servers == nil { - return nil, nil, errors.New("no message servers defined in your identity") + return nil, errors.New("no message servers defined in your identity") } for _, i := range MessageServerIdxs { if i > len(id.MessageServers.Servers)-1 { - return nil, nil, errors.New("requested server out of range of defined message servers") + return nil, errors.New("requested server out of range of defined message servers") } } for _, i := range MessageServerIdxs { srv := &id.MessageServers.Servers[i].ServerData - myContactCard.PullServers = append(myContactCard.PullServers, srv) + peer.MyContact.PullServers = append(peer.MyContact.PullServers, srv) } - myContactCard.Name = MyName - myContactCard.ContactPublicKey = peer.MyIdentity.Public - myContactCard.EncryptionPublicKey = peer.MyEncryptionKp.Public - myContactCard.LookupPublicKey = peer.MyLookupKp.Public - myContactCard.InvitationId = peer.InvitationId + peer.MyContact.Name = MyName + peer.MyContact.ContactPublicKey = peer.MyIdentity.Public + peer.MyContact.EncryptionPublicKey = peer.MyEncryptionKp.Public + peer.MyContact.LookupPublicKey = peer.MyLookupKp.Public + peer.MyContact.InvitationId = peer.InvitationId id.Peers = append(id.Peers, peer) - return &peer, &myContactCard, nil + return &peer, nil } func (id *Identity) CheckInvitation(ReceivedContact *meowlib.ContactCard) (isAnswer bool, proposedNick string, receivedNick string) { diff --git a/client/peer.go b/client/peer.go index d1c29d7..f07c1d7 100644 --- a/client/peer.go +++ b/client/peer.go @@ -25,9 +25,12 @@ type Peer struct { MyEncryptionKp meowlib.KeyPair `json:"my_encryption_kp,omitempty"` MyLookupKp meowlib.KeyPair `json:"my_lookup_kp,omitempty"` MyPullServers []meowlib.ServerCard `json:"my_pull_servers,omitempty"` + MyContact meowlib.ContactCard `json:"my_contact,omitempty"` // Peer keys and infos - Contact meowlib.ContactCard `json:"contact,omitempty"` - InvitationId string `json:"invitation_id,omitempty"` + Contact meowlib.ContactCard `json:"contact,omitempty"` + InvitationId string `json:"invitation_id,omitempty"` + InvitationUrl string `json:"invitation_url,omitempty"` + InvitationExpiry time.Time `json:"invitation_expiry,omitempty"` // Internal management attributes Visible bool `json:"visible,omitempty"` VisiblePassword string `json:"visible_password,omitempty"`