Fixing some issues, backed project study
This commit is contained in:
parent
b942166f69
commit
8c443d43e4
@ -24,7 +24,8 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
println("Address multicast : " + appConfig.MulticastAddress)
|
||||
println("Multicast Address : " + appConfig.MulticastAddress)
|
||||
println("StoreBacked Domain : " + appConfig.Domain)
|
||||
|
||||
protocolRepository := repository.CreateProtocolRepository()
|
||||
|
||||
|
@ -5,6 +5,8 @@ import (
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
// Read Méthode permettant de lire le fichier de donfiguration
|
||||
// return AppConfig
|
||||
func Read(filePath string) (*AppConfig, error) {
|
||||
config := AppConfig{}
|
||||
file, err := ioutil.ReadFile(filePath)
|
||||
@ -16,6 +18,5 @@ func Read(filePath string) (*AppConfig, error) {
|
||||
if errJson != nil {
|
||||
return nil, errJson
|
||||
}
|
||||
|
||||
return &config, nil
|
||||
}
|
||||
|
@ -39,18 +39,18 @@ type ClientMulticast struct {
|
||||
}
|
||||
|
||||
// Run Cette méthode démarre une commmunication multicast
|
||||
func (cMult ClientMulticast) Run() {
|
||||
addr, done := cMult.ResolveAddr()
|
||||
func (client ClientMulticast) Run() {
|
||||
addr, done := client.ResolveAddr()
|
||||
if done {
|
||||
return
|
||||
}
|
||||
|
||||
con, done2 := cMult.DialUdp(addr)
|
||||
con, done2 := client.DialUdp(addr)
|
||||
if done2 {
|
||||
return
|
||||
}
|
||||
|
||||
cmd, correct := cMult.repository.ExecuteWriter(writers.HelloRuleName, cMult.domain, fmt.Sprintf("%d", cMult.port))
|
||||
cmd, correct := client.repository.ExecuteWriter(writers.HelloRuleName, client.domain, fmt.Sprintf("%d", client.port))
|
||||
if !correct {
|
||||
println("[ClientMulticast] Hello rule isn't correct (" + cmd + ")")
|
||||
return
|
||||
@ -58,14 +58,14 @@ func (cMult ClientMulticast) Run() {
|
||||
|
||||
for {
|
||||
_, _ = con.Write([]byte(cmd))
|
||||
time.Sleep(time.Second * cMult.second)
|
||||
time.Sleep(time.Second * client.second)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ResolveAddr Permet de résoude l'addresse
|
||||
func (cMult ClientMulticast) ResolveAddr() (*net.UDPAddr, bool) {
|
||||
addr, errResUdp := net.ResolveUDPAddr("udp", cMult.address)
|
||||
func (client ClientMulticast) ResolveAddr() (*net.UDPAddr, bool) {
|
||||
addr, errResUdp := net.ResolveUDPAddr("udp", client.address)
|
||||
|
||||
if errResUdp != nil {
|
||||
println(errResUdp.Error())
|
||||
@ -75,7 +75,7 @@ func (cMult ClientMulticast) ResolveAddr() (*net.UDPAddr, bool) {
|
||||
}
|
||||
|
||||
// DialUdp Ouvre une connection UDP
|
||||
func (cMult ClientMulticast) DialUdp(addr *net.UDPAddr) (*net.UDPConn, bool) {
|
||||
func (client ClientMulticast) DialUdp(addr *net.UDPAddr) (*net.UDPConn, bool) {
|
||||
con, errDial := net.DialUDP("udp", nil, addr)
|
||||
if errDial != nil {
|
||||
println(errDial.Error())
|
||||
|
@ -14,7 +14,6 @@ type ServerUnicast struct {
|
||||
}
|
||||
|
||||
func (server ServerUnicast) Run() {
|
||||
|
||||
listen, err := net.Listen(server.Network, fmt.Sprintf("0.0.0.0:%d", server.Port)) // "tcp", "0.0.0.0:58000"
|
||||
|
||||
if err != nil {
|
||||
@ -39,5 +38,4 @@ func (server ServerUnicast) Run() {
|
||||
_, _ = con.Write(append([]byte(result), '\n')) // TODO : ATTENTION laisser les \n
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package protocol
|
||||
|
||||
// IProtocolReader Représentation abstraite d'un protocol
|
||||
// IProtocolWriter Représentation abstraite d'un protocol
|
||||
type IProtocolWriter interface {
|
||||
// GetCmd Permet de récupérer le nom de la commande
|
||||
GetCmd() string
|
||||
|
@ -8,7 +8,6 @@ func CreateRegexMatcher(pattern string) *RegexMatcher {
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &RegexMatcher{matcher: compile}
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,6 @@ func (receiver RequestManager) Execute(request string) string {
|
||||
return result
|
||||
} else {
|
||||
// TODO : Renvoyer qu'une erreur est survenue
|
||||
return "Error occured while execute command"
|
||||
return "Error occurred while execute command"
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,6 @@ func (repo ProtocolRepository) ExecuteReader(data string) (string, bool) {
|
||||
return (*reader).Execute(data)
|
||||
}
|
||||
}
|
||||
|
||||
return "", false
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,6 @@ func (rule EraseFileRule) GetCmd() string {
|
||||
}
|
||||
|
||||
func (rule EraseFileRule) Execute(data string) (string, bool) {
|
||||
|
||||
if rule.Match(data) {
|
||||
values := rule.matcher.Parse(data)
|
||||
println(values[1], " est le hash du fichier à supprimer")
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"multicastAddress" : "226.66.66.1:42500",
|
||||
"multicastSecond" : 10,
|
||||
"domain" : "lightcontainer.storebacked-01",
|
||||
"domain" : "lightcontainerSB01",
|
||||
"unicastPort" : 58000
|
||||
}
|
Loading…
Reference in New Issue
Block a user