From 09d4834cdfaa0f2134fc5d81920842aee4c3913a Mon Sep 17 00:00:00 2001 From: Benjamin Date: Tue, 22 Feb 2022 10:03:52 +0100 Subject: [PATCH] Hello rule patched --- cmd/main.go | 9 ++++++++- pkg/network/ClientMulticast.go | 4 ++-- pkg/protocol/RegexMatcher.go | 8 +++++++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index f5ff706..5649993 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -4,6 +4,7 @@ import ( "_StorBackEnd/pkg/network" "_StorBackEnd/pkg/protocol/managers" "_StorBackEnd/pkg/protocol/repository" + "_StorBackEnd/pkg/protocol/rules/readers" "_StorBackEnd/pkg/protocol/rules/writers" ) @@ -17,9 +18,15 @@ func main() { println("StorBackEnd started !") protocolRepository := repository.CreateProtocolRepository() - helloRule := writers.CreateHelloRule("") + + // Création des Writers + helloRule := writers.CreateHelloRule("^(HELLO) ([A-Za-z0-9]{5,20}) ([0-9]{1,5})\r\n$") protocolRepository.AddWriter(&helloRule) + // Création des Readers + eraseFileRule := readers.CreateEraseFileRule("^(ERASEFILE) ([A-Za-z0-9.]{50,200})\r\n$") + protocolRepository.AddReader(&eraseFileRule) + multicast := network.CreateClientMulticast(MULTICAST_ADDRESS, MULTICAST_SECOND, protocolRepository) go multicast.Run() diff --git a/pkg/network/ClientMulticast.go b/pkg/network/ClientMulticast.go index b7a3c9d..c136a3a 100644 --- a/pkg/network/ClientMulticast.go +++ b/pkg/network/ClientMulticast.go @@ -42,9 +42,9 @@ func (cMult ClientMulticast) Run() { } // Fake test - cmd, correct := cMult.repository.ExecuteWriter(writers.HelloRuleName, "benja.be", "5078") + cmd, correct := cMult.repository.ExecuteWriter(writers.HelloRuleName, "benja", "5078") if !correct { - println("Hello rule isn't correct") + println("[ClientMulticast] Hello rule isn't correct (" + cmd + ")") return } diff --git a/pkg/protocol/RegexMatcher.go b/pkg/protocol/RegexMatcher.go index ed444cf..6c78dc2 100644 --- a/pkg/protocol/RegexMatcher.go +++ b/pkg/protocol/RegexMatcher.go @@ -30,5 +30,11 @@ func (m RegexMatcher) Build(cmd string, datas ...string) (string, bool) { str += " " + data } - return str, m.Match(str) + str += "\r\n" + + if m.Match(str) { + return str, true + } else { + return "", false + } }