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

[c] Implement timeout error management

parent 9018943e
......@@ -94,7 +94,7 @@ func contains(s []uint32, e uint32) bool {
// GetAllButOne creates the slice of all sequence ids, except the one specified
func GetAllButOne(s []uint32, e uint32) []uint32 {
res := make([]uint32, 0)
var res = make([]uint32, 0)
for i := 0; i < len(s); i++ {
curID := s[i]
......
......@@ -3,17 +3,12 @@ package sign
import (
"errors"
"fmt"
"log"
"strconv"
"time"
"dfss"
cAPI "dfss/dfssc/api"
"dfss/dfssc/common"
"dfss/dfssc/security"
dAPI "dfss/dfssd/api"
pAPI "dfss/dfssp/api"
"dfss/dfssp/contract"
"dfss/net"
"golang.org/x/net/context"
"google.golang.org/grpc"
)
......@@ -27,14 +22,14 @@ func (m *SignatureManager) Sign() error {
// Promess rounds
for nextIndex != -1 {
pendingSet, err := common.GetPendingSet(m.sequence, myID, currentIndex)
if err != nil {
return err
pendingSet, err1 := common.GetPendingSet(m.sequence, myID, currentIndex)
if err1 != nil {
return err1 // err is renamed to avoid shadowing err on linter check
}
sendSet, err := common.GetSendSet(m.sequence, myID, currentIndex)
if err != nil {
return err
sendSet, err1 := common.GetSendSet(m.sequence, myID, currentIndex)
if err1 != nil {
return err1
}
// Reception of the due promesses
......@@ -64,9 +59,9 @@ func (m *SignatureManager) Sign() error {
}
currentIndex = nextIndex
nextIndex, err = common.FindNextIndex(m.sequence, myID, currentIndex)
if err != nil {
return err
nextIndex, err1 = common.FindNextIndex(m.sequence, myID, currentIndex)
if err1 != nil {
return err1
}
}
......@@ -106,14 +101,16 @@ func (m *SignatureManager) SendPromise(promise *cAPI.Promise, to uint32) (*pAPI.
return &pAPI.ErrorCode{}, err
}
// TODO
// 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).TreatPromise(ctx, promise)
if err != nil {
return &pAPI.ErrorCode{}, err
if err == grpc.ErrClientConnTimeout {
dAPI.DLog("Promise timeout for [" + fmt.Sprintf("%d", to) + "]")
return &pAPI.ErrorCode{Code: pAPI.ErrorCode_TIMEOUT, Message: "promise timeout"}, err
} else if err != nil {
return &pAPI.ErrorCode{Code: pAPI.ErrorCode_INTERR, Message: "internal server error"}, err
}
m.archives.sentPromises = append(m.archives.sentPromises, promise)
......
......@@ -19,8 +19,9 @@ message RegisterRequest {
string request = 2;
}
// ErrorCode message contains an error code (see dffs/dfssp/api/errorCodes.go)
// and a message
// ErrorCode message contains an error code and a message
// Above or zero : target-side error
// Less than 0 : local error
message ErrorCode {
enum Code {
// SUCCESS is the error code for a successful request
......@@ -33,6 +34,8 @@ message ErrorCode {
WARNING = 3;
// INTERR is the error code for an internal server error
INTERR = -1;
// TIMEOUT is the error code for a timeout or unreacheable target
TIMEOUT = -2;
}
Code code = 1;
string message = 2;
......
......@@ -66,7 +66,7 @@ func ReadySign(db *mgdb.MongoManager, rooms *common.WaitingGroupMap, ctx *contex
return nil
case <-time.After(10 * time.Minute):
rooms.Unjoin(roomID, channel)
return &api.LaunchSignature{ErrorCode: &api.ErrorCode{Code: api.ErrorCode_INTERR, Message: "timeout"}}
return &api.LaunchSignature{ErrorCode: &api.ErrorCode{Code: api.ErrorCode_TIMEOUT, Message: "timeout for ready signal"}}
}
}
......
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