From 1257cb70e7681071f5294d1074e540bd9e914e30 Mon Sep 17 00:00:00 2001 From: ycc Date: Sun, 18 Dec 2022 20:36:44 +0100 Subject: [PATCH] refactor #2 --- client/message.go | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) 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