From 8c443d43e4bdba9c11347dd5dcd281170ab9d51e Mon Sep 17 00:00:00 2001 From: EndMove Date: Sat, 5 Mar 2022 18:32:27 +0100 Subject: [PATCH] Fixing some issues, backed project study --- cmd/main.go | 3 ++- pkg/config/JsonConfigReader.go | 3 ++- pkg/network/ClientMulticast.go | 16 ++++++++-------- pkg/network/ServerUnicast.go | 2 -- pkg/protocol/IProtocolWriter.go | 2 +- pkg/protocol/RegexMatcher.go | 1 - pkg/protocol/managers/RequestManager.go | 2 +- pkg/protocol/repository/ProtocolRepository.go | 1 - pkg/protocol/rules/readers/EraseFileRule.go | 1 - resources/AppConfig.json | 2 +- 10 files changed, 15 insertions(+), 18 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 5add847..d312423 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -24,7 +24,8 @@ func main() { return } - println("Address multicast : " + appConfig.MulticastAddress) + println("Multicast Address : " + appConfig.MulticastAddress) + println("StoreBacked Domain : " + appConfig.Domain) protocolRepository := repository.CreateProtocolRepository() diff --git a/pkg/config/JsonConfigReader.go b/pkg/config/JsonConfigReader.go index 1cd3e96..f063606 100644 --- a/pkg/config/JsonConfigReader.go +++ b/pkg/config/JsonConfigReader.go @@ -5,6 +5,8 @@ import ( "io/ioutil" ) +// Read Méthode permettant de lire le fichier de donfiguration +// return AppConfig func Read(filePath string) (*AppConfig, error) { config := AppConfig{} file, err := ioutil.ReadFile(filePath) @@ -16,6 +18,5 @@ func Read(filePath string) (*AppConfig, error) { if errJson != nil { return nil, errJson } - return &config, nil } diff --git a/pkg/network/ClientMulticast.go b/pkg/network/ClientMulticast.go index 6bb46f5..097f18f 100644 --- a/pkg/network/ClientMulticast.go +++ b/pkg/network/ClientMulticast.go @@ -39,18 +39,18 @@ type ClientMulticast struct { } // Run Cette méthode démarre une commmunication multicast -func (cMult ClientMulticast) Run() { - addr, done := cMult.ResolveAddr() +func (client ClientMulticast) Run() { + addr, done := client.ResolveAddr() if done { return } - con, done2 := cMult.DialUdp(addr) + con, done2 := client.DialUdp(addr) if done2 { return } - cmd, correct := cMult.repository.ExecuteWriter(writers.HelloRuleName, cMult.domain, fmt.Sprintf("%d", cMult.port)) + cmd, correct := client.repository.ExecuteWriter(writers.HelloRuleName, client.domain, fmt.Sprintf("%d", client.port)) if !correct { println("[ClientMulticast] Hello rule isn't correct (" + cmd + ")") return @@ -58,14 +58,14 @@ func (cMult ClientMulticast) Run() { for { _, _ = con.Write([]byte(cmd)) - time.Sleep(time.Second * cMult.second) + time.Sleep(time.Second * client.second) } } // ResolveAddr Permet de résoude l'addresse -func (cMult ClientMulticast) ResolveAddr() (*net.UDPAddr, bool) { - addr, errResUdp := net.ResolveUDPAddr("udp", cMult.address) +func (client ClientMulticast) ResolveAddr() (*net.UDPAddr, bool) { + addr, errResUdp := net.ResolveUDPAddr("udp", client.address) if errResUdp != nil { println(errResUdp.Error()) @@ -75,7 +75,7 @@ func (cMult ClientMulticast) ResolveAddr() (*net.UDPAddr, bool) { } // DialUdp Ouvre une connection UDP -func (cMult ClientMulticast) DialUdp(addr *net.UDPAddr) (*net.UDPConn, bool) { +func (client ClientMulticast) DialUdp(addr *net.UDPAddr) (*net.UDPConn, bool) { con, errDial := net.DialUDP("udp", nil, addr) if errDial != nil { println(errDial.Error()) diff --git a/pkg/network/ServerUnicast.go b/pkg/network/ServerUnicast.go index 2ff83c0..f76b81d 100644 --- a/pkg/network/ServerUnicast.go +++ b/pkg/network/ServerUnicast.go @@ -14,7 +14,6 @@ type ServerUnicast struct { } func (server ServerUnicast) Run() { - listen, err := net.Listen(server.Network, fmt.Sprintf("0.0.0.0:%d", server.Port)) // "tcp", "0.0.0.0:58000" if err != nil { @@ -39,5 +38,4 @@ func (server ServerUnicast) Run() { _, _ = con.Write(append([]byte(result), '\n')) // TODO : ATTENTION laisser les \n } } - } diff --git a/pkg/protocol/IProtocolWriter.go b/pkg/protocol/IProtocolWriter.go index adbd040..688f51d 100644 --- a/pkg/protocol/IProtocolWriter.go +++ b/pkg/protocol/IProtocolWriter.go @@ -1,6 +1,6 @@ package protocol -// IProtocolReader Représentation abstraite d'un protocol +// IProtocolWriter Représentation abstraite d'un protocol type IProtocolWriter interface { // GetCmd Permet de récupérer le nom de la commande GetCmd() string diff --git a/pkg/protocol/RegexMatcher.go b/pkg/protocol/RegexMatcher.go index 517be7e..679cadb 100644 --- a/pkg/protocol/RegexMatcher.go +++ b/pkg/protocol/RegexMatcher.go @@ -8,7 +8,6 @@ func CreateRegexMatcher(pattern string) *RegexMatcher { if err != nil { return nil } - return &RegexMatcher{matcher: compile} } diff --git a/pkg/protocol/managers/RequestManager.go b/pkg/protocol/managers/RequestManager.go index 4228335..6ee6044 100644 --- a/pkg/protocol/managers/RequestManager.go +++ b/pkg/protocol/managers/RequestManager.go @@ -15,6 +15,6 @@ func (receiver RequestManager) Execute(request string) string { return result } else { // TODO : Renvoyer qu'une erreur est survenue - return "Error occured while execute command" + return "Error occurred while execute command" } } diff --git a/pkg/protocol/repository/ProtocolRepository.go b/pkg/protocol/repository/ProtocolRepository.go index e5ee8ac..6470360 100644 --- a/pkg/protocol/repository/ProtocolRepository.go +++ b/pkg/protocol/repository/ProtocolRepository.go @@ -42,7 +42,6 @@ func (repo ProtocolRepository) ExecuteReader(data string) (string, bool) { return (*reader).Execute(data) } } - return "", false } diff --git a/pkg/protocol/rules/readers/EraseFileRule.go b/pkg/protocol/rules/readers/EraseFileRule.go index e6a9de8..34bfbbf 100644 --- a/pkg/protocol/rules/readers/EraseFileRule.go +++ b/pkg/protocol/rules/readers/EraseFileRule.go @@ -27,7 +27,6 @@ func (rule EraseFileRule) GetCmd() string { } func (rule EraseFileRule) Execute(data string) (string, bool) { - if rule.Match(data) { values := rule.matcher.Parse(data) println(values[1], " est le hash du fichier à supprimer") diff --git a/resources/AppConfig.json b/resources/AppConfig.json index d878c64..feb7042 100644 --- a/resources/AppConfig.json +++ b/resources/AppConfig.json @@ -1,6 +1,6 @@ { "multicastAddress" : "226.66.66.1:42500", "multicastSecond" : 10, - "domain" : "lightcontainer.storebacked-01", + "domain" : "lightcontainerSB01", "unicastPort" : 58000 } \ No newline at end of file