mirror of
https://github.com/dragonheim/gagent.git
synced 2025-04-26 02:18:59 -07:00
refactor: converted int64 to int32 where appropriate.
refactor: reduced usage of fmt in favor of logs and string concatication. refactor: minor re-ordering of the data structures to reduce storage space required.
This commit is contained in:
parent
8640d42132
commit
1bcc682b7c
9 changed files with 53 additions and 48 deletions
|
@ -8,11 +8,11 @@ type GagentConfig struct {
|
|||
Mode string `hcl:"mode,attr"`
|
||||
UUID string `hcl:"uuid,optional"`
|
||||
ListenAddr string `hcl:"listenaddr,optional"`
|
||||
MonitorPort int64 `hcl:"monitorport,optional"`
|
||||
ClientPort int64 `hcl:"clientport,optional"`
|
||||
RouterPort int64 `hcl:"routerport,optional"`
|
||||
WorkerPort int64 `hcl:"workerport,optional"`
|
||||
ChainDBPath string `hcl:"chaindbpath,optional"`
|
||||
MonitorPort int `hcl:"monitorport,optional"`
|
||||
ClientPort int `hcl:"clientport,optional"`
|
||||
RouterPort int `hcl:"routerport,optional"`
|
||||
WorkerPort int `hcl:"workerport,optional"`
|
||||
Clients []*ClientDetails `hcl:"client,block"`
|
||||
Routers []*RouterDetails `hcl:"router,block"`
|
||||
Workers []*WorkerDetails `hcl:"worker,block"`
|
||||
|
@ -62,27 +62,27 @@ type RouterDetails struct {
|
|||
*/
|
||||
RouterAddr string `hcl:"address,attr"`
|
||||
|
||||
/*
|
||||
* G'Agent client will use this port to communicate with the routers.
|
||||
*/
|
||||
ClientPort int64 `hcl:"clientport,optional"`
|
||||
|
||||
/*
|
||||
* G'Agent router will use this port to communicate with other routers.
|
||||
*/
|
||||
RouterPort int64 `hcl:"routerport,optional"`
|
||||
|
||||
/*
|
||||
* G'Agent worker will use this port to communicate with the routers.
|
||||
*/
|
||||
WorkerPort int64 `hcl:"workerport,optional"`
|
||||
|
||||
/*
|
||||
* These tags will be passed to the router upon connection. The router
|
||||
* will then use these tags to help determine which worker / client to
|
||||
* send the client's requests and results to.
|
||||
*/
|
||||
RouterTags []string `hcl:"tags,optional"`
|
||||
|
||||
/*
|
||||
* G'Agent client will use this port to communicate with the routers.
|
||||
*/
|
||||
ClientPort int `hcl:"clientport,optional"`
|
||||
|
||||
/*
|
||||
* G'Agent router will use this port to communicate with other routers.
|
||||
*/
|
||||
RouterPort int `hcl:"routerport,optional"`
|
||||
|
||||
/*
|
||||
* G'Agent worker will use this port to communicate with the routers.
|
||||
*/
|
||||
WorkerPort int `hcl:"workerport,optional"`
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -111,8 +111,8 @@ type WorkerDetails struct {
|
|||
|
||||
type AgentDetails struct {
|
||||
Client string `hcl:"client"`
|
||||
Status int64 `hcl:"status"`
|
||||
Shasum string `hcl:"shasum"`
|
||||
Status int `hcl:"status"`
|
||||
Hints []string
|
||||
ScriptCode []byte
|
||||
Answer []byte
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
fmt "fmt"
|
||||
log "log"
|
||||
http "net/http"
|
||||
strconv "strconv"
|
||||
sync "sync"
|
||||
|
||||
gcdb "github.com/dragonheim/gagent/internal/chaindb"
|
||||
|
@ -44,7 +45,7 @@ func Main(wg *sync.WaitGroup, config gstructs.GagentConfig) {
|
|||
|
||||
db.Init()
|
||||
|
||||
workerListener := fmt.Sprintf("tcp://%s:%d", config.ListenAddr, config.WorkerPort)
|
||||
workerListener := "tcp://" + config.ListenAddr + ":" + strconv.Itoa(config.WorkerPort)
|
||||
_ = workerSock.Bind(workerListener)
|
||||
|
||||
workers := make([]string, 0)
|
||||
|
@ -112,7 +113,7 @@ func createClientListener(wg *sync.WaitGroup, config gstructs.GagentConfig) {
|
|||
clientSock, _ := zmq.NewSocket(zmq.ROUTER)
|
||||
defer clientSock.Close()
|
||||
|
||||
clientListener := fmt.Sprintf("tcp://%s:%d", config.ListenAddr, config.ClientPort)
|
||||
clientListener := "tcp://" + config.ListenAddr + ":" + strconv.Itoa(config.ClientPort)
|
||||
log.Printf("[DEBUG] Binding to: %s", clientListener)
|
||||
_ = clientSock.Bind(clientListener)
|
||||
|
||||
|
|
|
@ -24,9 +24,9 @@ func Main(wg *sync.WaitGroup, config gs.GagentConfig) {
|
|||
rootBody.SetAttributeValue("mode", cty.StringVal(config.Mode))
|
||||
rootBody.SetAttributeValue("uuid", cty.StringVal(config.UUID))
|
||||
rootBody.SetAttributeValue("listenaddr", cty.StringVal("0.0.0.0"))
|
||||
rootBody.SetAttributeValue("clientport", cty.NumberIntVal(config.ClientPort))
|
||||
rootBody.SetAttributeValue("routerport", cty.NumberIntVal(config.RouterPort))
|
||||
rootBody.SetAttributeValue("workerport", cty.NumberIntVal(config.WorkerPort))
|
||||
rootBody.SetAttributeValue("clientport", cty.NumberIntVal(int64(config.ClientPort)))
|
||||
rootBody.SetAttributeValue("routerport", cty.NumberIntVal(int64(config.RouterPort)))
|
||||
rootBody.SetAttributeValue("workerport", cty.NumberIntVal(int64(config.WorkerPort)))
|
||||
rootBody.AppendNewline()
|
||||
|
||||
clientBlock1 := rootBody.AppendNewBlock("client", []string{config.Name})
|
||||
|
@ -47,9 +47,9 @@ func Main(wg *sync.WaitGroup, config gs.GagentConfig) {
|
|||
routerBody1 := routerBlock1.Body()
|
||||
routerBody1.SetAttributeValue("routerid", cty.StringVal(config.UUID))
|
||||
routerBody1.SetAttributeValue("address", cty.StringVal("127.0.0.1"))
|
||||
routerBody1.SetAttributeValue("clientport", cty.NumberIntVal(config.ClientPort))
|
||||
routerBody1.SetAttributeValue("routerport", cty.NumberIntVal(config.RouterPort))
|
||||
routerBody1.SetAttributeValue("workerport", cty.NumberIntVal(config.WorkerPort))
|
||||
routerBody1.SetAttributeValue("clientport", cty.NumberIntVal(int64(config.ClientPort)))
|
||||
routerBody1.SetAttributeValue("routerport", cty.NumberIntVal(int64(config.RouterPort)))
|
||||
routerBody1.SetAttributeValue("workerport", cty.NumberIntVal(int64(config.WorkerPort)))
|
||||
rootBody.AppendNewline()
|
||||
|
||||
workerBlock1 := rootBody.AppendNewBlock("worker", []string{config.Name})
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
gstructs "github.com/dragonheim/gagent/internal/gstructs"
|
||||
|
||||
/*
|
||||
* picol "github.com/dragonheim/gagent/src/picol"
|
||||
* picol "github.com/dragonheim/gagent/pkg/picol"
|
||||
*/
|
||||
|
||||
prometheus "github.com/prometheus/client_golang/prometheus"
|
||||
|
@ -43,13 +43,13 @@ func Main(wg *sync.WaitGroup, config gstructs.GagentConfig) {
|
|||
/*
|
||||
* Generate connect string for this router.
|
||||
*/
|
||||
connectString := "tcp://" + config.Routers[key].RouterAddr + ":" + strconv.FormatInt(rport, 10)
|
||||
connectString := "tcp://" + config.Routers[key].RouterAddr + ":" + strconv.Itoa(rport)
|
||||
|
||||
wg.Add(1)
|
||||
go getAgent(wg, config.UUID, connectString)
|
||||
}
|
||||
/*
|
||||
* workerListener := "tcp://" + config.ListenAddr + ":" + strconv.FormatInt(config.WorkerPort, 10)
|
||||
* workerListener := "tcp://" + config.ListenAddr + ":" + strconv.Itoa(config.WorkerPort)
|
||||
*/
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue