Invitation process store my server card+ server invitation fields
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
ycc 2023-12-31 10:24:15 +01:00
parent 922668e2a3
commit 0998845817
2 changed files with 16 additions and 14 deletions

View File

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

View File

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