mirror of
https://github.com/dragonheim/gagent.git
synced 2025-04-25 22:48:59 -07:00
Adding support for a blockchain DB for agent history.
This commit is contained in:
parent
0d0695d195
commit
5e69931ed7
7 changed files with 199 additions and 147 deletions
|
@ -23,7 +23,9 @@ func Main(wg *sync.WaitGroup, config gs.GagentConfig, agent string) {
|
|||
log.Printf("[INFO] Starting client\n")
|
||||
|
||||
for key := range config.Routers {
|
||||
// Generate connect string for this router.
|
||||
/*
|
||||
* Generate connect string for this router.
|
||||
*/
|
||||
rport := config.ClientPort
|
||||
if config.Routers[key].ClientPort != 0 {
|
||||
rport = config.Routers[key].ClientPort
|
||||
|
|
|
@ -17,13 +17,9 @@ type GagentConfig struct {
|
|||
CMode bool
|
||||
}
|
||||
|
||||
type Agent struct {
|
||||
Client string
|
||||
ScriptCode []byte
|
||||
Hints []*string
|
||||
}
|
||||
|
||||
// ClientDetails is details about known clients
|
||||
/*
|
||||
* ClientDetails are details about known clients
|
||||
*/
|
||||
type ClientDetails struct {
|
||||
/*
|
||||
* Client name for display purposes in logs and
|
||||
|
@ -40,7 +36,9 @@ type ClientDetails struct {
|
|||
ClientID string `hcl:"clientid,optional"`
|
||||
}
|
||||
|
||||
// RouterDetails is details about known routers
|
||||
/*
|
||||
* RouterDetails is details about known routers
|
||||
*/
|
||||
type RouterDetails struct {
|
||||
/*
|
||||
* Router name for display purposes in logs and
|
||||
|
@ -93,7 +91,9 @@ type RouterDetails struct {
|
|||
RouterTags []string `hcl:"tags,optional"`
|
||||
}
|
||||
|
||||
// WorkerDetails is details about known workers
|
||||
/*
|
||||
* WorkerDetails is details about known workers
|
||||
*/
|
||||
type WorkerDetails struct {
|
||||
/*
|
||||
* Router name for display purposes in logs and
|
||||
|
@ -117,3 +117,15 @@ type WorkerDetails struct {
|
|||
*/
|
||||
WorkerTags []string `hcl:"tags,optional"`
|
||||
}
|
||||
|
||||
type BlockChainDB struct {
|
||||
DBName string `hcl:"chain_id,optional"`
|
||||
Agents []*AgentDetails `hcl:"agent,block"`
|
||||
}
|
||||
type AgentDetails struct {
|
||||
ScriptCode []byte
|
||||
Hints []*string
|
||||
Client string `hcl:"client"`
|
||||
Shasum string `hcl:"shasum"`
|
||||
Status string `hcl:"status"`
|
||||
}
|
||||
|
|
|
@ -52,7 +52,9 @@ func Main(wg *sync.WaitGroup, config gs.GagentConfig) {
|
|||
|
||||
LOOP:
|
||||
for {
|
||||
// Poll frontend only if we have available workers
|
||||
/*
|
||||
* Poll frontend only if we have available workers
|
||||
*/
|
||||
var sockets []zmq.Polled
|
||||
var err error
|
||||
if len(workers) > 0 {
|
||||
|
@ -61,16 +63,23 @@ LOOP:
|
|||
sockets, err = poller1.Poll(-1)
|
||||
}
|
||||
if err != nil {
|
||||
break // Interrupted
|
||||
/*
|
||||
* Interrupt
|
||||
*/
|
||||
break
|
||||
}
|
||||
for _, socket := range sockets {
|
||||
switch s := socket.Socket; s {
|
||||
case workerSock:
|
||||
// Handle worker activity on backend
|
||||
// Use worker identity for load-balancing
|
||||
/*
|
||||
* Handle worker activity on backend
|
||||
* Use worker identity for load-balancing
|
||||
*/
|
||||
msg, err := s.RecvMessage(0)
|
||||
if err != nil {
|
||||
// Interrupted
|
||||
/*
|
||||
* Interrupt
|
||||
*/
|
||||
break LOOP
|
||||
}
|
||||
var identity string
|
||||
|
@ -79,7 +88,9 @@ LOOP:
|
|||
workers = append(workers, identity)
|
||||
|
||||
case clientSock:
|
||||
// Get client request, route to first available worker
|
||||
/*
|
||||
* Get client request, route to first available worker
|
||||
*/
|
||||
msg, err := s.RecvMessage(0)
|
||||
log.Printf("[DEBUG] Client message received: %s", msg)
|
||||
if err == nil {
|
||||
|
@ -109,20 +120,32 @@ func answerClient(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
// Common code for all requests can go here...
|
||||
|
||||
/*
|
||||
* Common code for all requests can go here...
|
||||
*/
|
||||
switch r.Method {
|
||||
/*
|
||||
* Handle GET requests
|
||||
*/
|
||||
case http.MethodGet:
|
||||
fmt.Fprintf(w, "%v\n", r)
|
||||
// Handle the GET request...
|
||||
|
||||
/*
|
||||
* Handle POST requests
|
||||
*/
|
||||
case http.MethodPost:
|
||||
// Handle the POST request...
|
||||
fmt.Fprintf(w, "%v\n", r)
|
||||
|
||||
/*
|
||||
* Handle PUT requests
|
||||
*/
|
||||
case http.MethodOptions:
|
||||
w.Header().Set("Allow", "GET, POST, OPTIONS")
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
|
||||
/*
|
||||
* Handle everything else
|
||||
*/
|
||||
default:
|
||||
w.Header().Set("Allow", "GET, POST, OPTIONS")
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
|
|
|
@ -37,7 +37,9 @@ func Main(wg *sync.WaitGroup, config gs.GagentConfig) {
|
|||
rport = config.Routers[key].WorkerPort
|
||||
}
|
||||
|
||||
// Generate connect string for this router.
|
||||
/*
|
||||
* Generate connect string for this router.
|
||||
*/
|
||||
connectString := fmt.Sprintf("tcp://%s:%d", config.Routers[key].RouterAddr, rport)
|
||||
|
||||
wg.Add(1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue