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