Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • master
1 result

Target

Select target project
  • xavier.perret/perso-distributed-systems
1 result
Select Git revision
  • master
1 result
Show changes
Commits on Source (3)
......@@ -66,7 +66,7 @@ func ServerUserInputLoop(config Config, isAlsoServer bool, objectStorage Blob) {
fmt.Println("Please enter the operation you want to do")
fmt.Println("1. Fabricate a fake transaction")
fmt.Println("2. Print all transactions")
fmt.Println("4. Exit")
fmt.Println("3. Exit")
fmt.Print("Your choice: ")
_, err := fmt.Scanln(&operation)
if err != nil {
......@@ -107,9 +107,6 @@ func ServerUserInputLoop(config Config, isAlsoServer bool, objectStorage Blob) {
utilities.PrintingDatabaseToConsole(database)
break
case "3":
fmt.Println("You chose to ask for all transactions of a given node")
break
case "4":
fmt.Println("You chose to exit")
return
default:
......
......@@ -200,12 +200,31 @@ func processFakeRequest(conn net.Conn, serverListener net.Listener, serverConfig
trans := utilities.TranslateMessageToTransaction(mess)
utilities.PrintTransaction(trans)
fakeTrans := Transaction{
Id: trans.Id,
Sender: utilities.RandomString(),
Receiver: utilities.RandomString(),
Amount: utilities.RandomString(),
}
database := ObjectStorageAPI.ReadDatabaseFromBlobStorage(objectStorage)
database = ObjectStorageAPI.FakeTransaction(trans, fakeTrans, database)
ObjectStorageAPI.WriteDatabaseToBlobStorage(database, objectStorage)
}
func processVoteRequest(conn net.Conn, serverListener net.Listener, serverConfig Config, objectStorage Blob, mess Message, amIRoot bool) {
trans := utilities.TranslateMessageToTransaction(mess)
var transToRate Transaction
utilities.PrintTransaction(trans)
database := ObjectStorageAPI.ReadDatabaseFromBlobStorage(objectStorage)
for _, transactionInDatabase := range database {
if trans.Id == transactionInDatabase.Id {
transToRate = transactionInDatabase
}
}
vote(serverListener, serverConfig, transToRate, "", objectStorage, amIRoot)
}
func ProcessClient(conn net.Conn, server net.Listener, objectStorage Blob, serverConfig Config, amIRoot bool, mutex *sync.Mutex) {
......@@ -237,6 +256,10 @@ func ProcessClient(conn net.Conn, server net.Listener, objectStorage Blob, serve
} else if mess.MessageType == "voteRequest" {
fmt.Println("Received a request to vote on a given transaction")
processVoteRequest(conn, server, serverConfig, objectStorage, mess, amIRoot)
} else if mess.MessageType == "listTransactionsRequest" {
fmt.Println("Received a request to list all transactions")
database := ObjectStorageAPI.ReadDatabaseFromBlobStorage(objectStorage)
utilities.PrintingDatabaseToConsole(database)
} else {
fmt.Println("Unknown message type")
}
......
......@@ -2,8 +2,11 @@ package utilities
import (
"fmt"
"math/rand"
"net"
. "node/types"
"strconv"
"time"
)
func PrintTransaction(trans Transaction) {
......@@ -115,4 +118,10 @@ func TranslateMessageToTransaction(mess Message) Transaction {
newTrans.Amount = body["amount"].(string)
return newTrans
}
func RandomString() string {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
return strconv.Itoa(r.Int())
}