1 # Copyright (C) 2021 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # Authentication worker for anything that needs auth for read/write IMAP
5 # (eventually for read-only NNTP access)
6 package PublicInbox::LeiAuth;
9 use PublicInbox::PktOp qw(pkt_do);
11 sub do_auth_atfork { # used by IPC WQ workers
13 return if $wq->{-wq_worker_nr} != 0;
15 my $net = $lei->{net};
16 my $mics = $net->imap_common_init($lei);
17 pkt_do($lei->{pkt_op_p}, 'net_merge', $net) or
18 die "pkt_do net_merge: $!";
19 $net->{mics_cached} = $mics;
22 sub net_merge_done1 { # bump merge-count in top-level lei-daemon
24 return if ++$wq->{nr_net_merge_done} != $wq->{-wq_nr_workers};
25 $wq->net_merge_complete; # defined per wq-class (e.g. LeiImport)
28 sub net_merge_all { # called in wq worker via wq_broadcast
29 my ($wq, $net_new) = @_;
30 my $net = $wq->{lei}->{net};
31 %$net = (%$net, %$net_new);
32 pkt_do($wq->{lei}->{pkt_op_p}, 'net_merge_done1') or
33 die "pkt_op_do net_merge_done1: $!";
36 # called by top-level lei-daemon when first worker is done with auth
37 sub net_merge_continue {
38 my ($wq, $net_new) = @_;
39 $wq->wq_broadcast('net_merge_all', $net_new);
42 sub op_merge { # prepares PktOp->pair ops
43 my ($self, $ops, $wq) = @_;
44 $ops->{net_merge} = [ \&net_merge_continue, $wq ];
45 $ops->{net_merge_done1} = [ \&net_merge_done1, $wq ];
48 sub new { bless \(my $x), __PACKAGE__ }