server invitatio
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
ycc
2024-03-29 15:40:46 +01:00
parent ead810e666
commit b15f571938
3 changed files with 43 additions and 53 deletions

View File

@ -6,67 +6,48 @@ import (
"google.golang.org/protobuf/proto"
)
// InvitationGetAnswer
// Called by the invitation initiator
// invitationId: the id of the invitation
// serverUid: the uid of the server holding the invitation answer
func InvitationGetAnswer(invitationId string, serverUid string) ([]byte, string, error) {
// check if already in msg servers
srv, err := client.GetConfig().GetIdentity().MessageServers.LoadServer(serverUid)
if err != nil {
return nil, "InvitationGetAnswer: LoadServer", err
}
// buildserver message
toSrvMsg, err := srv.BuildToServerMessageInvitationAnswerRequest(invitationId)
if err != nil {
return nil, "InvitationGetAnswer: BuildToServerMessageInvitationRequest", err
}
// processoutbound
bytemsg, err := srv.ProcessOutboundMessage(toSrvMsg)
if err != nil {
return nil, "InvitationGetAnswer: ProcessOutboundMessage", err
}
return bytemsg, "", nil
}
// Got it by the message background check
// => noInvitationGetAnswer
// InvitationGetAnswerReadResponse
// Called by the invitation initiator
// invitationAnswerData: the data received from the server
// invitationServerUid: the uid of the server holding the invitation
func InvitationGetAnswerReadResponse(invitationAnswerData []byte, invitationServerUid string) (string, error) {
server, err := client.GetConfig().GetIdentity().MessageServers.LoadServer(invitationServerUid)
if err != nil {
return "InvitationGetAnswerReadResponse: LoadServer", err
}
// Server inbound processing : get the invitation server
serverMsg, err := server.ProcessInboundServerResponse(invitationAnswerData)
if err != nil {
return "InvitationGetAnswerReadResponse: ProcessInboundServerResponse", err
}
// fmt.Println("Inbound OK, Invitation Step: ", serverMsg.Invitation.Step, len(serverMsg.Invitation.Payload))
// fmt.Println("Invitation Check")
// fmt.Println(hex.EncodeToString(serverMsg.Invitation.Payload))
// contactCard decode
func InvitationGetAnswerReadResponse(invitation *meowlib.Invitation) (*client.Peer, string, error) {
// decode the payload
var invitationAnswer meowlib.PackedUserMessage
err = proto.Unmarshal(serverMsg.Invitation.Payload, &invitationAnswer)
err := proto.Unmarshal(invitation.Payload, &invitationAnswer)
if err != nil {
return "InvitationGetAnswerReadResponse: Unmarshal", err
return nil, "InvitationGetAnswerReadResponse: Unmarshal", err
}
// retreive user public key to check usermessage signature
//contactPublikKey := serverMsg.Invitation.From
// contactPublikKey := serverMsg.Invitation.From
peer := client.GetConfig().GetIdentity().Peers.GetFromInvitationId(invitation.Uuid)
peer.ContactPublicKey = invitation.From
if peer != nil {
// process the packed user message
// process the packed user message
usermsg, err := peer.ProcessInboundUserMessage(invitationAnswer.Payload, invitationAnswer.Signature)
if err != nil {
return nil, "InvitationGetAnswerReadResponse: ProcessInboundUserMessage", err
}
decodedInvitation := usermsg.Invitation
var cc meowlib.ContactCard
err = proto.Unmarshal(decodedInvitation.Payload, &cc)
if err != nil {
return nil, "InvitationGetAnswerReadResponse: Unmarshal", err
}
// finalize the invitation
// id := client.GetConfig().GetIdentity()
// cc, err := id.FinalizeInvitation(serverMsg.Invitation.)
return "", nil
// finalize the invitation
// id := client.GetConfig().GetIdentity()
peer.ContactLookupKey = cc.ContactPublicKey
peer.ContactEncryption = cc.EncryptionPublicKey
for _, server := range cc.PullServers {
peer.ContactPullServers = append(peer.ContactPullServers, server.GetUid())
}
client.GetConfig().GetIdentity().Save()
// cc, err := id.FinalizeInvitation(serverMsg.Invitation.)
}
return peer, "", nil
}