user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 3/4] imap: prioritize AUTH=ANONYMOUS clients
Date: Mon,  8 Aug 2022 23:16:47 +0000	[thread overview]
Message-ID: <20220808231648.1954885-4-e@80x24.org> (raw)
In-Reply-To: <20220808231648.1954885-1-e@80x24.org>

...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    |  2 +-
 lib/PublicInbox/IMAP.pm  | 10 ++++++++++
 lib/PublicInbox/IMAPD.pm |  7 +++++++
 3 files changed, 18 insertions(+), 1 deletion(-)

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;

  parent reply	other threads:[~2022-08-08 23:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-08 23:16 [PATCH 0/4] imap: reduce impact of bot scanners Eric Wong
2022-08-08 23:16 ` [PATCH 1/4] imap: limit ibx_async_prefetch to idle git processes Eric Wong
2022-08-08 23:16 ` [PATCH 2/4] imap: only give AUTH=ANONYMOUS clients prefetch Eric Wong
2022-08-08 23:16 ` Eric Wong [this message]
2022-08-08 23:16 ` [PATCH 4/4] README: recommend AUTH=ANONYMOUS on IMAP URLs Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220808231648.1954885-4-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).