Commit c8e658a4 authored by Richer Maximilien's avatar Richer Maximilien Committed by Loïck Bonniot

[c] Fix various typos from MR!45 and beyond

+ Fix alignement issue in dfssd/api
+ Add `TODO` for GetAllButOne complexity
+ Re-order vendor in sequence_analysis_test.go
+ Fix shadowing by refining var
+ and plenty of other fixes...
parent 1b61bc0e
......@@ -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 promise
// the identity of the sender and receiver, and the actual promise
//
// * sequence is transmitted by platform and identical across clients
// * TODO implement an global signature for content
......@@ -54,7 +54,7 @@ func (*Promise) ProtoMessage() {}
func (*Promise) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
// Signature message contains all the required information to verify
// the identity of the sender and reciever, and the actual signature
// the identity of the sender and receiver, and the actual signature
type Signature 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,22 +11,22 @@ service Client {
}
// Promise message contains all the required information to verify
// the identity of the sender and reciever, and the actual promise
// the identity of the sender and receiver, and the actual promise
//
// * sequence is transmitted by platform and identical across clients
// * TODO implement an global signature for content
message Promise {
bytes recipientKeyHash = 1; // SHA-512
bytes senderKeyHash = 2; // SHA-512
uint32 index = 3; // The index of the sequence for this message
string contractDocumentHash = 4; // Hash of the contract to be signed
string signatureUuid = 5; // Avoid re-use of the promise in another ctx
string contractUuid = 6;
// TODO the crypto payload
bytes recipientKeyHash = 1; // SHA-512
bytes senderKeyHash = 2; // SHA-512
uint32 index = 3; // The index of the sequence for this message
string contractDocumentHash = 4; // Hash of the contract to be signed
string signatureUuid = 5; // Avoid re-use of the promise in another ctx
string contractUuid = 6;
// TODO the crypto payload
}
// Signature message contains all the required information to verify
// the identity of the sender and reciever, and the actual signature
// the identity of the sender and receiver, and the actual signature
message Signature {
bytes recipientKeyHash = 1; // SHA-512
bytes senderKeyHash = 2; // SHA-512
......
......@@ -93,6 +93,8 @@ func contains(s []uint32, e uint32) bool {
}
// GetAllButOne creates the slice of all sequence ids, except the one specified
//
// TODO This is O(n^2) and need a rework with a map
func GetAllButOne(s []uint32, e uint32) []uint32 {
var res = make([]uint32, 0)
......
......@@ -2,8 +2,9 @@ package common
import (
"fmt"
"github.com/bmizerany/assert"
"testing"
"github.com/bmizerany/assert"
)
func TestFindNextIndex(t *testing.T) {
......
......@@ -62,5 +62,5 @@ func signContract(args []string) {
os.Exit(5)
}
fmt.Println("Signature complete ! See .proof file for evidences.")
fmt.Println("Signature complete! See .proof file for evidences.")
}
......@@ -9,7 +9,7 @@ import (
"dfss/dfssp/contract"
)
// SignedContractJSON is an union of contract and realted signatures
// SignedContractJSON is an union of contract and related signatures
type SignedContractJSON struct {
Contract contract.JSON
Signatures []cAPI.Signature
......@@ -19,7 +19,7 @@ type SignedContractJSON struct {
func (m *SignatureManager) PersistSignaturesToFile() error {
// Check content, don't write an empty file
if len(m.archives.recievedSignatures) == 0 {
if len(m.archives.receivedSignatures) == 0 {
return fmt.Errorf("No stored signatures, cannot create an empty file (yes I'm a coward)")
}
......@@ -28,7 +28,7 @@ func (m *SignatureManager) PersistSignaturesToFile() error {
Contract: *m.contract,
Signatures: make(
[]cAPI.Signature,
len(m.archives.sentSignatures)+len(m.archives.recievedSignatures),
len(m.archives.sentSignatures)+len(m.archives.receivedSignatures),
),
}
......@@ -36,11 +36,11 @@ func (m *SignatureManager) PersistSignaturesToFile() error {
signedContract.Signatures[i] = *s
}
for i, s := range m.archives.recievedSignatures {
for i, s := range m.archives.receivedSignatures {
signedContract.Signatures[len(m.archives.sentSignatures)+i] = *s
}
proof, err := json.MarshalIndent(signedContract, "", " ")
proof, err := json.MarshalIndent(signedContract, "", " ")
if err != nil {
return err
}
......
......@@ -9,7 +9,7 @@ import (
dAPI "dfss/dfssd/api"
)
// Sign performe all the message exchange for the contract to be signed
// Sign perform all the message exchanges for the contract to be signed
//
// * Initialize the SignatureManager from starter.go
// * Compute the reversed map [mail -> ID] of signers
......@@ -35,31 +35,33 @@ func (m *SignatureManager) Sign() error {
dAPI.DLog(fmt.Sprintf("{%d} ", myID) + "Starting round at index [" + fmt.Sprintf("%d", m.currentIndex) + "] with nextIndex=" + fmt.Sprintf("%d", nextIndex))
// Set of the promise we are waiting for
pendingSet, err1 := common.GetPendingSet(m.sequence, myID, m.currentIndex)
if err1 != nil {
return err1 // err is renamed to avoid shadowing err on linter check
var pendingSet []uint32
pendingSet, err = common.GetPendingSet(m.sequence, myID, m.currentIndex)
if err != nil {
return err
}
// Set of the promises we must send
sendSet, err1 := common.GetSendSet(m.sequence, myID, m.currentIndex)
if err1 != nil {
return err1
var sendSet []uint32
sendSet, err = common.GetSendSet(m.sequence, myID, m.currentIndex)
if err != nil {
return err
}
// Exchange messages
m.promiseRound(pendingSet, sendSet, myID)
m.currentIndex = nextIndex
nextIndex, err1 = common.FindNextIndex(m.sequence, myID, m.currentIndex)
if err1 != nil {
return err1
nextIndex, err = common.FindNextIndex(m.sequence, myID, m.currentIndex)
if err != nil {
return err
}
}
dAPI.DLog("{" + fmt.Sprintf("%d", myID) + "} Enter signature round")
// Signature round
err = m.SendAllSigns()
err = m.ExchangeAllSignatures()
if err != nil {
return err
}
......@@ -87,7 +89,7 @@ func (m *SignatureManager) GetClient(to uint32) (*cAPI.ClientClient, error) {
return m.peers[mailto], nil
}
// makeEMailMap build an association to reverse a hash to the sequence ID
// makeSignersHashToIDMap build an association to reverse a hash to the sequence ID
func (m *SignatureManager) makeSignersHashToIDMap() {
m.hashToID = make(map[string]uint32)
......@@ -112,10 +114,10 @@ func (m *SignatureManager) promiseRound(pendingSet, sendSet []uint32, myID uint3
var err error
pendingSet, err = common.Remove(pendingSet, senderID)
if err != nil {
_ = fmt.Errorf("Recieve unexpected promise")
_ = fmt.Errorf("Receive unexpected promise")
}
m.archives.recievedPromises = append(m.archives.recievedPromises, promise)
dAPI.DLog("{" + fmt.Sprintf("%d", myID) + "} Recieved promise from [" + fmt.Sprintf("%d", senderID) + "] for index " + fmt.Sprintf("%d", promise.Index))
m.archives.receivedPromises = append(m.archives.receivedPromises, promise)
dAPI.DLog("{" + fmt.Sprintf("%d", myID) + "} Received promise from [" + fmt.Sprintf("%d", senderID) + "] for index " + fmt.Sprintf("%d", promise.Index))
} else {
// Wrong sender keyHash
log.Println("{" + fmt.Sprintf("%d", myID) + "} Wrong sender keyhash !")
......@@ -134,14 +136,14 @@ func (m *SignatureManager) promiseRound(pendingSet, sendSet []uint32, myID uint3
dAPI.DLog("{" + fmt.Sprintf("%d", myID) + "} Send promise to " + fmt.Sprintf("%d", id))
_, err = m.SendPromise(promise, id)
if err != nil {
dAPI.DLog("{" + fmt.Sprintf("%d", myID) + "} Promise have not been recieved !")
dAPI.DLog("{" + fmt.Sprintf("%d", myID) + "} Promise have not been received !")
_ = fmt.Errorf("Failed to deliver promise from %d to %d", myID, id)
}
c <- promise
}(id, m)
}
// Verifying we sent all the due promesses
// Verifying we sent all the due promises
for _ = range sendSet {
promise := <-c
if promise != nil {
......@@ -155,10 +157,7 @@ func (m *SignatureManager) promiseRound(pendingSet, sendSet []uint32, myID uint3
// closeAllPeerClient tries to close all established connection with other peers
func (m *SignatureManager) closeAllPeerClient() {
for k, client := range m.peersConn {
err := client.Close()
if err != nil {
// We don't care
}
_ = client.Close()
// Remove associated grpc client
delete(m.peers, k)
fmt.Println("- Close connection to " + k)
......
package sign
import (
"fmt"
"dfss"
cAPI "dfss/dfssc/api"
pAPI "dfss/dfssp/api"
"dfss/net"
"fmt"
"golang.org/x/net/context"
"google.golang.org/grpc"
)
......
......@@ -14,11 +14,11 @@ import (
"google.golang.org/grpc"
)
// SendAllSigns creates and sends signatures to all the signers of the contract
func (m *SignatureManager) SendAllSigns() error {
// ExchangeAllSignatures creates and sends signatures to all the signers of the contract
func (m *SignatureManager) ExchangeAllSignatures() error {
allRecieved := make(chan error)
go m.RecieveAllSigns(allRecieved)
allReceived := make(chan error)
go m.ReceiveAllSigns(allReceived)
myID, err := m.FindID()
if err != nil {
......@@ -57,7 +57,7 @@ func (m *SignatureManager) SendAllSigns() error {
}
}
err = <-allRecieved
err = <-allReceived
if err != nil {
return err
}
......@@ -90,7 +90,7 @@ func (m *SignatureManager) SendSignature(signature *cAPI.Signature, to uint32) (
}
// Handle the timeout
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
errCode, err := (*connection).TreatSignature(ctx, signature)
......@@ -106,15 +106,15 @@ func (m *SignatureManager) SendSignature(signature *cAPI.Signature, to uint32) (
return errCode, nil
}
// RecieveAllSigns recieve all the signatures
func (m *SignatureManager) RecieveAllSigns(out chan error) {
// ReceiveAllSigns receive all the signatures
func (m *SignatureManager) ReceiveAllSigns(out chan error) {
myID, err := m.FindID()
if err != nil {
out <- err
return
}
// compute a set of all signers exept me
// compute a set of all signers except me
pendingSet := common.GetAllButOne(m.sequence, myID)
// TODO this ctx needs a timeout !
......@@ -126,9 +126,9 @@ func (m *SignatureManager) RecieveAllSigns(out chan error) {
var err error
pendingSet, err = common.Remove(pendingSet, senderID)
if err != nil {
// Recieve unexpected signature, ignore ?
// Receive unexpected signature, ignore ?
}
m.archives.recievedSignatures = append(m.archives.recievedSignatures, signature)
m.archives.receivedSignatures = append(m.archives.receivedSignatures, signature)
} else {
// Wrong sender keyHash
}
......
......@@ -39,12 +39,12 @@ type SignatureManager struct {
archives *Archives
}
// Archives stores the recieved and sent messages, as evidence if needed
// Archives stores the received and sent messages, as evidence if needed
type Archives struct {
sentPromises []*cAPI.Promise
recievedPromises []*cAPI.Promise
receivedPromises []*cAPI.Promise
sentSignatures []*cAPI.Signature
recievedSignatures []*cAPI.Signature
receivedSignatures []*cAPI.Signature
}
// NewSignatureManager populates a SignatureManager and connects to the platform.
......@@ -55,9 +55,9 @@ func NewSignatureManager(fileCA, fileCert, fileKey, addrPort, passphrase string,
contract: c,
archives: &Archives{
sentPromises: make([]*cAPI.Promise, 0),
recievedPromises: make([]*cAPI.Promise, 0),
receivedPromises: make([]*cAPI.Promise, 0),
sentSignatures: make([]*cAPI.Signature, 0),
recievedSignatures: make([]*cAPI.Signature, 0),
receivedSignatures: make([]*cAPI.Signature, 0),
},
}
var err error
......
......@@ -294,7 +294,7 @@ func ExampleAuth() {
fmt.Println("The certificate should have been given as an answer")
}
fmt.Println("Certificate successfully recieved")
fmt.Println("Certificate successfully received")
res := entities.User{}
err = repository.Collection.FindByID(*user, &res)
......@@ -312,7 +312,7 @@ func ExampleAuth() {
// User successfully inserted
// Client successfully connected
// AuthRequest successfully sent
// Certificate successfully recieved
// Certificate successfully received
// Database successfully updated with cert and certHash
}
......
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