2022-02-15 11:08:07 +01:00
|
|
|
package main
|
|
|
|
|
2022-02-19 18:10:52 +01:00
|
|
|
import (
|
2022-02-23 13:07:48 +01:00
|
|
|
"StorBackEnd/pkg/config"
|
|
|
|
"StorBackEnd/pkg/network"
|
|
|
|
"StorBackEnd/pkg/protocol/managers"
|
|
|
|
"StorBackEnd/pkg/protocol/repository"
|
|
|
|
"StorBackEnd/pkg/protocol/rules/readers"
|
|
|
|
"StorBackEnd/pkg/protocol/rules/writers"
|
2022-02-19 18:10:52 +01:00
|
|
|
)
|
2022-02-15 11:08:07 +01:00
|
|
|
|
|
|
|
const (
|
2022-02-22 13:05:33 +01:00
|
|
|
FILE_PATH = "resources/AppConfig.json"
|
2022-02-20 11:41:41 +01:00
|
|
|
MULTICAST_ADDRESS = "226.66.66.1:42500"
|
|
|
|
MULTICAST_SECOND = 10 // TODO : Changer en 30 secondes
|
|
|
|
UNICAST_ADDRESS = "0.0.0.0:58000"
|
2022-02-15 11:08:07 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
println("StorBackEnd started !")
|
2022-02-22 09:35:44 +01:00
|
|
|
|
2022-02-22 13:05:33 +01:00
|
|
|
// Loading App config
|
|
|
|
appConfig, err := config.Read(FILE_PATH)
|
|
|
|
if err != nil {
|
|
|
|
println("Impossible de charger la configuration du server : " + err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
println("Adresse multicast : " + appConfig.MulticastAddress)
|
|
|
|
|
2022-02-22 08:29:11 +01:00
|
|
|
protocolRepository := repository.CreateProtocolRepository()
|
2022-02-22 10:03:52 +01:00
|
|
|
|
|
|
|
// Création des Writers
|
2022-02-22 10:52:07 +01:00
|
|
|
helloRule := writers.CreateHelloRule("^HELLO ([A-Za-z0-9]{5,20}) ([0-9]{1,5})\r\n$")
|
2022-02-22 09:35:44 +01:00
|
|
|
protocolRepository.AddWriter(&helloRule)
|
2022-02-15 11:08:07 +01:00
|
|
|
|
2022-02-22 10:03:52 +01:00
|
|
|
// Création des Readers
|
2022-02-22 10:52:07 +01:00
|
|
|
eraseFileRule := readers.CreateEraseFileRule("^ERASEFILE ([A-Za-z0-9.]{50,200})\r\n$")
|
2022-02-22 10:03:52 +01:00
|
|
|
protocolRepository.AddReader(&eraseFileRule)
|
|
|
|
|
2022-02-22 08:29:11 +01:00
|
|
|
multicast := network.CreateClientMulticast(MULTICAST_ADDRESS, MULTICAST_SECOND, protocolRepository)
|
2022-02-20 11:41:41 +01:00
|
|
|
go multicast.Run()
|
2022-02-15 11:08:07 +01:00
|
|
|
|
2022-02-22 09:35:44 +01:00
|
|
|
requestManager := managers.RequestManager{Repository: protocolRepository}
|
2022-02-22 08:29:11 +01:00
|
|
|
|
|
|
|
server := network.ServerUnicast{Network: "tcp", Address: UNICAST_ADDRESS, ReqManager: &requestManager}
|
2022-02-20 11:34:10 +01:00
|
|
|
server.Run()
|
2022-02-15 11:08:07 +01:00
|
|
|
|
|
|
|
}
|