Skip to content
Snippets Groups Projects
Commit 474a41a7 authored by Xavier Perret's avatar Xavier Perret
Browse files

bim

parent 4a913086
No related branches found
No related tags found
1 merge request!2added file to separate client function from the server
Showing
with 36 additions and 11 deletions
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
...@@ -96,7 +96,6 @@ func processRate(conn net.Conn, serverListener net.Listener, serverConfig Config ...@@ -96,7 +96,6 @@ func processRate(conn net.Conn, serverListener net.Listener, serverConfig Config
trans := utilities.TranslateMessageToTransaction(mess) trans := utilities.TranslateMessageToTransaction(mess)
utilities.PrintTransaction(trans) utilities.PrintTransaction(trans)
// todo change this for cloud
address := strings.Split(conn.RemoteAddr().String(), ":")[0] address := strings.Split(conn.RemoteAddr().String(), ":")[0]
vote(serverListener, serverConfig, trans, address, objectStorage, amIRoot) vote(serverListener, serverConfig, trans, address, objectStorage, amIRoot)
} }
...@@ -106,10 +105,11 @@ func processRate(conn net.Conn, serverListener net.Listener, serverConfig Config ...@@ -106,10 +105,11 @@ func processRate(conn net.Conn, serverListener net.Listener, serverConfig Config
// transactions which are the same as the one stored locally. This function relies on the broadcast by wave // transactions which are the same as the one stored locally. This function relies on the broadcast by wave
// with ACK distributed algorithm. However, some adjustments are needed to implement this function. // with ACK distributed algorithm. However, some adjustments are needed to implement this function.
func vote(server net.Listener, serverConfig Config, trans Transaction, parentAddress string, objectStorage Blob, amIRoot bool) AckTransaction { func vote(server net.Listener, serverConfig Config, trans Transaction, parentAddress string, objectStorage Blob, amIRoot bool) AckTransaction {
var ack AckTransaction ack := AckTransaction{
ack.Id = "" Id: "",
ack.TotalNodes = 0 TotalNodes: 0,
ack.AmountOfCorrectNode = 0 AmountOfCorrectNode: 0,
}
var transactionToRate Transaction var transactionToRate Transaction
...@@ -225,7 +225,8 @@ func processVoteRequest(conn net.Conn, serverListener net.Listener, serverConfig ...@@ -225,7 +225,8 @@ func processVoteRequest(conn net.Conn, serverListener net.Listener, serverConfig
} }
} }
vote(serverListener, serverConfig, transToRate, "", objectStorage, amIRoot) ack := vote(serverListener, serverConfig, transToRate, "", objectStorage, amIRoot)
utilities.PrintAckTransaction(ack)
} }
func ProcessClient(conn net.Conn, server net.Listener, objectStorage Blob, serverConfig Config, amIRoot bool, mutex *sync.Mutex) { func ProcessClient(conn net.Conn, server net.Listener, objectStorage Blob, serverConfig Config, amIRoot bool, mutex *sync.Mutex) {
......
File moved
File moved
File moved
File moved
...@@ -98,14 +98,29 @@ func PrintConnection(connection net.Conn, connectionNumber int) { ...@@ -98,14 +98,29 @@ func PrintConnection(connection net.Conn, connectionNumber int) {
} }
func TranslateMessageToAckTransaction(mess Message) AckTransaction { func TranslateMessageToAckTransaction(mess Message) AckTransaction {
var newAck AckTransaction var transactionId string
var amountOfCorrectNode int
var totalNodes int
var err error
var body map[string]interface{} = mess.MessageBody.(map[string]interface{}) var body map[string]interface{} = mess.MessageBody.(map[string]interface{})
newAck.Id = body["id"].(string) transactionId = body["id"].(string)
newAck.AmountOfCorrectNode = body["amountOfCorrectNode"].(int) amountOfCorrectNode, err = strconv.Atoi(body["amountOfCorrectNode"].(string))
newAck.TotalNodes = body["totalNodes"].(int) if err != nil {
fmt.Println("Error while converting amountOfCorrectNode to int", err)
return AckTransaction{}
}
totalNodes, err = strconv.Atoi(body["totalNodes"].(string))
if err != nil {
fmt.Println("Error while converting totalNodes to int", err)
return AckTransaction{}
}
return newAck return AckTransaction{
Id: transactionId,
AmountOfCorrectNode: amountOfCorrectNode,
TotalNodes: totalNodes,
}
} }
func TranslateMessageToTransaction(mess Message) Transaction { func TranslateMessageToTransaction(mess Message) Transaction {
...@@ -131,3 +146,12 @@ func PrintTransactionDoneMessage() { ...@@ -131,3 +146,12 @@ func PrintTransactionDoneMessage() {
fmt.Println("All transactions have been received") fmt.Println("All transactions have been received")
fmt.Println("***********************************") fmt.Println("***********************************")
} }
func PrintAckTransaction(ack AckTransaction) {
fmt.Println("***********************************")
fmt.Println("Printing ack transaction")
fmt.Println("The id is ", ack.Id)
fmt.Println("The amount of correct node is ", ack.AmountOfCorrectNode)
fmt.Println("The total nodes is ", ack.TotalNodes)
fmt.Println("***********************************")
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment