Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
perso-distributed-systems
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Maintenance Gitedu aujourd'hui à 12h00 pour env. 30 minutes
Show more breadcrumbs
xavier.perret
perso-distributed-systems
Commits
6cf0442a
Commit
6cf0442a
authored
2 years ago
by
Xavier Perret
Browse files
Options
Downloads
Patches
Plain Diff
added function to init object storage
parent
86ceee09
No related branches found
No related tags found
1 merge request
!2
added file to separate client function from the server
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/server.go
+43
-3
43 additions, 3 deletions
app/server.go
with
43 additions
and
3 deletions
app/server.go
+
43
−
3
View file @
6cf0442a
...
...
@@ -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"
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment