Change inbox handling so it can't get stuck if fs_list glitches, start adding routes for urn: and did:, change fetch timeouts, change when tor gets used

master
teknomunk 4 months ago
parent d9c90deb84
commit 55a6a6c05c

@ -228,6 +228,7 @@ bool handle_post( struct http_request* req, struct account* a )
status_make_quote_of( s, atoi(id) );
}
s->url = aformat( "https://%s/note/%d", g_server->domain, s->id );
// Save status data
status_save(s);

@ -0,0 +1,8 @@
#include "did.h"
bool route_wellknown_did( struct http_request* req )
{
// TODO: implement Decentralized Identifier (DID) handler
return false;
}

@ -0,0 +1,8 @@
#pragma once
#include <stdbool.h>
struct http_request;
bool route_wellknown_did( struct http_request* req );

@ -28,6 +28,7 @@
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <dirent.h>
extern bool terminate;
@ -561,6 +562,22 @@ bool route_activity( struct ap_object* act )
return false;
}
int find_next_inbox_id()
{
int res = 0;
DIR* d = opendir("data/inbox/");
struct dirent* entry;
char* remain;
while( (entry=readdir(d)) ) {
res = strtol(entry->d_name,&remain,10);
if( 0 != strcmp( remain, ".json" ) ) { continue; }
break;
}
closedir(d);
return res;
}
static bool process_one()
{
// Items requiring cleanup
@ -568,6 +585,7 @@ static bool process_one()
struct ap_envelope* env = NULL;
bool result = false;
/*
int tail_pos = fs_list_get("data/inbox/TAIL");
int head_pos = fs_list_get("data/inbox/HEAD");
if( head_pos <= tail_pos ) { return false; }
@ -576,10 +594,13 @@ static bool process_one()
printf( "Inbox has %d items pending processing...\n", (head_pos - tail_pos) );
int id = tail_pos + 1;
*/
int id = find_next_inbox_id();
if( id == 0 ) { return false; }
printf( "Next item is #%d\n", id );
env = ap_envelope_from_id(id);
bool step_tail = false;
//bool step_tail = false;
if( !env ) {
printf( "! Failed to parse envelope+activity for data/inbox/%d.json\n", id );
@ -647,11 +668,17 @@ static bool process_one()
}
cleanup:
/*
printf( "\nstep_tail=%c\n", step_tail ? 'T' : 'F' );
if( step_tail ) {
fs_list_set( "data/inbox/TAIL", id );
result = true;
}
*/
char filename[512];
snprintf( filename, 512, "data/inbox/%d.json", id );
remove(filename);
ap_object_free(act);
ap_envelope_free(env);
@ -663,11 +690,12 @@ failed:
result = false;
goto cleanup;
discard:
step_tail = true;
//step_tail = true;
result = true;
goto cleanup;
}
/*
bool cleanup_box( const char* box )
{
char tail[512];
@ -695,6 +723,7 @@ bool cleanup_box( const char* box )
}
return false;
}
*/
void process_inbox()
{
@ -703,7 +732,7 @@ void process_inbox()
while( !terminate ) {
bool activity = false;
activity |= process_one();
activity |= cleanup_box( "data/inbox" );
//activity |= cleanup_box( "data/inbox" );
if( !activity ) {
fflush(stdout);

@ -8,16 +8,18 @@
#include "model/server.h"
// Controller
#include "controller/activity_pub.h"
#include "controller/admin.h"
#include "controller/api/emoji.h"
#include "controller/did.h"
#include "controller/inbox.h"
#include "controller/mastodon_api.h"
#include "controller/pleroma_api.h"
#include "controller/oauth.h"
#include "controller/webfinger.h"
#include "controller/nodeinfo.h"
#include "controller/oauth.h"
#include "controller/owner.h"
#include "controller/inbox.h"
#include "controller/activity_pub.h"
#include "controller/api/emoji.h"
#include "controller/admin.h"
#include "controller/pleroma_api.h"
#include "controller/urn.h"
#include "controller/webfinger.h"
// Standard Library
#include <string.h>
@ -195,6 +197,15 @@ bool route_request( struct http_request* req )
} else if( http_request_route( req, "/.well-known" ) ) {
if( http_request_route( req, "/webfinger?" ) ) {
return route_wellknown_webfinger( req );
// DID handler
} else if( http_request_route( req, "did:" ) ) {
return route_wellknown_did( req );
// URN handler
} else if( http_request_route( req, "urn:" ) ) {
return route_wellknown_urn( req );
} else if( http_request_route( req, "/nodeinfo" ) ) {
printf( "Nodeinfo\n" );
return route_wellknown_nodeinfo( req );

@ -0,0 +1,9 @@
#include "urn.h"
bool route_wellknown_urn( struct http_request* req )
{
return false;
}

@ -0,0 +1,8 @@
#pragma once
#include <stdbool.h>
struct http_request;
bool route_wellknown_urn( struct http_request* req );

@ -238,7 +238,7 @@ int activity_like( struct status* s )
struct ap_object* activity_create_Note( struct status* s )
{
struct ap_object* act = activity_new_local_activity();
act->id = aformat( "https://%s/note/%d", g_server->domain, s->id );
act->id = strdup( s->url );
act->type = ap_Note;
act->published = s->published;
if( s->source ) {

@ -90,7 +90,7 @@ static bool do_fetch_tor( const char* uri, struct fetch_data* fd, const char* re
HTTP_REQ_RESULT_STATUS, &status_code,
HTTP_RES_HEADER_CALLBACK, fetch_handle_header, (void*)fd,
HTTP_REQ_PROXY, proxy,
HTTP_REQ_TIMEOUT, (void*)10,
HTTP_REQ_TIMEOUT, (void*)5,
NULL,
};
printf( "GET %s\n", uri );
@ -213,7 +213,7 @@ static bool do_fetch_signed_clearnet( const char* uri, struct fetch_data* fd, co
HTTP_REQ_HEADER, "Accept: application/activity+json",
HTTP_REQ_OUTFILE, result,
HTTP_REQ_RESULT_STATUS, &status_code,
HTTP_REQ_TIMEOUT, (void*)10,
HTTP_REQ_TIMEOUT, (void*)2,
NULL,
};
@ -243,7 +243,7 @@ static bool do_fetch( const char* uri, const char* fh )
bool result = false;
if( do_fetch_tor( uri, &fd, fh ) ) {
if( fd.p && fd.p->last_tor_delivery && do_fetch_tor( uri, &fd, fh ) ) {
goto success;
}
if( do_fetch_clearnet( uri, &fd, fh ) ) {

@ -31,6 +31,7 @@
#include <stddef.h>
#include <sys/stat.h>
#include <unistd.h>
#include <assert.h>
#define STATUSES_BY_URI "data/statuses/by-uri"

Loading…
Cancel
Save