Merge branch 'master' of https://git.kappach.at/lda/Parsee into lmdb

This commit is contained in:
LDA 2024-08-10 14:13:26 +02:00
commit b192f4b27f
5 changed files with 58 additions and 10 deletions

View file

@ -1,6 +1,6 @@
Some dates for Parsee-related events. They mostly serve as LDA's TODOs with
a strict deadline:
- ~September 2024:
- ~September 2024[star-of-hope]:
Get Parsee into the _Phantasmagoria of Bug View_ stage (essentially
v0.0.1 for a public testing) once I can afford `yama`, and start
bridging the Matrix room alongside a shiny XMPP MUC, bridged by

View file

@ -3,12 +3,14 @@
#include <Cytoplasm/Memory.h>
#include <Cytoplasm/Util.h>
#include <Cytoplasm/Cron.h>
#include <Cytoplasm/Args.h>
#include <Cytoplasm/Log.h>
#include <Cytoplasm/Str.h>
#include <pthread.h>
#include <string.h>
#include <signal.h>
#include <stdlib.h>
#include <StringStream.h>
#include <Parsee.h>
@ -30,7 +32,7 @@ ParseeUptime(void)
}
int
Main(void)
Main(Array *args, HashMap *env)
{
HttpServerConfig conf;
const ParseeConfig *parsee_conf;
@ -50,13 +52,34 @@ Main(void)
ParseeConfigLoad("parsee.json");
ParseeConfigInit();
parsee_conf = ParseeConfigGet();
{
ArgParseState state;
int flag;
int xmpp = 8;
int http = 8;
ArgParseStateInit(&state);
while ((flag = ArgParse(&state, args, "H:J:")) != -1)
{
switch (flag)
{
case 'H':
http = strtol(state.optArg, NULL, 10);
break;
case 'J':
xmpp = strtol(state.optArg, NULL, 10);
break;
}
}
ParseeSetThreads(xmpp, http);
}
/* Write out the config file to a YAML document */
yaml = StreamOpen("parsee.yaml", "w");
ParseeExportConfigYAML(yaml);
StreamClose(yaml);
parsee_conf = ParseeConfigGet();
{
Log(LOG_NOTICE, "Connecting to XMPP...");
jabber = XMPPInitialiseCompStream(
@ -83,8 +106,8 @@ Main(void)
ASRegisterUser(parsee_conf, parsee_conf->sender_localpart);
conf.port = parsee_conf->port;
conf.threads = 4;
conf.maxConnections = 32;
conf.threads = parsee_conf->http_threads;
conf.maxConnections = 32; /* TODO */
conf.handlerArgs = ParseeInitData(jabber);
conf.handler = ParseeRequest;

View file

@ -133,6 +133,8 @@ ParseeConfigInit(void)
config = Malloc(sizeof(*config));
config->as_token = StrRandom(32);
config->hs_token = StrRandom(32);
config->http_threads = 8;
config->xmpp_threads = 8;
/* TODO: This is NOT user friendly, and I know it! */
config->sender_localpart = PromptString(
@ -237,6 +239,9 @@ ParseeConfigLoad(char *conf)
JsonValueAsInteger(HashMapGet(json, str)) \
)
config->http_threads = 8;
config->xmpp_threads = 8;
CopyToStr(as_token, "as_token");
CopyToStr(hs_token, "hs_token");
CopyToStr(sender_localpart, "sender");
@ -260,6 +265,17 @@ ParseeConfigLoad(char *conf)
StreamClose(stream);
}
void
ParseeSetThreads(int xmpp, int http)
{
if (!config)
{
return;
}
config->http_threads = http;
config->xmpp_threads = xmpp;
}
void
ParseeExportConfigYAML(Stream *stream)
{

View file

@ -155,7 +155,7 @@ ParseeXMPPThread(void *argp)
/* ... and its readers. */
/* TODO: Make that configurable. */
info.available_dispatchers = 16;
info.available_dispatchers = args->config->xmpp_threads;
info.dispatchers = Malloc(
sizeof(*info.dispatchers) * info.available_dispatchers
);

View file

@ -41,6 +41,9 @@ typedef struct ParseeConfig {
/* ------- DB -------- */
char *db_path;
/* - COMMAND-LINE FLAGS - */
int xmpp_threads, http_threads;
} ParseeConfig;
typedef struct ParseeData {
@ -234,7 +237,7 @@ extern void ParseePushHeadTable(char *room, char *id);
extern char *ParseeLookupHead(char *room);
extern void ParseeDestroyHeadTable(void);
/* Disables a user/room/MUC's ability to interact from Parsee, and attempts
/** Disables a user/room/MUC's ability to interact from Parsee, and attempts
* to ban them from rooms where Parsee has the ability to do so ("noflying").
* ---------------
* Returns: NOTHING
@ -242,7 +245,7 @@ extern void ParseeDestroyHeadTable(void);
* Modifies: the database */
extern void ParseeGlobalBan(ParseeData *, char *user, char *reason);
/* Verifies if a user was banned globally. If so (and if {room} is set),
/** Verifies if a user was banned globally. If so (and if {room} is set),
* tries to ban the user from it.
* ---------------
* Returns: NOTHING
@ -260,7 +263,7 @@ extern bool ParseeVerifyDMStanza(ParseeData *data, char *room_id, char *id);
* Modifies: NOTHING */
extern bool ParseeIsAdmin(ParseeData *data, char *user);
/* Measures Parsee's overall uptime.
/** Measures Parsee's overall uptime.
* ----------------
* Returns: uptime since the call to Main in milliseconds.
* Modifies: NOTHING */
@ -301,4 +304,10 @@ extern void ParseeAchievement(const char *func, const char *msg, bool die);
* Thrasher: Free */
extern char * ParseeGenerateMTO(char *common_id);
/** Sets the amount of XMPP/HTTP threads to use
* ----------------------
* Returns: NOTHING
* Modifies: the Parsee config */
extern void ParseeSetThreads(int xmpp, int http);
#endif