cleaner invitation step messages

This commit is contained in:
yc
2026-04-14 19:12:09 +02:00
parent 327bd390c4
commit 00e4e6b046
9 changed files with 208 additions and 179 deletions
+29 -13
View File
@@ -8,39 +8,55 @@ import (
"google.golang.org/protobuf/proto"
)
// Step3InitiatorFinalizesInviteeAndCreatesContactCard is called by the initiator when a
// step-2 answer (invitee's encrypted ContactCard) arrives. It decrypts the card, upgrades
// the invitee's peer entry with the real keys, and returns the initiator's own ContactCard
// ready to be sent to the invitee via any transport.
func Step3InitiatorFinalizesInviteeAndCreatesContactCard(invitation *meowlib.Invitation) (*client.Peer, *meowlib.ContactCard, error) {
// Step3InitiatorFinalizesInviteeAndCreatesContactCard is called by the initiator when the
// step-2 answer (serialized Invitation bytes) arrives. It decrypts the invitee's ContactCard,
// upgrades the pending peer with the invitee's real keys, and returns a serialized Invitation
// (step=3) whose Payload is the initiator's ContactCard, ready to be consumed directly by
// Step4InviteeFinalizesInitiator on the invitee side.
func Step3InitiatorFinalizesInviteeAndCreatesContactCard(invitationBytes []byte) ([]byte, error) {
var invitation meowlib.Invitation
if err := proto.Unmarshal(invitationBytes, &invitation); err != nil {
return nil, err
}
var invitationAnswer meowlib.PackedUserMessage
if err := proto.Unmarshal(invitation.Payload, &invitationAnswer); err != nil {
return nil, nil, err
return nil, err
}
peer := client.GetConfig().GetIdentity().Peers.GetFromInvitationId(invitation.Uuid)
if peer == nil {
return nil, nil, errors.New("no peer for invitation uuid " + invitation.Uuid)
return nil, errors.New("no peer for invitation uuid " + invitation.Uuid)
}
// Guard against duplicate delivery (e.g., same answer from multiple servers).
if peer.InvitationKp == nil {
return nil, nil, nil
return nil, nil
}
usermsg, err := peer.ProcessInboundStep2UserMessage(&invitationAnswer, invitation.From)
if err != nil {
return nil, nil, err
return nil, err
}
var inviteeCC meowlib.ContactCard
if err := proto.Unmarshal(usermsg.Invitation.Payload, &inviteeCC); err != nil {
return nil, nil, err
return nil, err
}
myCC, peer, err := client.GetConfig().GetIdentity().InvitationStep3(&inviteeCC)
myCC, _, err := client.GetConfig().GetIdentity().InvitationStep3(&inviteeCC)
if err != nil {
return nil, nil, err
return nil, err
}
client.GetConfig().GetIdentity().Save()
return peer, myCC, nil
ccBytes, err := proto.Marshal(myCC)
if err != nil {
return nil, err
}
inv := &meowlib.Invitation{
Uuid: myCC.InvitationId,
Step: 3,
Payload: ccBytes,
}
return proto.Marshal(inv)
}