diff --git a/client/message.go b/client/message.go index d7087f7..22ca8f4 100644 --- a/client/message.go +++ b/client/message.go @@ -7,7 +7,7 @@ import ( "google.golang.org/protobuf/proto" ) -func ProcessOutputUserMessage(peer *Peer, usermessage *meowlib.UserMessage) (*meowlib.PackedUserMessage, error) { +func ProcessOutboundUserMessage(peer *Peer, usermessage *meowlib.UserMessage) (*meowlib.PackedUserMessage, error) { serializedMessage, err := peer.SerializeUserMessage(usermessage) if err != nil { return nil, err @@ -31,30 +31,16 @@ func ProcessOutboundTextMessage(peer *Peer, text string, srv *InternalServer) ([ return nil, err } // Prepare cyphered + packed user message - packedMsg, err := ProcessOutputUserMessage(peer, usermessage) + packedMsg, err := ProcessOutboundUserMessage(peer, usermessage) if err != nil { return nil, err } - // Creating Server message for transporting the user message - toServerMessageBA, err := srv.BuildMessageSendingMessage(packedMsg) - if err != nil { - return nil, err - } - // Encrypting it - encToServerMessage, encToServerMessageSignature, err := srv.AsymEncryptMessage(toServerMessageBA) - if err != nil { - return nil, err - } - // Packing it - protoPackedServerMsg, err := srv.PackServerMessage(encToServerMessage, encToServerMessageSignature) - if err != nil { - return nil, err - } - return protoPackedServerMsg, nil + toServerMessage := srv.BuildToServerMessageFromUserMessage(packedMsg) + + return ProcessOutboundMessage(toServerMessage, srv) } -// TODO refactor protobuf to avid 2 methods func ProcessOutboundMessage(toServerMessage *meowlib.ToServerMessage, srv *InternalServer) ([]byte, error) { byteToServerMessage, err := proto.Marshal(toServerMessage) if err != nil { @@ -73,7 +59,7 @@ func ProcessOutboundMessage(toServerMessage *meowlib.ToServerMessage, srv *Inter return protoPackedServerMsg, nil } -func ProcessServerResponse(srv *InternalServer, msg []byte) (*meowlib.FromServerMessage, error) { +func ProcessInboundServerResponse(srv *InternalServer, msg []byte) (*meowlib.FromServerMessage, error) { fsmsg := &meowlib.FromServerMessage{} payload, signature, err := srv.UnPackServerMessage(msg) if err != nil { @@ -89,7 +75,7 @@ func ProcessServerResponse(srv *InternalServer, msg []byte) (*meowlib.FromServer return fsmsg, nil } -func ProcessUserMessage(peer *Peer, message []byte, signature []byte) (*meowlib.UserMessage, error) { +func ProcessInboundUserMessage(peer *Peer, message []byte, signature []byte) (*meowlib.UserMessage, error) { dec, err := peer.AsymDecryptMessage(message, signature) if err != nil { return nil, err