Skip to content
Snippets Groups Projects
Commit 28a81d76 authored by Fabian Seidl's avatar Fabian Seidl
Browse files

Resolve "Consider adding mechanism in etsi14 polling to restart process after...

Resolve "Consider adding mechanism in etsi14 polling to restart process after a while after requests failed"

See merge request !187
parent 509fcade
No related branches found
No related tags found
1 merge request!187Resolve "Consider adding mechanism in etsi14 polling to restart process after a while after requests failed"
Pipeline #221343 passed
...@@ -109,49 +109,21 @@ func (qm *ETSI014HTTPQuantumModule) Initialize() error { ...@@ -109,49 +109,21 @@ func (qm *ETSI014HTTPQuantumModule) Initialize() error {
// start polling keys // start polling keys
if qm.master { if qm.master {
go func() { go func() {
ticker := time.NewTicker(time.Duration(qm.keyFetchInterval) * time.Second) restartWaitingTime := time.Duration(2) * time.Minute
ticker := time.NewTicker(restartWaitingTime)
defer ticker.Stop() defer ticker.Stop()
failedAttemps := 0 restartedAfterWaitingTime := new(int)
// TODO: add context/channel to stop // immediately start with the ticker instead of waiting the defined amount
for range ticker.C { for ; true; <-ticker.C {
if failedAttemps == maxFailedKeyRequestAttempts { if *restartedAfterWaitingTime == 5 {
log.Errorf("stopped trying to fetch keys from qkd module after %d tries", failedAttemps) log.Fatalf("Stopped retrying to fetch keys after %d attempts waiting %v each time in between.", restartedAfterWaitingTime, restartWaitingTime)
break break
} }
if qm.keyStore.Length() < int(qm.maxKeyFillLevel) { qm.doKeyFetching(restartedAfterWaitingTime)
container, err := qm.GetKeys(qm.keyFetchAmount, 256, nil, nil, nil) *restartedAfterWaitingTime++
if err != nil {
log.Error(err)
failedAttemps++
continue
}
keyIds := make([]string, len(container.GetKeys()))
for i, keyItem := range container.GetKeys() {
keyIds[i] = keyItem.GetKeyID()
}
_, err = qm.kmsClient.KeyIdNotification(context.Background(),
&pbIC.KeyIdNotificationRequest{
Timestamp: time.Now().Unix(),
KmsId: qm.kmsId,
KeyIds: keyIds,
})
if err != nil {
log.Error(err)
failedAttemps++
continue
}
if err := store.AddETSIKeysToKeystore(qm.keyStore, container.GetKeys()); err != nil {
log.Error(err)
}
failedAttemps = 0
}
} }
}() }()
} }
...@@ -211,3 +183,54 @@ func (qm *ETSI014HTTPQuantumModule) GetKeyWithIds(keyIds []etsi14ClientGenerated ...@@ -211,3 +183,54 @@ func (qm *ETSI014HTTPQuantumModule) GetKeyWithIds(keyIds []etsi14ClientGenerated
return container, nil return container, nil
} }
func (qm *ETSI014HTTPQuantumModule) doKeyFetching(restartedAfterWaitingTime *int) {
ticker := time.NewTicker(time.Duration(qm.keyFetchInterval) * time.Second)
defer ticker.Stop()
failedAttemps := 0
// TODO: add context/channel to stop
for range ticker.C {
if failedAttemps == maxFailedKeyRequestAttempts {
log.Errorf("stopped trying to fetch keys from qkd module after %d tries", failedAttemps)
break
}
if qm.keyStore.Length() < int(qm.maxKeyFillLevel) {
container, err := qm.GetKeys(qm.keyFetchAmount, 256, nil, nil, nil)
if err != nil {
log.Error(err)
failedAttemps++
continue
}
keyIds := make([]string, len(container.GetKeys()))
for i, keyItem := range container.GetKeys() {
keyIds[i] = keyItem.GetKeyID()
}
_, err = qm.kmsClient.KeyIdNotification(context.Background(),
&pbIC.KeyIdNotificationRequest{
Timestamp: time.Now().Unix(),
KmsId: qm.kmsId,
KeyIds: keyIds,
})
if err != nil {
log.Error(err)
failedAttemps++
continue
}
err = store.AddETSIKeysToKeystore(qm.keyStore, container.GetKeys())
if err != nil {
log.Error(err)
failedAttemps++
continue
}
failedAttemps = 0
*restartedAfterWaitingTime = 0
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment