2015-06-21 21:28:39 +02:00
package ICCC
import (
"fmt"
"github.com/SommerEngineering/Ocean/ICCC/SystemMessages"
"github.com/SommerEngineering/Ocean/Log"
LM "github.com/SommerEngineering/Ocean/Log/Meta"
)
// The receiver function for the ICCC message, that registers a host.
2015-07-10 14:36:47 +02:00
func ICCCRegisterHostReceiver ( data map [ string ][] string ) ( result map [ string ][] string ) {
2015-06-21 21:28:39 +02:00
// Recover from errors:
defer func () {
if err := recover (); err != nil {
2015-07-10 14:36:47 +02:00
Log . LogFull ( senderName , LM . CategorySYSTEM , LM . LevelERROR , LM . SeverityUnknown , LM . ImpactUnknown , LM . MessageNamePARSE , "Was not able to execute the ICCC register host message." )
2015-06-21 21:28:39 +02:00
result = make ( map [ string ][] string , 0 )
return
}
}()
// Converts the HTTP form data into an object:
_ , _ , obj := Data2Message ( SystemMessages . ICCCRegisterHost {}, data )
// Was it possible to convert the data?
if obj != nil {
// Cast the object to the right type:
messageData := obj .( SystemMessages . ICCCRegisterHost )
// Provide a log entry:
2015-07-10 14:36:47 +02:00
Log . LogShort ( senderName , LM . CategorySYSTEM , LM . LevelINFO , LM . MessageNameSTARTUP , `ICCC message: Register another host.` , fmt . Sprintf ( "hostname=%s" , messageData . Hostname ), fmt . Sprintf ( "ipAddressPort=%s" , messageData . IPAddressPort ))
2015-06-21 21:28:39 +02:00
// Execute the command:
2015-07-13 10:44:03 +02:00
registerHost2Database ( messageData . Hostname , messageData . IPAddressPort , messageData . Kind )
2015-06-21 21:28:39 +02:00
2015-07-10 14:36:47 +02:00
// Update the caches:
InitCacheNow ()
2015-06-21 21:28:39 +02:00
// An answer is necessary:
return Message2Data ( `` , `` , SystemMessages . AnswerACK )
} else {
Log . LogShort ( senderName , LM . CategorySYSTEM , LM . LevelINFO , LM . MessageNameSTARTUP , `ICCC message: Was not able to create the message.` )
}
// In any other error case:
result = make ( map [ string ][] string , 0 )
return
}