Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dfss
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
7
Issues
7
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mpcs
dfss
Commits
0f175c74
Commit
0f175c74
authored
May 24, 2016
by
Caro Axel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add mutex on ttp
parent
d05936eb
Pipeline
#2125
passed with stage
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
8 deletions
+22
-8
dfsst/server/server.go
dfsst/server/server.go
+22
-8
No files found.
dfsst/server/server.go
View file @
0f175c74
...
...
@@ -18,28 +18,37 @@ import (
"github.com/spf13/viper"
"golang.org/x/net/context"
"google.golang.org/grpc"
"gopkg.in/mgo.v2/bson"
)
// InternalError : constant string used to return a generic error message through gRPC in case of an internal error.
const
InternalError
string
=
"Internal server error"
var
mutex
sync
.
Mutex
type
ttpServer
struct
{
DB
*
mgdb
.
MongoManager
DB
*
mgdb
.
MongoManager
globalMut
*
sync
.
Mutex
mutMap
map
[
bson
.
ObjectId
]
*
sync
.
Mutex
}
// Alert route for the TTP.
func
(
server
*
ttpServer
)
Alert
(
ctx
context
.
Context
,
in
*
tAPI
.
AlertRequest
)
(
*
tAPI
.
TTPResponse
,
error
)
{
mutex
.
Lock
()
defer
mutex
.
Unlock
()
valid
,
signatureUUID
,
signers
,
senderIndex
:=
entities
.
IsRequestValid
(
ctx
,
in
.
Promises
)
if
!
valid
{
dAPI
.
DLog
(
"invalid request from "
+
net
.
GetCN
(
&
ctx
))
return
nil
,
errors
.
New
(
InternalError
)
}
server
.
globalMut
.
Lock
()
_
,
ok
:=
server
.
mutMap
[
signatureUUID
]
if
!
ok
{
server
.
mutMap
[
signatureUUID
]
=
&
sync
.
Mutex
{}
}
server
.
mutMap
[
signatureUUID
]
.
Lock
()
server
.
globalMut
.
Unlock
()
defer
server
.
mutMap
[
signatureUUID
]
.
Unlock
()
dAPI
.
DLog
(
"resolve index is: "
+
fmt
.
Sprint
(
in
.
Index
))
valid
=
int
(
in
.
Index
)
<
len
(
in
.
Promises
[
0
]
.
Context
.
Sequence
)
if
!
valid
{
...
...
@@ -91,7 +100,7 @@ func (server *ttpServer) Alert(ctx context.Context, in *tAPI.AlertRequest) (*tAP
// Try to generate the contract now
message
,
err
=
server
.
handleContractGenerationTry
(
manager
)
// We manually update the database
ok
,
err
:
=
server
.
DB
.
Get
(
"signatures"
)
.
UpdateByID
(
*
(
manager
.
Archives
))
ok
,
err
=
server
.
DB
.
Get
(
"signatures"
)
.
UpdateByID
(
*
(
manager
.
Archives
))
if
!
ok
{
dAPI
.
DLog
(
"error during 'UpdateByID' l.81"
+
fmt
.
Sprint
(
err
.
Error
()))
return
nil
,
errors
.
New
(
InternalError
)
...
...
@@ -235,9 +244,14 @@ func GetServer() *grpc.Server {
os
.
Exit
(
2
)
}
mutmap
:=
make
(
map
[
bson
.
ObjectId
]
*
sync
.
Mutex
)
server
:=
&
ttpServer
{
DB
:
dbManager
,
DB
:
dbManager
,
globalMut
:
&
sync
.
Mutex
{},
mutMap
:
mutmap
,
}
netServer
:=
net
.
NewServer
(
cert
,
key
,
ca
)
tAPI
.
RegisterTTPServer
(
netServer
,
server
)
return
netServer
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment