2021-02-24 09:58:02 +00:00
|
|
|
package steward
|
|
|
|
|
|
|
|
import (
|
2021-04-07 16:54:08 +00:00
|
|
|
"context"
|
2021-02-24 09:58:02 +00:00
|
|
|
"fmt"
|
2021-03-12 11:08:11 +00:00
|
|
|
"log"
|
2021-08-11 08:11:57 +00:00
|
|
|
"sync"
|
2021-03-09 10:58:50 +00:00
|
|
|
"time"
|
2021-03-04 15:27:55 +00:00
|
|
|
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
2021-02-24 09:58:02 +00:00
|
|
|
)
|
|
|
|
|
2021-08-11 08:11:57 +00:00
|
|
|
// processes holds all the information about running processes
|
|
|
|
type processes struct {
|
2022-06-22 03:03:11 +00:00
|
|
|
// mutex for processes
|
|
|
|
mu sync.Mutex
|
2021-08-11 10:23:37 +00:00
|
|
|
// The main context for subscriber processes.
|
|
|
|
ctx context.Context
|
|
|
|
// cancel func to send cancel signal to the subscriber processes context.
|
|
|
|
cancel context.CancelFunc
|
2021-08-11 08:11:57 +00:00
|
|
|
// The active spawned processes
|
2022-04-01 05:09:55 +00:00
|
|
|
// server
|
|
|
|
server *server
|
2021-10-08 10:07:10 +00:00
|
|
|
active procsMap
|
2021-08-11 08:11:57 +00:00
|
|
|
// mutex to lock the map
|
2021-10-08 20:39:46 +00:00
|
|
|
// mu sync.RWMutex
|
2021-08-11 08:11:57 +00:00
|
|
|
// The last processID created
|
|
|
|
lastProcessID int
|
2021-08-18 10:16:21 +00:00
|
|
|
// The instance global prometheus registry.
|
|
|
|
metrics *metrics
|
2022-02-02 07:54:36 +00:00
|
|
|
// Waitgroup to keep track of all the processes started.
|
2021-08-12 07:21:56 +00:00
|
|
|
wg sync.WaitGroup
|
2022-01-12 06:42:41 +00:00
|
|
|
// tui
|
|
|
|
tui *tui
|
2022-01-19 04:44:20 +00:00
|
|
|
// errorKernel
|
|
|
|
errorKernel *errorKernel
|
2022-02-02 07:54:36 +00:00
|
|
|
// configuration
|
|
|
|
configuration *Configuration
|
|
|
|
|
2022-02-04 09:33:31 +00:00
|
|
|
// Signatures
|
2022-04-21 11:21:36 +00:00
|
|
|
nodeAuth *nodeAuth
|
2021-08-11 08:11:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// newProcesses will prepare and return a *processes which
|
|
|
|
// is map containing all the currently running processes.
|
2022-04-01 05:09:55 +00:00
|
|
|
func newProcesses(ctx context.Context, server *server) *processes {
|
2021-08-11 08:11:57 +00:00
|
|
|
p := processes{
|
2022-04-01 05:09:55 +00:00
|
|
|
server: server,
|
2022-02-02 07:54:36 +00:00
|
|
|
active: *newProcsMap(),
|
2022-04-01 05:09:55 +00:00
|
|
|
tui: server.tui,
|
|
|
|
errorKernel: server.errorKernel,
|
|
|
|
configuration: server.configuration,
|
2022-04-21 11:21:36 +00:00
|
|
|
nodeAuth: server.nodeAuth,
|
2022-04-01 06:51:14 +00:00
|
|
|
metrics: server.metrics,
|
2021-08-11 08:11:57 +00:00
|
|
|
}
|
|
|
|
|
2021-08-16 11:01:12 +00:00
|
|
|
// Prepare the parent context for the subscribers.
|
2021-08-11 10:23:37 +00:00
|
|
|
ctx, cancel := context.WithCancel(ctx)
|
|
|
|
|
2021-10-08 11:42:19 +00:00
|
|
|
// // Start the processes map.
|
|
|
|
// go func() {
|
|
|
|
// p.active.run(ctx)
|
|
|
|
// }()
|
2021-10-08 10:07:10 +00:00
|
|
|
|
2021-08-11 10:23:37 +00:00
|
|
|
p.ctx = ctx
|
|
|
|
p.cancel = cancel
|
|
|
|
|
2021-08-11 08:11:57 +00:00
|
|
|
return &p
|
|
|
|
}
|
|
|
|
|
2021-10-08 06:16:12 +00:00
|
|
|
// ----------------------
|
|
|
|
|
2022-02-02 07:54:36 +00:00
|
|
|
// ----------------------
|
|
|
|
|
2021-10-08 06:16:12 +00:00
|
|
|
type procsMap struct {
|
2021-11-16 18:07:24 +00:00
|
|
|
procNames map[processName]process
|
2021-11-16 09:21:44 +00:00
|
|
|
mu sync.Mutex
|
2021-10-08 06:16:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newProcsMap() *procsMap {
|
|
|
|
cM := procsMap{
|
2021-11-16 18:07:24 +00:00
|
|
|
procNames: make(map[processName]process),
|
2021-10-08 06:16:12 +00:00
|
|
|
}
|
|
|
|
return &cM
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------
|
|
|
|
|
2021-08-11 08:11:57 +00:00
|
|
|
// Start all the subscriber processes.
|
|
|
|
// Takes an initial process as it's input. All processes
|
|
|
|
// will be tied to this single process's context.
|
|
|
|
func (p *processes) Start(proc process) {
|
2021-08-11 10:23:37 +00:00
|
|
|
// Set the context for the initial process.
|
|
|
|
proc.ctx = p.ctx
|
2021-03-26 08:08:47 +00:00
|
|
|
|
|
|
|
// --- Subscriber services that can be started via flags
|
|
|
|
|
2021-09-20 04:40:34 +00:00
|
|
|
{
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("tarting REQOpProcessList subscriber: %#v", proc.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2021-09-20 04:40:34 +00:00
|
|
|
sub := newSubject(REQOpProcessList, string(proc.node))
|
2022-04-01 05:09:55 +00:00
|
|
|
proc := newProcess(proc.ctx, p.server, sub, processKindSubscriber, nil)
|
|
|
|
go proc.spawnWorker()
|
2021-09-20 04:40:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting REQOpProcessStart subscriber: %#v", proc.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2021-09-20 04:40:34 +00:00
|
|
|
sub := newSubject(REQOpProcessStart, string(proc.node))
|
2022-04-01 05:09:55 +00:00
|
|
|
proc := newProcess(proc.ctx, p.server, sub, processKindSubscriber, nil)
|
|
|
|
go proc.spawnWorker()
|
2021-09-20 04:40:34 +00:00
|
|
|
}
|
|
|
|
|
2021-09-20 09:53:17 +00:00
|
|
|
{
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting REQOpProcessStop subscriber: %#v", proc.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2021-09-20 09:53:17 +00:00
|
|
|
sub := newSubject(REQOpProcessStop, string(proc.node))
|
2022-04-01 05:09:55 +00:00
|
|
|
proc := newProcess(proc.ctx, p.server, sub, processKindSubscriber, nil)
|
|
|
|
go proc.spawnWorker()
|
2021-09-20 09:53:17 +00:00
|
|
|
}
|
|
|
|
|
2022-05-22 04:36:02 +00:00
|
|
|
{
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting REQTest subscriber: %#v", proc.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2022-05-22 04:36:02 +00:00
|
|
|
sub := newSubject(REQTest, string(proc.node))
|
|
|
|
proc := newProcess(proc.ctx, p.server, sub, processKindSubscriber, nil)
|
|
|
|
go proc.spawnWorker()
|
|
|
|
}
|
|
|
|
|
2021-09-08 16:56:23 +00:00
|
|
|
if proc.configuration.StartSubREQToFileAppend {
|
2021-08-11 08:11:57 +00:00
|
|
|
proc.startup.subREQToFileAppend(proc)
|
2021-02-24 09:58:02 +00:00
|
|
|
}
|
|
|
|
|
2021-09-08 16:56:23 +00:00
|
|
|
if proc.configuration.StartSubREQToFile {
|
2021-08-11 08:11:57 +00:00
|
|
|
proc.startup.subREQToFile(proc)
|
2021-04-06 17:42:03 +00:00
|
|
|
}
|
|
|
|
|
2022-03-04 14:02:43 +00:00
|
|
|
if proc.configuration.StartSubREQToFileNACK {
|
|
|
|
proc.startup.subREQToFileNACK(proc)
|
|
|
|
}
|
|
|
|
|
2022-06-09 03:59:37 +00:00
|
|
|
if proc.configuration.StartSubREQCopySrc {
|
|
|
|
proc.startup.subREQCopySrc(proc)
|
|
|
|
}
|
|
|
|
|
|
|
|
if proc.configuration.StartSubREQCopyDst {
|
|
|
|
proc.startup.subREQCopyDst(proc)
|
|
|
|
}
|
|
|
|
|
2021-09-08 16:56:23 +00:00
|
|
|
if proc.configuration.StartSubREQHello {
|
2021-08-11 08:11:57 +00:00
|
|
|
proc.startup.subREQHello(proc)
|
2021-02-24 09:58:02 +00:00
|
|
|
}
|
2021-02-24 14:43:31 +00:00
|
|
|
|
2022-06-03 04:02:27 +00:00
|
|
|
if proc.configuration.IsCentralErrorLogger {
|
2021-08-11 08:11:57 +00:00
|
|
|
proc.startup.subREQErrorLog(proc)
|
2021-02-24 14:43:31 +00:00
|
|
|
}
|
2021-03-09 10:58:50 +00:00
|
|
|
|
2021-09-08 16:56:23 +00:00
|
|
|
if proc.configuration.StartSubREQPing {
|
2021-08-11 08:11:57 +00:00
|
|
|
proc.startup.subREQPing(proc)
|
2021-03-26 08:08:47 +00:00
|
|
|
}
|
|
|
|
|
2021-09-08 16:56:23 +00:00
|
|
|
if proc.configuration.StartSubREQPong {
|
2021-08-11 08:11:57 +00:00
|
|
|
proc.startup.subREQPong(proc)
|
2021-03-26 08:08:47 +00:00
|
|
|
}
|
|
|
|
|
2021-09-08 16:56:23 +00:00
|
|
|
if proc.configuration.StartSubREQCliCommand {
|
2021-08-11 08:11:57 +00:00
|
|
|
proc.startup.subREQCliCommand(proc)
|
2021-03-26 08:08:47 +00:00
|
|
|
}
|
|
|
|
|
2021-09-08 16:56:23 +00:00
|
|
|
if proc.configuration.StartSubREQToConsole {
|
2021-08-11 08:11:57 +00:00
|
|
|
proc.startup.subREQToConsole(proc)
|
2021-03-26 08:08:47 +00:00
|
|
|
}
|
|
|
|
|
2022-01-13 07:34:22 +00:00
|
|
|
if proc.configuration.EnableTUI {
|
|
|
|
proc.startup.subREQTuiToConsole(proc)
|
|
|
|
}
|
|
|
|
|
2021-08-11 08:11:57 +00:00
|
|
|
if proc.configuration.StartPubREQHello != 0 {
|
|
|
|
proc.startup.pubREQHello(proc)
|
2021-03-09 10:58:50 +00:00
|
|
|
}
|
2021-04-06 17:42:03 +00:00
|
|
|
|
2022-05-30 05:14:15 +00:00
|
|
|
if proc.configuration.EnableKeyUpdates {
|
2022-05-24 05:21:48 +00:00
|
|
|
proc.startup.pubREQKeysRequestUpdate(proc)
|
2022-05-26 06:07:23 +00:00
|
|
|
proc.startup.subREQKeysDeliverUpdate(proc)
|
|
|
|
}
|
|
|
|
|
2022-05-30 05:14:15 +00:00
|
|
|
if proc.configuration.EnableAclUpdates {
|
2022-05-24 13:51:36 +00:00
|
|
|
proc.startup.pubREQAclRequestUpdate(proc)
|
2022-05-26 05:13:34 +00:00
|
|
|
proc.startup.subREQAclDeliverUpdate(proc)
|
2022-04-07 07:34:06 +00:00
|
|
|
}
|
|
|
|
|
2022-04-07 12:18:28 +00:00
|
|
|
if proc.configuration.IsCentralAuth {
|
2022-05-24 05:21:48 +00:00
|
|
|
proc.startup.subREQKeysRequestUpdate(proc)
|
|
|
|
proc.startup.subREQKeysAllow(proc)
|
2022-06-01 05:29:25 +00:00
|
|
|
proc.startup.subREQKeysDelete(proc)
|
2022-05-24 10:00:38 +00:00
|
|
|
|
|
|
|
proc.startup.subREQAclRequestUpdate(proc)
|
|
|
|
|
2022-05-18 12:43:35 +00:00
|
|
|
proc.startup.subREQAclAddCommand(proc)
|
|
|
|
proc.startup.subREQAclDeleteCommand(proc)
|
2022-05-19 19:35:14 +00:00
|
|
|
proc.startup.subREQAclDeleteSource(proc)
|
2022-05-19 20:19:22 +00:00
|
|
|
proc.startup.subREQAclGroupNodesAddNode(proc)
|
|
|
|
proc.startup.subREQAclGroupNodesDeleteNode(proc)
|
2022-05-20 03:18:26 +00:00
|
|
|
proc.startup.subREQAclGroupNodesDeleteGroup(proc)
|
2022-05-20 03:59:34 +00:00
|
|
|
proc.startup.subREQAclGroupCommandsAddCommand(proc)
|
2022-05-20 04:27:46 +00:00
|
|
|
proc.startup.subREQAclGroupCommandsDeleteCommand(proc)
|
2022-05-20 11:56:17 +00:00
|
|
|
proc.startup.subREQAclGroupCommandsDeleteGroup(proc)
|
2022-05-21 05:09:35 +00:00
|
|
|
proc.startup.subREQAclExport(proc)
|
2022-05-21 05:26:36 +00:00
|
|
|
proc.startup.subREQAclImport(proc)
|
2022-04-07 07:34:06 +00:00
|
|
|
}
|
|
|
|
|
2022-05-26 06:07:23 +00:00
|
|
|
// Moved this together with proc.configuration.StartPubREQKeysRequestUpdate since they belong together.
|
|
|
|
// if proc.configuration.StartSubREQKeysDeliverUpdate {
|
|
|
|
// proc.startup.subREQKeysDeliverUpdate(proc)
|
|
|
|
// }
|
2022-04-07 07:34:06 +00:00
|
|
|
|
2021-09-08 16:56:23 +00:00
|
|
|
if proc.configuration.StartSubREQHttpGet {
|
2021-08-11 08:11:57 +00:00
|
|
|
proc.startup.subREQHttpGet(proc)
|
2021-04-06 17:42:03 +00:00
|
|
|
}
|
2021-04-13 09:28:52 +00:00
|
|
|
|
2022-02-11 06:27:51 +00:00
|
|
|
if proc.configuration.StartSubREQHttpGetScheduled {
|
|
|
|
proc.startup.subREQHttpGetScheduled(proc)
|
|
|
|
}
|
|
|
|
|
2021-09-08 16:56:23 +00:00
|
|
|
if proc.configuration.StartSubREQTailFile {
|
2021-08-11 08:11:57 +00:00
|
|
|
proc.startup.subREQTailFile(proc)
|
2021-04-13 09:28:52 +00:00
|
|
|
}
|
2021-07-01 08:05:34 +00:00
|
|
|
|
2021-09-17 08:17:10 +00:00
|
|
|
if proc.configuration.StartSubREQCliCommandCont {
|
|
|
|
proc.startup.subREQCliCommandCont(proc)
|
2021-08-10 10:49:42 +00:00
|
|
|
}
|
|
|
|
|
2022-02-08 10:49:32 +00:00
|
|
|
proc.startup.subREQPublicKey(proc)
|
2021-02-24 09:58:02 +00:00
|
|
|
}
|
2021-04-08 11:43:47 +00:00
|
|
|
|
2021-08-11 10:23:37 +00:00
|
|
|
// Stop all subscriber processes.
|
|
|
|
func (p *processes) Stop() {
|
2021-08-12 10:27:47 +00:00
|
|
|
log.Printf("info: canceling all subscriber processes...\n")
|
2021-08-11 10:23:37 +00:00
|
|
|
p.cancel()
|
2021-08-12 10:27:47 +00:00
|
|
|
p.wg.Wait()
|
|
|
|
log.Printf("info: done canceling all subscriber processes.\n")
|
|
|
|
|
2021-08-11 10:23:37 +00:00
|
|
|
}
|
|
|
|
|
2021-04-09 09:30:40 +00:00
|
|
|
// ---------------------------------------------------------------------------------------
|
2021-04-08 11:43:47 +00:00
|
|
|
|
2021-08-11 08:11:57 +00:00
|
|
|
// Startup holds all the startup methods for subscribers.
|
2021-08-18 10:16:21 +00:00
|
|
|
type startup struct {
|
2022-04-05 08:35:59 +00:00
|
|
|
server *server
|
|
|
|
centralAuth *centralAuth
|
|
|
|
metrics *metrics
|
2021-08-18 10:16:21 +00:00
|
|
|
}
|
|
|
|
|
2022-04-01 05:09:55 +00:00
|
|
|
func newStartup(server *server) *startup {
|
2022-04-01 07:21:50 +00:00
|
|
|
s := startup{
|
2022-04-05 08:35:59 +00:00
|
|
|
server: server,
|
|
|
|
centralAuth: server.centralAuth,
|
|
|
|
metrics: server.metrics,
|
2022-04-01 07:21:50 +00:00
|
|
|
}
|
2021-08-18 10:16:21 +00:00
|
|
|
|
|
|
|
return &s
|
|
|
|
}
|
2021-04-09 09:30:40 +00:00
|
|
|
|
|
|
|
func (s startup) subREQHttpGet(p process) {
|
|
|
|
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting Http Get subscriber: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2021-04-09 09:30:40 +00:00
|
|
|
sub := newSubject(REQHttpGet, string(p.node))
|
2022-04-01 05:09:55 +00:00
|
|
|
proc := newProcess(p.ctx, p.processes.server, sub, processKindSubscriber, nil)
|
2021-11-09 13:01:42 +00:00
|
|
|
|
2022-04-01 05:09:55 +00:00
|
|
|
go proc.spawnWorker()
|
2021-04-09 09:30:40 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-02-11 06:27:51 +00:00
|
|
|
func (s startup) subREQHttpGetScheduled(p process) {
|
|
|
|
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting Http Get Scheduled subscriber: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2023-01-12 07:48:01 +00:00
|
|
|
|
2022-02-11 06:27:51 +00:00
|
|
|
sub := newSubject(REQHttpGetScheduled, string(p.node))
|
2022-04-01 05:09:55 +00:00
|
|
|
proc := newProcess(p.ctx, p.server, sub, processKindSubscriber, nil)
|
2022-02-11 06:27:51 +00:00
|
|
|
|
2022-04-01 05:09:55 +00:00
|
|
|
go proc.spawnWorker()
|
2022-02-11 06:27:51 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-04-09 09:30:40 +00:00
|
|
|
func (s startup) pubREQHello(p process) {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting Hello Publisher: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2021-04-09 09:30:40 +00:00
|
|
|
|
|
|
|
sub := newSubject(REQHello, p.configuration.CentralNodeName)
|
2022-04-01 05:09:55 +00:00
|
|
|
proc := newProcess(p.ctx, s.server, sub, processKindPublisher, nil)
|
2023-01-13 14:09:23 +00:00
|
|
|
proc.isLongRunningPublisher = true
|
2021-04-09 09:30:40 +00:00
|
|
|
|
|
|
|
// Define the procFunc to be used for the process.
|
2022-03-31 12:57:30 +00:00
|
|
|
proc.procFunc = func(ctx context.Context, procFuncCh chan Message) error {
|
|
|
|
ticker := time.NewTicker(time.Second * time.Duration(p.configuration.StartPubREQHello))
|
2022-12-26 09:52:43 +00:00
|
|
|
defer ticker.Stop()
|
2022-03-31 12:57:30 +00:00
|
|
|
for {
|
|
|
|
|
2022-04-04 08:29:14 +00:00
|
|
|
// d := fmt.Sprintf("Hello from %v\n", p.node)
|
2022-04-19 16:30:00 +00:00
|
|
|
// Send the ed25519 public key used for signing as the payload of the message.
|
2022-04-21 11:21:36 +00:00
|
|
|
d := s.server.nodeAuth.SignPublicKey
|
2022-03-31 12:57:30 +00:00
|
|
|
|
|
|
|
m := Message{
|
|
|
|
FileName: "hello.log",
|
|
|
|
Directory: "hello-messages",
|
|
|
|
ToNode: Node(p.configuration.CentralNodeName),
|
|
|
|
FromNode: Node(p.node),
|
|
|
|
Data: []byte(d),
|
|
|
|
Method: REQHello,
|
2023-01-05 00:55:52 +00:00
|
|
|
ACKTimeout: proc.configuration.DefaultMessageTimeout,
|
2022-03-31 12:57:30 +00:00
|
|
|
Retries: 1,
|
2021-04-09 09:30:40 +00:00
|
|
|
}
|
2022-03-31 12:57:30 +00:00
|
|
|
|
|
|
|
sam, err := newSubjectAndMessage(m)
|
|
|
|
if err != nil {
|
|
|
|
// In theory the system should drop the message before it reaches here.
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("error: ProcessesStart: %v", err)
|
|
|
|
p.errorKernel.errSend(p, m, er, logError)
|
2022-03-31 12:57:30 +00:00
|
|
|
}
|
|
|
|
proc.toRingbufferCh <- []subjectAndMessage{sam}
|
|
|
|
|
|
|
|
select {
|
|
|
|
case <-ticker.C:
|
|
|
|
case <-ctx.Done():
|
|
|
|
er := fmt.Errorf("info: stopped handleFunc for: publisher %v", proc.subject.name())
|
|
|
|
// sendErrorLogMessage(proc.toRingbufferCh, proc.node, er)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2022-03-31 12:57:30 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-04-01 05:09:55 +00:00
|
|
|
go proc.spawnWorker()
|
2021-04-09 09:30:40 +00:00
|
|
|
}
|
|
|
|
|
2022-05-24 05:21:48 +00:00
|
|
|
// pubREQKeysRequestUpdate defines the startup of a publisher that will send REQREQKeysRequestUpdate
|
2022-04-07 07:34:06 +00:00
|
|
|
// to central server and ask for publics keys, and to get them deliver back with a request
|
2022-05-24 05:21:48 +00:00
|
|
|
// of type pubREQKeysDeliverUpdate.
|
|
|
|
func (s startup) pubREQKeysRequestUpdate(p process) {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting PublicKeysGet Publisher: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2022-04-07 07:34:06 +00:00
|
|
|
|
2022-05-24 05:21:48 +00:00
|
|
|
sub := newSubject(REQKeysRequestUpdate, p.configuration.CentralNodeName)
|
2022-04-07 07:34:06 +00:00
|
|
|
proc := newProcess(p.ctx, s.server, sub, processKindPublisher, nil)
|
2023-01-13 14:09:23 +00:00
|
|
|
proc.isLongRunningPublisher = true
|
2022-04-07 07:34:06 +00:00
|
|
|
|
|
|
|
// Define the procFunc to be used for the process.
|
|
|
|
proc.procFunc = func(ctx context.Context, procFuncCh chan Message) error {
|
2022-05-26 06:07:23 +00:00
|
|
|
ticker := time.NewTicker(time.Second * time.Duration(p.configuration.REQKeysRequestUpdateInterval))
|
2022-12-26 09:52:43 +00:00
|
|
|
defer ticker.Stop()
|
2022-04-07 07:34:06 +00:00
|
|
|
for {
|
|
|
|
|
2022-06-22 12:32:58 +00:00
|
|
|
// Send a message with the hash of the currently stored keys,
|
2022-05-11 11:45:49 +00:00
|
|
|
// so we would know on the subscriber at central if it should send
|
|
|
|
// and update with new keys back.
|
|
|
|
|
2022-05-16 05:15:38 +00:00
|
|
|
proc.nodeAuth.publicKeys.mu.Lock()
|
2022-06-22 05:31:43 +00:00
|
|
|
er := fmt.Errorf(" ----> publisher REQKeysRequestUpdate: sending our current hash: %v", []byte(proc.nodeAuth.publicKeys.keysAndHash.Hash[:]))
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2022-05-16 05:15:38 +00:00
|
|
|
|
2022-04-07 07:34:06 +00:00
|
|
|
m := Message{
|
2022-05-16 05:15:38 +00:00
|
|
|
FileName: "publickeysget.log",
|
|
|
|
Directory: "publickeysget",
|
|
|
|
ToNode: Node(p.configuration.CentralNodeName),
|
|
|
|
FromNode: Node(p.node),
|
|
|
|
Data: []byte(proc.nodeAuth.publicKeys.keysAndHash.Hash[:]),
|
2022-05-24 05:21:48 +00:00
|
|
|
Method: REQKeysRequestUpdate,
|
|
|
|
ReplyMethod: REQKeysDeliverUpdate,
|
2022-04-07 07:34:06 +00:00
|
|
|
ACKTimeout: proc.configuration.DefaultMessageTimeout,
|
|
|
|
Retries: 1,
|
|
|
|
}
|
2022-05-16 05:15:38 +00:00
|
|
|
proc.nodeAuth.publicKeys.mu.Unlock()
|
2022-04-07 07:34:06 +00:00
|
|
|
|
|
|
|
sam, err := newSubjectAndMessage(m)
|
|
|
|
if err != nil {
|
|
|
|
// In theory the system should drop the message before it reaches here.
|
2023-01-11 07:38:15 +00:00
|
|
|
p.errorKernel.errSend(p, m, err, logError)
|
2022-05-24 13:51:36 +00:00
|
|
|
}
|
|
|
|
proc.toRingbufferCh <- []subjectAndMessage{sam}
|
|
|
|
|
|
|
|
select {
|
|
|
|
case <-ticker.C:
|
|
|
|
case <-ctx.Done():
|
|
|
|
er := fmt.Errorf("info: stopped handleFunc for: publisher %v", proc.subject.name())
|
|
|
|
// sendErrorLogMessage(proc.toRingbufferCh, proc.node, er)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2022-05-24 13:51:36 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
go proc.spawnWorker()
|
|
|
|
}
|
|
|
|
|
|
|
|
// pubREQAclRequestUpdate defines the startup of a publisher that will send REQREQKeysRequestUpdate
|
|
|
|
// to central server and ask for publics keys, and to get them deliver back with a request
|
|
|
|
// of type pubREQKeysDeliverUpdate.
|
|
|
|
func (s startup) pubREQAclRequestUpdate(p process) {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting REQAclRequestUpdate Publisher: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2022-05-24 13:51:36 +00:00
|
|
|
|
|
|
|
sub := newSubject(REQAclRequestUpdate, p.configuration.CentralNodeName)
|
|
|
|
proc := newProcess(p.ctx, s.server, sub, processKindPublisher, nil)
|
2023-01-13 14:09:23 +00:00
|
|
|
proc.isLongRunningPublisher = true
|
2022-05-24 13:51:36 +00:00
|
|
|
|
|
|
|
// Define the procFunc to be used for the process.
|
|
|
|
proc.procFunc = func(ctx context.Context, procFuncCh chan Message) error {
|
2022-05-26 06:07:23 +00:00
|
|
|
ticker := time.NewTicker(time.Second * time.Duration(p.configuration.REQAclRequestUpdateInterval))
|
2022-12-26 09:52:43 +00:00
|
|
|
defer ticker.Stop()
|
2022-05-24 13:51:36 +00:00
|
|
|
for {
|
|
|
|
|
2022-06-22 12:32:58 +00:00
|
|
|
// Send a message with the hash of the currently stored acl's,
|
|
|
|
// so we would know for the subscriber at central if it should send
|
2022-05-24 13:51:36 +00:00
|
|
|
// and update with new keys back.
|
|
|
|
|
|
|
|
proc.nodeAuth.nodeAcl.mu.Lock()
|
2022-06-22 05:31:43 +00:00
|
|
|
er := fmt.Errorf(" ----> publisher REQAclRequestUpdate: sending our current hash: %v", []byte(proc.nodeAuth.nodeAcl.aclAndHash.Hash[:]))
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2022-05-24 13:51:36 +00:00
|
|
|
|
|
|
|
m := Message{
|
|
|
|
FileName: "aclRequestUpdate.log",
|
|
|
|
Directory: "aclRequestUpdate",
|
|
|
|
ToNode: Node(p.configuration.CentralNodeName),
|
|
|
|
FromNode: Node(p.node),
|
|
|
|
Data: []byte(proc.nodeAuth.nodeAcl.aclAndHash.Hash[:]),
|
|
|
|
Method: REQAclRequestUpdate,
|
|
|
|
ReplyMethod: REQAclDeliverUpdate,
|
|
|
|
ACKTimeout: proc.configuration.DefaultMessageTimeout,
|
|
|
|
Retries: 1,
|
|
|
|
}
|
|
|
|
proc.nodeAuth.nodeAcl.mu.Unlock()
|
|
|
|
|
|
|
|
sam, err := newSubjectAndMessage(m)
|
|
|
|
if err != nil {
|
|
|
|
// In theory the system should drop the message before it reaches here.
|
2023-01-11 07:38:15 +00:00
|
|
|
p.errorKernel.errSend(p, m, err, logError)
|
2022-04-07 07:34:06 +00:00
|
|
|
log.Printf("error: ProcessesStart: %v\n", err)
|
|
|
|
}
|
|
|
|
proc.toRingbufferCh <- []subjectAndMessage{sam}
|
|
|
|
|
|
|
|
select {
|
|
|
|
case <-ticker.C:
|
|
|
|
case <-ctx.Done():
|
|
|
|
er := fmt.Errorf("info: stopped handleFunc for: publisher %v", proc.subject.name())
|
|
|
|
// sendErrorLogMessage(proc.toRingbufferCh, proc.node, er)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2022-04-07 07:34:06 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
go proc.spawnWorker()
|
|
|
|
}
|
|
|
|
|
2022-05-24 05:21:48 +00:00
|
|
|
func (s startup) subREQKeysRequestUpdate(p process) {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting Public keys request update subscriber: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2022-05-24 05:21:48 +00:00
|
|
|
sub := newSubject(REQKeysRequestUpdate, string(p.node))
|
2022-04-07 07:34:06 +00:00
|
|
|
proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil)
|
|
|
|
go proc.spawnWorker()
|
|
|
|
}
|
|
|
|
|
2022-05-24 10:00:38 +00:00
|
|
|
func (s startup) subREQKeysDeliverUpdate(p process) {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting Public keys to Node subscriber: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2022-05-24 10:00:38 +00:00
|
|
|
sub := newSubject(REQKeysDeliverUpdate, string(p.node))
|
|
|
|
proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil)
|
|
|
|
go proc.spawnWorker()
|
|
|
|
}
|
|
|
|
|
2022-05-24 05:21:48 +00:00
|
|
|
func (s startup) subREQKeysAllow(p process) {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting Public keys allow subscriber: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2022-05-24 05:21:48 +00:00
|
|
|
sub := newSubject(REQKeysAllow, string(p.node))
|
2022-04-20 16:33:52 +00:00
|
|
|
proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil)
|
|
|
|
go proc.spawnWorker()
|
|
|
|
}
|
|
|
|
|
2022-06-01 05:29:25 +00:00
|
|
|
func (s startup) subREQKeysDelete(p process) {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting Public keys delete subscriber: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2022-06-01 05:29:25 +00:00
|
|
|
sub := newSubject(REQKeysDelete, string(p.node))
|
|
|
|
proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil)
|
|
|
|
go proc.spawnWorker()
|
|
|
|
}
|
|
|
|
|
2022-05-24 10:00:38 +00:00
|
|
|
func (s startup) subREQAclRequestUpdate(p process) {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting Acl Request update subscriber: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2022-05-24 10:00:38 +00:00
|
|
|
sub := newSubject(REQAclRequestUpdate, string(p.node))
|
2022-04-07 07:34:06 +00:00
|
|
|
proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil)
|
|
|
|
go proc.spawnWorker()
|
|
|
|
}
|
|
|
|
|
2022-05-26 05:13:34 +00:00
|
|
|
func (s startup) subREQAclDeliverUpdate(p process) {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting Acl deliver update subscriber: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2022-05-26 05:13:34 +00:00
|
|
|
sub := newSubject(REQAclDeliverUpdate, string(p.node))
|
|
|
|
proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil)
|
|
|
|
go proc.spawnWorker()
|
|
|
|
}
|
|
|
|
|
2022-05-24 10:00:38 +00:00
|
|
|
// HERE!
|
|
|
|
|
2022-05-18 12:43:35 +00:00
|
|
|
func (s startup) subREQAclAddCommand(p process) {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting Acl Add Command subscriber: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2022-05-18 12:43:35 +00:00
|
|
|
sub := newSubject(REQAclAddCommand, string(p.node))
|
|
|
|
proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil)
|
|
|
|
go proc.spawnWorker()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s startup) subREQAclDeleteCommand(p process) {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting Acl Delete Command subscriber: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2022-05-18 12:43:35 +00:00
|
|
|
sub := newSubject(REQAclDeleteCommand, string(p.node))
|
2022-05-18 09:26:06 +00:00
|
|
|
proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil)
|
|
|
|
go proc.spawnWorker()
|
|
|
|
}
|
|
|
|
|
2022-05-19 19:35:14 +00:00
|
|
|
func (s startup) subREQAclDeleteSource(p process) {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting Acl Delete Source subscriber: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2022-05-19 19:35:14 +00:00
|
|
|
sub := newSubject(REQAclDeleteSource, string(p.node))
|
|
|
|
proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil)
|
|
|
|
go proc.spawnWorker()
|
|
|
|
}
|
|
|
|
|
2022-05-19 20:19:22 +00:00
|
|
|
func (s startup) subREQAclGroupNodesAddNode(p process) {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting Acl Add node to nodeGroup subscriber: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2022-05-19 20:19:22 +00:00
|
|
|
sub := newSubject(REQAclGroupNodesAddNode, string(p.node))
|
|
|
|
proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil)
|
|
|
|
go proc.spawnWorker()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s startup) subREQAclGroupNodesDeleteNode(p process) {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting Acl Delete node from nodeGroup subscriber: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2022-05-19 20:19:22 +00:00
|
|
|
sub := newSubject(REQAclGroupNodesDeleteNode, string(p.node))
|
|
|
|
proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil)
|
|
|
|
go proc.spawnWorker()
|
|
|
|
}
|
|
|
|
|
2022-05-20 03:18:26 +00:00
|
|
|
func (s startup) subREQAclGroupNodesDeleteGroup(p process) {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting Acl Delete nodeGroup subscriber: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2022-05-20 03:18:26 +00:00
|
|
|
sub := newSubject(REQAclGroupNodesDeleteGroup, string(p.node))
|
|
|
|
proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil)
|
|
|
|
go proc.spawnWorker()
|
|
|
|
}
|
|
|
|
|
2022-05-20 03:59:34 +00:00
|
|
|
func (s startup) subREQAclGroupCommandsAddCommand(p process) {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting Acl add command to command group subscriber: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2022-05-20 03:59:34 +00:00
|
|
|
sub := newSubject(REQAclGroupCommandsAddCommand, string(p.node))
|
|
|
|
proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil)
|
|
|
|
go proc.spawnWorker()
|
|
|
|
}
|
|
|
|
|
2022-05-20 04:27:46 +00:00
|
|
|
func (s startup) subREQAclGroupCommandsDeleteCommand(p process) {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting Acl delete command from command group subscriber: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2022-05-20 04:27:46 +00:00
|
|
|
sub := newSubject(REQAclGroupCommandsDeleteCommand, string(p.node))
|
|
|
|
proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil)
|
|
|
|
go proc.spawnWorker()
|
|
|
|
}
|
|
|
|
|
2022-05-20 11:56:17 +00:00
|
|
|
func (s startup) subREQAclGroupCommandsDeleteGroup(p process) {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting Acl delete command group subscriber: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2022-05-20 11:56:17 +00:00
|
|
|
sub := newSubject(REQAclGroupCommandsDeleteGroup, string(p.node))
|
|
|
|
proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil)
|
|
|
|
go proc.spawnWorker()
|
|
|
|
}
|
|
|
|
|
2022-05-21 05:09:35 +00:00
|
|
|
func (s startup) subREQAclExport(p process) {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting Acl export subscriber: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2022-05-21 05:09:35 +00:00
|
|
|
sub := newSubject(REQAclExport, string(p.node))
|
|
|
|
proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil)
|
|
|
|
go proc.spawnWorker()
|
|
|
|
}
|
|
|
|
|
2022-05-21 05:26:36 +00:00
|
|
|
func (s startup) subREQAclImport(p process) {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting Acl import subscriber: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2022-05-21 05:26:36 +00:00
|
|
|
sub := newSubject(REQAclImport, string(p.node))
|
|
|
|
proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil)
|
|
|
|
go proc.spawnWorker()
|
|
|
|
}
|
|
|
|
|
2021-04-13 15:22:25 +00:00
|
|
|
func (s startup) subREQToConsole(p process) {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting Text To Console subscriber: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2021-04-13 15:22:25 +00:00
|
|
|
sub := newSubject(REQToConsole, string(p.node))
|
2022-04-01 05:09:55 +00:00
|
|
|
proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil)
|
|
|
|
go proc.spawnWorker()
|
2022-01-13 07:34:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s startup) subREQTuiToConsole(p process) {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting Tui To Console subscriber: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2022-01-13 07:34:22 +00:00
|
|
|
sub := newSubject(REQTuiToConsole, string(p.node))
|
2022-04-01 05:09:55 +00:00
|
|
|
proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil)
|
|
|
|
go proc.spawnWorker()
|
2021-04-09 09:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s startup) subREQCliCommand(p process) {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting CLICommand Request subscriber: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2021-04-09 09:30:40 +00:00
|
|
|
sub := newSubject(REQCliCommand, string(p.node))
|
2022-04-01 05:09:55 +00:00
|
|
|
proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil)
|
|
|
|
go proc.spawnWorker()
|
2021-04-09 09:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s startup) subREQPong(p process) {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting Pong subscriber: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2021-04-09 09:30:40 +00:00
|
|
|
sub := newSubject(REQPong, string(p.node))
|
2022-04-01 05:09:55 +00:00
|
|
|
proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil)
|
|
|
|
go proc.spawnWorker()
|
2021-04-09 09:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s startup) subREQPing(p process) {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting Ping Request subscriber: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2021-04-09 09:30:40 +00:00
|
|
|
sub := newSubject(REQPing, string(p.node))
|
2022-04-01 05:09:55 +00:00
|
|
|
proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil)
|
|
|
|
go proc.spawnWorker()
|
2021-04-09 09:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s startup) subREQErrorLog(p process) {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting REQErrorLog subscriber: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2021-04-09 09:30:40 +00:00
|
|
|
sub := newSubject(REQErrorLog, "errorCentral")
|
2022-04-01 05:09:55 +00:00
|
|
|
proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil)
|
|
|
|
go proc.spawnWorker()
|
2021-04-09 09:30:40 +00:00
|
|
|
}
|
|
|
|
|
2022-01-01 09:13:35 +00:00
|
|
|
// subREQHello is the handler that is triggered when we are receiving a hello
|
|
|
|
// message. To keep the state of all the hello's received from nodes we need
|
|
|
|
// to also start a procFunc that will live as a go routine tied to this process,
|
|
|
|
// where the procFunc will receive messages from the handler when a message is
|
|
|
|
// received, the handler will deliver the message to the procFunc on the
|
|
|
|
// proc.procFuncCh, and we can then read that message from the procFuncCh in
|
|
|
|
// the procFunc running.
|
2021-04-09 09:30:40 +00:00
|
|
|
func (s startup) subREQHello(p process) {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting Hello subscriber: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2021-04-09 09:30:40 +00:00
|
|
|
sub := newSubject(REQHello, string(p.node))
|
2022-04-01 05:09:55 +00:00
|
|
|
proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil)
|
2021-04-09 09:30:40 +00:00
|
|
|
|
|
|
|
// The reason for running the say hello subscriber as a procFunc is that
|
|
|
|
// a handler are not able to hold state, and we need to hold the state
|
|
|
|
// of the nodes we've received hello's from in the sayHelloNodes map,
|
|
|
|
// which is the information we pass along to generate metrics.
|
2022-03-31 12:57:30 +00:00
|
|
|
proc.procFunc = func(ctx context.Context, procFuncCh chan Message) error {
|
2022-04-04 08:29:14 +00:00
|
|
|
// sayHelloNodes := make(map[Node]struct{})
|
2022-03-31 12:57:30 +00:00
|
|
|
|
|
|
|
for {
|
|
|
|
// Receive a copy of the message sent from the method handler.
|
|
|
|
var m Message
|
|
|
|
|
|
|
|
select {
|
|
|
|
case m = <-procFuncCh:
|
|
|
|
case <-ctx.Done():
|
|
|
|
er := fmt.Errorf("info: stopped handleFunc for: subscriber %v", proc.subject.name())
|
|
|
|
// sendErrorLogMessage(proc.toRingbufferCh, proc.node, er)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2022-03-31 12:57:30 +00:00
|
|
|
return nil
|
2022-03-31 12:54:39 +00:00
|
|
|
}
|
2022-03-31 12:57:30 +00:00
|
|
|
|
2022-06-01 13:11:23 +00:00
|
|
|
s.centralAuth.addPublicKey(proc, m)
|
2022-03-31 12:57:30 +00:00
|
|
|
|
|
|
|
// update the prometheus metrics
|
2022-04-20 16:33:52 +00:00
|
|
|
|
2022-05-16 05:15:38 +00:00
|
|
|
s.server.centralAuth.pki.nodesAcked.mu.Lock()
|
|
|
|
mapLen := len(s.server.centralAuth.pki.nodesAcked.keysAndHash.Keys)
|
|
|
|
s.server.centralAuth.pki.nodesAcked.mu.Unlock()
|
2022-04-20 16:33:52 +00:00
|
|
|
s.metrics.promHelloNodesTotal.Set(float64(mapLen))
|
2022-04-01 07:21:50 +00:00
|
|
|
s.metrics.promHelloNodesContactLast.With(prometheus.Labels{"nodeName": string(m.FromNode)}).SetToCurrentTime()
|
2022-03-31 12:57:30 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2022-04-01 05:09:55 +00:00
|
|
|
go proc.spawnWorker()
|
2021-04-09 09:30:40 +00:00
|
|
|
}
|
|
|
|
|
2021-04-13 15:15:13 +00:00
|
|
|
func (s startup) subREQToFile(p process) {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting text to file subscriber: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2021-04-13 15:15:13 +00:00
|
|
|
sub := newSubject(REQToFile, string(p.node))
|
2022-04-01 05:09:55 +00:00
|
|
|
proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil)
|
2021-11-09 13:01:42 +00:00
|
|
|
|
2022-04-01 05:09:55 +00:00
|
|
|
go proc.spawnWorker()
|
2021-04-09 09:30:40 +00:00
|
|
|
}
|
|
|
|
|
2022-03-04 14:02:43 +00:00
|
|
|
func (s startup) subREQToFileNACK(p process) {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting text to file subscriber: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2022-03-04 14:02:43 +00:00
|
|
|
sub := newSubject(REQToFileNACK, string(p.node))
|
2022-04-01 05:09:55 +00:00
|
|
|
proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil)
|
2022-03-04 14:02:43 +00:00
|
|
|
|
2022-04-01 05:09:55 +00:00
|
|
|
go proc.spawnWorker()
|
2022-03-04 14:02:43 +00:00
|
|
|
}
|
|
|
|
|
2022-06-09 03:59:37 +00:00
|
|
|
func (s startup) subREQCopySrc(p process) {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting copy src subscriber: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2022-06-09 03:59:37 +00:00
|
|
|
sub := newSubject(REQCopySrc, string(p.node))
|
|
|
|
proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil)
|
|
|
|
|
|
|
|
go proc.spawnWorker()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s startup) subREQCopyDst(p process) {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting copy dst subscriber: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2022-06-09 03:59:37 +00:00
|
|
|
sub := newSubject(REQCopyDst, string(p.node))
|
|
|
|
proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil)
|
|
|
|
|
|
|
|
go proc.spawnWorker()
|
|
|
|
}
|
|
|
|
|
2021-04-13 13:54:04 +00:00
|
|
|
func (s startup) subREQToFileAppend(p process) {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting text logging subscriber: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2021-04-13 13:54:04 +00:00
|
|
|
sub := newSubject(REQToFileAppend, string(p.node))
|
2022-04-01 05:09:55 +00:00
|
|
|
proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil)
|
2021-11-09 13:01:42 +00:00
|
|
|
|
2022-04-01 05:09:55 +00:00
|
|
|
go proc.spawnWorker()
|
2021-04-08 11:43:47 +00:00
|
|
|
}
|
2021-04-13 09:28:52 +00:00
|
|
|
|
|
|
|
func (s startup) subREQTailFile(p process) {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting tail log files subscriber: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2021-04-13 09:28:52 +00:00
|
|
|
sub := newSubject(REQTailFile, string(p.node))
|
2022-04-01 05:09:55 +00:00
|
|
|
proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil)
|
2021-11-09 13:01:42 +00:00
|
|
|
|
2022-04-01 05:09:55 +00:00
|
|
|
go proc.spawnWorker()
|
2021-04-13 09:28:52 +00:00
|
|
|
}
|
2021-07-01 08:05:34 +00:00
|
|
|
|
2021-09-17 08:17:10 +00:00
|
|
|
func (s startup) subREQCliCommandCont(p process) {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting cli command with continous delivery: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2021-09-17 08:17:10 +00:00
|
|
|
sub := newSubject(REQCliCommandCont, string(p.node))
|
2022-04-01 05:09:55 +00:00
|
|
|
proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil)
|
2021-11-10 10:21:38 +00:00
|
|
|
|
2022-04-01 05:09:55 +00:00
|
|
|
go proc.spawnWorker()
|
2021-11-10 10:21:38 +00:00
|
|
|
}
|
|
|
|
|
2022-02-08 10:49:32 +00:00
|
|
|
func (s startup) subREQPublicKey(p process) {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("starting get Public Key subscriber: %#v", p.node)
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2022-02-08 10:49:32 +00:00
|
|
|
sub := newSubject(REQPublicKey, string(p.node))
|
2022-04-01 05:09:55 +00:00
|
|
|
proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil)
|
2022-02-08 10:49:32 +00:00
|
|
|
|
2022-04-01 05:09:55 +00:00
|
|
|
go proc.spawnWorker()
|
2022-02-08 10:49:32 +00:00
|
|
|
}
|
|
|
|
|
2021-08-11 10:23:37 +00:00
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
|
|
|
// Print the content of the processes map.
|
|
|
|
func (p *processes) printProcessesMap() {
|
2023-01-12 07:48:01 +00:00
|
|
|
er := fmt.Errorf("output of processes map : ")
|
2023-01-12 11:03:10 +00:00
|
|
|
p.errorKernel.logDebug(er, p.configuration)
|
2021-10-08 10:07:10 +00:00
|
|
|
|
2021-11-16 09:21:44 +00:00
|
|
|
{
|
|
|
|
p.active.mu.Lock()
|
2021-10-08 10:07:10 +00:00
|
|
|
|
2021-11-16 18:07:24 +00:00
|
|
|
for pName, proc := range p.active.procNames {
|
2022-10-05 07:16:22 +00:00
|
|
|
er := fmt.Errorf("info: proc - pub/sub: %v, procName in map: %v , id: %v, subject: %v", proc.processKind, pName, proc.processID, proc.subject.name())
|
2023-01-12 11:03:10 +00:00
|
|
|
proc.errorKernel.logDebug(er, proc.configuration)
|
2021-08-11 10:23:37 +00:00
|
|
|
}
|
|
|
|
|
2022-04-01 07:21:50 +00:00
|
|
|
p.metrics.promProcessesTotal.Set(float64(len(p.active.procNames)))
|
2021-11-16 09:21:44 +00:00
|
|
|
|
|
|
|
p.active.mu.Unlock()
|
|
|
|
}
|
2021-08-11 10:23:37 +00:00
|
|
|
|
|
|
|
}
|