Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sys_distrib
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
julien.debray
sys_distrib
Commits
7d58b3e3
Commit
7d58b3e3
authored
2 years ago
by
julien.debray
Browse files
Options
Downloads
Patches
Plain Diff
Ajout fake et list
parent
5b1c497c
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
client/client.go
+13
-20
13 additions, 20 deletions
client/client.go
server/server.go
+33
-6
33 additions, 6 deletions
server/server.go
server/yaml/neighbour-1.yaml
+2
-2
2 additions, 2 deletions
server/yaml/neighbour-1.yaml
server/yaml/neighbour-3.yaml
+2
-2
2 additions, 2 deletions
server/yaml/neighbour-3.yaml
with
50 additions
and
30 deletions
client/client.go
+
13
−
20
View file @
7d58b3e3
...
...
@@ -6,13 +6,14 @@ import (
"math/rand"
"net"
"os"
"strconv"
"time"
"gopkg.in/yaml.v3"
)
const
(
SERVER_HOST
=
"
127.0.0.1
"
SERVER_HOST
=
"
4.233.112.40
"
SERVER_PORT
=
"9876"
SERVER_TYPE
=
"tcp"
)
...
...
@@ -26,9 +27,9 @@ type Transaction struct {
type
Data
struct
{
Sender
int
`yaml:"sender"`
// = sender's node ID or 0 if sender is not a node
Create
bool
`yaml:"create"`
//
create transaction or verify
voteOK
int
`yaml:"voteOK"`
// counter for v
erify
voteKO
int
`yaml:"voteKO"`
// counter for v
erify
Action
int
`yaml:"create"`
//
action to do
voteOK
int
`yaml:"voteOK"`
// counter for v
ote
voteKO
int
`yaml:"voteKO"`
// counter for v
ote
Transaction
struct
{
// transaction
ID
int
`yaml:"id"`
Sender
string
`yaml:"sender"`
...
...
@@ -38,17 +39,9 @@ type Data struct {
}
func
main
()
{
if
os
.
Args
[
1
]
!=
"0"
&&
os
.
Args
[
1
]
!=
"1"
{
fmt
.
Print
(
"Use: go run client.go x with x = 0 / 1
\n
"
)
os
.
Exit
(
1
)
}
var
create
bool
if
os
.
Args
[
1
]
==
"0"
{
create
=
false
}
else
{
create
=
true
}
data
:=
createData
(
create
)
action
,
_
:=
strconv
.
Atoi
(
os
.
Args
[
1
])
// action -> 0: vote / 1: create / 2: fake / 3: list
data
:=
createData
(
action
)
str
,
_
:=
yaml
.
Marshal
(
data
)
connection
,
err
:=
net
.
Dial
(
SERVER_TYPE
,
SERVER_HOST
+
":"
+
SERVER_PORT
)
if
err
!=
nil
{
...
...
@@ -60,23 +53,23 @@ func main() {
func
createTransaction
()
Transaction
{
var
transaction
Transaction
rand2
:=
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
transaction
.
id
=
rand2
.
Intn
(
1000
)
transaction
.
id
=
rand2
.
Intn
(
1000
0
)
transaction
.
sender
=
"A"
transaction
.
receiver
=
"B"
transaction
.
amount
=
100
return
transaction
}
func
createData
(
create
bool
)
Data
{
func
createData
(
action
int
)
Data
{
var
data
Data
data
.
Sender
=
0
data
.
voteKO
=
0
data
.
voteOK
=
0
data
.
Create
=
create
data
.
Action
=
action
transaction
:=
createTransaction
()
if
create
{
if
action
==
1
{
data
.
Transaction
.
ID
=
transaction
.
id
}
else
{
}
else
if
action
!=
3
{
var
transactionID
int
fmt
.
Scanf
(
"%d"
,
&
transactionID
)
data
.
Transaction
.
ID
=
transactionID
...
...
This diff is collapsed.
Click to expand it.
server/server.go
+
33
−
6
View file @
7d58b3e3
...
...
@@ -40,9 +40,9 @@ type Transaction struct {
type
Data
struct
{
Sender
int
`yaml:"sender"`
// = sender's node ID or 0 if sender is not a node
Create
bool
`yaml:"create"`
//
create transaction or verify
voteOK
int
`yaml:"voteOK"`
// counter for v
erify
voteKO
int
`yaml:"voteKO"`
// counter for v
erify
Action
int
`yaml:"create"`
//
action to do
voteOK
int
`yaml:"voteOK"`
// counter for v
ote
voteKO
int
`yaml:"voteKO"`
// counter for v
ote
Transaction
struct
{
// transaction
ID
int
`yaml:"id"`
Sender
string
`yaml:"sender"`
...
...
@@ -84,10 +84,14 @@ func main() {
data
:=
parseData
(
connection
)
connection
.
Write
([]
byte
(
"ok"
))
if
data
.
Create
{
createTransaction
(
data
)
}
else
{
if
data
.
Action
==
0
{
fmt
.
Print
(
"Rate: "
+
strconv
.
Itoa
(
vote
(
data
,
strings
.
Split
(
connection
.
RemoteAddr
()
.
String
(),
":"
)[
0
]))
+
"
\n
"
)
}
else
if
data
.
Action
==
1
{
createTransaction
(
data
)
}
else
if
data
.
Action
==
2
{
fake
(
data
)
}
else
if
data
.
Action
==
3
{
list
()
}
connection
.
Close
()
}
...
...
@@ -234,6 +238,29 @@ func blobExists(transactionId int) bool {
return
false
}
func
list
()
{
pager
:=
azureClient
.
NewListBlobsFlatPager
(
containerName
,
nil
)
for
pager
.
More
()
{
resp
,
err
:=
pager
.
NextPage
(
context
.
TODO
())
handleError
(
err
)
for
_
,
v
:=
range
resp
.
Segment
.
BlobItems
{
id
,
_
:=
strconv
.
Atoi
(
*
v
.
Name
)
transaction
:=
downloadBlob
(
id
)
data
:=
strconv
.
Itoa
(
transaction
.
id
)
+
";"
+
transaction
.
sender
+
";"
+
transaction
.
receiver
+
";"
+
fmt
.
Sprintf
(
"%f"
,
transaction
.
amount
)
fmt
.
Println
(
"Transaction "
+
strconv
.
Itoa
(
id
)
+
": "
+
data
)
}
}
}
func
fake
(
data
Data
)
{
transaction
:=
parseTransaction
(
data
)
if
blobExists
(
transaction
.
id
)
{
transaction
:=
downloadBlob
(
transaction
.
id
)
transaction
.
amount
=
20
uploadBlob
(
transaction
)
}
}
func
handleError
(
err
error
)
{
if
err
!=
nil
{
log
.
Fatal
(
err
.
Error
())
...
...
This diff is collapsed.
Click to expand it.
server/yaml/neighbour-1.yaml
+
2
−
2
View file @
7d58b3e3
...
...
@@ -4,5 +4,5 @@ neighbours:
-
id
:
2
address
:
"
20.216.148.5"
-
id
:
3
address
:
"
20.123.192.218"
\ No newline at end of file
-
id
:
4
address
:
"
20.224.123.38"
\ No newline at end of file
This diff is collapsed.
Click to expand it.
server/yaml/neighbour-3.yaml
+
2
−
2
View file @
7d58b3e3
...
...
@@ -4,5 +4,5 @@ neighbours:
-
id
:
2
address
:
"
20.216.148.5"
-
id
:
1
address
:
"
4.233.112.40"
\ No newline at end of file
-
id
:
6
address
:
"
20.203.221.39"
\ No newline at end of file
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