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

removed port

parent 009cf814
No related branches found
No related tags found
No related merge requests found
...@@ -46,7 +46,8 @@ func userCreatedTransaction(config Config) Transaction { ...@@ -46,7 +46,8 @@ func userCreatedTransaction(config Config) Transaction {
for neighbour := range config.Neighbours { for neighbour := range config.Neighbours {
fmt.Println("Neighbour ", config.Neighbours[neighbour].ID) fmt.Println("Neighbour ", config.Neighbours[neighbour].ID)
fmt.Println("address ", config.Neighbours[neighbour].Address) 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--------------------") fmt.Println("--------------------FINISHED USER CREATED TRANSACTION--------------------")
...@@ -160,7 +161,8 @@ func ClientUserInputLoop(clientConfig Config, isAlsoServer bool) { ...@@ -160,7 +161,8 @@ func ClientUserInputLoop(clientConfig Config, isAlsoServer bool) {
fmt.Println("error :", err.Error()) fmt.Println("error :", err.Error())
os.Exit(1) 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 break
case "2": case "2":
...@@ -194,7 +196,8 @@ func ClientUserInputLoop(clientConfig Config, isAlsoServer bool) { ...@@ -194,7 +196,8 @@ func ClientUserInputLoop(clientConfig Config, isAlsoServer bool) {
fmt.Println("error :", err.Error()) fmt.Println("error :", err.Error())
os.Exit(1) 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) fmt.Println("Sending rate demand to ", address)
Sender.SendVoteRequestToNode(clientConfig, transIDInt, address) Sender.SendVoteRequestToNode(clientConfig, transIDInt, address)
...@@ -230,7 +233,9 @@ func ClientUserInputLoop(clientConfig Config, isAlsoServer bool) { ...@@ -230,7 +233,9 @@ func ClientUserInputLoop(clientConfig Config, isAlsoServer bool) {
fmt.Println("error :", err.Error()) fmt.Println("error :", err.Error())
os.Exit(1) 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) fmt.Println("Sending rate demand to ", address)
Sender.SendFakeRequestToNode(clientConfig, transIDInt, address) Sender.SendFakeRequestToNode(clientConfig, transIDInt, address)
...@@ -252,7 +257,8 @@ func ClientUserInputLoop(clientConfig Config, isAlsoServer bool) { ...@@ -252,7 +257,8 @@ func ClientUserInputLoop(clientConfig Config, isAlsoServer bool) {
fmt.Println("error :", err.Error()) fmt.Println("error :", err.Error())
os.Exit(1) 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) fmt.Println("Sending rate demand to ", address)
Sender.SendListTransactionsRequestToNode(clientConfig, address) Sender.SendListTransactionsRequestToNode(clientConfig, address)
......
...@@ -187,7 +187,8 @@ func vote(server net.Listener, serverConfig Config, trans Transaction, parentAdd ...@@ -187,7 +187,8 @@ func vote(server net.Listener, serverConfig Config, trans Transaction, parentAdd
fmt.Println("Comparing ", neighbour.Address, " with ", parentAddress) fmt.Println("Comparing ", neighbour.Address, " with ", parentAddress)
if neighbour.Address == 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) fmt.Println("Calculated address is ", address)
} }
} }
...@@ -230,8 +231,6 @@ func processVoteRequest(conn net.Conn, serverListener net.Listener, serverConfig ...@@ -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) { 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) utilities.PrintConnection(conn, 0)
var mess Message var mess Message
......
...@@ -65,7 +65,8 @@ func SendAckToNeighbour(config Config, ack AckTransaction, address string) { ...@@ -65,7 +65,8 @@ func SendAckToNeighbour(config Config, ack AckTransaction, address string) {
func SendVoteToAllNeighbours(config Config, trans Transaction, parentIp string) { func SendVoteToAllNeighbours(config Config, trans Transaction, parentIp string) {
for neighbour := range config.Neighbours { for neighbour := range config.Neighbours {
ip := config.Neighbours[neighbour].Address 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 address := ip + ":" + port
if parentIp != ip { if parentIp != ip {
go SendVoteToNeighbour(config, trans, address) go SendVoteToNeighbour(config, trans, address)
...@@ -78,7 +79,8 @@ func SendTransactionToAllNeighbours(config Config, trans Transaction) { ...@@ -78,7 +79,8 @@ func SendTransactionToAllNeighbours(config Config, trans Transaction) {
for neighbour := range config.Neighbours { for neighbour := range config.Neighbours {
fmt.Println("Sending transaction to neighbour ", config.Neighbours[neighbour].ID) fmt.Println("Sending transaction to neighbour ", config.Neighbours[neighbour].ID)
ip := config.Neighbours[neighbour].Address 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) SendTransactionToNeighbour(config, trans, ip, port)
} }
} }
......
...@@ -6,7 +6,7 @@ import ( ...@@ -6,7 +6,7 @@ import (
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
"log" "log"
"net" "net"
command_line "node/command-line" commandline "node/command-line"
ObjectStorage "node/object-storage" ObjectStorage "node/object-storage"
ProcessConnection "node/process-connection" ProcessConnection "node/process-connection"
. "node/types" . "node/types"
...@@ -25,7 +25,8 @@ import ( ...@@ -25,7 +25,8 @@ import (
*/ */
func listenForConnections(serverConfig Config, objectStorage Blob, addressToListenOn string, amIRoot bool) { 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 completeAddress := addressToListenOn + ":" + port
server, err := net.Listen("tcp", completeAddress) server, err := net.Listen("tcp", completeAddress)
...@@ -94,7 +95,7 @@ func main() { ...@@ -94,7 +95,7 @@ func main() {
addressToListenOn := "0.0.0.0" addressToListenOn := "0.0.0.0"
go listenForConnections(serverConfig, objectStorage, addressToListenOn, amIRoot) go listenForConnections(serverConfig, objectStorage, addressToListenOn, amIRoot)
command_line.ServerUserInputLoop(serverConfig, true, objectStorage) commandline.ServerUserInputLoop(serverConfig, true, objectStorage)
_, err = objectStorage.BlockBlobClient.Delete(ctx, nil) _, err = objectStorage.BlockBlobClient.Delete(ctx, nil)
if err != nil { if err != nil {
......
...@@ -33,7 +33,8 @@ func PrintNeighbors(neighbors []Neighbors) { ...@@ -33,7 +33,8 @@ func PrintNeighbors(neighbors []Neighbors) {
fmt.Println("***********INDEX N=,", i, "****************") fmt.Println("***********INDEX N=,", i, "****************")
fmt.Println("The id is ", neighbor.ID) fmt.Println("The id is ", neighbor.ID)
fmt.Println("The address is ", neighbor.Address) 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("***********************************") fmt.Println("***********************************")
} }
} }
...@@ -42,7 +43,8 @@ func PrintConfig(config Config) { ...@@ -42,7 +43,8 @@ func PrintConfig(config Config) {
fmt.Println("Printing config") fmt.Println("Printing config")
fmt.Println("The id is ", config.ID) fmt.Println("The id is ", config.ID)
fmt.Println("The address is ", config.Address) 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) PrintNeighbors(config.Neighbours)
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment