From 5f8e3e558b9cc55ad90eb290fb6a829764a974b7 Mon Sep 17 00:00:00 2001 From: db0 Date: Mon, 26 Jun 2023 00:32:41 +0200 Subject: [PATCH] feat: report sus per monthly active user --- fediseer/apis/models/v1.py | 10 ++-------- fediseer/apis/v1/base.py | 3 ++- fediseer/observer.py | 7 ++++++- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/fediseer/apis/models/v1.py b/fediseer/apis/models/v1.py index 64e8fe4..1fe369e 100644 --- a/fediseer/apis/models/v1.py +++ b/fediseer/apis/models/v1.py @@ -16,8 +16,8 @@ class Models: 'total_users': fields.Integer(description="The total amount of users registered in that instance"), 'active_users_monthly': fields.Integer(description="The amount of active users monthly."), 'signup': fields.Boolean(default=False,description="True when subscriptions are open, else False"), - 'activity_suspicion': fields.Float(description="Local Comments+Posts per User. Higher is worse"), - 'activity_suspicion': fields.Float(description="Local Comments+Posts per User. Higher is worse"), + 'activity_suspicion': fields.Float(description="Local Comments+Posts per user. Higher is worse"), + 'active_users_suspicion': fields.Float(description="Monthly active users per user. Higher is worse"), }) self.response_model_model_Suspicions_get = api.model('SuspiciousInstances', { 'instances': fields.List(fields.Nested(self.response_model_suspicious_instances)), @@ -40,9 +40,3 @@ class Models: 'domains': fields.List(fields.String(description="The instance domains as a list.")), 'csv': fields.String(description="The instance domains as a csv."), }) - self.response_model_model_Suspicions_get = api.model('SuspiciousInstances', { - 'self': fields.Nested(self.response_model_instances), - 'guaranteed': fields.List(fields.Nested(self.response_model_instances)), - 'endorsed': fields.List(fields.String(description="The suspicious domains as a list.")), - 'endorsing': fields.String(description="The suspicious domains as a csv."), - }) diff --git a/fediseer/apis/v1/base.py b/fediseer/apis/v1/base.py index 3f4abde..ccb4e2c 100644 --- a/fediseer/apis/v1/base.py +++ b/fediseer/apis/v1/base.py @@ -34,6 +34,7 @@ class Suspicions(Resource): get_parser = reqparse.RequestParser() get_parser.add_argument("Client-Agent", default="unknown:0:unknown", type=str, required=False, help="The client name and version.", location="headers") get_parser.add_argument("activity_suspicion", required=False, default=20, type=int, help="How many users per local post+comment to consider suspicious", location="args") + get_parser.add_argument("active_suspicion", required=False, default=500, type=int, help="How many users per active users to consider suspicious", location="args") get_parser.add_argument("csv", required=False, type=bool, help="Set to true to return just the domains as a csv. Mutually exclusive with domains", location="args") get_parser.add_argument("domains", required=False, type=bool, help="Set to true to return just the domains as a list. Mutually exclusive with csv", location="args") @@ -45,7 +46,7 @@ class Suspicions(Resource): '''A List with the details of all suspicious instances ''' self.args = self.get_parser.parse_args() - sus_instances = retrieve_suspicious_instances(self.args.activity_suspicion) + sus_instances = retrieve_suspicious_instances(self.args.activity_suspicion, self.args.active_suspicion) if self.args.csv: return {"csv": ",".join([instance["domain"] for instance in sus_instances])},200 if self.args.domains: diff --git a/fediseer/observer.py b/fediseer/observer.py index aae71c2..24dc6af 100644 --- a/fediseer/observer.py +++ b/fediseer/observer.py @@ -69,7 +69,11 @@ def retrieve_suspicious_instances(activity_suspicion = 20, active_suspicious = 5 # print(node) # check active users (monthly is a lot lower than total users) - if node["total_users"] / node["active_users_monthly"] > active_suspicious: + local_active_monthly_users = node["active_users_monthly"] + # Avoid division by 0 + if local_active_monthly_users == 0: + local_active_monthly_users= 0.5 + if node["total_users"] / local_active_monthly_users > active_suspicious: is_bad = True # print(node) @@ -83,6 +87,7 @@ def retrieve_suspicious_instances(activity_suspicion = 20, active_suspicious = 5 "active_users_monthly": node["active_users_monthly"], "signup": node["signup"], "activity_suspicion": node["total_users"] / local_activity, + "active_users_suspicion": node["total_users"] / local_active_monthly_users, } bad_nodes.append(bad_node) return bad_nodes