mirror of
https://github.com/postmannen/ctrl.git
synced 2024-12-14 12:37:31 +00:00
Renamed REQPublicKeysPut to REQPublicKeysToNode
This commit is contained in:
parent
81c8610ff1
commit
102cfd43c9
4 changed files with 24 additions and 22 deletions
|
@ -13,6 +13,8 @@ import (
|
|||
|
||||
type signatureBase32 string
|
||||
type argsString string
|
||||
|
||||
// centralAuth holds the logic related to handling public keys and auth maps.
|
||||
type centralAuth struct {
|
||||
// schema map[Node]map[argsString]signatureBase32
|
||||
nodePublicKeys *nodePublicKeys
|
||||
|
@ -22,6 +24,7 @@ type centralAuth struct {
|
|||
errorKernel *errorKernel
|
||||
}
|
||||
|
||||
// newCentralAuth will return a prepared *centralAuth with input values set.
|
||||
func newCentralAuth(configuration *Configuration, errorKernel *errorKernel) *centralAuth {
|
||||
c := centralAuth{
|
||||
// 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.
|
||||
// We should return an error if the key have changed.
|
||||
func (c *centralAuth) addPublicKey(proc process, msg Message) {
|
||||
c.nodePublicKeys.mu.Lock()
|
||||
|
||||
|
@ -94,7 +96,7 @@ func (c *centralAuth) addPublicKey(proc process, msg Message) {
|
|||
//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) {
|
||||
var value []byte
|
||||
// View is a help function to get values out of the database.
|
||||
|
|
|
@ -92,7 +92,7 @@ type Configuration struct {
|
|||
// Publisher for asking central for public keys
|
||||
StartPubREQPublicKeysGet bool
|
||||
// Subscriber for receiving updates of public keys from central
|
||||
StartSubREQPublicKeysPut bool
|
||||
StartSubREQPublicKeysToNode bool
|
||||
// Start the central error logger.
|
||||
StartSubREQErrorLog bool
|
||||
// Subscriber for hello messages
|
||||
|
@ -168,7 +168,7 @@ type ConfigurationFromFile struct {
|
|||
|
||||
StartPubREQHello *int
|
||||
StartPubREQPublicKeysGet *bool
|
||||
StartSubREQPublicKeysPut *bool
|
||||
StartSubREQPublicKeysToNode *bool
|
||||
StartSubREQErrorLog *bool
|
||||
StartSubREQHello *bool
|
||||
StartSubREQToFileAppend *bool
|
||||
|
@ -232,7 +232,7 @@ func newConfigurationDefaults() Configuration {
|
|||
|
||||
StartPubREQHello: 30,
|
||||
StartPubREQPublicKeysGet: true,
|
||||
StartSubREQPublicKeysPut: true,
|
||||
StartSubREQPublicKeysToNode: true,
|
||||
StartSubREQErrorLog: false,
|
||||
StartSubREQHello: true,
|
||||
StartSubREQToFileAppend: true,
|
||||
|
@ -437,10 +437,10 @@ func checkConfigValues(cf ConfigurationFromFile) Configuration {
|
|||
} else {
|
||||
conf.StartPubREQPublicKeysGet = *cf.StartPubREQPublicKeysGet
|
||||
}
|
||||
if cf.StartSubREQPublicKeysPut == nil {
|
||||
conf.StartSubREQPublicKeysPut = cd.StartSubREQPublicKeysPut
|
||||
if cf.StartSubREQPublicKeysToNode == nil {
|
||||
conf.StartSubREQPublicKeysToNode = cd.StartSubREQPublicKeysToNode
|
||||
} else {
|
||||
conf.StartSubREQPublicKeysPut = *cf.StartSubREQPublicKeysPut
|
||||
conf.StartSubREQPublicKeysToNode = *cf.StartSubREQPublicKeysToNode
|
||||
}
|
||||
if cf.StartSubREQErrorLog == nil {
|
||||
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.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.StartSubREQHello, "startSubREQHello", fc.StartSubREQHello, "true/false")
|
||||
flag.BoolVar(&c.StartSubREQToFileAppend, "startSubREQToFileAppend", fc.StartSubREQToFileAppend, "true/false")
|
||||
|
|
14
processes.go
14
processes.go
|
@ -174,8 +174,8 @@ func (p *processes) Start(proc process) {
|
|||
proc.startup.subREQPublicKeysGet(proc)
|
||||
}
|
||||
|
||||
if proc.configuration.StartSubREQPublicKeysPut {
|
||||
proc.startup.subREQPublicKeysPut(proc)
|
||||
if proc.configuration.StartSubREQPublicKeysToNode {
|
||||
proc.startup.subREQPublicKeysToNode(proc)
|
||||
}
|
||||
|
||||
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
|
||||
// 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) {
|
||||
log.Printf("Starting PublicKeysGet Publisher: %#v\n", p.node)
|
||||
|
||||
|
@ -322,7 +322,7 @@ func (s startup) pubREQPublicKeysGet(p process) {
|
|||
FromNode: Node(p.node),
|
||||
// Data: []byte(d),
|
||||
Method: REQPublicKeysGet,
|
||||
ReplyMethod: REQPublicKeysPut,
|
||||
ReplyMethod: REQPublicKeysToNode,
|
||||
ACKTimeout: proc.configuration.DefaultMessageTimeout,
|
||||
Retries: 1,
|
||||
}
|
||||
|
@ -355,9 +355,9 @@ func (s startup) subREQPublicKeysGet(p process) {
|
|||
go proc.spawnWorker()
|
||||
}
|
||||
|
||||
func (s startup) subREQPublicKeysPut(p process) {
|
||||
log.Printf("Starting Public keys put subscriber: %#v\n", p.node)
|
||||
sub := newSubject(REQPublicKeysPut, string(p.node))
|
||||
func (s startup) subREQPublicKeysToNode(p process) {
|
||||
log.Printf("Starting Public keys to Node subscriber: %#v\n", p.node)
|
||||
sub := newSubject(REQPublicKeysToNode, string(p.node))
|
||||
proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil)
|
||||
go proc.spawnWorker()
|
||||
}
|
||||
|
|
12
requests.go
12
requests.go
|
@ -138,8 +138,8 @@ const (
|
|||
REQPublicKey Method = "REQPublicKey"
|
||||
// REQPublicKeysGet will get all the public keys from central.
|
||||
REQPublicKeysGet Method = "REQPublicKeysGet"
|
||||
// REQPublicKeysPut will put all the public received from central.
|
||||
REQPublicKeysPut Method = "REQPublicKeysPut"
|
||||
// REQPublicKeysToNode will put all the public received from central.
|
||||
REQPublicKeysToNode Method = "REQPublicKeysToNode"
|
||||
)
|
||||
|
||||
// The mapping of all the method constants specified, what type
|
||||
|
@ -227,7 +227,7 @@ func (m Method) GetMethodsAvailable() MethodsAvailable {
|
|||
REQPublicKeysGet: methodREQPublicKeysGet{
|
||||
event: EventNACK,
|
||||
},
|
||||
REQPublicKeysPut: methodREQPublicKeysPut{
|
||||
REQPublicKeysToNode: methodREQPublicKeysToNode{
|
||||
event: EventNACK,
|
||||
},
|
||||
},
|
||||
|
@ -2091,18 +2091,18 @@ func (m methodREQPublicKeysGet) handler(proc process, message Message, node stri
|
|||
|
||||
// ----
|
||||
|
||||
type methodREQPublicKeysPut struct {
|
||||
type methodREQPublicKeysToNode struct {
|
||||
event Event
|
||||
}
|
||||
|
||||
func (m methodREQPublicKeysPut) getKind() Event {
|
||||
func (m methodREQPublicKeysToNode) getKind() Event {
|
||||
return m.event
|
||||
}
|
||||
|
||||
// TODO: Rename to :REQPublicKeysToNode
|
||||
//
|
||||
// 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.
|
||||
|
||||
// TODO:
|
||||
|
|
Loading…
Reference in a new issue