2022-12-02 23:18:13 +01:00
|
|
|
package client
|
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
|
2022-12-03 00:05:28 +01:00
|
|
|
func ProcessOutboundTextMessage(peer *Peer, text string, srv *InternalServer) ([]byte, error) {
|
2022-12-02 23:18:13 +01:00
|
|
|
// Creating User message
|
|
|
|
usermessage, err := peer.BuildSimpleUserMessage([]byte(text))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
serializedMessage, err := peer.SerializeUserMessage(usermessage)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
// Encrypting it
|
|
|
|
EncMsg, EncMsgSignature, FriendServers, err := peer.AsymEncryptMessage(serializedMessage)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
fmt.Println(len(FriendServers))
|
|
|
|
// Packing it
|
|
|
|
packedMsg := peer.PackUserMessage(EncMsg, EncMsgSignature)
|
|
|
|
|
|
|
|
// Creating Server message for transporting the user message
|
2022-12-03 00:05:28 +01:00
|
|
|
toServerMessage, err := srv.BuildMessageSendingMessage(packedMsg)
|
2022-12-02 23:18:13 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
// Encrypting it
|
|
|
|
encToServerMessage, encToServerMessageSignature, err := srv.AsymEncryptMessage(toServerMessage)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
// Packing it
|
|
|
|
protoPackedServerMsg, err := srv.PackServerMessage(encToServerMessage, encToServerMessageSignature)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return protoPackedServerMsg, nil
|
|
|
|
}
|