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
Compare revisions
ab01bb30ae6cf0a5f315e01b9e3b22877d2c0b6d to 241f2f8a46e32240b59926286f135e875e2cc91e
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
xavier.perret/perso-distributed-systems
Select target project
No results found
241f2f8a46e32240b59926286f135e875e2cc91e
Select Git revision
Branches
master
1 result
Swap
Target
xavier.perret/perso-distributed-systems
Select target project
xavier.perret/perso-distributed-systems
1 result
ab01bb30ae6cf0a5f315e01b9e3b22877d2c0b6d
Select Git revision
Branches
master
1 result
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (3)
added rand function
· 9778f230
Xavier Perret
authored
2 years ago
9778f230
only debugging now
· 2ecaf178
Xavier Perret
authored
2 years ago
2ecaf178
removed prints
· 241f2f8a
Xavier Perret
authored
2 years ago
241f2f8a
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/command-line/userinput.go
+1
-4
1 addition, 4 deletions
app/command-line/userinput.go
app/process-connection/process-connection.go
+23
-0
23 additions, 0 deletions
app/process-connection/process-connection.go
app/utilities/utilities.go
+10
-1
10 additions, 1 deletion
app/utilities/utilities.go
with
34 additions
and
5 deletions
app/command-line/userinput.go
View file @
241f2f8a
...
...
@@ -66,7 +66,7 @@ func ServerUserInputLoop(config Config, isAlsoServer bool, objectStorage Blob) {
fmt
.
Println
(
"Please enter the operation you want to do"
)
fmt
.
Println
(
"1. Fabricate a fake transaction"
)
fmt
.
Println
(
"2. Print all transactions"
)
fmt
.
Println
(
"
4
. Exit"
)
fmt
.
Println
(
"
3
. Exit"
)
fmt
.
Print
(
"Your choice: "
)
_
,
err
:=
fmt
.
Scanln
(
&
operation
)
if
err
!=
nil
{
...
...
@@ -107,9 +107,6 @@ func ServerUserInputLoop(config Config, isAlsoServer bool, objectStorage Blob) {
utilities
.
PrintingDatabaseToConsole
(
database
)
break
case
"3"
:
fmt
.
Println
(
"You chose to ask for all transactions of a given node"
)
break
case
"4"
:
fmt
.
Println
(
"You chose to exit"
)
return
default
:
...
...
This diff is collapsed.
Click to expand it.
app/process-connection/process-connection.go
View file @
241f2f8a
...
...
@@ -200,12 +200,31 @@ func processFakeRequest(conn net.Conn, serverListener net.Listener, serverConfig
trans
:=
utilities
.
TranslateMessageToTransaction
(
mess
)
utilities
.
PrintTransaction
(
trans
)
fakeTrans
:=
Transaction
{
Id
:
trans
.
Id
,
Sender
:
utilities
.
RandomString
(),
Receiver
:
utilities
.
RandomString
(),
Amount
:
utilities
.
RandomString
(),
}
database
:=
ObjectStorageAPI
.
ReadDatabaseFromBlobStorage
(
objectStorage
)
database
=
ObjectStorageAPI
.
FakeTransaction
(
trans
,
fakeTrans
,
database
)
ObjectStorageAPI
.
WriteDatabaseToBlobStorage
(
database
,
objectStorage
)
}
func
processVoteRequest
(
conn
net
.
Conn
,
serverListener
net
.
Listener
,
serverConfig
Config
,
objectStorage
Blob
,
mess
Message
,
amIRoot
bool
)
{
trans
:=
utilities
.
TranslateMessageToTransaction
(
mess
)
var
transToRate
Transaction
utilities
.
PrintTransaction
(
trans
)
database
:=
ObjectStorageAPI
.
ReadDatabaseFromBlobStorage
(
objectStorage
)
for
_
,
transactionInDatabase
:=
range
database
{
if
trans
.
Id
==
transactionInDatabase
.
Id
{
transToRate
=
transactionInDatabase
}
}
vote
(
serverListener
,
serverConfig
,
transToRate
,
""
,
objectStorage
,
amIRoot
)
}
func
ProcessClient
(
conn
net
.
Conn
,
server
net
.
Listener
,
objectStorage
Blob
,
serverConfig
Config
,
amIRoot
bool
,
mutex
*
sync
.
Mutex
)
{
...
...
@@ -237,6 +256,10 @@ func ProcessClient(conn net.Conn, server net.Listener, objectStorage Blob, serve
}
else
if
mess
.
MessageType
==
"voteRequest"
{
fmt
.
Println
(
"Received a request to vote on a given transaction"
)
processVoteRequest
(
conn
,
server
,
serverConfig
,
objectStorage
,
mess
,
amIRoot
)
}
else
if
mess
.
MessageType
==
"listTransactionsRequest"
{
fmt
.
Println
(
"Received a request to list all transactions"
)
database
:=
ObjectStorageAPI
.
ReadDatabaseFromBlobStorage
(
objectStorage
)
utilities
.
PrintingDatabaseToConsole
(
database
)
}
else
{
fmt
.
Println
(
"Unknown message type"
)
}
...
...
This diff is collapsed.
Click to expand it.
app/utilities/utilities.go
View file @
241f2f8a
...
...
@@ -2,8 +2,11 @@ package utilities
import
(
"fmt"
"math/rand"
"net"
.
"node/types"
"strconv"
"time"
)
func
PrintTransaction
(
trans
Transaction
)
{
...
...
@@ -115,4 +118,10 @@ func TranslateMessageToTransaction(mess Message) Transaction {
newTrans
.
Amount
=
body
[
"amount"
]
.
(
string
)
return
newTrans
}
func
RandomString
()
string
{
r
:=
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
return
strconv
.
Itoa
(
r
.
Int
())
}
This diff is collapsed.
Click to expand it.