mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 16:55:10 +00:00
[MOD] -J and -H flags for the max XMPP/HTTP thread
This commit is contained in:
parent
61b248363d
commit
4d6ba32e98
5 changed files with 58 additions and 10 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
Some dates for Parsee-related events. They mostly serve as LDA's TODOs with
|
Some dates for Parsee-related events. They mostly serve as LDA's TODOs with
|
||||||
a strict deadline:
|
a strict deadline:
|
||||||
- ~September 2024:
|
- ~September 2024[star-of-hope]:
|
||||||
Get Parsee into the _Phantasmagoria of Bug View_ stage (essentially
|
Get Parsee into the _Phantasmagoria of Bug View_ stage (essentially
|
||||||
v0.0.1 for a public testing) once I can afford `yama`, and start
|
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
|
bridging the Matrix room alongside a shiny XMPP MUC, bridged by
|
||||||
|
|
|
||||||
31
src/Main.c
31
src/Main.c
|
|
@ -3,12 +3,14 @@
|
||||||
#include <Cytoplasm/Memory.h>
|
#include <Cytoplasm/Memory.h>
|
||||||
#include <Cytoplasm/Util.h>
|
#include <Cytoplasm/Util.h>
|
||||||
#include <Cytoplasm/Cron.h>
|
#include <Cytoplasm/Cron.h>
|
||||||
|
#include <Cytoplasm/Args.h>
|
||||||
#include <Cytoplasm/Log.h>
|
#include <Cytoplasm/Log.h>
|
||||||
#include <Cytoplasm/Str.h>
|
#include <Cytoplasm/Str.h>
|
||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <StringStream.h>
|
#include <StringStream.h>
|
||||||
#include <Parsee.h>
|
#include <Parsee.h>
|
||||||
|
|
@ -30,7 +32,7 @@ ParseeUptime(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
Main(void)
|
Main(Array *args, HashMap *env)
|
||||||
{
|
{
|
||||||
HttpServerConfig conf;
|
HttpServerConfig conf;
|
||||||
const ParseeConfig *parsee_conf;
|
const ParseeConfig *parsee_conf;
|
||||||
|
|
@ -50,13 +52,34 @@ Main(void)
|
||||||
|
|
||||||
ParseeConfigLoad("parsee.json");
|
ParseeConfigLoad("parsee.json");
|
||||||
ParseeConfigInit();
|
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 */
|
/* Write out the config file to a YAML document */
|
||||||
yaml = StreamOpen("parsee.yaml", "w");
|
yaml = StreamOpen("parsee.yaml", "w");
|
||||||
ParseeExportConfigYAML(yaml);
|
ParseeExportConfigYAML(yaml);
|
||||||
StreamClose(yaml);
|
StreamClose(yaml);
|
||||||
|
|
||||||
parsee_conf = ParseeConfigGet();
|
|
||||||
{
|
{
|
||||||
Log(LOG_NOTICE, "Connecting to XMPP...");
|
Log(LOG_NOTICE, "Connecting to XMPP...");
|
||||||
jabber = XMPPInitialiseCompStream(
|
jabber = XMPPInitialiseCompStream(
|
||||||
|
|
@ -83,8 +106,8 @@ Main(void)
|
||||||
ASRegisterUser(parsee_conf, parsee_conf->sender_localpart);
|
ASRegisterUser(parsee_conf, parsee_conf->sender_localpart);
|
||||||
|
|
||||||
conf.port = parsee_conf->port;
|
conf.port = parsee_conf->port;
|
||||||
conf.threads = 4;
|
conf.threads = parsee_conf->http_threads;
|
||||||
conf.maxConnections = 32;
|
conf.maxConnections = 32; /* TODO */
|
||||||
conf.handlerArgs = ParseeInitData(jabber);
|
conf.handlerArgs = ParseeInitData(jabber);
|
||||||
conf.handler = ParseeRequest;
|
conf.handler = ParseeRequest;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -133,6 +133,8 @@ ParseeConfigInit(void)
|
||||||
config = Malloc(sizeof(*config));
|
config = Malloc(sizeof(*config));
|
||||||
config->as_token = StrRandom(32);
|
config->as_token = StrRandom(32);
|
||||||
config->hs_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! */
|
/* TODO: This is NOT user friendly, and I know it! */
|
||||||
config->sender_localpart = PromptString(
|
config->sender_localpart = PromptString(
|
||||||
|
|
@ -237,6 +239,9 @@ ParseeConfigLoad(char *conf)
|
||||||
JsonValueAsInteger(HashMapGet(json, str)) \
|
JsonValueAsInteger(HashMapGet(json, str)) \
|
||||||
)
|
)
|
||||||
|
|
||||||
|
config->http_threads = 8;
|
||||||
|
config->xmpp_threads = 8;
|
||||||
|
|
||||||
CopyToStr(as_token, "as_token");
|
CopyToStr(as_token, "as_token");
|
||||||
CopyToStr(hs_token, "hs_token");
|
CopyToStr(hs_token, "hs_token");
|
||||||
CopyToStr(sender_localpart, "sender");
|
CopyToStr(sender_localpart, "sender");
|
||||||
|
|
@ -260,6 +265,17 @@ ParseeConfigLoad(char *conf)
|
||||||
StreamClose(stream);
|
StreamClose(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ParseeSetThreads(int xmpp, int http)
|
||||||
|
{
|
||||||
|
if (!config)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
config->http_threads = http;
|
||||||
|
config->xmpp_threads = xmpp;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParseeExportConfigYAML(Stream *stream)
|
ParseeExportConfigYAML(Stream *stream)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -155,7 +155,7 @@ ParseeXMPPThread(void *argp)
|
||||||
|
|
||||||
/* ... and its readers. */
|
/* ... and its readers. */
|
||||||
/* TODO: Make that configurable. */
|
/* TODO: Make that configurable. */
|
||||||
info.available_dispatchers = 16;
|
info.available_dispatchers = args->config->xmpp_threads;
|
||||||
info.dispatchers = Malloc(
|
info.dispatchers = Malloc(
|
||||||
sizeof(*info.dispatchers) * info.available_dispatchers
|
sizeof(*info.dispatchers) * info.available_dispatchers
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,9 @@ typedef struct ParseeConfig {
|
||||||
|
|
||||||
/* ------- DB -------- */
|
/* ------- DB -------- */
|
||||||
char *db_path;
|
char *db_path;
|
||||||
|
|
||||||
|
/* - COMMAND-LINE FLAGS - */
|
||||||
|
int xmpp_threads, http_threads;
|
||||||
} ParseeConfig;
|
} ParseeConfig;
|
||||||
|
|
||||||
typedef struct ParseeData {
|
typedef struct ParseeData {
|
||||||
|
|
@ -228,7 +231,7 @@ extern void ParseePushHeadTable(char *room, char *id);
|
||||||
extern char *ParseeLookupHead(char *room);
|
extern char *ParseeLookupHead(char *room);
|
||||||
extern void ParseeDestroyHeadTable(void);
|
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").
|
* to ban them from rooms where Parsee has the ability to do so ("noflying").
|
||||||
* ---------------
|
* ---------------
|
||||||
* Returns: NOTHING
|
* Returns: NOTHING
|
||||||
|
|
@ -236,7 +239,7 @@ extern void ParseeDestroyHeadTable(void);
|
||||||
* Modifies: the database */
|
* Modifies: the database */
|
||||||
extern void ParseeGlobalBan(ParseeData *, char *user, char *reason);
|
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.
|
* tries to ban the user from it.
|
||||||
* ---------------
|
* ---------------
|
||||||
* Returns: NOTHING
|
* Returns: NOTHING
|
||||||
|
|
@ -254,7 +257,7 @@ extern bool ParseeVerifyDMStanza(ParseeData *data, char *room_id, char *id);
|
||||||
* Modifies: NOTHING */
|
* Modifies: NOTHING */
|
||||||
extern bool ParseeIsAdmin(ParseeData *data, char *user);
|
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.
|
* Returns: uptime since the call to Main in milliseconds.
|
||||||
* Modifies: NOTHING */
|
* Modifies: NOTHING */
|
||||||
|
|
@ -295,4 +298,10 @@ extern void ParseeAchievement(const char *func, const char *msg, bool die);
|
||||||
* Thrasher: Free */
|
* Thrasher: Free */
|
||||||
extern char * ParseeGenerateMTO(char *common_id);
|
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
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue