Commit b647a8ab authored by Caro Axel's avatar Caro Axel

Merge branch '471_servers_on_demo' into 'master'

[d] Add servers event (platform and TTP)



See merge request !83
parents eacf1637 57af36cd
Pipeline #2130 passed with stages
...@@ -5,8 +5,8 @@ import ( ...@@ -5,8 +5,8 @@ import (
"time" "time"
"dfss" "dfss"
"dfss/net"
dapi "dfss/dfssd/api" dapi "dfss/dfssd/api"
"dfss/net"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
......
...@@ -3,7 +3,6 @@ package sign ...@@ -3,7 +3,6 @@ package sign
import ( import (
"dfss" "dfss"
cAPI "dfss/dfssc/api" cAPI "dfss/dfssc/api"
dAPI "dfss/dfssd/api"
pAPI "dfss/dfssp/api" pAPI "dfss/dfssp/api"
"dfss/dfsst/entities" "dfss/dfsst/entities"
"dfss/net" "dfss/net"
...@@ -32,10 +31,8 @@ func (s *clientServer) TreatPromise(ctx context.Context, in *cAPI.Promise) (*pAP ...@@ -32,10 +31,8 @@ func (s *clientServer) TreatPromise(ctx context.Context, in *cAPI.Promise) (*pAP
// we do not check that we expected that promise // we do not check that we expected that promise
valid, _, _, _ := entities.IsRequestValid(ctx, []*cAPI.Promise{in}) valid, _, _, _ := entities.IsRequestValid(ctx, []*cAPI.Promise{in})
if !valid { if !valid {
dAPI.DLog("TreatPromise route did not treat promise from " + net.GetCN(&ctx) + " because it is invalid")
return &pAPI.ErrorCode{Code: pAPI.ErrorCode_SUCCESS}, nil return &pAPI.ErrorCode{Code: pAPI.ErrorCode_SUCCESS}, nil
} }
dAPI.DLog("TreatPromise route treated promise from " + net.GetCN(&ctx) + " because it is valid")
return getServerErrorCode(s.incomingPromises, in), nil return getServerErrorCode(s.incomingPromises, in), nil
} }
......
...@@ -5,10 +5,13 @@ package gui ...@@ -5,10 +5,13 @@ package gui
import "github.com/visualfc/goqt/ui" import "github.com/visualfc/goqt/ui"
var colors = map[string]uint32{ var colors = map[string]uint32{
"red": 0x00ff0000, "red": 0x00ff0000,
"green": 0x0000aa00, "green": 0x0000aa00,
"blue": 0x000000ff, "blue": 0x000000ff,
"black": 0x00000000, "black": 0x00000000,
"purple": 0x00aa00aa,
"lime": 0x0000ee00,
"grey": 0x00888888,
} }
var pen_black = ui.NewPenWithColor(ui.NewColorWithGlobalcolor(ui.Qt_black)) var pen_black = ui.NewPenWithColor(ui.NewColorWithGlobalcolor(ui.Qt_black))
......
...@@ -17,8 +17,12 @@ import ( ...@@ -17,8 +17,12 @@ import (
// Timestamp: unix nano timestamp // Timestamp: unix nano timestamp
// Identifier: either "platform", "ttp" or "<email>" // Identifier: either "platform", "ttp" or "<email>"
// Log: one of the following // Log: one of the following
// "sync with <entity>"
// "sent promise to <email>" // "sent promise to <email>"
// "sent signature to <email>" // "sent signature to <email>"
// "contacting TTP with resolve index <index>"
// "sent abort token to <email>"
// "send signed contract to <email>"
// //
// Other messages are currently ignored. // Other messages are currently ignored.
func (w *Window) AddEvent(e *api.Log) { func (w *Window) AddEvent(e *api.Log) {
...@@ -30,17 +34,30 @@ func (w *Window) AddEvent(e *api.Log) { ...@@ -30,17 +34,30 @@ func (w *Window) AddEvent(e *api.Log) {
w.Log(fmt.Sprint(e.Identifier, " ", e.Log)) w.Log(fmt.Sprint(e.Identifier, " ", e.Log))
var receiver string var receiver string
var index int
if n, _ := fmt.Sscanf(e.Log, "sent promise to %s", &receiver); n > 0 { if n, _ := fmt.Sscanf(e.Log, "sent promise to %s", &receiver); n > 0 {
event.Type = PROMISE event.Type = PROMISE
event.Receiver = w.scene.identifierToIndex(receiver) event.Receiver = w.scene.identifierToIndex(receiver)
} else if n, _ := fmt.Sscanf(e.Log, "sent signature to %s", &receiver); n > 0 { } else if n, _ := fmt.Sscanf(e.Log, "sent signature to %s", &receiver); n > 0 {
event.Type = SIGNATURE event.Type = SIGNATURE
event.Receiver = w.scene.identifierToIndex(receiver) event.Receiver = w.scene.identifierToIndex(receiver)
} else if n, _ := fmt.Sscanf(e.Log, "contacting TTP with resolve index %d", &index); n > 0 {
event.Type = TTPCALL
event.Receiver = w.scene.identifierToIndex("ttp")
} else if n, _ := fmt.Sscanf(e.Log, "sent abort token to %s", &receiver); n > 0 {
event.Type = TTPABORT
event.Receiver = w.scene.identifierToIndex(receiver)
} else if n, _ := fmt.Sscanf(e.Log, "sent signed contract to %s", &receiver); n > 0 {
event.Type = TTPSIGNED
event.Receiver = w.scene.identifierToIndex(receiver)
} else if n, _ := fmt.Sscanf(e.Log, "sync with %s", &receiver); n > 0 {
event.Type = SYNC
event.Receiver = w.scene.identifierToIndex(receiver)
} else {
return
} }
if receiver != "" { w.scene.Events = append(w.scene.Events, event)
w.scene.Events = append(w.scene.Events, event)
}
} }
// DrawEvent triggers the appropriate draw action for a spectific event. // DrawEvent triggers the appropriate draw action for a spectific event.
...@@ -54,8 +71,14 @@ func (w *Window) DrawEvent(e *Event) { ...@@ -54,8 +71,14 @@ func (w *Window) DrawEvent(e *Event) {
color = "blue" color = "blue"
case SIGNATURE: case SIGNATURE:
color = "green" color = "green"
case TTPCALL:
color = "purple"
case TTPABORT:
color = "red"
case TTPSIGNED:
color = "lime"
default: default:
color = "black" color = "grey"
} }
w.DrawArrow(xa, ya, xb, yb, colors[color]) w.DrawArrow(xa, ya, xb, yb, colors[color])
......
...@@ -41,6 +41,10 @@ type EventType int ...@@ -41,6 +41,10 @@ type EventType int
const ( const (
PROMISE EventType = iota PROMISE EventType = iota
SIGNATURE SIGNATURE
SYNC
TTPCALL
TTPABORT
TTPSIGNED
OTHER OTHER
) )
......
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"os" "os"
"dfss/auth" "dfss/auth"
dAPI "dfss/dfssd/api"
"dfss/dfssp/api" "dfss/dfssp/api"
"dfss/dfssp/authority" "dfss/dfssp/authority"
"dfss/dfssp/common" "dfss/dfssp/common"
...@@ -110,6 +111,7 @@ func (s *platformServer) ReadySign(ctx context.Context, in *api.ReadySignRequest ...@@ -110,6 +111,7 @@ func (s *platformServer) ReadySign(ctx context.Context, in *api.ReadySignRequest
} }
} }
dAPI.DLog("sync with " + cn)
return signal, nil return signal, nil
} }
......
...@@ -79,7 +79,7 @@ func (server *ttpServer) Alert(ctx context.Context, in *tAPI.AlertRequest) (*tAP ...@@ -79,7 +79,7 @@ func (server *ttpServer) Alert(ctx context.Context, in *tAPI.AlertRequest) (*tAP
// We check that the sender of the request sent valid and complete information // We check that the sender of the request sent valid and complete information
stop, message, tmpPromises, err := server.handleInvalidPromises(manager, in.Promises, senderIndex, in.Index) stop, message, tmpPromises, err := server.handleInvalidPromises(manager, in.Promises, senderIndex, in.Index)
if stop { if stop {
dAPI.DLog("invalid promise caused stop") dAPI.DLog("sent abort token to " + net.GetCN(&ctx))
return message, err return message, err
} }
// Now we are sure that the sender of the AlertRequest is not dishonest // Now we are sure that the sender of the AlertRequest is not dishonest
...@@ -87,7 +87,7 @@ func (server *ttpServer) Alert(ctx context.Context, in *tAPI.AlertRequest) (*tAP ...@@ -87,7 +87,7 @@ func (server *ttpServer) Alert(ctx context.Context, in *tAPI.AlertRequest) (*tAP
// We try to use the already generated contract if it exists // We try to use the already generated contract if it exists
generated, contract := manager.WasContractSigned() generated, contract := manager.WasContractSigned()
if generated { if generated {
dAPI.DLog("sending the signed contract") dAPI.DLog("sent signed contract to " + net.GetCN(&ctx))
return &tAPI.TTPResponse{ return &tAPI.TTPResponse{
Abort: false, Abort: false,
Contract: contract, Contract: contract,
...@@ -102,10 +102,16 @@ func (server *ttpServer) Alert(ctx context.Context, in *tAPI.AlertRequest) (*tAP ...@@ -102,10 +102,16 @@ func (server *ttpServer) Alert(ctx context.Context, in *tAPI.AlertRequest) (*tAP
// We manually update the database // 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 { if !ok {
dAPI.DLog("error during 'UpdateByID' l.81" + fmt.Sprint(err.Error())) fmt.Fprintln(os.Stderr, err)
return nil, errors.New(InternalError) return nil, errors.New(InternalError)
} }
if message.Abort {
dAPI.DLog("sent abort token to " + net.GetCN(&ctx))
} else {
dAPI.DLog("sent signed contract to " + net.GetCN(&ctx))
}
return message, err return message, err
} }
...@@ -121,7 +127,7 @@ func (server *ttpServer) handleAbortedSender(manager *entities.ArchivesManager, ...@@ -121,7 +127,7 @@ func (server *ttpServer) handleAbortedSender(manager *entities.ArchivesManager,
ok, err := manager.DB.Get("signatures").UpdateByID(*(manager.Archives)) ok, err := manager.DB.Get("signatures").UpdateByID(*(manager.Archives))
if !ok { if !ok {
dAPI.DLog("error during 'UpdateByID' l.99" + fmt.Sprint(err.Error())) fmt.Fprintln(os.Stderr, err)
return true, nil, errors.New(InternalError) return true, nil, errors.New(InternalError)
} }
...@@ -166,11 +172,10 @@ func (server *ttpServer) handleInvalidPromises(manager *entities.ArchivesManager ...@@ -166,11 +172,10 @@ func (server *ttpServer) handleInvalidPromises(manager *entities.ArchivesManager
ok, err := manager.DB.Get("signatures").UpdateByID(*(manager.Archives)) ok, err := manager.DB.Get("signatures").UpdateByID(*(manager.Archives))
if !ok { if !ok {
dAPI.DLog("error during 'UpdateByID' l.132" + fmt.Sprint(err.Error())) fmt.Fprintln(os.Stderr, err)
return true, nil, nil, errors.New(InternalError) return true, nil, nil, errors.New(InternalError)
} }
dAPI.DLog("sending an abort token")
return true, &tAPI.TTPResponse{ return true, &tAPI.TTPResponse{
Abort: true, Abort: true,
Contract: nil, Contract: nil,
...@@ -199,14 +204,12 @@ func (server *ttpServer) updateArchiveWithEvidence(manager *entities.ArchivesMan ...@@ -199,14 +204,12 @@ func (server *ttpServer) updateArchiveWithEvidence(manager *entities.ArchivesMan
// Returns the response to send back to the sender of the request. // Returns the response to send back to the sender of the request.
// //
// Does not take into account if the sender is dishonest. // Does not take into account if the sender is dishonest.
//
// If the contract has been successfully generated, returns it. Otherwise, returns an abort token. // If the contract has been successfully generated, returns it. Otherwise, returns an abort token.
// //
// DOES NOT UPDATE THE DATABASE (should be handled manually) // DOES NOT UPDATE THE DATABASE (should be handled manually)
func (server *ttpServer) handleContractGenerationTry(manager *entities.ArchivesManager) (*tAPI.TTPResponse, error) { func (server *ttpServer) handleContractGenerationTry(manager *entities.ArchivesManager) (*tAPI.TTPResponse, error) {
generated, contract := resolve.Solve(manager) generated, contract := resolve.Solve(manager)
if !generated { if !generated {
dAPI.DLog("contract couldn't be generated. Sending an abort token.")
return &tAPI.TTPResponse{ return &tAPI.TTPResponse{
Abort: true, Abort: true,
Contract: nil, Contract: nil,
...@@ -215,7 +218,6 @@ func (server *ttpServer) handleContractGenerationTry(manager *entities.ArchivesM ...@@ -215,7 +218,6 @@ func (server *ttpServer) handleContractGenerationTry(manager *entities.ArchivesM
// We add the generated contract to the signatureArchives // We add the generated contract to the signatureArchives
manager.Archives.SignedContract = contract manager.Archives.SignedContract = contract
dAPI.DLog("contract was generated. Sending the signed contract.")
return &tAPI.TTPResponse{ return &tAPI.TTPResponse{
Abort: false, Abort: false,
Contract: contract, Contract: contract,
...@@ -241,7 +243,7 @@ func GetServer() *grpc.Server { ...@@ -241,7 +243,7 @@ func GetServer() *grpc.Server {
dbManager, err := mgdb.NewManager(viper.GetString("dbURI")) dbManager, err := mgdb.NewManager(viper.GetString("dbURI"))
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, "An error occured during the connection to MongoDB:", err) fmt.Fprintln(os.Stderr, "An error occured during the connection to MongoDB:", err)
os.Exit(2) os.Exit(1)
} }
mutmap := make(map[bson.ObjectId]*sync.Mutex) mutmap := make(map[bson.ObjectId]*sync.Mutex)
......
...@@ -107,7 +107,7 @@ func createClient(tmpDir string, ca []byte, port int) (*exec.Cmd, error) { ...@@ -107,7 +107,7 @@ func createClient(tmpDir string, ca []byte, port int) (*exec.Cmd, error) {
// Prepare the client command. // Prepare the client command.
// The last argument is up to you! // The last argument is up to you!
cmd := exec.Command(path, "--ca", caPath, "--cert", certPath, "--host", "127.0.0.1:"+testPort, "--key", keyPath, "--port", strconv.Itoa(port), "--timeout", "3s" ,"-v", "-d", "localhost:9099") cmd := exec.Command(path, "--ca", caPath, "--cert", certPath, "--host", "127.0.0.1:"+testPort, "--key", keyPath, "--port", strconv.Itoa(port), "--timeout", "3s", "-v", "-d", "localhost:9099")
return cmd, nil return cmd, nil
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment