From bcf8cdd256324f7fa3dbfceef51f7bc82bb02683 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Tue, 8 Mar 2022 14:48:14 +0100 Subject: [PATCH] =?UTF-8?q?Mse=20=C3=A0=20jours=20du=20syst=C3=A8me=20de?= =?UTF-8?q?=20r=C3=A9ception=20message=20+=20fichier.=20Il=20reste=20?= =?UTF-8?q?=C3=A0=20pouvoir=20vider=20correctement=20un=20fichier=20lorsqu?= =?UTF-8?q?'il=20est=20re=C3=A7u?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/StoreBackEnd.iml | 3 +-- cmd/main.go | 6 +++--- pkg/network/ServerUnicast.go | 4 ++-- pkg/protocol/managers/RequestManager.go | 3 ++- pkg/protocol/rules/readers/SendFileRule.go | 19 ++++++++++++++++--- 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/.idea/StoreBackEnd.iml b/.idea/StoreBackEnd.iml index 5e764c4..eeb7bce 100644 --- a/.idea/StoreBackEnd.iml +++ b/.idea/StoreBackEnd.iml @@ -1,9 +1,8 @@ - + - \ No newline at end of file diff --git a/cmd/main.go b/cmd/main.go index 9e76eee..3241a39 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -37,11 +37,11 @@ func main() { protocolRepository.AddWriter(&helloRule) // Creation of the SendOkRule - sendOkRule := writers.CreateSendOkRule("^SEND_OK\n$") + sendOkRule := writers.CreateSendOkRule("^SEND_OK\r\n$") protocolRepository.AddWriter(&sendOkRule) // Creation of the SendErrorRule - sendErrorRule := writers.CreateSendOkRule("^SEND_ERROR\n$") + sendErrorRule := writers.CreateSendOkRule("^SEND_ERROR\r\n$") protocolRepository.AddWriter(&sendErrorRule) /** @@ -52,7 +52,7 @@ func main() { protocolRepository.AddReader(&eraseFileRule) // 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$") + 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 diff --git a/pkg/network/ServerUnicast.go b/pkg/network/ServerUnicast.go index bd9bccd..bdb838f 100644 --- a/pkg/network/ServerUnicast.go +++ b/pkg/network/ServerUnicast.go @@ -32,12 +32,12 @@ func (server ServerUnicast) Run() { for { // TODO : Extraire cette partie de code reader := bufio.NewReader(con) line, err := reader.ReadString('\n') - println("OK ") // TODO REMOVE - println(line) + println("AH " + line) if err != nil { return } result := server.ReqManager.Execute(line, reader) + println("Réponse : ", result) _, _ = con.Write(append([]byte(result), '\n')) // TODO : ATTENTION laisser les \n } } diff --git a/pkg/protocol/managers/RequestManager.go b/pkg/protocol/managers/RequestManager.go index 946d728..77aa6f9 100644 --- a/pkg/protocol/managers/RequestManager.go +++ b/pkg/protocol/managers/RequestManager.go @@ -12,7 +12,7 @@ type RequestManager struct { func (receiver RequestManager) Execute(request string, reader *bufio.Reader) string { // On lis ce que l'on reçoit result, executed, readCb := receiver.Repository.ExecuteReader(request) - + println("TESTTESTETTETT") // On renvoie la réponse (Comment pour fichier ?) if executed { if readCb != nil { @@ -23,6 +23,7 @@ func (receiver RequestManager) Execute(request string, reader *bufio.Reader) str } return result } else { + println("HMMM") // TODO : Renvoyer qu'une erreur est survenue return "Error occurred while execute command" } diff --git a/pkg/protocol/rules/readers/SendFileRule.go b/pkg/protocol/rules/readers/SendFileRule.go index 1cf2c20..99c8f4d 100644 --- a/pkg/protocol/rules/readers/SendFileRule.go +++ b/pkg/protocol/rules/readers/SendFileRule.go @@ -3,6 +3,7 @@ package readers import ( "StoreBackEnd/pkg/protocol" "bufio" + "io" ) // SendFileRulePrefix Rule command prefix @@ -41,12 +42,24 @@ func (rule SendFileRule) Execute(data string) (string, bool, func(r *bufio.Reade // function callback callback := func(r *bufio.Reader) (string, bool) { + //var fileContent []byte + // readedByte := -1 + /* + for readedByte == -1 || readedByte > 0 { + readedByte, _ = r.Read(fileContent) + println("SendFileRule Reading file ", " - Hey - ", string(readedByte)) + } - return "", false + */ + var fileContent []byte + readedCount, err := io.ReadFull(r, fileContent) + println("Un test ici : ", readedCount, err) + return "SEND_OK\r", true } - return "SEND_OK\r\n", true, callback + return "SEND_OK\r", true, callback } else { - return "jjdjd", false, nil + println("AHAHAHAHAHAHA") + return "SEND_ERROR\r", false, nil } }