client to server process outbound generic method

This commit is contained in:
ycc 2022-12-16 22:26:58 +01:00
parent fccb32b0b1
commit 8879ef3f02

View File

@ -44,6 +44,25 @@ func ProcessOutboundTextMessage(peer *Peer, text string, srv *InternalServer) ([
return protoPackedServerMsg, nil return protoPackedServerMsg, nil
} }
// TODO refactor protobuf to avid 2 methods
func ProcessOutboundMessage(peer *Peer, toServerMessage *meowlib.ToServerMessage, srv *InternalServer) ([]byte, error) {
byteToServerMessage, err := proto.Marshal(toServerMessage)
if err != nil {
return nil, err
}
// Encrypting it
encToServerMessage, encToServerMessageSignature, err := srv.AsymEncryptMessage(byteToServerMessage)
if err != nil {
return nil, err
}
// Packing it
protoPackedServerMsg, err := srv.PackServerMessage(encToServerMessage, encToServerMessageSignature)
if err != nil {
return nil, err
}
return protoPackedServerMsg, nil
}
func ProcessServerResponse(srv *InternalServer, msg []byte) (*meowlib.FromServerMessage, error) { func ProcessServerResponse(srv *InternalServer, msg []byte) (*meowlib.FromServerMessage, error) {
fsmsg := &meowlib.FromServerMessage{} fsmsg := &meowlib.FromServerMessage{}
payload, signature, err := srv.UnPackServerMessage(msg) payload, signature, err := srv.UnPackServerMessage(msg)