Start commit 22/02/2022
This commit is contained in:
parent
a8d6197b60
commit
c8de92d99b
@ -2,6 +2,8 @@ package main
|
||||
|
||||
import (
|
||||
"_StorBackEnd/pkg/network"
|
||||
"_StorBackEnd/pkg/protocol"
|
||||
"_StorBackEnd/pkg/protocol/repository"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -12,11 +14,14 @@ const (
|
||||
|
||||
func main() {
|
||||
println("StorBackEnd started !")
|
||||
protocolRepository := repository.CreateProtocolRepository()
|
||||
|
||||
multicast := network.CreateClientMulticast(MULTICAST_ADDRESS, MULTICAST_SECOND)
|
||||
multicast := network.CreateClientMulticast(MULTICAST_ADDRESS, MULTICAST_SECOND, protocolRepository)
|
||||
go multicast.Run()
|
||||
|
||||
server := network.ServerUnicast{Network: "tcp", Address: UNICAST_ADDRESS}
|
||||
requestManager := protocol.RequestManager{Repository: protocolRepository}
|
||||
|
||||
server := network.ServerUnicast{Network: "tcp", Address: UNICAST_ADDRESS, ReqManager: &requestManager}
|
||||
server.Run()
|
||||
|
||||
}
|
||||
|
@ -1,15 +1,17 @@
|
||||
package network
|
||||
|
||||
import (
|
||||
"_StorBackEnd/pkg/protocol/repository"
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
// CreateClientMulticast Méthode de construction d'un instance de la stuct ClientMulticast
|
||||
func CreateClientMulticast(address string, second time.Duration) ClientMulticast {
|
||||
func CreateClientMulticast(address string, second time.Duration, repository *repository.ProtocolRepository) ClientMulticast {
|
||||
return ClientMulticast{
|
||||
address: address,
|
||||
second: second,
|
||||
address: address,
|
||||
second: second,
|
||||
repository: repository,
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,6 +23,9 @@ type ClientMulticast struct {
|
||||
|
||||
// second Temps en seconde entre chaque ping
|
||||
second time.Duration
|
||||
|
||||
// Repository de protocol permettant de
|
||||
repository *repository.ProtocolRepository
|
||||
}
|
||||
|
||||
// Run Cette méthode démarre une commmunication multicast
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
type ServerUnicast struct {
|
||||
Network string
|
||||
Address string
|
||||
ReqManager protocol.RequestManager
|
||||
ReqManager *protocol.RequestManager
|
||||
}
|
||||
|
||||
func (server ServerUnicast) Run() {
|
||||
@ -29,12 +29,15 @@ func (server ServerUnicast) Run() {
|
||||
fmt.Printf("Error while accepting client : %s\n", err)
|
||||
return
|
||||
} else {
|
||||
line, err := bufio.NewReader(con).ReadString('\n')
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for { // TODO : Extraire cette partie de code
|
||||
line, err := bufio.NewReader(con).ReadString('\n')
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
server.ReqManager.Execute(line)
|
||||
result := server.ReqManager.Execute(line)
|
||||
con.Write(append([]byte(result), '\n'))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,12 +3,12 @@ package protocol
|
||||
import "_StorBackEnd/pkg/protocol/repository"
|
||||
|
||||
type RequestManager struct {
|
||||
repository repository.ProtocolRepository
|
||||
Repository *repository.ProtocolRepository
|
||||
}
|
||||
|
||||
func (receiver RequestManager) Execute(request string) string {
|
||||
// On lis ce que l'on reçoit
|
||||
result, executed := receiver.repository.ExecuteReader(request)
|
||||
result, executed := receiver.Repository.ExecuteReader(request)
|
||||
|
||||
// On renvoie la réponse (Comment pour fichier ?)
|
||||
if executed {
|
||||
|
@ -4,6 +4,13 @@ import (
|
||||
"_StorBackEnd/pkg/protocol"
|
||||
)
|
||||
|
||||
func CreateProtocolRepository() *ProtocolRepository {
|
||||
return &ProtocolRepository{
|
||||
protocolReaders: make(map[string]*protocol.IProtocolReader),
|
||||
protocolWriters: make(map[string]*protocol.IProtocolWriter),
|
||||
}
|
||||
}
|
||||
|
||||
type ProtocolRepository struct {
|
||||
protocolReaders map[string]*protocol.IProtocolReader
|
||||
protocolWriters map[string]*protocol.IProtocolWriter
|
||||
|
Loading…
Reference in New Issue
Block a user