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