Commit 7f65e9f7 authored by Loïck Bonniot's avatar Loïck Bonniot

[p][c][t] Fix typos and improve performances

See !41
parent bd1ddace
Pipeline #365 passed with stage
......@@ -28,4 +28,5 @@ protobuf:
cd .. && \
protoc --go_out=plugins=grpc:. dfss/dfssc/api/client.proto && \
protoc --go_out=plugins=grpc:. dfss/dfssd/api/demonstrator.proto && \
protoc --go_out=plugins=grpc:. dfss/dfssp/api/platform.proto
\ No newline at end of file
protoc --go_out=plugins=grpc:. dfss/dfssp/api/platform.proto && \
protoc --go_out=plugins=grpc:. dfss/dfsst/api/resolution.proto
......@@ -35,7 +35,7 @@ var _ = math.Inf
const _ = proto.ProtoPackageIsVersion1
// Promise message contains all the required information to verify
// the identity of the sender and reciever, and the actual promess
// the identity of the sender and reciever, and the actual promise
type Promise struct {
RecipientKeyHash []byte `protobuf:"bytes,1,opt,name=recipientKeyHash,proto3" json:"recipientKeyHash,omitempty"`
SenderKeyHash []byte `protobuf:"bytes,2,opt,name=senderKeyHash,proto3" json:"senderKeyHash,omitempty"`
......
......@@ -11,7 +11,7 @@ service Client {
}
// Promise message contains all the required information to verify
// the identity of the sender and reciever, and the actual promess
// the identity of the sender and reciever, and the actual promise
message Promise {
bytes recipientKeyHash = 1; // SHA-512
bytes senderKeyHash = 2; // SHA-512
......@@ -32,4 +32,4 @@ message Signature {
// Hello message is used when discovering peers. It contains the current version of the software.
message Hello {
string version = 1;
}
\ No newline at end of file
}
......@@ -11,7 +11,7 @@ func newContract() {
fmt.Println("Creating a new contract")
passphrase, filepath, comment, signers := getContractInfo()
err := sign.NewCreateManager(fca, fcert, fkey, addrPort, passphrase, filepath, comment, signers)
err := sign.SendNewContract(fca, fcert, fkey, addrPort, passphrase, filepath, comment, signers)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
......
......@@ -19,7 +19,7 @@ type AuthContainer struct {
Key *rsa.PrivateKey
}
// NewAuthContainer is a shortcut to build a AuthContainer
// NewAuthContainer is a shortcut to build an AuthContainer
func NewAuthContainer(fileCA, fileCert, fileKey, addrPort, passphrase string) *AuthContainer {
return &AuthContainer{
FileCA: fileCA,
......
......@@ -44,6 +44,7 @@ func signContract(filename string) {
os.Exit(5)
}
// TODO Warning, integration tests are checking Stdout
fmt.Println("Everybody is ready, starting the signature", signatureUUID)
// Signature
......
......@@ -23,8 +23,8 @@ type CreateManager struct {
filename string
}
// NewCreateManager tries to create a contract on the platform and returns an error or nil
func NewCreateManager(fileCA, fileCert, fileKey, addrPort, passphrase, filepath, comment string, signers []string) error {
// SendNewContract tries to create a contract on the platform and returns an error or nil
func SendNewContract(fileCA, fileCert, fileKey, addrPort, passphrase, filepath, comment string, signers []string) error {
m := &CreateManager{
auth: security.NewAuthContainer(fileCA, fileCert, fileKey, addrPort, passphrase),
filepath: filepath,
......
......@@ -44,10 +44,10 @@ func TestMain(m *testing.M) {
}
func TestNewCreateManager(t *testing.T) {
err := NewCreateManager(fca, fcert, fkey, addrPort, "password", fcontract, "success", []string{"a@example.com", "b@example.com"})
err := SendNewContract(fca, fcert, fkey, addrPort, "password", fcontract, "success", []string{"a@example.com", "b@example.com"})
assert.Equal(t, nil, err)
err = NewCreateManager(fca, fcert, fkey, addrPort, "password", fcontract, "warning", []string{"a@example.com", "b@example.com"})
err = SendNewContract(fca, fcert, fkey, addrPort, "password", fcontract, "warning", []string{"a@example.com", "b@example.com"})
assert.Equal(t, "Operation succeeded with a warning message: Some users are not ready yet", err.Error())
}
......
......@@ -34,9 +34,9 @@ func (s *clientServer) Discover(ctx context.Context, in *cAPI.Hello) (*cAPI.Hell
return &cAPI.Hello{Version: dfss.Version}, nil
}
// GetServer create and registers a ClientServer, returning the associted GRPC server
// GetServer create and registers a ClientServer, returning the associated GRPC server
func (m *SignatureManager) GetServer() *grpc.Server {
server := net.NewServer(m.cert, m.key, m.ca)
server := net.NewServer(m.auth.Cert, m.auth.Key, m.auth.CA)
cAPI.RegisterClientServer(server, &clientServer{})
return server
}
package sign
import (
"crypto/rsa"
"crypto/x509"
"errors"
"fmt"
"log"
......@@ -26,9 +24,8 @@ type SignatureManager struct {
contract *contract.JSON
platform pAPI.PlatformClient
peers map[string]*cAPI.ClientClient
nbReady int
cServer *grpc.Server
cert, ca *x509.Certificate
key *rsa.PrivateKey
sequence []uint32
uuid string
}
......@@ -41,7 +38,7 @@ func NewSignatureManager(fileCA, fileCert, fileKey, addrPort, passphrase string,
contract: c,
}
var err error
m.ca, m.cert, m.key, err = m.auth.LoadFiles()
_, _, _, err = m.auth.LoadFiles()
if err != nil {
return nil, err
}
......@@ -49,7 +46,7 @@ func NewSignatureManager(fileCA, fileCert, fileKey, addrPort, passphrase string,
m.cServer = m.GetServer()
go func() { log.Fatalln(net.Listen("0.0.0.0:"+strconv.Itoa(port), m.cServer)) }()
conn, err := net.Connect(m.auth.AddrPort, m.cert, m.key, m.ca)
conn, err := net.Connect(m.auth.AddrPort, m.auth.Cert, m.auth.Key, m.auth.CA)
if err != nil {
return nil, err
}
......@@ -58,7 +55,7 @@ func NewSignatureManager(fileCA, fileCert, fileKey, addrPort, passphrase string,
m.peers = make(map[string]*cAPI.ClientClient)
for _, u := range c.Signers {
if u.Email != m.cert.Subject.CommonName {
if u.Email != m.auth.Cert.Subject.CommonName {
m.peers[u.Email] = nil
}
}
......@@ -110,13 +107,14 @@ func (m *SignatureManager) addPeer(user *pAPI.User) (ready bool, err error) {
addrPort := user.Ip + ":" + strconv.Itoa(int(user.Port))
fmt.Println("- Trying to connect with", user.Email, "/", addrPort)
conn, err := net.Connect(addrPort, m.cert, m.key, m.ca)
conn, err := net.Connect(addrPort, m.auth.Cert, m.auth.Key, m.auth.CA)
if err != nil {
return false, err
}
// Sending Hello message
client := cAPI.NewClientClient(conn)
lastConnection := m.peers[user.Email]
m.peers[user.Email] = &client
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
......@@ -131,13 +129,14 @@ func (m *SignatureManager) addPeer(user *pAPI.User) (ready bool, err error) {
fmt.Println(" Successfully connected!", "[", msg.Version, "]")
// Check if we have any other peer to connect to
for _, u := range m.peers {
if u == nil {
return false, nil
if lastConnection == nil {
m.nbReady++
if m.nbReady == len(m.contract.Signers)-1 {
return true, nil
}
}
return true, nil
return false, nil
}
// SendReadySign sends the READY signal to the platform, and wait (potentially a long time) for START signal.
......
......@@ -17,7 +17,7 @@ import (
// Firstly, every client present BEFORE the call of this function is sent to the stream.
// Then, client information is sent to the stream as it's available.
//
// Please note that the current user will also receive it's own information.
// Please note that the current user will also receive its own information.
// There is no timeout, this function will shut down on stream disconnection or on error.
func JoinSignature(db *mgdb.MongoManager, rooms *common.WaitingGroupMap, in *api.JoinSignatureRequest, stream api.Platform_JoinSignatureServer) {
ctx := stream.Context()
......
......@@ -21,7 +21,7 @@ type readySignal struct {
}
// ReadySign is the last job of the platform before the signature can occur.
// When a new client is ready, it joins a waitingGroup a waits for a master broadcast announcing that everybody is ready.
// When a new client is ready, it joins a waitingGroup and waits for a master broadcast announcing that everybody is ready.
//
// Doing it this way is efficient in time, as only one goroutine deals with the database and do global checks.
func ReadySign(db *mgdb.MongoManager, rooms *common.WaitingGroupMap, ctx *context.Context, in *api.ReadySignRequest) *api.LaunchSignature {
......
......@@ -14,7 +14,7 @@ func SquaredSignEngine(n uint32) []uint32 {
var i, k uint32
for i = 0; i < n; i++ {
for k = 0; k < n; k++ {
sequence[i*n+k] = uint32(k)
sequence[i*n+k] = k
}
}
......
all:
protoc --go_out=plugins=grpc:. resolution.proto
// Code generated by protoc-gen-go.
// source: resolution.proto
// source: dfss/dfsst/api/resolution.proto
// DO NOT EDIT!
/*
Package api is a generated protocol buffer package.
It is generated from these files:
resolution.proto
dfss/dfsst/api/resolution.proto
It has these top-level messages:
AlertRequest
......@@ -159,16 +159,17 @@ var _TTP_serviceDesc = grpc.ServiceDesc{
}
var fileDescriptor0 = []byte{
// 170 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0x12, 0x28, 0x4a, 0x2d, 0xce,
0xcf, 0x29, 0x2d, 0xc9, 0xcc, 0xcf, 0xd3, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x4e, 0x2c,
0xc8, 0x54, 0xe2, 0xe3, 0xe2, 0x71, 0xcc, 0x49, 0x2d, 0x2a, 0x09, 0x4a, 0x2d, 0x2c, 0x4d, 0x2d,
0x2e, 0x51, 0x12, 0xe0, 0xe2, 0x0b, 0x4a, 0x4d, 0xce, 0x2f, 0x4b, 0x2d, 0x82, 0x89, 0xe8, 0x71,
0x71, 0x87, 0x84, 0x04, 0x04, 0xa5, 0x16, 0x17, 0xe4, 0xe7, 0x15, 0xa7, 0x0a, 0xf1, 0x72, 0xb1,
0x26, 0x26, 0xe5, 0x17, 0x95, 0x48, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x08, 0x09, 0x70, 0x71, 0x24,
0xe7, 0xe7, 0x95, 0x14, 0x25, 0x26, 0x97, 0x48, 0x30, 0x01, 0x45, 0x78, 0x8c, 0x32, 0xb9, 0x98,
0x81, 0xea, 0x85, 0xf4, 0xb8, 0x58, 0xc1, 0x06, 0x0b, 0x09, 0xea, 0x01, 0xed, 0xd1, 0x43, 0xb6,
0x44, 0x4a, 0x00, 0x2c, 0x84, 0x64, 0xaa, 0x12, 0x83, 0x90, 0x11, 0x17, 0x3b, 0xd4, 0x62, 0x21,
0x61, 0xb0, 0x34, 0xaa, 0x33, 0xb0, 0xe9, 0x49, 0x62, 0x03, 0x7b, 0xc4, 0x18, 0x10, 0x00, 0x00,
0xff, 0xff, 0x27, 0xdb, 0xc9, 0x27, 0xdc, 0x00, 0x00, 0x00,
// 188 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0x92, 0x4f, 0x49, 0x2b, 0x2e,
0xd6, 0x07, 0x11, 0x25, 0xfa, 0x89, 0x05, 0x99, 0xfa, 0x45, 0xa9, 0xc5, 0xf9, 0x39, 0xa5, 0x25,
0x99, 0xf9, 0x79, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0xcc, 0x40, 0x51, 0x25, 0x3e, 0x2e,
0x1e, 0xc7, 0x9c, 0xd4, 0xa2, 0x92, 0xa0, 0xd4, 0xc2, 0xd2, 0xd4, 0xe2, 0x12, 0x25, 0x01, 0x2e,
0xbe, 0xa0, 0xd4, 0xe4, 0xfc, 0xb2, 0xd4, 0x22, 0x98, 0x88, 0x3d, 0x17, 0x77, 0x48, 0x48, 0x40,
0x50, 0x6a, 0x71, 0x41, 0x7e, 0x5e, 0x71, 0xaa, 0x90, 0x08, 0x17, 0x6b, 0x62, 0x52, 0x7e, 0x51,
0x89, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0x47, 0x10, 0x84, 0x23, 0x24, 0xc5, 0xc5, 0x91, 0x9c, 0x9f,
0x57, 0x52, 0x94, 0x98, 0x5c, 0x22, 0xc1, 0x04, 0x94, 0xe0, 0x09, 0x82, 0xf3, 0x8d, 0x32, 0xb9,
0x98, 0x81, 0x06, 0x08, 0xe9, 0x71, 0xb1, 0x82, 0x6d, 0x12, 0x12, 0xd4, 0x03, 0x5a, 0xac, 0x87,
0x6c, 0xab, 0x94, 0x00, 0x58, 0x08, 0xc9, 0x1a, 0x25, 0x06, 0x21, 0x23, 0x2e, 0x76, 0xa8, 0x4b,
0x84, 0x84, 0xc1, 0xd2, 0xa8, 0xee, 0xc2, 0xa6, 0x27, 0x89, 0x0d, 0xec, 0x33, 0x63, 0x40, 0x00,
0x00, 0x00, 0xff, 0xff, 0xa7, 0x4b, 0x1a, 0xea, 0xfc, 0x00, 0x00, 0x00,
}
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