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

added function to init object storage

parent 86ceee09
Branches
No related tags found
1 merge request!2added file to separate client function from the server
......@@ -3,9 +3,14 @@ package main
import (
"fmt"
"gopkg.in/yaml.v3"
"net"
"node/connection"
object_storage "node/object-storage"
. "node/types"
"node/utilities"
"os"
"strconv"
"sync"
)
/**
......@@ -16,6 +21,33 @@ import (
* @version 1.3
*/
func listenForConnections(serverConfig Config, objectStorage Blob, addressToListenOn string, amIRoot bool) {
port := strconv.FormatInt(int64(serverConfig.Port), 10)
completeAddress := addressToListenOn + ":" + port
server, err := net.Listen("tcp", completeAddress)
if err != nil {
fmt.Println("Error while creating the server :", err)
os.Exit(1)
}
fmt.Println("Server is ready to accept connections")
fmt.Println("listening on ", completeAddress)
ServerReady = true
var mu sync.Mutex
for {
// Listening for connections
conn, err := server.Accept()
if err != nil {
fmt.Println("Error accepting: ", err.Error())
} else {
go connection.ProcessClient(conn, server, serverConfig, amIRoot, &mu)
}
}
}
func main() {
argsLen := len(os.Args)
isThereEnoughArgs := argsLen <= 1
......@@ -36,13 +68,13 @@ func main() {
os.Exit(1)
}
var c Config
err = yaml.Unmarshal(buf, &c)
var serverConfig Config
err = yaml.Unmarshal(buf, &serverConfig)
if err != nil {
os.Exit(1)
}
utilities.PrintConfig(c)
utilities.PrintConfig(serverConfig)
amIRoot := argsLen == 3
if amIRoot {
......@@ -55,5 +87,13 @@ func main() {
}
fmt.Println("Launching server loop")
addressToListenOn := "0.0.0.0"
azureCreds := object_storage.InitAzureCredentials("hepiadistributedsystems")
blobName := "blockchain" + "-" + "database" + "" + strconv.Itoa(serverConfig.ID)
objectStorage := object_storage.InitializeBlobFromObjectStorageCreds(blobName, azureCreds)
go listenForConnections(serverConfig, objectStorage, addressToListenOn, amIRoot)
fmt.Println("Launching user input command line")
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment