mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 13:45: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
|
||||
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
|
||||
|
|
|
|||
33
src/Main.c
33
src/Main.c
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
@ -236,6 +238,9 @@ ParseeConfigLoad(char *conf)
|
|||
#define CopyToInt(to, str) config->to = (int) ( \
|
||||
JsonValueAsInteger(HashMapGet(json, str)) \
|
||||
)
|
||||
|
||||
config->http_threads = 8;
|
||||
config->xmpp_threads = 8;
|
||||
|
||||
CopyToStr(as_token, "as_token");
|
||||
CopyToStr(hs_token, "hs_token");
|
||||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
);
|
||||
|
|
|
|||
|
|
@ -41,6 +41,9 @@ typedef struct ParseeConfig {
|
|||
|
||||
/* ------- DB -------- */
|
||||
char *db_path;
|
||||
|
||||
/* - COMMAND-LINE FLAGS - */
|
||||
int xmpp_threads, http_threads;
|
||||
} ParseeConfig;
|
||||
|
||||
typedef struct ParseeData {
|
||||
|
|
@ -228,7 +231,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
|
||||
|
|
@ -236,7 +239,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
|
||||
|
|
@ -254,7 +257,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 */
|
||||
|
|
@ -295,4 +298,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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue