1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2025-01-05 20:09:16 +00:00

Renamed REQPublicKeysPut to REQPublicKeysToNode

This commit is contained in:
postmannen 2022-04-20 06:26:01 +02:00
parent 81c8610ff1
commit 102cfd43c9
4 changed files with 24 additions and 22 deletions

View file

@ -13,6 +13,8 @@ import (
type signatureBase32 string type signatureBase32 string
type argsString string type argsString string
// centralAuth holds the logic related to handling public keys and auth maps.
type centralAuth struct { type centralAuth struct {
// schema map[Node]map[argsString]signatureBase32 // schema map[Node]map[argsString]signatureBase32
nodePublicKeys *nodePublicKeys nodePublicKeys *nodePublicKeys
@ -22,6 +24,7 @@ type centralAuth struct {
errorKernel *errorKernel errorKernel *errorKernel
} }
// newCentralAuth will return a prepared *centralAuth with input values set.
func newCentralAuth(configuration *Configuration, errorKernel *errorKernel) *centralAuth { func newCentralAuth(configuration *Configuration, errorKernel *errorKernel) *centralAuth {
c := centralAuth{ c := centralAuth{
// schema: make(map[Node]map[argsString]signatureBase32), // schema: make(map[Node]map[argsString]signatureBase32),
@ -60,7 +63,6 @@ func newCentralAuth(configuration *Configuration, errorKernel *errorKernel) *cen
} }
// addPublicKey to the db if the node do not exist, or if it is a new value. // addPublicKey to the db if the node do not exist, or if it is a new value.
// We should return an error if the key have changed.
func (c *centralAuth) addPublicKey(proc process, msg Message) { func (c *centralAuth) addPublicKey(proc process, msg Message) {
c.nodePublicKeys.mu.Lock() c.nodePublicKeys.mu.Lock()
@ -94,7 +96,7 @@ func (c *centralAuth) addPublicKey(proc process, msg Message) {
//c.dbDump(c.bucketPublicKeys) //c.dbDump(c.bucketPublicKeys)
} }
// dbView will look up and return a specific value if it exists for a key in a bucket in a DB. // dbGetPublicKey will look up and return a specific value if it exists for a key in a bucket in a DB.
func (c *centralAuth) dbGetPublicKey(node string) ([]byte, error) { func (c *centralAuth) dbGetPublicKey(node string) ([]byte, error) {
var value []byte var value []byte
// View is a help function to get values out of the database. // View is a help function to get values out of the database.

View file

@ -92,7 +92,7 @@ type Configuration struct {
// Publisher for asking central for public keys // Publisher for asking central for public keys
StartPubREQPublicKeysGet bool StartPubREQPublicKeysGet bool
// Subscriber for receiving updates of public keys from central // Subscriber for receiving updates of public keys from central
StartSubREQPublicKeysPut bool StartSubREQPublicKeysToNode bool
// Start the central error logger. // Start the central error logger.
StartSubREQErrorLog bool StartSubREQErrorLog bool
// Subscriber for hello messages // Subscriber for hello messages
@ -168,7 +168,7 @@ type ConfigurationFromFile struct {
StartPubREQHello *int StartPubREQHello *int
StartPubREQPublicKeysGet *bool StartPubREQPublicKeysGet *bool
StartSubREQPublicKeysPut *bool StartSubREQPublicKeysToNode *bool
StartSubREQErrorLog *bool StartSubREQErrorLog *bool
StartSubREQHello *bool StartSubREQHello *bool
StartSubREQToFileAppend *bool StartSubREQToFileAppend *bool
@ -232,7 +232,7 @@ func newConfigurationDefaults() Configuration {
StartPubREQHello: 30, StartPubREQHello: 30,
StartPubREQPublicKeysGet: true, StartPubREQPublicKeysGet: true,
StartSubREQPublicKeysPut: true, StartSubREQPublicKeysToNode: true,
StartSubREQErrorLog: false, StartSubREQErrorLog: false,
StartSubREQHello: true, StartSubREQHello: true,
StartSubREQToFileAppend: true, StartSubREQToFileAppend: true,
@ -437,10 +437,10 @@ func checkConfigValues(cf ConfigurationFromFile) Configuration {
} else { } else {
conf.StartPubREQPublicKeysGet = *cf.StartPubREQPublicKeysGet conf.StartPubREQPublicKeysGet = *cf.StartPubREQPublicKeysGet
} }
if cf.StartSubREQPublicKeysPut == nil { if cf.StartSubREQPublicKeysToNode == nil {
conf.StartSubREQPublicKeysPut = cd.StartSubREQPublicKeysPut conf.StartSubREQPublicKeysToNode = cd.StartSubREQPublicKeysToNode
} else { } else {
conf.StartSubREQPublicKeysPut = *cf.StartSubREQPublicKeysPut conf.StartSubREQPublicKeysToNode = *cf.StartSubREQPublicKeysToNode
} }
if cf.StartSubREQErrorLog == nil { if cf.StartSubREQErrorLog == nil {
conf.StartSubREQErrorLog = cd.StartSubREQErrorLog conf.StartSubREQErrorLog = cd.StartSubREQErrorLog
@ -591,7 +591,7 @@ func (c *Configuration) CheckFlags() error {
flag.IntVar(&c.StartPubREQHello, "startPubREQHello", fc.StartPubREQHello, "Make the current node send hello messages to central at given interval in seconds") flag.IntVar(&c.StartPubREQHello, "startPubREQHello", fc.StartPubREQHello, "Make the current node send hello messages to central at given interval in seconds")
flag.BoolVar(&c.StartPubREQPublicKeysGet, "startPubREQPublicKeysGet", fc.StartPubREQPublicKeysGet, "true/false") flag.BoolVar(&c.StartPubREQPublicKeysGet, "startPubREQPublicKeysGet", fc.StartPubREQPublicKeysGet, "true/false")
flag.BoolVar(&c.StartSubREQPublicKeysPut, "startSubREQPublicKeysPut", fc.StartSubREQPublicKeysPut, "true/false") flag.BoolVar(&c.StartSubREQPublicKeysToNode, "startSubREQPublicKeysToNode", fc.StartSubREQPublicKeysToNode, "true/false")
flag.BoolVar(&c.StartSubREQErrorLog, "startSubREQErrorLog", fc.StartSubREQErrorLog, "true/false") flag.BoolVar(&c.StartSubREQErrorLog, "startSubREQErrorLog", fc.StartSubREQErrorLog, "true/false")
flag.BoolVar(&c.StartSubREQHello, "startSubREQHello", fc.StartSubREQHello, "true/false") flag.BoolVar(&c.StartSubREQHello, "startSubREQHello", fc.StartSubREQHello, "true/false")
flag.BoolVar(&c.StartSubREQToFileAppend, "startSubREQToFileAppend", fc.StartSubREQToFileAppend, "true/false") flag.BoolVar(&c.StartSubREQToFileAppend, "startSubREQToFileAppend", fc.StartSubREQToFileAppend, "true/false")

View file

@ -174,8 +174,8 @@ func (p *processes) Start(proc process) {
proc.startup.subREQPublicKeysGet(proc) proc.startup.subREQPublicKeysGet(proc)
} }
if proc.configuration.StartSubREQPublicKeysPut { if proc.configuration.StartSubREQPublicKeysToNode {
proc.startup.subREQPublicKeysPut(proc) proc.startup.subREQPublicKeysToNode(proc)
} }
if proc.configuration.StartSubREQHttpGet { if proc.configuration.StartSubREQHttpGet {
@ -302,7 +302,7 @@ func (s startup) pubREQHello(p process) {
// pubREQPublicKeysGet defines the startup of a publisher that will send REQPublicKeysGet // pubREQPublicKeysGet defines the startup of a publisher that will send REQPublicKeysGet
// to central server and ask for publics keys, and to get them deliver back with a request // to central server and ask for publics keys, and to get them deliver back with a request
// of type pubREQPublicKeysPut. // of type pubREQPublicKeysToNode.
func (s startup) pubREQPublicKeysGet(p process) { func (s startup) pubREQPublicKeysGet(p process) {
log.Printf("Starting PublicKeysGet Publisher: %#v\n", p.node) log.Printf("Starting PublicKeysGet Publisher: %#v\n", p.node)
@ -322,7 +322,7 @@ func (s startup) pubREQPublicKeysGet(p process) {
FromNode: Node(p.node), FromNode: Node(p.node),
// Data: []byte(d), // Data: []byte(d),
Method: REQPublicKeysGet, Method: REQPublicKeysGet,
ReplyMethod: REQPublicKeysPut, ReplyMethod: REQPublicKeysToNode,
ACKTimeout: proc.configuration.DefaultMessageTimeout, ACKTimeout: proc.configuration.DefaultMessageTimeout,
Retries: 1, Retries: 1,
} }
@ -355,9 +355,9 @@ func (s startup) subREQPublicKeysGet(p process) {
go proc.spawnWorker() go proc.spawnWorker()
} }
func (s startup) subREQPublicKeysPut(p process) { func (s startup) subREQPublicKeysToNode(p process) {
log.Printf("Starting Public keys put subscriber: %#v\n", p.node) log.Printf("Starting Public keys to Node subscriber: %#v\n", p.node)
sub := newSubject(REQPublicKeysPut, string(p.node)) sub := newSubject(REQPublicKeysToNode, string(p.node))
proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil) proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil)
go proc.spawnWorker() go proc.spawnWorker()
} }

View file

@ -138,8 +138,8 @@ const (
REQPublicKey Method = "REQPublicKey" REQPublicKey Method = "REQPublicKey"
// REQPublicKeysGet will get all the public keys from central. // REQPublicKeysGet will get all the public keys from central.
REQPublicKeysGet Method = "REQPublicKeysGet" REQPublicKeysGet Method = "REQPublicKeysGet"
// REQPublicKeysPut will put all the public received from central. // REQPublicKeysToNode will put all the public received from central.
REQPublicKeysPut Method = "REQPublicKeysPut" REQPublicKeysToNode Method = "REQPublicKeysToNode"
) )
// The mapping of all the method constants specified, what type // The mapping of all the method constants specified, what type
@ -227,7 +227,7 @@ func (m Method) GetMethodsAvailable() MethodsAvailable {
REQPublicKeysGet: methodREQPublicKeysGet{ REQPublicKeysGet: methodREQPublicKeysGet{
event: EventNACK, event: EventNACK,
}, },
REQPublicKeysPut: methodREQPublicKeysPut{ REQPublicKeysToNode: methodREQPublicKeysToNode{
event: EventNACK, event: EventNACK,
}, },
}, },
@ -2091,18 +2091,18 @@ func (m methodREQPublicKeysGet) handler(proc process, message Message, node stri
// ---- // ----
type methodREQPublicKeysPut struct { type methodREQPublicKeysToNode struct {
event Event event Event
} }
func (m methodREQPublicKeysPut) getKind() Event { func (m methodREQPublicKeysToNode) getKind() Event {
return m.event return m.event
} }
// TODO: Rename to :REQPublicKeysToNode // TODO: Rename to :REQPublicKeysToNode
// //
// Handler to put the public key replies received from a central server. // Handler to put the public key replies received from a central server.
func (m methodREQPublicKeysPut) handler(proc process, message Message, node string) ([]byte, error) { func (m methodREQPublicKeysToNode) handler(proc process, message Message, node string) ([]byte, error) {
// Get a context with the timeout specified in message.MethodTimeout. // Get a context with the timeout specified in message.MethodTimeout.
// TODO: // TODO: