mirror of
https://github.com/dragonheim/gagent.git
synced 2025-04-25 22:48:59 -07:00
Updated to clear errors captured by gosec.
This commit is contained in:
parent
27045c94d6
commit
749bd6557e
6 changed files with 49 additions and 30 deletions
|
@ -86,10 +86,10 @@ func sendAgent(wg *sync.WaitGroup, uuid string, connectString string, agent gstr
|
|||
sock, _ := zmq.NewSocket(zmq.REQ)
|
||||
defer sock.Close()
|
||||
|
||||
sock.SetIdentity(uuid)
|
||||
err := sock.SetIdentity(uuid)
|
||||
|
||||
log.Printf("[DEBUG] Attempting to connect to %s\n", connectString)
|
||||
err := sock.Connect(connectString)
|
||||
err = sock.Connect(connectString)
|
||||
if err != nil {
|
||||
log.Printf("[ERROR] Failed to connect to %s\n", connectString)
|
||||
os.Exit(10)
|
||||
|
|
|
@ -39,7 +39,7 @@ func Main(wg *sync.WaitGroup, config gstructs.GagentConfig) {
|
|||
defer workerSock.Close()
|
||||
|
||||
workerListener := fmt.Sprintf("tcp://%s:%d", config.ListenAddr, config.WorkerPort)
|
||||
workerSock.Bind(workerListener)
|
||||
_ = workerSock.Bind(workerListener)
|
||||
|
||||
workers := make([]string, 0)
|
||||
|
||||
|
@ -49,6 +49,9 @@ func Main(wg *sync.WaitGroup, config gstructs.GagentConfig) {
|
|||
poller2 := zmq.NewPoller()
|
||||
poller2.Add(workerSock, zmq.POLLIN)
|
||||
|
||||
wg.Add(1)
|
||||
go createClientListener(wg, config)
|
||||
|
||||
LOOP:
|
||||
for {
|
||||
/*
|
||||
|
@ -87,20 +90,36 @@ LOOP:
|
|||
workers = append(workers, identity)
|
||||
|
||||
case clientSock:
|
||||
/*
|
||||
* Get client request, route to first available worker
|
||||
*/
|
||||
msg, err := s.RecvMessage(0)
|
||||
log.Printf("[DEBUG] Client message received: %s", msg)
|
||||
if err == nil {
|
||||
workerSock.SendMessage(workers[0], "", msg)
|
||||
workers = workers[1:]
|
||||
}
|
||||
wg.Add(1)
|
||||
go createClientListener(wg, config)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Create listener for client requests
|
||||
*/
|
||||
func createClientListener(wg *sync.WaitGroup, config gstructs.GagentConfig) {
|
||||
defer wg.Done()
|
||||
|
||||
clientSock, _ := zmq.NewSocket(zmq.ROUTER)
|
||||
defer clientSock.Close()
|
||||
|
||||
clientListener := fmt.Sprintf("tcp://%s:%d", config.ListenAddr, config.ClientPort)
|
||||
log.Printf("[DEBUG] Binding to: %s", clientListener)
|
||||
_ = clientSock.Bind(clientListener)
|
||||
|
||||
for {
|
||||
msg, err := clientSock.RecvMessage(0)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
log.Printf("[DEBUG] Client message received: %s", msg)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func unwrap(msg []string) (head string, tail []string) {
|
||||
head = msg[0]
|
||||
if len(msg) > 1 && msg[1] == "" {
|
||||
|
|
|
@ -56,7 +56,7 @@ func getAgent(wg *sync.WaitGroup, uuid string, connectString string) {
|
|||
subscriber, _ := zmq.NewSocket(zmq.REP)
|
||||
defer subscriber.Close()
|
||||
|
||||
subscriber.Connect(connectString)
|
||||
_ = subscriber.Connect(connectString)
|
||||
|
||||
msg, err := subscriber.Recv(0)
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue