Fixing some issues, backed project study

This commit is contained in:
Jérémi N ‘EndMove’ 2022-03-05 18:32:27 +01:00
parent b942166f69
commit 8c443d43e4
Signed by: EndMove
GPG Key ID: 65C4A02E1F5371A4
10 changed files with 15 additions and 18 deletions

View File

@ -24,7 +24,8 @@ func main() {
return return
} }
println("Address multicast : " + appConfig.MulticastAddress) println("Multicast Address : " + appConfig.MulticastAddress)
println("StoreBacked Domain : " + appConfig.Domain)
protocolRepository := repository.CreateProtocolRepository() protocolRepository := repository.CreateProtocolRepository()

View File

@ -5,6 +5,8 @@ import (
"io/ioutil" "io/ioutil"
) )
// Read Méthode permettant de lire le fichier de donfiguration
// return AppConfig
func Read(filePath string) (*AppConfig, error) { func Read(filePath string) (*AppConfig, error) {
config := AppConfig{} config := AppConfig{}
file, err := ioutil.ReadFile(filePath) file, err := ioutil.ReadFile(filePath)
@ -16,6 +18,5 @@ func Read(filePath string) (*AppConfig, error) {
if errJson != nil { if errJson != nil {
return nil, errJson return nil, errJson
} }
return &config, nil return &config, nil
} }

View File

@ -39,18 +39,18 @@ type ClientMulticast struct {
} }
// Run Cette méthode démarre une commmunication multicast // Run Cette méthode démarre une commmunication multicast
func (cMult ClientMulticast) Run() { func (client ClientMulticast) Run() {
addr, done := cMult.ResolveAddr() addr, done := client.ResolveAddr()
if done { if done {
return return
} }
con, done2 := cMult.DialUdp(addr) con, done2 := client.DialUdp(addr)
if done2 { if done2 {
return 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 { if !correct {
println("[ClientMulticast] Hello rule isn't correct (" + cmd + ")") println("[ClientMulticast] Hello rule isn't correct (" + cmd + ")")
return return
@ -58,14 +58,14 @@ func (cMult ClientMulticast) Run() {
for { for {
_, _ = con.Write([]byte(cmd)) _, _ = con.Write([]byte(cmd))
time.Sleep(time.Second * cMult.second) time.Sleep(time.Second * client.second)
} }
} }
// ResolveAddr Permet de résoude l'addresse // ResolveAddr Permet de résoude l'addresse
func (cMult ClientMulticast) ResolveAddr() (*net.UDPAddr, bool) { func (client ClientMulticast) ResolveAddr() (*net.UDPAddr, bool) {
addr, errResUdp := net.ResolveUDPAddr("udp", cMult.address) addr, errResUdp := net.ResolveUDPAddr("udp", client.address)
if errResUdp != nil { if errResUdp != nil {
println(errResUdp.Error()) println(errResUdp.Error())
@ -75,7 +75,7 @@ func (cMult ClientMulticast) ResolveAddr() (*net.UDPAddr, bool) {
} }
// DialUdp Ouvre une connection UDP // 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) con, errDial := net.DialUDP("udp", nil, addr)
if errDial != nil { if errDial != nil {
println(errDial.Error()) println(errDial.Error())

View File

@ -14,7 +14,6 @@ type ServerUnicast struct {
} }
func (server ServerUnicast) Run() { 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" listen, err := net.Listen(server.Network, fmt.Sprintf("0.0.0.0:%d", server.Port)) // "tcp", "0.0.0.0:58000"
if err != nil { if err != nil {
@ -39,5 +38,4 @@ func (server ServerUnicast) Run() {
_, _ = con.Write(append([]byte(result), '\n')) // TODO : ATTENTION laisser les \n _, _ = con.Write(append([]byte(result), '\n')) // TODO : ATTENTION laisser les \n
} }
} }
} }

View File

@ -1,6 +1,6 @@
package protocol package protocol
// IProtocolReader Représentation abstraite d'un protocol // IProtocolWriter Représentation abstraite d'un protocol
type IProtocolWriter interface { type IProtocolWriter interface {
// GetCmd Permet de récupérer le nom de la commande // GetCmd Permet de récupérer le nom de la commande
GetCmd() string GetCmd() string

View File

@ -8,7 +8,6 @@ func CreateRegexMatcher(pattern string) *RegexMatcher {
if err != nil { if err != nil {
return nil return nil
} }
return &RegexMatcher{matcher: compile} return &RegexMatcher{matcher: compile}
} }

View File

@ -15,6 +15,6 @@ func (receiver RequestManager) Execute(request string) string {
return result return result
} else { } else {
// TODO : Renvoyer qu'une erreur est survenue // TODO : Renvoyer qu'une erreur est survenue
return "Error occured while execute command" return "Error occurred while execute command"
} }
} }

View File

@ -42,7 +42,6 @@ func (repo ProtocolRepository) ExecuteReader(data string) (string, bool) {
return (*reader).Execute(data) return (*reader).Execute(data)
} }
} }
return "", false return "", false
} }

View File

@ -27,7 +27,6 @@ func (rule EraseFileRule) GetCmd() string {
} }
func (rule EraseFileRule) Execute(data string) (string, bool) { func (rule EraseFileRule) Execute(data string) (string, bool) {
if rule.Match(data) { if rule.Match(data) {
values := rule.matcher.Parse(data) values := rule.matcher.Parse(data)
println(values[1], " est le hash du fichier à supprimer") println(values[1], " est le hash du fichier à supprimer")

View File

@ -1,6 +1,6 @@
{ {
"multicastAddress" : "226.66.66.1:42500", "multicastAddress" : "226.66.66.1:42500",
"multicastSecond" : 10, "multicastSecond" : 10,
"domain" : "lightcontainer.storebacked-01", "domain" : "lightcontainerSB01",
"unicastPort" : 58000 "unicastPort" : 58000
} }