Envoie de l'annonce en multicast fonctionnelle

This commit is contained in:
Benjamin Lejeune 2022-02-22 09:35:44 +01:00
parent e9e1dbf6d8
commit 9eb4e8204e
7 changed files with 36 additions and 14 deletions

View File

@ -2,8 +2,9 @@ package main
import (
"_StorBackEnd/pkg/network"
"_StorBackEnd/pkg/protocol"
"_StorBackEnd/pkg/protocol/managers"
"_StorBackEnd/pkg/protocol/repository"
"_StorBackEnd/pkg/protocol/rules/writers"
)
const (
@ -14,12 +15,15 @@ const (
func main() {
println("StorBackEnd started !")
protocolRepository := repository.CreateProtocolRepository()
helloRule := writers.CreateHelloRule("")
protocolRepository.AddWriter(&helloRule)
multicast := network.CreateClientMulticast(MULTICAST_ADDRESS, MULTICAST_SECOND, protocolRepository)
go multicast.Run()
requestManager := protocol.RequestManager{Repository: protocolRepository}
requestManager := managers.RequestManager{Repository: protocolRepository}
server := network.ServerUnicast{Network: "tcp", Address: UNICAST_ADDRESS, ReqManager: &requestManager}
server.Run()

View File

@ -2,6 +2,7 @@ package network
import (
"_StorBackEnd/pkg/protocol/repository"
"_StorBackEnd/pkg/protocol/rules/writers"
"net"
"time"
)
@ -40,8 +41,15 @@ func (cMult ClientMulticast) Run() {
return
}
// Fake test
cmd, correct := cMult.repository.ExecuteWriter(writers.HelloRuleName, "benja.be", "5078")
if !correct {
println("Hello rule isn't correct")
return
}
for {
con.Write([]byte("Hello"))
con.Write([]byte(cmd))
time.Sleep(time.Second * cMult.second)
}

View File

@ -1,7 +1,7 @@
package network
import (
"_StorBackEnd/pkg/protocol"
"_StorBackEnd/pkg/protocol/managers"
"bufio"
"fmt"
"net"
@ -10,7 +10,7 @@ import (
type ServerUnicast struct {
Network string
Address string
ReqManager *protocol.RequestManager
ReqManager *managers.RequestManager
}
func (server ServerUnicast) Run() {

View File

@ -6,5 +6,5 @@ type IProtocolWriter interface {
GetCmd() string
// Execute Permet de vérifier la validité d'une donnée censée suivre les règles d'un protocol
Execute(argsData []string)
Execute(argsData ...string) (string, bool)
}

View File

@ -1,4 +1,4 @@
package protocol
package managers
import "_StorBackEnd/pkg/protocol/repository"

View File

@ -1,8 +1,6 @@
package repository
import (
"_StorBackEnd/pkg/protocol"
)
import "_StorBackEnd/pkg/protocol"
func CreateProtocolRepository() *ProtocolRepository {
return &ProtocolRepository{
@ -48,6 +46,19 @@ func (repo ProtocolRepository) ExecuteReader(data string) (string, bool) {
return "", false
}
/*
ExecuteReader Permet d'exécuter un Wrier et de récupérer la commande construite avec nos argument et un indicateur de réussite.
*/
func (repo ProtocolRepository) ExecuteWriter(ruleName string, data ...string) (string, bool) {
protWriter, has := repo.protocolWriters[ruleName]
if has {
println("OHOH")
return (*protWriter).Execute(data...)
} else {
return "", false
}
}
// containsReader Permet de vérifier si le reader est déjà contenu
func (repo ProtocolRepository) containsReader(cmd string) bool {
_, has := repo.protocolReaders[cmd]

View File

@ -13,7 +13,7 @@ type HelloRule struct {
}
// CreateHelloRule Création d'une instance de HelloRule
func CreateHelloRule(pattern string) *HelloRule {
func CreateHelloRule(pattern string) protocol.IProtocolWriter {
return &HelloRule{
Cmd: HelloRuleName,
matcher: protocol.CreateRegexMatcher(pattern),
@ -24,7 +24,6 @@ func (rule HelloRule) GetCmd() string {
return rule.Cmd
}
func (rule HelloRule) Execute(argsData []string) {
//TODO implement me
panic("implement me")
func (rule HelloRule) Execute(argsData ...string) (string, bool) {
return rule.matcher.Build("HELLO", argsData...)
}