Commit 57af36cd authored by Loïck Bonniot's avatar Loïck Bonniot

[d] Add servers event (platform and TTP)

parent d05936eb
Pipeline #2129 passed with stage
......@@ -5,8 +5,8 @@ import (
"time"
"dfss"
"dfss/net"
dapi "dfss/dfssd/api"
"dfss/net"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
......
......@@ -3,7 +3,6 @@ package sign
import (
"dfss"
cAPI "dfss/dfssc/api"
dAPI "dfss/dfssd/api"
pAPI "dfss/dfssp/api"
"dfss/dfsst/entities"
"dfss/net"
......@@ -32,10 +31,8 @@ func (s *clientServer) TreatPromise(ctx context.Context, in *cAPI.Promise) (*pAP
// we do not check that we expected that promise
valid, _, _, _ := entities.IsRequestValid(ctx, []*cAPI.Promise{in})
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
}
dAPI.DLog("TreatPromise route treated promise from " + net.GetCN(&ctx) + " because it is valid")
return getServerErrorCode(s.incomingPromises, in), nil
}
......
......@@ -5,10 +5,13 @@ package gui
import "github.com/visualfc/goqt/ui"
var colors = map[string]uint32{
"red": 0x00ff0000,
"green": 0x0000aa00,
"blue": 0x000000ff,
"black": 0x00000000,
"red": 0x00ff0000,
"green": 0x0000aa00,
"blue": 0x000000ff,
"black": 0x00000000,
"purple": 0x00aa00aa,
"lime": 0x0000ee00,
"grey": 0x00888888,
}
var pen_black = ui.NewPenWithColor(ui.NewColorWithGlobalcolor(ui.Qt_black))
......
......@@ -17,8 +17,12 @@ import (
// Timestamp: unix nano timestamp
// Identifier: either "platform", "ttp" or "<email>"
// Log: one of the following
// "sync with <entity>"
// "sent promise 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.
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))
var receiver string
var index int
if n, _ := fmt.Sscanf(e.Log, "sent promise to %s", &receiver); n > 0 {
event.Type = PROMISE
event.Receiver = w.scene.identifierToIndex(receiver)
} else if n, _ := fmt.Sscanf(e.Log, "sent signature to %s", &receiver); n > 0 {
event.Type = SIGNATURE
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.
......@@ -54,8 +71,14 @@ func (w *Window) DrawEvent(e *Event) {
color = "blue"
case SIGNATURE:
color = "green"
case TTPCALL:
color = "purple"
case TTPABORT:
color = "red"
case TTPSIGNED:
color = "lime"
default:
color = "black"
color = "grey"
}
w.DrawArrow(xa, ya, xb, yb, colors[color])
......
......@@ -41,6 +41,10 @@ type EventType int
const (
PROMISE EventType = iota
SIGNATURE
SYNC
TTPCALL
TTPABORT
TTPSIGNED
OTHER
)
......
......@@ -6,6 +6,7 @@ import (
"os"
"dfss/auth"
dAPI "dfss/dfssd/api"
"dfss/dfssp/api"
"dfss/dfssp/authority"
"dfss/dfssp/common"
......@@ -110,6 +111,7 @@ func (s *platformServer) ReadySign(ctx context.Context, in *api.ReadySignRequest
}
}
dAPI.DLog("sync with " + cn)
return signal, nil
}
......
......@@ -70,7 +70,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
stop, message, tmpPromises, err := server.handleInvalidPromises(manager, in.Promises, senderIndex, in.Index)
if stop {
dAPI.DLog("invalid promise caused stop")
dAPI.DLog("sent abort token to " + net.GetCN(&ctx))
return message, err
}
// Now we are sure that the sender of the AlertRequest is not dishonest
......@@ -78,7 +78,7 @@ func (server *ttpServer) Alert(ctx context.Context, in *tAPI.AlertRequest) (*tAP
// We try to use the already generated contract if it exists
generated, contract := manager.WasContractSigned()
if generated {
dAPI.DLog("sending the signed contract")
dAPI.DLog("sent signed contract to " + net.GetCN(&ctx))
return &tAPI.TTPResponse{
Abort: false,
Contract: contract,
......@@ -93,10 +93,16 @@ func (server *ttpServer) Alert(ctx context.Context, in *tAPI.AlertRequest) (*tAP
// We manually update the database
ok, err := server.DB.Get("signatures").UpdateByID(*(manager.Archives))
if !ok {
dAPI.DLog("error during 'UpdateByID' l.81" + fmt.Sprint(err.Error()))
fmt.Fprintln(os.Stderr, err)
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
}
......@@ -112,7 +118,7 @@ func (server *ttpServer) handleAbortedSender(manager *entities.ArchivesManager,
ok, err := manager.DB.Get("signatures").UpdateByID(*(manager.Archives))
if !ok {
dAPI.DLog("error during 'UpdateByID' l.99" + fmt.Sprint(err.Error()))
fmt.Fprintln(os.Stderr, err)
return true, nil, errors.New(InternalError)
}
......@@ -157,11 +163,10 @@ func (server *ttpServer) handleInvalidPromises(manager *entities.ArchivesManager
ok, err := manager.DB.Get("signatures").UpdateByID(*(manager.Archives))
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)
}
dAPI.DLog("sending an abort token")
return true, &tAPI.TTPResponse{
Abort: true,
Contract: nil,
......@@ -190,14 +195,12 @@ func (server *ttpServer) updateArchiveWithEvidence(manager *entities.ArchivesMan
// Returns the response to send back to the sender of the request.
//
// Does not take into account if the sender is dishonest.
//
// If the contract has been successfully generated, returns it. Otherwise, returns an abort token.
//
// DOES NOT UPDATE THE DATABASE (should be handled manually)
func (server *ttpServer) handleContractGenerationTry(manager *entities.ArchivesManager) (*tAPI.TTPResponse, error) {
generated, contract := resolve.Solve(manager)
if !generated {
dAPI.DLog("contract couldn't be generated. Sending an abort token.")
return &tAPI.TTPResponse{
Abort: true,
Contract: nil,
......@@ -206,7 +209,6 @@ func (server *ttpServer) handleContractGenerationTry(manager *entities.ArchivesM
// We add the generated contract to the signatureArchives
manager.Archives.SignedContract = contract
dAPI.DLog("contract was generated. Sending the signed contract.")
return &tAPI.TTPResponse{
Abort: false,
Contract: contract,
......@@ -232,7 +234,7 @@ func GetServer() *grpc.Server {
dbManager, err := mgdb.NewManager(viper.GetString("dbURI"))
if err != nil {
fmt.Fprintln(os.Stderr, "An error occured during the connection to MongoDB:", err)
os.Exit(2)
os.Exit(1)
}
server := &ttpServer{
......
......@@ -107,7 +107,7 @@ func createClient(tmpDir string, ca []byte, port int) (*exec.Cmd, error) {
// Prepare the client command.
// 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
}
......
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