diff --git a/lab1/app/command-line/userinput.go b/lab1/app/command-line/userinput.go index 78d1f53fe3543fb5c335c9b96490a12e224e3b3a..5db6e2c8fe0c9459ff1bc560e13c5f5408303490 100644 --- a/lab1/app/command-line/userinput.go +++ b/lab1/app/command-line/userinput.go @@ -46,7 +46,8 @@ func userCreatedTransaction(config Config) Transaction { for neighbour := range config.Neighbours { fmt.Println("Neighbour ", config.Neighbours[neighbour].ID) fmt.Println("address ", config.Neighbours[neighbour].Address) - fmt.Println("port", config.Neighbours[neighbour].Port) + basePort := config.Neighbours[neighbour].ID + 5000 + fmt.Println("port", strconv.Itoa(basePort)) } fmt.Println("--------------------FINISHED USER CREATED TRANSACTION--------------------") @@ -160,7 +161,8 @@ func ClientUserInputLoop(clientConfig Config, isAlsoServer bool) { fmt.Println("error :", err.Error()) os.Exit(1) } - Sender.SendTransactionToNeighbour(clientConfig, newTrans, clientConfig.Neighbours[neighbourIDInt].Address, strconv.Itoa(clientConfig.Neighbours[neighbourIDInt].Port)) + basePort := clientConfig.Neighbours[neighbourIDInt].ID + 5000 + Sender.SendTransactionToNeighbour(clientConfig, newTrans, clientConfig.Neighbours[neighbourIDInt].Address, strconv.Itoa(basePort)) } break case "2": @@ -194,7 +196,8 @@ func ClientUserInputLoop(clientConfig Config, isAlsoServer bool) { fmt.Println("error :", err.Error()) os.Exit(1) } - address := clientConfig.Neighbours[neighbourIDInt].Address + ":" + strconv.Itoa(clientConfig.Neighbours[neighbourIDInt].Port) + basePort := clientConfig.Neighbours[neighbourIDInt].ID + 5000 + address := clientConfig.Neighbours[neighbourIDInt].Address + ":" + strconv.Itoa(basePort) fmt.Println("Sending rate demand to ", address) Sender.SendVoteRequestToNode(clientConfig, transIDInt, address) @@ -230,7 +233,9 @@ func ClientUserInputLoop(clientConfig Config, isAlsoServer bool) { fmt.Println("error :", err.Error()) os.Exit(1) } - address := clientConfig.Neighbours[neighbourIDInt].Address + ":" + strconv.Itoa(clientConfig.Neighbours[neighbourIDInt].Port) + + basePort := clientConfig.Neighbours[neighbourIDInt].ID + 5000 + address := clientConfig.Neighbours[neighbourIDInt].Address + ":" + strconv.Itoa(basePort) fmt.Println("Sending rate demand to ", address) Sender.SendFakeRequestToNode(clientConfig, transIDInt, address) @@ -252,7 +257,8 @@ func ClientUserInputLoop(clientConfig Config, isAlsoServer bool) { fmt.Println("error :", err.Error()) os.Exit(1) } - address := clientConfig.Neighbours[neighbourIDInt].Address + ":" + strconv.Itoa(clientConfig.Neighbours[neighbourIDInt].Port) + basePort := clientConfig.Neighbours[neighbourIDInt].ID + 5000 + address := clientConfig.Neighbours[neighbourIDInt].Address + ":" + strconv.Itoa(basePort) fmt.Println("Sending rate demand to ", address) Sender.SendListTransactionsRequestToNode(clientConfig, address) diff --git a/lab1/app/process-connection/process-connection.go b/lab1/app/process-connection/process-connection.go index d7563e092cd5087c31b32bf872be1d8b9f101874..c68ea111427fc51a1051e0173e410b8487ccbaa9 100644 --- a/lab1/app/process-connection/process-connection.go +++ b/lab1/app/process-connection/process-connection.go @@ -187,7 +187,8 @@ func vote(server net.Listener, serverConfig Config, trans Transaction, parentAdd fmt.Println("Comparing ", neighbour.Address, " with ", parentAddress) if neighbour.Address == parentAddress { - address = address + ":" + strconv.Itoa(neighbour.Port) + basePort := 5000 + neighbour.ID + address = address + ":" + strconv.Itoa(basePort) fmt.Println("Calculated address is ", address) } } @@ -230,8 +231,6 @@ func processVoteRequest(conn net.Conn, serverListener net.Listener, serverConfig } func ProcessClient(conn net.Conn, server net.Listener, objectStorage Blob, serverConfig Config, amIRoot bool, mutex *sync.Mutex) { - // mutex.Lock() - // defer mutex.Unlock() utilities.PrintConnection(conn, 0) var mess Message diff --git a/lab1/app/sender/sender.go b/lab1/app/sender/sender.go index b87212507c18274a2cbb5c6dc55e569e855e783d..fe886f56c8bfea97ab634cb0a1bcaf048bc8f98b 100644 --- a/lab1/app/sender/sender.go +++ b/lab1/app/sender/sender.go @@ -65,7 +65,8 @@ func SendAckToNeighbour(config Config, ack AckTransaction, address string) { func SendVoteToAllNeighbours(config Config, trans Transaction, parentIp string) { for neighbour := range config.Neighbours { ip := config.Neighbours[neighbour].Address - port := strconv.Itoa(config.Neighbours[neighbour].Port) + basePort := config.Neighbours[neighbour].ID + 5000 + port := strconv.Itoa(basePort) address := ip + ":" + port if parentIp != ip { go SendVoteToNeighbour(config, trans, address) @@ -78,7 +79,8 @@ func SendTransactionToAllNeighbours(config Config, trans Transaction) { for neighbour := range config.Neighbours { fmt.Println("Sending transaction to neighbour ", config.Neighbours[neighbour].ID) ip := config.Neighbours[neighbour].Address - port := strconv.Itoa(config.Neighbours[neighbour].Port) + basePort := config.Neighbours[neighbour].ID + 5000 + port := strconv.Itoa(basePort) SendTransactionToNeighbour(config, trans, ip, port) } } diff --git a/lab1/app/server.go b/lab1/app/server.go index 3d99060928b39de7242b1b4d42d1bfb50873b4bb..3deb124bf24952a5769f2de3f8accf9766c72bec 100644 --- a/lab1/app/server.go +++ b/lab1/app/server.go @@ -6,7 +6,7 @@ import ( "gopkg.in/yaml.v3" "log" "net" - command_line "node/command-line" + commandline "node/command-line" ObjectStorage "node/object-storage" ProcessConnection "node/process-connection" . "node/types" @@ -25,7 +25,8 @@ import ( */ func listenForConnections(serverConfig Config, objectStorage Blob, addressToListenOn string, amIRoot bool) { - port := strconv.FormatInt(int64(serverConfig.Port), 10) + basePort := 5000 + serverConfig.ID + port := strconv.Itoa(basePort) completeAddress := addressToListenOn + ":" + port server, err := net.Listen("tcp", completeAddress) @@ -94,7 +95,7 @@ func main() { addressToListenOn := "0.0.0.0" go listenForConnections(serverConfig, objectStorage, addressToListenOn, amIRoot) - command_line.ServerUserInputLoop(serverConfig, true, objectStorage) + commandline.ServerUserInputLoop(serverConfig, true, objectStorage) _, err = objectStorage.BlockBlobClient.Delete(ctx, nil) if err != nil { diff --git a/lab1/app/utilities/utilities.go b/lab1/app/utilities/utilities.go index 87d597fb31751124c96c0fac66f8e8e27fa199b0..a6806c13788be775ba24cc9dcbc5359751263dac 100644 --- a/lab1/app/utilities/utilities.go +++ b/lab1/app/utilities/utilities.go @@ -33,7 +33,8 @@ func PrintNeighbors(neighbors []Neighbors) { fmt.Println("***********INDEX N=,", i, "****************") fmt.Println("The id is ", neighbor.ID) fmt.Println("The address is ", neighbor.Address) - fmt.Println("The port is ", neighbor.Port) + basePort := neighbor.ID + 5000 + fmt.Println("The port is ", strconv.Itoa(basePort)) fmt.Println("***********************************") } } @@ -42,7 +43,8 @@ func PrintConfig(config Config) { fmt.Println("Printing config") fmt.Println("The id is ", config.ID) fmt.Println("The address is ", config.Address) - fmt.Println("The port is ", config.Port) + basePort := config.ID + 5000 + fmt.Println("The port is ", strconv.Itoa(basePort)) PrintNeighbors(config.Neighbours) }