]> Sergey Matveev's repositories - public-inbox.git/commitdiff
imap: prioritize AUTH=ANONYMOUS clients
authorEric Wong <e@80x24.org>
Mon, 8 Aug 2022 23:16:47 +0000 (23:16 +0000)
committerEric Wong <e@80x24.org>
Tue, 9 Aug 2022 16:41:49 +0000 (16:41 +0000)
...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.

lib/PublicInbox/DS.pm
lib/PublicInbox/IMAP.pm
lib/PublicInbox/IMAPD.pm

index 77e2e5e9d4a4ed0b96ab02be1f246f4c0ad76048..5e8a6a6601c51238a859f429bda5f584cda7a1b1 100644 (file)
@@ -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 ($$;@) {
index 4ef5252b56d02167eaf342bb77892e0f08824202..605c5e515110d1b0f1a077be70174149a78b22de 100644 (file)
@@ -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;
index 5368ff040edd457111cdb3984f722ebd67b5904f..dd0d2c53905a94012328b2bd3094f0026b9a159a 100644 (file)
@@ -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;