Masterthesis

This commit is contained in:
hoernschen 2020-11-27 05:52:27 +01:00
parent 473dc4a495
commit 4479fcf7f4
7 changed files with 28 additions and 57 deletions

View file

@ -2,7 +2,6 @@ package event
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
@ -17,9 +16,8 @@ import (
"git.nutfactory.org/hoernschen/Matrix/entities/user"
"git.nutfactory.org/hoernschen/Matrix/utils"
//"github.com/cenkalti/backoff/v4"
"github.com/cenkalti/backoff/v4"
"github.com/gorilla/mux"
"github.com/lestrrat-go/backoff"
)
func New(
@ -178,16 +176,15 @@ func SendMessageHandler(w http.ResponseWriter, r *http.Request) {
for _, server := range servers {
if server != config.Homeserver {
log.Printf("Send Transaction to %s", server)
/*
operation := func() error {
return SendTransaction(transaction, server, config.HttpString, config.AuthentificationCheck)
}
notify := func(err error, duration time.Duration) {
log.Printf("Error Sending Transaction, retrying in %ss: %s", duration/1000000000, err)
}
backoff.RetryNotify(operation, backoff.NewExponentialBackOff(), notify)
*/
go retryTransaction(transaction, server, config.HttpString, config.AuthentificationCheck)
operation := func() error {
return SendTransaction(transaction, server, config.HttpString, config.AuthentificationCheck)
}
notify := func(err error, duration time.Duration) {
log.Printf("Error Sending Transaction, retrying in %ss: %s", duration/1000000000, err)
}
backoff.RetryNotify(operation, backoff.NewExponentialBackOff(), notify)
}
}
response := createEventResponse{
@ -199,20 +196,6 @@ func SendMessageHandler(w http.ResponseWriter, r *http.Request) {
}
}
func retryTransaction(transactionToSend *Transaction, server string, httpString string, authCheck bool) (err error) {
b, cancel := config.BackoffPolicy.Start(context.Background())
defer cancel()
for backoff.Continue(b) {
err := SendTransaction(transactionToSend, server, httpString, authCheck)
if err == nil {
return nil
}
}
err = errors.New("Not able to send transaction")
return
}
func CreateStateEventHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
errResponse := utils.CheckRequest(r)
@ -294,14 +277,13 @@ func CreateStateEventHandler(w http.ResponseWriter, r *http.Request) {
return
}
for _, server := range servers {
/*operation := func() error {
operation := func() error {
return SendTransaction(transaction, server, config.HttpString, config.AuthentificationCheck)
}
notify := func(err error, duration time.Duration) {
log.Printf("Error Sending Transaction, retrying in %ss: %s", duration/1000000000, err)
}
go backoff.RetryNotify(operation, backoff.NewExponentialBackOff(), notify)*/
go retryTransaction(transaction, server, config.HttpString, config.AuthentificationCheck)
go backoff.RetryNotify(operation, backoff.NewExponentialBackOff(), notify)
}
response := createEventResponse{