diff --git a/app/utilities/utilities.go b/app/utilities/utilities.go index 0958407346beb53d1ba608ca47372fd2a568cb6e..23603349560691a231cdf2f59e7cc1beb3fb8687 100644 --- a/app/utilities/utilities.go +++ b/app/utilities/utilities.go @@ -2,6 +2,7 @@ package utilities import ( "fmt" + "net" . "node/types" ) @@ -83,3 +84,35 @@ func CompareTransactions(trans1 Transaction, trans2 Transaction, ack AckTransact return newAck } + +func PrintConnection(connection net.Conn, connectionNumber int) { + fmt.Println("*****************************************") + fmt.Println("Processing client request number ", connectionNumber) + fmt.Println("The process-manage-connection is ", connection) + fmt.Println("The remote address is ", connection.RemoteAddr()) + fmt.Println("The local address is ", connection.LocalAddr()) + fmt.Println("*****************************************") +} + +func TranslateMessageToAckTransaction(mess Message) AckTransaction { + var newAck AckTransaction + + var body map[string]interface{} = mess.MessageBody.(map[string]interface{}) + newAck.Id = body["id"].(string) + newAck.AmountOfCorrectNode = body["amountOfCorrectNode"].(int) + newAck.TotalNodes = body["totalNodes"].(int) + + return newAck +} + +func TranslateMessageToTransaction(mess Message) Transaction { + var newTrans Transaction + + var body map[string]interface{} = mess.MessageBody.(map[string]interface{}) + newTrans.Id = body["id"].(string) + newTrans.Sender = body["sender"].(string) + newTrans.Receiver = body["receiver"].(string) + newTrans.Amount = body["amount"].(string) + + return newTrans +} \ No newline at end of file