2022-02-15 11:08:07 +01:00
|
|
|
package main
|
|
|
|
|
2022-02-19 18:10:52 +01:00
|
|
|
import (
|
2022-03-05 17:21:46 +01:00
|
|
|
"StoreBackEnd/pkg/config"
|
|
|
|
"StoreBackEnd/pkg/network"
|
|
|
|
"StoreBackEnd/pkg/protocol/managers"
|
|
|
|
"StoreBackEnd/pkg/protocol/repository"
|
|
|
|
"StoreBackEnd/pkg/protocol/rules/readers"
|
|
|
|
"StoreBackEnd/pkg/protocol/rules/writers"
|
2022-03-08 19:41:54 +01:00
|
|
|
"StoreBackEnd/pkg/utils"
|
2022-03-15 17:11:31 +01:00
|
|
|
"log"
|
2022-02-23 14:08:41 +01:00
|
|
|
"time"
|
2022-02-19 18:10:52 +01:00
|
|
|
)
|
2022-02-15 11:08:07 +01:00
|
|
|
|
|
|
|
const (
|
2022-03-05 17:21:46 +01:00
|
|
|
FilePath = "resources/AppConfig.json"
|
2022-02-15 11:08:07 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2022-03-15 17:11:31 +01:00
|
|
|
hash, err := utils.HashFileCompare("D:\\HELMoCrypted.png", "bacf89bd47be38ac445d5519c4e945bbea79c4a1f250cb31579e331e67941939")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
println("Hash : ", hash)
|
2022-03-08 19:41:54 +01:00
|
|
|
utils.NetworkLister() // TODO REMOVE
|
2022-03-05 17:21:46 +01:00
|
|
|
println("StoreBackEnd started !")
|
2022-02-22 09:35:44 +01:00
|
|
|
|
2022-02-22 13:05:33 +01:00
|
|
|
// Loading App config
|
2022-03-05 17:21:46 +01:00
|
|
|
appConfig, err := config.Read(FilePath)
|
2022-02-22 13:05:33 +01:00
|
|
|
if err != nil {
|
|
|
|
println("Impossible de charger la configuration du server : " + err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-03-08 14:58:41 +01:00
|
|
|
println(" - Multicast Network Interface : " + appConfig.MulticastNetworkInterface)
|
|
|
|
println(" - Multicast Address : " + appConfig.MulticastAddress)
|
|
|
|
println(" - StoreBacked Domain : " + appConfig.Domain)
|
2022-02-22 13:05:33 +01:00
|
|
|
|
2022-02-22 08:29:11 +01:00
|
|
|
protocolRepository := repository.CreateProtocolRepository()
|
2022-02-22 10:03:52 +01:00
|
|
|
|
2022-03-08 10:25:00 +01:00
|
|
|
/**
|
|
|
|
===== Init all Write here =====
|
|
|
|
*/
|
|
|
|
// Creation of the HelloRule
|
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-03-08 10:25:00 +01:00
|
|
|
// Creation of the SendOkRule
|
2022-03-08 14:48:14 +01:00
|
|
|
sendOkRule := writers.CreateSendOkRule("^SEND_OK\r\n$")
|
2022-03-08 10:25:00 +01:00
|
|
|
protocolRepository.AddWriter(&sendOkRule)
|
|
|
|
|
|
|
|
// Creation of the SendErrorRule
|
2022-03-08 14:48:14 +01:00
|
|
|
sendErrorRule := writers.CreateSendOkRule("^SEND_ERROR\r\n$")
|
2022-03-08 10:25:00 +01:00
|
|
|
protocolRepository.AddWriter(&sendErrorRule)
|
|
|
|
|
2022-03-13 15:49:06 +01:00
|
|
|
// Creation of the EraseOkRule
|
|
|
|
eraseOkRule := writers.CreateEraseOkRule("^ERASE_OK\r\n$")
|
|
|
|
protocolRepository.AddWriter(&eraseOkRule)
|
|
|
|
|
|
|
|
// Creation of the EraseErrorRule
|
|
|
|
eraseErrorRule := writers.CreateEraseErrorRule("^ERASE_ERROR\r\n$")
|
|
|
|
protocolRepository.AddWriter(&eraseErrorRule)
|
|
|
|
|
2022-03-15 11:58:06 +01:00
|
|
|
// Creation of the EraseOkRule
|
|
|
|
retrieveOkRule := writers.CreateRetrieveOkRule("^RETRIEVE_OK ([A-Za-z0-9.]{50,200} [0-9]{1,10} [A-Za-z0-9.]{50,200})\r\n$", appConfig.StoragePath)
|
|
|
|
protocolRepository.AddWriter(&retrieveOkRule)
|
|
|
|
|
|
|
|
// Creation of the EraseErrorRule
|
|
|
|
retrieveErrorRule := writers.CreateRetrieveErrorRule("^RETRIEVE_ERROR\r\n$")
|
|
|
|
protocolRepository.AddWriter(&retrieveErrorRule)
|
|
|
|
|
2022-03-08 10:25:00 +01:00
|
|
|
/**
|
|
|
|
===== Init all Reader here =====
|
|
|
|
*/
|
|
|
|
// Creation of the EraseFileRule
|
2022-03-13 15:49:06 +01:00
|
|
|
eraseFileRule := readers.CreateEraseFileRule("^ERASEFILE ([A-Za-z0-9.]{50,200})\r\n$", protocolRepository, appConfig.StoragePath)
|
|
|
|
protocolRepository.AddReader(&eraseFileRule)
|
2022-02-22 10:03:52 +01:00
|
|
|
|
2022-03-15 11:58:06 +01:00
|
|
|
// Creation of the SendFileRule
|
2022-03-14 11:10:23 +01:00
|
|
|
sendFileRule := readers.CreateSendFileRule("^SENDFILE ([A-Za-z0-9.]{50,200}) ([0-9]{1,10}) ([A-Za-z0-9.]{50,200})\r\n$", protocolRepository, appConfig.StoragePath)
|
2022-03-08 10:25:00 +01:00
|
|
|
protocolRepository.AddReader(&sendFileRule)
|
|
|
|
|
2022-03-15 11:58:06 +01:00
|
|
|
// Create of the RetrieveFileRule
|
|
|
|
retrieveFileRule := readers.CreateRetrieveFileRule("^RETRIEVEFILE ([A-Za-z0-9.]{50,200})\r\n$", protocolRepository, appConfig.StoragePath)
|
|
|
|
protocolRepository.AddReader(&retrieveFileRule)
|
|
|
|
|
2022-03-08 10:25:00 +01:00
|
|
|
// Create a Multicast Client & run it
|
2022-03-08 14:58:41 +01:00
|
|
|
multicast := network.CreateClientMulticast(
|
|
|
|
appConfig.MulticastNetworkInterface, appConfig.MulticastAddress, appConfig.Domain,
|
|
|
|
appConfig.UnicastPort, time.Duration(appConfig.MulticastSecond), 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
|
|
|
|
2022-02-26 18:08:52 +01:00
|
|
|
server := network.ServerUnicast{Network: "tcp", Port: appConfig.UnicastPort, ReqManager: &requestManager}
|
2022-03-08 10:25:00 +01:00
|
|
|
server.Run() // TODO : -> pourquoi ne pas partir dans un thread ici.
|
|
|
|
|
|
|
|
//reader := bufio.NewReader(os.Stdin) TODO ne pas oublier ici de mettre en place un point de sortie pour le programme.
|
|
|
|
//fmt.Print("Type Enter to quite: ")
|
|
|
|
//cmd, _ := reader.ReadString('\n')
|
|
|
|
//println(cmd)
|
2022-02-15 11:08:07 +01:00
|
|
|
}
|