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
949ea52a
Commit
949ea52a
authored
2 years ago
by
Xavier Perret
Browse files
Options
Downloads
Patches
Plain Diff
removed duplicate code
parent
fc55dcd1
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/process-connection/process-connection.go
+24
-16
24 additions, 16 deletions
app/process-connection/process-connection.go
with
24 additions
and
16 deletions
app/process-connection/process-connection.go
+
24
−
16
View file @
949ea52a
...
@@ -73,12 +73,7 @@ func processTransaction(serverListener net.Listener, serverConfig Config, object
...
@@ -73,12 +73,7 @@ func processTransaction(serverListener net.Listener, serverConfig Config, object
err
=
nil
err
=
nil
continue
continue
}
}
fmt
.
Println
(
"*****************************************"
)
utilities
.
PrintConnection
(
connection
,
count
)
fmt
.
Println
(
"Processing client request number "
,
count
)
fmt
.
Println
(
"The process-manage-connection is "
,
connection
)
fmt
.
Println
(
"The remote address is "
,
connection
.
RemoteAddr
())
fmt
.
Println
(
"The local address is "
,
connection
.
LocalAddr
())
fmt
.
Println
(
"*****************************************"
)
err
=
json
.
NewDecoder
(
connection
)
.
Decode
(
&
trans
)
err
=
json
.
NewDecoder
(
connection
)
.
Decode
(
&
trans
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -165,12 +160,8 @@ func vote(server net.Listener, serverConfig Config, trans Transaction, parentAdd
...
@@ -165,12 +160,8 @@ func vote(server net.Listener, serverConfig Config, trans Transaction, parentAdd
err
=
nil
err
=
nil
continue
continue
}
}
fmt
.
Println
(
"*****************************************"
)
fmt
.
Println
(
"Processing client request number "
,
count
)
utilities
.
PrintConnection
(
connection
,
count
)
fmt
.
Println
(
"The process-manage-connection is "
,
connection
)
fmt
.
Println
(
"The remote address is "
,
connection
.
RemoteAddr
())
fmt
.
Println
(
"The local address is "
,
connection
.
LocalAddr
())
fmt
.
Println
(
"*****************************************"
)
err
=
json
.
NewDecoder
(
connection
)
.
Decode
(
&
mess
)
err
=
json
.
NewDecoder
(
connection
)
.
Decode
(
&
mess
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -219,13 +210,24 @@ func vote(server net.Listener, serverConfig Config, trans Transaction, parentAdd
...
@@ -219,13 +210,24 @@ func vote(server net.Listener, serverConfig Config, trans Transaction, parentAdd
return
ack
return
ack
}
}
func
processFakeRequest
(
conn
net
.
Conn
,
serverListener
net
.
Listener
,
serverConfig
Config
,
objectStorage
Blob
,
mess
Message
,
amIRoot
bool
)
{
var
trans
Transaction
var
body
map
[
string
]
interface
{}
=
mess
.
MessageBody
.
(
map
[
string
]
interface
{})
}
func
processVoteRequest
(
conn
net
.
Conn
,
serverListener
net
.
Listener
,
serverConfig
Config
,
objectStorage
Blob
,
mess
Message
,
amIRoot
bool
)
{
var
trans
Transaction
var
body
map
[
string
]
interface
{}
=
mess
.
MessageBody
.
(
map
[
string
]
interface
{})
fmt
.
Println
(
"Received back a transaction"
)
utilities
.
PrintTransaction
(
trans
)
}
func
ProcessClient
(
conn
net
.
Conn
,
server
net
.
Listener
,
objectStorage
Blob
,
serverConfig
Config
,
amIRoot
bool
,
mutex
*
sync
.
Mutex
)
{
func
ProcessClient
(
conn
net
.
Conn
,
server
net
.
Listener
,
objectStorage
Blob
,
serverConfig
Config
,
amIRoot
bool
,
mutex
*
sync
.
Mutex
)
{
mutex
.
Lock
()
mutex
.
Lock
()
defer
mutex
.
Unlock
()
defer
mutex
.
Unlock
()
fmt
.
Println
(
"Processing client"
)
utilities
.
PrintConnection
(
conn
,
0
)
fmt
.
Println
(
"The conn is "
,
conn
)
fmt
.
Println
(
"The remote address is "
,
conn
.
RemoteAddr
())
fmt
.
Println
(
"The local address is "
,
conn
.
LocalAddr
())
var
mess
Message
var
mess
Message
jsonDecoder
:=
json
.
NewDecoder
(
conn
)
jsonDecoder
:=
json
.
NewDecoder
(
conn
)
...
@@ -245,6 +247,12 @@ func ProcessClient(conn net.Conn, server net.Listener, objectStorage Blob, serve
...
@@ -245,6 +247,12 @@ func ProcessClient(conn net.Conn, server net.Listener, objectStorage Blob, serve
}
else
if
mess
.
MessageType
==
"list"
{
}
else
if
mess
.
MessageType
==
"list"
{
fmt
.
Println
(
"Received an order to list all transactions"
)
fmt
.
Println
(
"Received an order to list all transactions"
)
listAllTransactionsToClient
(
conn
,
objectStorage
)
listAllTransactionsToClient
(
conn
,
objectStorage
)
}
else
if
mess
.
MessageType
==
"fakeRequest"
{
fmt
.
Println
(
"Received a request to fake transaction"
)
processFakeRequest
(
conn
,
server
,
serverConfig
,
objectStorage
,
mess
,
amIRoot
)
}
else
if
mess
.
MessageType
==
"voteRequest"
{
fmt
.
Println
(
"Received a request to vote on a given transaction"
)
processVoteRequest
(
conn
,
server
,
serverConfig
,
objectStorage
,
mess
,
amIRoot
)
}
else
{
}
else
{
fmt
.
Println
(
"Unknown message type"
)
fmt
.
Println
(
"Unknown message type"
)
}
}
...
...
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