This commit is contained in:
parent
ead810e666
commit
b15f571938
@ -103,7 +103,7 @@ func SaveCheckJobs() (string, error) {
|
||||
}
|
||||
|
||||
// ReadMessage
|
||||
func ReadMessage(messageFilename string, storagePath string) (string, string, error) {
|
||||
func ReadMessage(messageFilename string, detachFilesStoragePath string) (string, string, error) {
|
||||
result := map[string]interface{}{}
|
||||
|
||||
// read message file
|
||||
@ -119,7 +119,7 @@ func ReadMessage(messageFilename string, storagePath string) (string, string, er
|
||||
}
|
||||
// check if invitation answer
|
||||
if fromServerMessage.Invitation != nil {
|
||||
|
||||
InvitationGetAnswerReadResponse(fromServerMessage.Invitation)
|
||||
}
|
||||
// Chat messages
|
||||
if len(fromServerMessage.Chat) > 0 {
|
||||
@ -146,7 +146,7 @@ func ReadMessage(messageFilename string, storagePath string) (string, string, er
|
||||
filename := uuid.New().String() + "_" + file.Filename
|
||||
filenames = append(filenames, filename)
|
||||
// detach file
|
||||
os.WriteFile(filepath.Join(storagePath, "files", filename), file.Data, 0600)
|
||||
os.WriteFile(filepath.Join(detachFilesStoragePath, "files", filename), file.Data, 0600)
|
||||
}
|
||||
//? result["invitation finalized"] = peer.Name
|
||||
}
|
||||
|
@ -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
|
||||
peer := client.GetConfig().GetIdentity().Peers.GetFromInvitationId(invitation.Uuid)
|
||||
peer.ContactPublicKey = invitation.From
|
||||
if peer != nil {
|
||||
|
||||
// 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
|
||||
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
|
||||
}
|
||||
|
@ -15,6 +15,15 @@ func (pl *PeerList) GetFromPublicKey(publickey string) *Peer {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (pl *PeerList) GetFromInvitationId(invitationId string) *Peer {
|
||||
for _, peer := range *pl {
|
||||
if peer.InvitationId == invitationId {
|
||||
return peer
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (pl *PeerList) GetFromMyLookupKey(publickey string) *Peer {
|
||||
for _, peer := range *pl {
|
||||
if peer.MyLookupKp.Public == publickey {
|
||||
|
Loading…
Reference in New Issue
Block a user