about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2022-08-08 23:16:47 +0000
committerEric Wong <e@80x24.org>2022-08-09 16:41:49 +0000
commit6bfbb1d477d1adf40fa15a9f6e326f01cf966fc9 (patch)
tree56dcd892a1301c85c66539317a7e83828877d38e
parent42fe10a95f0bac3beea2fc277c604158d3275d1f (diff)
downloadpublic-inbox-6bfbb1d477d1adf40fa15a9f6e326f01cf966fc9.tar.gz
...by deprioritizing clients using a username + password.

As IMAP provides AUTH=ANONYMOUS for designating anonymous
access, we'll rely on it as a heuristic for favoring "good"
clients.  Clients using a username + password seem to (more
often than not) be malicious and looking for info which doesn't
belong in public inboxes.

This copies the technique used by WWW + -httpd to deprioritize
expensive mbox.gz downloads.
-rw-r--r--lib/PublicInbox/DS.pm2
-rw-r--r--lib/PublicInbox/IMAP.pm10
-rw-r--r--lib/PublicInbox/IMAPD.pm7
3 files changed, 18 insertions, 1 deletions
diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm
index 77e2e5e9..5e8a6a66 100644
--- a/lib/PublicInbox/DS.pm
+++ b/lib/PublicInbox/DS.pm
@@ -688,7 +688,7 @@ sub requeue_once {
         # but only after all pending writes are done.
         # autovivify wbuf.  wbuf may be populated by $cb,
         # no need to rearm if so: (push returns new size of array)
-        requeue($self) if push(@{$self->{wbuf}}, \&long_step) == 1;
+        $self->requeue if push(@{$self->{wbuf}}, \&long_step) == 1;
 }
 
 sub long_response ($$;@) {
diff --git a/lib/PublicInbox/IMAP.pm b/lib/PublicInbox/IMAP.pm
index 4ef5252b..605c5e51 100644
--- a/lib/PublicInbox/IMAP.pm
+++ b/lib/PublicInbox/IMAP.pm
@@ -575,6 +575,16 @@ sub fetch_run_ops {
         $self->msg_more(")\r\n");
 }
 
+sub requeue { # overrides PublicInbox::DS::requeue
+        my ($self) = @_;
+        if ($self->{anon}) { # AUTH=ANONYMOUS gets high priority
+                $self->SUPER::requeue;
+        } else { # low priority
+                push(@{$self->{imapd}->{-authed_q}}, $self) == 1 and
+                        PublicInbox::DS::requeue($self->{imapd});
+        }
+}
+
 sub fetch_blob_cb { # called by git->cat_async via ibx_async_cat
         my ($bref, $oid, $type, $size, $fetch_arg) = @_;
         my ($self, undef, $msgs, $range_info, $ops, $partial) = @$fetch_arg;
diff --git a/lib/PublicInbox/IMAPD.pm b/lib/PublicInbox/IMAPD.pm
index 5368ff04..dd0d2c53 100644
--- a/lib/PublicInbox/IMAPD.pm
+++ b/lib/PublicInbox/IMAPD.pm
@@ -87,4 +87,11 @@ sub idler_start {
         $_[0]->{idler} //= PublicInbox::InboxIdle->new($_[0]->{pi_cfg});
 }
 
+sub event_step { # called vai requeue for low-priority IMAP clients
+        my ($self) = @_;
+        my $imap = shift(@{$self->{-authed_q}}) // return;
+        PublicInbox::DS::requeue($self) if scalar(@{$self->{-authed_q}});
+        $imap->event_step; # PublicInbox::IMAP::event_step
+}
+
 1;