mirror of
https://github.com/dragonheim/gagent.git
synced 2025-05-24 19:16:47 -07:00
fix: (issues/9) Worker does not support port assignment for routers (#11)
Quite a refactor and some code cleanup. Co-authored-by: James Wells <jwells@dragonheim.net> Reviewed-on: #11 Co-authored-by: James Wells <jwells@noreply.localhost> Co-committed-by: James Wells <jwells@noreply.localhost>
This commit is contained in:
parent
881a11316d
commit
7d6fbfef24
21 changed files with 451 additions and 271 deletions
|
@ -3,31 +3,28 @@ package client
|
|||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
gs "git.dragonheim.net/dragonheim/gagent/src/gstructs"
|
||||
|
||||
zmq "github.com/pebbe/zmq4"
|
||||
)
|
||||
|
||||
// Main is the initiation function for a Client
|
||||
func Main(config gs.GagentConfig, routerID int, agent string) {
|
||||
var mu sync.Mutex
|
||||
var rport = int(config.ListenPort)
|
||||
if config.Routers[routerID].RouterPort != "" {
|
||||
rport, _ = strconv.Atoi(config.Routers[routerID].RouterPort)
|
||||
func Main(config gs.GagentConfig, rid int, agent string) {
|
||||
log.Printf("[INFO] Starting client\n")
|
||||
|
||||
// Generate connect string for this router.
|
||||
var rport = int64(config.ClientPort)
|
||||
if config.Routers[rid].ClientPort != 0 {
|
||||
rport = config.Routers[rid].ClientPort
|
||||
}
|
||||
connectString := fmt.Sprintf("tcp://%s:%d", config.Routers[rid].RouterAddr, rport)
|
||||
log.Printf("[DEBUG] Attempting to connect to %s\n", connectString)
|
||||
|
||||
log.Printf("--|%#v|--\n", agent)
|
||||
var mu sync.Mutex
|
||||
|
||||
connectString := fmt.Sprintf("tcp://%s:%d",
|
||||
config.Routers[routerID].RouterAddr,
|
||||
rport)
|
||||
log.Printf("Attempting to connect to %s\n", connectString)
|
||||
|
||||
sock, _ := zmq.NewSocket(zmq.DEALER)
|
||||
sock, _ := zmq.NewSocket(zmq.REQ)
|
||||
defer sock.Close()
|
||||
|
||||
sock.SetIdentity(config.UUID)
|
||||
|
@ -35,17 +32,22 @@ func Main(config gs.GagentConfig, routerID int, agent string) {
|
|||
|
||||
go func() {
|
||||
mu.Lock()
|
||||
log.Printf("[DEBUG] Start sending agent...\n")
|
||||
sock.SendMessage(agent)
|
||||
log.Printf("[DEBUG] End sending agent...\n")
|
||||
mu.Unlock()
|
||||
}()
|
||||
|
||||
for {
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
mu.Lock()
|
||||
msg, err := sock.RecvMessage(zmq.DONTWAIT)
|
||||
if err == nil {
|
||||
log.Println(msg[0], config.UUID)
|
||||
}
|
||||
mu.Unlock()
|
||||
}
|
||||
// time.Sleep(10 * time.Millisecond)
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
// for {
|
||||
// time.Sleep(10 * time.Millisecond)
|
||||
// mu.Lock()
|
||||
// msg, err := sock.RecvMessage(zmq.DONTWAIT)
|
||||
// if err == nil {
|
||||
// log.Println(msg[0], config.UUID)
|
||||
// }
|
||||
// mu.Unlock()
|
||||
// }
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue