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)
id: -1
address: "127.0.0.1"
port: 4000
neighbors:
- id: 0
address: "127.0.0.1"
port: 5001
- id: 1
address: "127.0.0.2"
port: 5002
- id: 2
address: "127.0.0.3"
port: 5002
- id: 3
address: "127.0.0.4"
port: 5004
- id: 4
address: "127.0.0.5"
port: 5005
- id: 5
address: "127.0.0.6"
\ No newline at end of file
port: 5006
\ No newline at end of file
......@@ -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)
......
id: 0
address: "127.0.0.1"
port: 5001
neighbors:
- id: 2
address: "127.0.0.3"
port: 5003
- id: 3
address: "127.0.0.4"
\ No newline at end of file
port: 5004
\ No newline at end of file
id: 1
address: "127.0.0.2"
port: 5002
neighbors:
- id: 2
address: "127.0.0.3"
\ No newline at end of file
port: 5003
\ No newline at end of file
id: 2
address: "127.0.0.3"
port: 5003
neighbors:
- id: 0
address: "127.0.0.1"
port: 5001
- id: 1
address: "127.0.0.2"
port: 5002
- id: 4
address: "127.0.0.5"
port: 5005
- id: 5
address: "127.0.0.6"
\ No newline at end of file
port: 5006
\ No newline at end of file
id: 3
address: "127.0.0.4"
port: 5004
neighbors:
- id: 0
address: "127.0.0.1"
\ No newline at end of file
port: 5001
\ No newline at end of file
id: 4
address: "127.0.0.5"
port: 5005
neighbors:
- id: 2
address: "127.0.0.3"
\ No newline at end of file
port: 5003
\ No newline at end of file
id: 5
address: "127.0.0.6"
port: 5006
neighbors:
- id: 2
address: "127.0.0.3"
\ No newline at end of file
port: 5003
\ No newline at end of file
......@@ -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
......
......@@ -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)
}
}
......
......@@ -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 {
......
......@@ -45,12 +45,10 @@ type Blob struct {
type Config struct {
ID int `yaml:"id"`
Address string `yaml:"address"`
Port int `yaml:"port"`
Neighbours []Neighbors `yaml:"neighbors"`
}
type Neighbors struct {
ID int `yaml:"id"`
Address string `yaml:"address"`
Port int `yaml:"port"`
}
......@@ -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)
}
......