Envoie de l'annonce en multicast fonctionnelle
This commit is contained in:
parent
e9e1dbf6d8
commit
9eb4e8204e
@ -2,8 +2,9 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"_StorBackEnd/pkg/network"
|
"_StorBackEnd/pkg/network"
|
||||||
"_StorBackEnd/pkg/protocol"
|
"_StorBackEnd/pkg/protocol/managers"
|
||||||
"_StorBackEnd/pkg/protocol/repository"
|
"_StorBackEnd/pkg/protocol/repository"
|
||||||
|
"_StorBackEnd/pkg/protocol/rules/writers"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -14,12 +15,15 @@ const (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
println("StorBackEnd started !")
|
println("StorBackEnd started !")
|
||||||
|
|
||||||
protocolRepository := repository.CreateProtocolRepository()
|
protocolRepository := repository.CreateProtocolRepository()
|
||||||
|
helloRule := writers.CreateHelloRule("")
|
||||||
|
protocolRepository.AddWriter(&helloRule)
|
||||||
|
|
||||||
multicast := network.CreateClientMulticast(MULTICAST_ADDRESS, MULTICAST_SECOND, protocolRepository)
|
multicast := network.CreateClientMulticast(MULTICAST_ADDRESS, MULTICAST_SECOND, protocolRepository)
|
||||||
go multicast.Run()
|
go multicast.Run()
|
||||||
|
|
||||||
requestManager := protocol.RequestManager{Repository: protocolRepository}
|
requestManager := managers.RequestManager{Repository: protocolRepository}
|
||||||
|
|
||||||
server := network.ServerUnicast{Network: "tcp", Address: UNICAST_ADDRESS, ReqManager: &requestManager}
|
server := network.ServerUnicast{Network: "tcp", Address: UNICAST_ADDRESS, ReqManager: &requestManager}
|
||||||
server.Run()
|
server.Run()
|
||||||
|
@ -2,6 +2,7 @@ package network
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"_StorBackEnd/pkg/protocol/repository"
|
"_StorBackEnd/pkg/protocol/repository"
|
||||||
|
"_StorBackEnd/pkg/protocol/rules/writers"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -40,8 +41,15 @@ func (cMult ClientMulticast) Run() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fake test
|
||||||
|
cmd, correct := cMult.repository.ExecuteWriter(writers.HelloRuleName, "benja.be", "5078")
|
||||||
|
if !correct {
|
||||||
|
println("Hello rule isn't correct")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
con.Write([]byte("Hello"))
|
con.Write([]byte(cmd))
|
||||||
time.Sleep(time.Second * cMult.second)
|
time.Sleep(time.Second * cMult.second)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package network
|
package network
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"_StorBackEnd/pkg/protocol"
|
"_StorBackEnd/pkg/protocol/managers"
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
@ -10,7 +10,7 @@ import (
|
|||||||
type ServerUnicast struct {
|
type ServerUnicast struct {
|
||||||
Network string
|
Network string
|
||||||
Address string
|
Address string
|
||||||
ReqManager *protocol.RequestManager
|
ReqManager *managers.RequestManager
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server ServerUnicast) Run() {
|
func (server ServerUnicast) Run() {
|
||||||
|
@ -6,5 +6,5 @@ type IProtocolWriter interface {
|
|||||||
GetCmd() string
|
GetCmd() string
|
||||||
|
|
||||||
// Execute Permet de vérifier la validité d'une donnée censée suivre les règles d'un protocol
|
// 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)
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package protocol
|
package managers
|
||||||
|
|
||||||
import "_StorBackEnd/pkg/protocol/repository"
|
import "_StorBackEnd/pkg/protocol/repository"
|
||||||
|
|
@ -1,8 +1,6 @@
|
|||||||
package repository
|
package repository
|
||||||
|
|
||||||
import (
|
import "_StorBackEnd/pkg/protocol"
|
||||||
"_StorBackEnd/pkg/protocol"
|
|
||||||
)
|
|
||||||
|
|
||||||
func CreateProtocolRepository() *ProtocolRepository {
|
func CreateProtocolRepository() *ProtocolRepository {
|
||||||
return &ProtocolRepository{
|
return &ProtocolRepository{
|
||||||
@ -48,6 +46,19 @@ func (repo ProtocolRepository) ExecuteReader(data string) (string, bool) {
|
|||||||
return "", false
|
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
|
// containsReader Permet de vérifier si le reader est déjà contenu
|
||||||
func (repo ProtocolRepository) containsReader(cmd string) bool {
|
func (repo ProtocolRepository) containsReader(cmd string) bool {
|
||||||
_, has := repo.protocolReaders[cmd]
|
_, has := repo.protocolReaders[cmd]
|
||||||
|
@ -13,7 +13,7 @@ type HelloRule struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreateHelloRule Création d'une instance de HelloRule
|
// CreateHelloRule Création d'une instance de HelloRule
|
||||||
func CreateHelloRule(pattern string) *HelloRule {
|
func CreateHelloRule(pattern string) protocol.IProtocolWriter {
|
||||||
return &HelloRule{
|
return &HelloRule{
|
||||||
Cmd: HelloRuleName,
|
Cmd: HelloRuleName,
|
||||||
matcher: protocol.CreateRegexMatcher(pattern),
|
matcher: protocol.CreateRegexMatcher(pattern),
|
||||||
@ -24,7 +24,6 @@ func (rule HelloRule) GetCmd() string {
|
|||||||
return rule.Cmd
|
return rule.Cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rule HelloRule) Execute(argsData []string) {
|
func (rule HelloRule) Execute(argsData ...string) (string, bool) {
|
||||||
//TODO implement me
|
return rule.matcher.Build("HELLO", argsData...)
|
||||||
panic("implement me")
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user