From c379c15932653be646368a179d24250e898df9ee Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 26 Feb 2022 18:08:52 +0100 Subject: [PATCH] =?UTF-8?q?Mise=20=C3=A0=20jours=20du=20App=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/main.go | 4 ++-- pkg/config/AppConfig.go | 9 ++++++--- pkg/network/ClientMulticast.go | 16 ++++++++++++---- pkg/network/ServerUnicast.go | 4 ++-- resources/AppConfig.json | 3 ++- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index dc6d83f..2807cd8 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -36,12 +36,12 @@ func main() { eraseFileRule := readers.CreateEraseFileRule("^ERASEFILE ([A-Za-z0-9.]{50,200})\r\n$") protocolRepository.AddReader(&eraseFileRule) - multicast := network.CreateClientMulticast(appConfig.MulticastAddress, time.Duration(appConfig.MulticastSecond), protocolRepository) + multicast := network.CreateClientMulticast(appConfig.MulticastAddress, appConfig.Domain, appConfig.UnicastPort, time.Duration(appConfig.MulticastSecond), protocolRepository) go multicast.Run() requestManager := managers.RequestManager{Repository: protocolRepository} - server := network.ServerUnicast{Network: "tcp", Address: appConfig.UnicastAddress, ReqManager: &requestManager} + server := network.ServerUnicast{Network: "tcp", Port: appConfig.UnicastPort, ReqManager: &requestManager} server.Run() } diff --git a/pkg/config/AppConfig.go b/pkg/config/AppConfig.go index 0d04491..9b5e2e5 100644 --- a/pkg/config/AppConfig.go +++ b/pkg/config/AppConfig.go @@ -2,12 +2,15 @@ package config // AppConfig Contient toute la configuration du server type AppConfig struct { - // multicastAddress Contient l'adresse multicast du FileFrontEnd (adresse:port) + // multicastAddress Contient l'adresse multicast du FileFrontEnd MulticastAddress string `json:"multicastAddress"` // multicastSecond Contient le nombre de seconde entre chaque annonce MulticastSecond int `json:"multicastSecond"` - // unicastAddress Contient l'adresse unicast auquel le FileFrontEnd se connecte (adresse:port) - UnicastAddress string `json:"unicastAddress"` + // domain Domain du StorBackEnd + Domain string `json:"domain"` + + // unicastPort Contient le port unicast auquel le FileFrontEnd se connecte + UnicastPort int `json:"unicastPort"` } diff --git a/pkg/network/ClientMulticast.go b/pkg/network/ClientMulticast.go index f902bdb..8a26121 100644 --- a/pkg/network/ClientMulticast.go +++ b/pkg/network/ClientMulticast.go @@ -3,14 +3,17 @@ package network import ( "StorBackEnd/pkg/protocol/repository" "StorBackEnd/pkg/protocol/rules/writers" + "fmt" "net" "time" ) // CreateClientMulticast Méthode de construction d'un instance de la stuct ClientMulticast -func CreateClientMulticast(address string, second time.Duration, repository *repository.ProtocolRepository) ClientMulticast { +func CreateClientMulticast(address string, domain string, port int, second time.Duration, repository *repository.ProtocolRepository) ClientMulticast { return ClientMulticast{ address: address, + domain: domain, + port: port, second: second, repository: repository, } @@ -19,9 +22,15 @@ func CreateClientMulticast(address string, second time.Duration, repository *rep // ClientMulticast Cette structure représente une communication en multicast. // TODO : Prévoir une fermeture de la connection (con.Close()) type ClientMulticast struct { - // address Adresse de multicast (address:port) + // address Adresse de multicast address string + // address Domain de du StorBackEnd + domain string + + // port Port de connexion en unicast + port int + // second Temps en seconde entre chaque ping second time.Duration @@ -41,8 +50,7 @@ func (cMult ClientMulticast) Run() { return } - // Fake test - cmd, correct := cMult.repository.ExecuteWriter(writers.HelloRuleName, "benja", "5078") + cmd, correct := cMult.repository.ExecuteWriter(writers.HelloRuleName, cMult.domain, fmt.Sprintf("%d", cMult.port)) if !correct { println("[ClientMulticast] Hello rule isn't correct (" + cmd + ")") return diff --git a/pkg/network/ServerUnicast.go b/pkg/network/ServerUnicast.go index 079621d..ecb24ed 100644 --- a/pkg/network/ServerUnicast.go +++ b/pkg/network/ServerUnicast.go @@ -9,13 +9,13 @@ import ( type ServerUnicast struct { Network string - Address string + Port int ReqManager *managers.RequestManager } func (server ServerUnicast) Run() { - listen, err := net.Listen(server.Network, server.Address) // "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 { fmt.Printf("Can't start server : %s\n", err) diff --git a/resources/AppConfig.json b/resources/AppConfig.json index 1b61acd..a25c31e 100644 --- a/resources/AppConfig.json +++ b/resources/AppConfig.json @@ -1,5 +1,6 @@ { "multicastAddress" : "226.66.66.1:42500", "multicastSecond" : 10, - "unicastAddress" : "0.0.0.0:58000" + "domain" : "benjamin", + "unicastPort" : 58000 } \ No newline at end of file