Recherche d'un bug d'interface réseaux multicast
This commit is contained in:
parent
e9fafd3cd8
commit
30e21ce042
@ -51,8 +51,8 @@ func main() {
|
||||
eraseFileRule := readers.CreateEraseFileRule("^ERASEFILE ([A-Za-z0-9.]{50,200})\r\n$")
|
||||
protocolRepository.AddReader(&eraseFileRule)
|
||||
|
||||
// Creation of the SendFileRule
|
||||
sendFileRule := readers.CreateSendFileRule("^SENDFILE ([A-Za-z0-9.]{50,200} [0-9]{1,10} [A-Za-z0-9.]{50,200})\r\n$")
|
||||
// Creation of the SendFileRule // TODO reset to 50,200
|
||||
sendFileRule := readers.CreateSendFileRule("^SENDFILE ([A-Za-z0-9.]{1,200} [0-9]{1,10} [A-Za-z0-9.]{50,200})\r\n$")
|
||||
protocolRepository.AddReader(&sendFileRule)
|
||||
|
||||
// Create a Multicast Client & run it
|
||||
|
@ -23,18 +23,21 @@ func (server ServerUnicast) Run() {
|
||||
|
||||
// Attente connexion du FileFrontEnd
|
||||
con, err := listen.Accept()
|
||||
print("connection ok")
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("Error while accepting client : %s\n", err)
|
||||
return
|
||||
} else {
|
||||
for { // TODO : Extraire cette partie de code
|
||||
line, err := bufio.NewReader(con).ReadString('\n')
|
||||
reader := bufio.NewReader(con)
|
||||
line, err := reader.ReadString('\n')
|
||||
println("OK ") // TODO REMOVE
|
||||
println(line)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
result := server.ReqManager.Execute(line)
|
||||
result := server.ReqManager.Execute(line, reader)
|
||||
_, _ = con.Write(append([]byte(result), '\n')) // TODO : ATTENTION laisser les \n
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
1
pkg/utils/FileReceiver.go
Normal file
1
pkg/utils/FileReceiver.go
Normal file
@ -0,0 +1 @@
|
||||
package utils
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"multicastAddress" : "226.66.66.1:42500",
|
||||
"multicastAddress" : "226.66.66.1:15502",
|
||||
"multicastSecond" : 10,
|
||||
"domain" : "lightcontainerSB01",
|
||||
"unicastPort" : 58000
|
||||
|
Loading…
Reference in New Issue
Block a user