]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/LeiAuth.pm
099bdaca2a1fc454dc3770064c4d8ede7b7a38d4
[public-inbox.git] / lib / PublicInbox / LeiAuth.pm
1 # Copyright (C) 2021 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3
4 # Authentication worker for anything that needs auth for read/write IMAP
5 # (eventually for read-only NNTP access)
6 package PublicInbox::LeiAuth;
7 use strict;
8 use v5.10.1;
9 use PublicInbox::PktOp qw(pkt_do);
10
11 sub do_auth_atfork { # used by IPC WQ workers
12         my ($self, $wq) = @_;
13         return if $wq->{-wq_worker_nr} != 0;
14         my $lei = $wq->{lei};
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;
20 }
21
22 sub net_merge_done1 { # bump merge-count in top-level lei-daemon
23         my ($wq) = @_;
24         return if ++$wq->{nr_net_merge_done} != $wq->{-wq_nr_workers};
25         $wq->net_merge_complete; # defined per wq-class (e.g. LeiImport)
26 }
27
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: $!";
34 }
35
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);
40 }
41
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 ];
46 }
47
48 sub new { bless \(my $x), __PACKAGE__ }
49
50 1;