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

removed duplicate code

parent fc55dcd1
No related branches found
No related tags found
1 merge request!2added file to separate client function from the server
...@@ -73,12 +73,7 @@ func processTransaction(serverListener net.Listener, serverConfig Config, object ...@@ -73,12 +73,7 @@ func processTransaction(serverListener net.Listener, serverConfig Config, object
err = nil err = nil
continue continue
} }
fmt.Println("*****************************************") utilities.PrintConnection(connection, count)
fmt.Println("Processing client request number ", count)
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("*****************************************")
err = json.NewDecoder(connection).Decode(&trans) err = json.NewDecoder(connection).Decode(&trans)
if err != nil { if err != nil {
...@@ -165,12 +160,8 @@ func vote(server net.Listener, serverConfig Config, trans Transaction, parentAdd ...@@ -165,12 +160,8 @@ func vote(server net.Listener, serverConfig Config, trans Transaction, parentAdd
err = nil err = nil
continue continue
} }
fmt.Println("*****************************************")
fmt.Println("Processing client request number ", count) utilities.PrintConnection(connection, count)
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("*****************************************")
err = json.NewDecoder(connection).Decode(&mess) err = json.NewDecoder(connection).Decode(&mess)
if err != nil { if err != nil {
...@@ -219,13 +210,24 @@ func vote(server net.Listener, serverConfig Config, trans Transaction, parentAdd ...@@ -219,13 +210,24 @@ func vote(server net.Listener, serverConfig Config, trans Transaction, parentAdd
return ack return ack
} }
func processFakeRequest(conn net.Conn, serverListener net.Listener, serverConfig Config, objectStorage Blob, mess Message, amIRoot bool) {
var trans Transaction
var body map[string]interface{} = mess.MessageBody.(map[string]interface{})
}
func processVoteRequest(conn net.Conn, serverListener net.Listener, serverConfig Config, objectStorage Blob, mess Message, amIRoot bool) {
var trans Transaction
var body map[string]interface{} = mess.MessageBody.(map[string]interface{})
fmt.Println("Received back a transaction")
utilities.PrintTransaction(trans)
}
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) {
mutex.Lock() mutex.Lock()
defer mutex.Unlock() defer mutex.Unlock()
fmt.Println("Processing client") utilities.PrintConnection(conn, 0)
fmt.Println("The conn is ", conn)
fmt.Println("The remote address is ", conn.RemoteAddr())
fmt.Println("The local address is ", conn.LocalAddr())
var mess Message var mess Message
jsonDecoder := json.NewDecoder(conn) jsonDecoder := json.NewDecoder(conn)
...@@ -245,6 +247,12 @@ func ProcessClient(conn net.Conn, server net.Listener, objectStorage Blob, serve ...@@ -245,6 +247,12 @@ func ProcessClient(conn net.Conn, server net.Listener, objectStorage Blob, serve
} else if mess.MessageType == "list" { } else if mess.MessageType == "list" {
fmt.Println("Received an order to list all transactions") fmt.Println("Received an order to list all transactions")
listAllTransactionsToClient(conn, objectStorage) listAllTransactionsToClient(conn, objectStorage)
} else if mess.MessageType == "fakeRequest" {
fmt.Println("Received a request to fake transaction")
processFakeRequest(conn, server, serverConfig, objectStorage, mess, amIRoot)
} else if mess.MessageType == "voteRequest" {
fmt.Println("Received a request to vote on a given transaction")
processVoteRequest(conn, server, serverConfig, objectStorage, mess, amIRoot)
} else { } else {
fmt.Println("Unknown message type") fmt.Println("Unknown message type")
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment