trivial-discovered
Initial Setup, main()
The main() function: initializes a UUID as an instance ID to be sent along as part of the referer ID; ensures that the addresses, of the discovery-svc registration and GraphQL server, are passed as arguments; set a SIGINT handler for when the program is aborted; subscribe to IPSME messages; and, start a background thread discovery-svc registration.
Register with discovery-svc
After the initial setup, a thread is spun up to execute thread_main_udp_(). This function first resolves the address of the discovery-svc, which was passed as a commandline argument, creates a Registration message and sends the registration off to the service.
Since the protocol is UDP, the function loops until a confirmation is received. If successful, the expiration is read out and the loop registers again after the expirattion datetime.
IPSME
This project has been implemented using the sdbus implementation of IPSME for Linux. If trivial-discovered is to be run locally on macOS, then the cpp-msgenv-sdbus can be substituted with objc-msgenv-NSDNC. The handlers would pass the original message as a id id_msg, instead of a sd_bus_message* p_msg, but the response chain functions the same.
cpp-msgenv-sdbus |
|
|---|---|
objc-msgenv-NSDNC |
JSON_MsgDiscovery
The main loop registers the first handler of the resolver chain i.e., handler_(). Thereafter, cascading handlers validate messages until a Discovery query is accepted.
bool handler_json_msgDiscovery_(sd_bus_message* p_msg, json json_msgDiscovery)
{
// ...
}
bool handler_json_(sd_bus_message* p_msg, json json_msg)
{
if (JSON_MsgDiscovery::validate(json_msg) && handler_json_msgDiscovery_(p_msg, json_msg) )
return true;
}
No API — if trivial-discovered does not need to translate from another API, then an immediate response can be returned in handler_json_msgDiscovery_(). The response follows the Subverse/Instance announcement of the Discovery Protocol.
API — Examining the code will show that trivial-discovered does query an API; GraphQL. This means trivial-discovered is a translator (i.e., more specifically a mask) IPSME participant, that translates the API to the protocol of discovery. If the API is not GraphQL, then the call in handler_json_msgDiscovery_() can be replaced with the relevant API code. The function tx_graphql_subverse_() translates the GraphQL response to the Discovery response; an announcement.
{
"announcement": {
"subverse": {
// ...
}
}
// ... JSON_Msg_msg format
}