This commit is contained in:
Reid 'arrdem' McKenzie 2022-11-20 22:39:44 -07:00
parent 53bf982217
commit 1c41b6dca4
8 changed files with 42 additions and 37 deletions

View file

@ -1,14 +1,16 @@
import Crypto
import asyncio
import click
import platform
import logging
import os
import platform
from urllib.parse import urlparse
from relay import misc, __version__
from relay.application import Application, request_id_middleware
import Crypto
import click
from relay import __version__, misc
from relay.application import (
Application,
request_id_middleware,
)
from relay.config import relay_software_names
@ -39,7 +41,6 @@ def cli(ctx, config):
@click.pass_obj
def cli_inbox(ctx: Application):
"Manage the inboxes in the database"
pass
@cli_inbox.command("list")
@ -161,7 +162,6 @@ def cli_inbox_remove(obj: Application, inbox):
@cli.group("instance")
def cli_instance():
"Manage instance bans"
pass
@cli_instance.command("list")
@ -214,7 +214,6 @@ def cli_instance_unban(obj: Application, target):
@cli.group("software")
def cli_software():
"Manage banned software"
pass
@cli_software.command("list")
@ -301,7 +300,6 @@ def cli_software_unban(obj: Application, name, fetch_nodeinfo):
@cli.group("whitelist")
def cli_whitelist():
"Manage the instance whitelist"
pass
@cli_whitelist.command("list")

View file

@ -1,19 +1,21 @@
import asyncio
from datetime import datetime, timedelta
import logging
import os
import signal
from uuid import uuid4
from aiohttp import web
from cachetools import LRUCache
from datetime import datetime, timedelta
from relay.config import RelayConfig
from relay.database import RelayDatabase
from relay.misc import DotDict, check_open_port, set_app
from relay.misc import (
check_open_port,
DotDict,
set_app,
)
from relay.views import routes
from uuid import uuid4
class Application(web.Application):
def __init__(self, cfgpath, middlewares=None):

View file

@ -2,7 +2,6 @@ from pathlib import Path
from urllib.parse import urlparse
from relay.misc import DotDict
import yaml

View file

@ -1,8 +1,8 @@
import json
import logging
from urllib.parse import urlparse
from Crypto.PublicKey import RSA
from urllib.parse import urlparse
class RelayDatabase(dict):

View file

@ -1,7 +1,7 @@
import logging
import aiohttp
from collections import defaultdict
import logging
import aiohttp
STATS = {

View file

@ -1,24 +1,27 @@
import base64
from datetime import datetime
import json
from json.decoder import JSONDecodeError
import logging
import socket
from urllib.parse import urlparse
import uuid
from random import randint
from Crypto.Hash import SHA, SHA256, SHA512
from Crypto.PublicKey import RSA
from Crypto.Signature import PKCS1_v1_5
from aiohttp import ClientSession
from aiohttp.client_exceptions import ClientResponseError, ClientConnectorError
from aiohttp.client_exceptions import (
ClientConnectorError,
ClientResponseError,
)
from aiohttp.hdrs import METH_ALL as METHODS
from aiohttp.web import Response as AiohttpResponse, View as AiohttpView
from datetime import datetime
from json.decoder import JSONDecodeError
from urllib.parse import urlparse
from aiohttp.web import (
Response as AiohttpResponse,
View as AiohttpView,
)
from async_lru import alru_cache
from relay.http_debug import http_debug
from retry import retry
@ -339,7 +342,7 @@ class DotDict(dict):
# misc properties
@property
def domain(self):
return urlparse(getattr(self, 'id', None) or getattr(self, 'actor')).hostname
return urlparse(getattr(self, "id", None) or getattr(self, "actor")).hostname
# actor properties
@property

View file

@ -1,5 +1,4 @@
import asyncio
import json
import logging
from relay import misc
@ -105,11 +104,11 @@ async def run_processor(request, actor, data, software):
return
logging.info(f'{request.id}: New "{data.type}" from actor: {actor.id}')
logging.debug(f'{request.id}: {data!r}')
logging.debug(f"{request.id}: {data!r}")
env = dict(data=data, actor=actor, software=software)
try:
return await processors.get(data.type, handle_dont)(request, actor, data, software)
except:
logging.exception(f'{request.id}] {env!r}')
logging.exception(f"{request.id}] {env!r}")

View file

@ -1,12 +1,16 @@
import json
import logging
from aiohttp.web import HTTPUnauthorized
from relay import __version__, misc
from relay.http_debug import STATS
from relay.misc import DotDict, Message, Response, WKNodeinfo
from relay.misc import (
DotDict,
Message,
Response,
WKNodeinfo,
)
from relay.processors import run_processor
from aiohttp.web import HTTPUnauthorized
routes = []
@ -91,7 +95,7 @@ async def inbox(request):
# This PROBABLY means we can do without this data ever ... but here it is.
# Trying to deal with actors/visibility
if isinstance(data.object, dict) and not data.object.get('discoverable', True):
if isinstance(data.object, dict) and not data.object.get("discoverable", True):
actor = DotDict({"id": "dummy-for-undiscoverable-object"})
# Normal path of looking up the actor...
@ -100,7 +104,7 @@ async def inbox(request):
# FIXME: Needs a cache
actor = await misc.request(data.actorid)
except:
logging.exception(f'{request.id}: {data!r}')
logging.exception(f"{request.id}: {data!r}")
return
logging.debug(f"Inbox >> {data!r}")