This commit is contained in:
parent
ead810e666
commit
b15f571938
@ -103,7 +103,7 @@ func SaveCheckJobs() (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ReadMessage
|
// ReadMessage
|
||||||
func ReadMessage(messageFilename string, storagePath string) (string, string, error) {
|
func ReadMessage(messageFilename string, detachFilesStoragePath string) (string, string, error) {
|
||||||
result := map[string]interface{}{}
|
result := map[string]interface{}{}
|
||||||
|
|
||||||
// read message file
|
// read message file
|
||||||
@ -119,7 +119,7 @@ func ReadMessage(messageFilename string, storagePath string) (string, string, er
|
|||||||
}
|
}
|
||||||
// check if invitation answer
|
// check if invitation answer
|
||||||
if fromServerMessage.Invitation != nil {
|
if fromServerMessage.Invitation != nil {
|
||||||
|
InvitationGetAnswerReadResponse(fromServerMessage.Invitation)
|
||||||
}
|
}
|
||||||
// Chat messages
|
// Chat messages
|
||||||
if len(fromServerMessage.Chat) > 0 {
|
if len(fromServerMessage.Chat) > 0 {
|
||||||
@ -146,7 +146,7 @@ func ReadMessage(messageFilename string, storagePath string) (string, string, er
|
|||||||
filename := uuid.New().String() + "_" + file.Filename
|
filename := uuid.New().String() + "_" + file.Filename
|
||||||
filenames = append(filenames, filename)
|
filenames = append(filenames, filename)
|
||||||
// detach file
|
// 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
|
//? result["invitation finalized"] = peer.Name
|
||||||
}
|
}
|
||||||
|
@ -6,67 +6,48 @@ import (
|
|||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
// InvitationGetAnswer
|
// Got it by the message background check
|
||||||
// Called by the invitation initiator
|
// => noInvitationGetAnswer
|
||||||
// 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
|
|
||||||
}
|
|
||||||
|
|
||||||
// InvitationGetAnswerReadResponse
|
// InvitationGetAnswerReadResponse
|
||||||
// Called by the invitation initiator
|
// Called by the invitation initiator
|
||||||
// invitationAnswerData: the data received from the server
|
// invitationAnswerData: the data received from the server
|
||||||
// invitationServerUid: the uid of the server holding the invitation
|
// invitationServerUid: the uid of the server holding the invitation
|
||||||
func InvitationGetAnswerReadResponse(invitationAnswerData []byte, invitationServerUid string) (string, error) {
|
func InvitationGetAnswerReadResponse(invitation *meowlib.Invitation) (*client.Peer, 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
|
|
||||||
|
|
||||||
// decode the payload
|
// decode the payload
|
||||||
var invitationAnswer meowlib.PackedUserMessage
|
var invitationAnswer meowlib.PackedUserMessage
|
||||||
err = proto.Unmarshal(serverMsg.Invitation.Payload, &invitationAnswer)
|
err := proto.Unmarshal(invitation.Payload, &invitationAnswer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "InvitationGetAnswerReadResponse: Unmarshal", err
|
return nil, "InvitationGetAnswerReadResponse: Unmarshal", err
|
||||||
}
|
}
|
||||||
// retreive user public key to check usermessage signature
|
// 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
|
// finalize the invitation
|
||||||
// id := client.GetConfig().GetIdentity()
|
// id := client.GetConfig().GetIdentity()
|
||||||
|
peer.ContactLookupKey = cc.ContactPublicKey
|
||||||
// cc, err := id.FinalizeInvitation(serverMsg.Invitation.)
|
peer.ContactEncryption = cc.EncryptionPublicKey
|
||||||
|
for _, server := range cc.PullServers {
|
||||||
return "", nil
|
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
|
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 {
|
func (pl *PeerList) GetFromMyLookupKey(publickey string) *Peer {
|
||||||
for _, peer := range *pl {
|
for _, peer := range *pl {
|
||||||
if peer.MyLookupKp.Public == publickey {
|
if peer.MyLookupKp.Public == publickey {
|
||||||
|
Loading…
Reference in New Issue
Block a user