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
Show more breadcrumbs
xavier.perret
perso-distributed-systems
Commits
841fd6d8
Commit
841fd6d8
authored
2 years ago
by
Xavier Perret
Browse files
Options
Downloads
Patches
Plain Diff
improved userinput
parent
a9c6b071
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/command-line/userinput.go
+28
-37
28 additions, 37 deletions
app/command-line/userinput.go
with
28 additions
and
37 deletions
app/command-line/userinput.go
+
28
−
37
View file @
841fd6d8
...
@@ -2,7 +2,11 @@ package command_line
...
@@ -2,7 +2,11 @@ package command_line
import
(
import
(
"fmt"
"fmt"
"math/rand"
ObjectStorageAPI
"node/object-storage"
Sender
"node/sender"
.
"node/types"
.
"node/types"
"node/utilities"
"os"
"os"
"strconv"
"strconv"
"time"
"time"
...
@@ -53,12 +57,10 @@ func userCreatedTransaction(config Config) Transaction {
...
@@ -53,12 +57,10 @@ func userCreatedTransaction(config Config) Transaction {
return
trans
return
trans
}
}
func
UserInputLoop
(
config
Config
,
isAlsoServer
bool
)
{
func
UserInputLoop
(
config
Config
,
isAlsoServer
bool
,
objectStorage
Blob
)
{
var
database
Database
for
true
{
for
true
{
var
operation
string
var
operation
string
if
!
ServerReady
{
continue
}
fmt
.
Println
()
fmt
.
Println
()
fmt
.
Println
()
fmt
.
Println
()
fmt
.
Println
(
"Please enter the operation you want to do"
)
fmt
.
Println
(
"Please enter the operation you want to do"
)
...
@@ -82,8 +84,9 @@ func UserInputLoop(config Config, isAlsoServer bool) {
...
@@ -82,8 +84,9 @@ func UserInputLoop(config Config, isAlsoServer bool) {
//createTransaction(newTrans)
//createTransaction(newTrans)
}
else
{
}
else
{
newTrans
:=
userCreatedTransaction
(
config
)
newTrans
:=
userCreatedTransaction
(
config
)
addTransactionToDb
(
newTrans
)
database
=
ObjectStorageAPI
.
ReadDatabaseFromBlobStorage
(
objectStorage
)
printAllNeighbours
(
config
)
database
=
ObjectStorageAPI
.
AddTransactionToBlobStorage
(
newTrans
,
database
,
objectStorage
)
utilities
.
PrintNeighbors
(
config
.
Neighbours
)
fmt
.
Println
(
"TRANSACTION READY TO BE SENT"
)
fmt
.
Println
(
"TRANSACTION READY TO BE SENT"
)
fmt
.
Println
(
"Please enter the ID of the neighbour you want to send the transaction to"
)
fmt
.
Println
(
"Please enter the ID of the neighbour you want to send the transaction to"
)
var
neighbourID
string
var
neighbourID
string
...
@@ -97,12 +100,13 @@ func UserInputLoop(config Config, isAlsoServer bool) {
...
@@ -97,12 +100,13 @@ func UserInputLoop(config Config, isAlsoServer bool) {
fmt
.
Println
(
"error :"
,
err
.
Error
())
fmt
.
Println
(
"error :"
,
err
.
Error
())
os
.
Exit
(
1
)
os
.
Exit
(
1
)
}
}
s
endTransactionToNeighbour
(
config
,
newTrans
,
config
.
Neighbours
[
neighbourIDInt
]
.
Address
,
strconv
.
Itoa
(
config
.
Neighbours
[
neighbourIDInt
]
.
Port
))
Sender
.
S
endTransactionToNeighbour
(
config
,
newTrans
,
config
.
Neighbours
[
neighbourIDInt
]
.
Address
,
strconv
.
Itoa
(
config
.
Neighbours
[
neighbourIDInt
]
.
Port
))
}
}
break
break
case
"2"
:
case
"2"
:
fmt
.
Println
(
"You chose to rate a transaction"
)
fmt
.
Println
(
"You chose to rate a transaction"
)
listAllTransactions
()
database
=
ObjectStorageAPI
.
ReadDatabaseFromBlobStorage
(
objectStorage
)
utilities
.
PrintingDatabaseToConsole
(
database
)
fmt
.
Print
(
"
\n
Please enter the index of the transaction you want to rate:"
)
fmt
.
Print
(
"
\n
Please enter the index of the transaction you want to rate:"
)
var
transID
string
var
transID
string
_
,
err
:=
fmt
.
Scanln
(
&
transID
)
_
,
err
:=
fmt
.
Scanln
(
&
transID
)
...
@@ -115,7 +119,7 @@ func UserInputLoop(config Config, isAlsoServer bool) {
...
@@ -115,7 +119,7 @@ func UserInputLoop(config Config, isAlsoServer bool) {
fmt
.
Println
(
"error :"
,
err
.
Error
())
fmt
.
Println
(
"error :"
,
err
.
Error
())
os
.
Exit
(
1
)
os
.
Exit
(
1
)
}
}
p
rint
All
Neighbo
u
rs
(
config
)
utilities
.
P
rintNeighbors
(
config
.
Neighbours
)
fmt
.
Println
(
"Please enter the ID of the neighbour you want to send the transaction to"
)
fmt
.
Println
(
"Please enter the ID of the neighbour you want to send the transaction to"
)
var
neighbourID
string
var
neighbourID
string
_
,
err
=
fmt
.
Scanln
(
&
neighbourID
)
_
,
err
=
fmt
.
Scanln
(
&
neighbourID
)
...
@@ -130,53 +134,40 @@ func UserInputLoop(config Config, isAlsoServer bool) {
...
@@ -130,53 +134,40 @@ func UserInputLoop(config Config, isAlsoServer bool) {
}
}
address
:=
config
.
Neighbours
[
neighbourIDInt
]
.
Address
+
":"
+
strconv
.
Itoa
(
config
.
Neighbours
[
neighbourIDInt
]
.
Port
)
address
:=
config
.
Neighbours
[
neighbourIDInt
]
.
Address
+
":"
+
strconv
.
Itoa
(
config
.
Neighbours
[
neighbourIDInt
]
.
Port
)
fmt
.
Println
(
"Sending rate demand to "
,
address
)
fmt
.
Println
(
"Sending rate demand to "
,
address
)
sendVoteToNeighbour
(
config
,
DB
[
transIDInt
],
address
)
database
=
ObjectStorageAPI
.
ReadDatabaseFromBlobStorage
(
objectStorage
)
Sender
.
SendVoteToNeighbour
(
config
,
database
[
transIDInt
],
address
)
break
break
case
"3"
:
case
"3"
:
fmt
.
Println
(
"You chose to fabricate a fake transaction"
)
fmt
.
Println
(
"You chose to fabricate a fake transaction"
)
fmt
.
Println
(
"You chose to fake a transaction"
)
fmt
.
Println
(
"You chose to fake a transaction"
)
listAllTransactions
()
database
=
ObjectStorageAPI
.
ReadDatabaseFromBlobStorage
(
objectStorage
)
utilities
.
PrintingDatabaseToConsole
(
database
)
fmt
.
Print
(
"
\n
Please enter the index of the transaction you want to overwrite by faking:"
)
fmt
.
Print
(
"
\n
Please enter the index of the transaction you want to overwrite by faking:"
)
var
transID
string
var
transID
string
_
,
err
:=
fmt
.
Scanln
(
&
transID
)
_
,
err
:=
fmt
.
Scanln
(
&
transID
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
"error :"
,
err
.
Error
())
fmt
.
Println
(
"error :"
,
err
.
Error
())
os
.
Exit
(
1
)
os
.
Exit
(
1
)
}
}
transIDInt
,
err
:=
strconv
.
ParseInt
(
transID
,
10
,
64
)
transIDInt
,
err
:=
strconv
.
ParseInt
(
transID
,
10
,
64
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
"error :"
,
err
.
Error
())
fmt
.
Println
(
"error :"
,
err
.
Error
())
os
.
Exit
(
1
)
os
.
Exit
(
1
)
}
}
printAllNeighbours
(
config
)
fmt
.
Println
(
"Please enter the ID of the neighbour you to ask to fake the given transaction"
)
var
neighbourID
string
_
,
err
=
fmt
.
Scanln
(
&
neighbourID
)
if
err
!=
nil
{
fmt
.
Println
(
"error :"
,
err
.
Error
())
os
.
Exit
(
1
)
}
neighbourIDInt
,
err
:=
strconv
.
ParseInt
(
neighbourID
,
10
,
64
)
if
err
!=
nil
{
fmt
.
Println
(
"error :"
,
err
.
Error
())
os
.
Exit
(
1
)
}
tmpFakeTrans
:=
userCreatedTransaction
(
config
)
tmpFakeTrans
:=
userCreatedTransaction
(
config
)
transToFake
:=
DB
[
transIDInt
]
database
=
ObjectStorageAPI
.
ReadDatabaseFromBlobStorage
(
objectStorage
)
fakeTrans
:=
Transaction
{
database
=
ObjectStorageAPI
.
FakeTransaction
(
database
[
transIDInt
],
tmpFakeTrans
,
database
)
Id
:
transToFake
.
Id
,
ObjectStorageAPI
.
WriteDatabaseToBlobStorage
(
database
,
objectStorage
)
Sender
:
tmpFakeTrans
.
Sender
,
database
=
ObjectStorageAPI
.
ReadDatabaseFromBlobStorage
(
objectStorage
)
Receiver
:
tmpFakeTrans
.
Receiver
,
fmt
.
Println
(
"Database after faking:"
)
Amount
:
tmpFakeTrans
.
Amount
,
utilities
.
PrintingDatabaseToConsole
(
database
)
}
ip
:=
config
.
Neighbours
[
neighbourIDInt
]
.
Address
port
:=
strconv
.
Itoa
(
config
.
Neighbours
[
neighbourIDInt
]
.
Port
)
address
:=
ip
+
":"
+
port
sendFakeTransactionToNeighbour
(
fakeTrans
,
address
)
break
case
"4"
:
case
"4"
:
fmt
.
Println
(
"You chose to print all transactions"
)
fmt
.
Println
(
"You chose to print all transactions"
)
listAllTransactions
()
database
=
ObjectStorageAPI
.
ReadDatabaseFromBlobStorage
(
objectStorage
)
utilities
.
PrintingDatabaseToConsole
(
database
)
break
break
case
"5"
:
case
"5"
:
fmt
.
Println
(
"You chose to ask for all transactions of a given node"
)
fmt
.
Println
(
"You chose to ask for all transactions of a given node"
)
...
...
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