Recherche d'un bug d'interface réseaux multicast
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
package protocol
|
||||
|
||||
import "bufio"
|
||||
|
||||
// IProtocolReader Représentation abstraite d'un protocol
|
||||
type IProtocolReader interface {
|
||||
// GetCmd Permet de récupérer le nom de la commande
|
||||
GetCmd() string
|
||||
|
||||
// Execute Permet d'exécuter l'action implémentée par une règle. Retourne le message (rule) de retour et bool pour savoir si tout s'est bien passé ou non
|
||||
Execute(data string) (string, bool)
|
||||
Execute(data string) (string, bool, func(r *bufio.Reader) (string, bool))
|
||||
|
||||
// Match Permet de vérifier la validité d'une donnée censée suivre les règles d'un protocol
|
||||
Match(data string) bool
|
||||
|
||||
@@ -1,17 +1,26 @@
|
||||
package managers
|
||||
|
||||
import "StoreBackEnd/pkg/protocol/repository"
|
||||
import (
|
||||
"StoreBackEnd/pkg/protocol/repository"
|
||||
"bufio"
|
||||
)
|
||||
|
||||
type RequestManager struct {
|
||||
Repository *repository.ProtocolRepository
|
||||
}
|
||||
|
||||
func (receiver RequestManager) Execute(request string) string {
|
||||
func (receiver RequestManager) Execute(request string, reader *bufio.Reader) string {
|
||||
// On lis ce que l'on reçoit
|
||||
result, executed := receiver.Repository.ExecuteReader(request)
|
||||
result, executed, readCb := receiver.Repository.ExecuteReader(request)
|
||||
|
||||
// On renvoie la réponse (Comment pour fichier ?)
|
||||
if executed {
|
||||
if readCb != nil {
|
||||
cbResult, _ := readCb(reader)
|
||||
if cbResult != "" {
|
||||
result = cbResult
|
||||
}
|
||||
}
|
||||
return result
|
||||
} else {
|
||||
// TODO : Renvoyer qu'une erreur est survenue
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package repository
|
||||
|
||||
import "StoreBackEnd/pkg/protocol"
|
||||
import (
|
||||
"StoreBackEnd/pkg/protocol"
|
||||
"bufio"
|
||||
)
|
||||
|
||||
func CreateProtocolRepository() *ProtocolRepository {
|
||||
return &ProtocolRepository{
|
||||
@@ -33,14 +36,14 @@ func (repo ProtocolRepository) AddWriter(writer *protocol.IProtocolWriter) {
|
||||
/*
|
||||
ExecuteReader Permet d'exécuter un Reader et de récupérer la commande à renvoyer. La deuxième valeur de retour permet de savoir si une commande a put être exécuté
|
||||
*/
|
||||
func (repo ProtocolRepository) ExecuteReader(data string) (string, bool) {
|
||||
func (repo ProtocolRepository) ExecuteReader(data string) (string, bool, func(r *bufio.Reader) (string, bool)) {
|
||||
for _, reader := range repo.protocolReaders {
|
||||
if (*reader).Match(data) { // Exécuter si match
|
||||
// Récupérer résultat à renvoyer (Donc donner ProtocolRepository aux reader ?!)
|
||||
return (*reader).Execute(data)
|
||||
}
|
||||
}
|
||||
return "", false
|
||||
return "", false, nil
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package readers
|
||||
|
||||
import "StoreBackEnd/pkg/protocol"
|
||||
import (
|
||||
"StoreBackEnd/pkg/protocol"
|
||||
"bufio"
|
||||
)
|
||||
|
||||
// EraseFileRulePrefix Identifiant de cette règle
|
||||
const EraseFileRulePrefix = "ERASEFILE"
|
||||
@@ -26,13 +29,13 @@ func (rule EraseFileRule) GetCmd() string {
|
||||
return rule.Cmd
|
||||
}
|
||||
|
||||
func (rule EraseFileRule) Execute(data string) (string, bool) {
|
||||
func (rule EraseFileRule) Execute(data string) (string, bool, func(r *bufio.Reader) (string, bool)) {
|
||||
if rule.Match(data) {
|
||||
values := rule.matcher.Parse(data)
|
||||
println(values[1], " est le hash du fichier à supprimer")
|
||||
return "Parsing : Fichier avec le hash " + values[1] + " supprimé", true
|
||||
return "Parsing : Fichier avec le hash " + values[1] + " supprimé", true, nil
|
||||
} else {
|
||||
return "Parsing : EraseFileRule command incorrecte", false
|
||||
return "Parsing : EraseFileRule command incorrecte", false, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package readers
|
||||
|
||||
import "StoreBackEnd/pkg/protocol"
|
||||
import (
|
||||
"StoreBackEnd/pkg/protocol"
|
||||
"bufio"
|
||||
)
|
||||
|
||||
// SendFileRulePrefix Rule command prefix
|
||||
const SendFileRulePrefix = "ffe_sendfile"
|
||||
@@ -27,19 +30,23 @@ func (rule SendFileRule) GetCmd() string {
|
||||
}
|
||||
|
||||
// Execute the Rule with a string command.
|
||||
func (rule SendFileRule) Execute(data string) (string, bool) {
|
||||
func (rule SendFileRule) Execute(data string) (string, bool, func(r *bufio.Reader) (string, bool)) {
|
||||
if rule.Match(data) { // TODO : cloture this command.
|
||||
values := rule.matcher.Parse(data)
|
||||
//callback := func() {
|
||||
//
|
||||
//}
|
||||
//callback()
|
||||
|
||||
// print received data
|
||||
println(values[1], " File Name Hash")
|
||||
println(values[2], " File Size")
|
||||
println(values[3], " File Content Hash")
|
||||
return "SEND_OK\r\n", true
|
||||
|
||||
// function callback
|
||||
callback := func(r *bufio.Reader) (string, bool) {
|
||||
|
||||
return "", false
|
||||
}
|
||||
return "SEND_OK\r\n", true, callback
|
||||
} else {
|
||||
return "jjdjd", false
|
||||
return "jjdjd", false, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user