2 # Copyright (C) 2015 all contributors <meta@public-inbox.org>
3 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
6 require PublicInbox::Daemon;
7 require PublicInbox::NewsGroup;
8 require PublicInbox::NNTP;
9 my $nntpd = PublicInbox::NNTPD->new;
10 daemon_run('0.0.0.0:119',
11 sub { $nntpd->refresh_groups },
12 sub ($) { PublicInbox::NNTP->new($_[0], $nntpd) });
15 package PublicInbox::NNTPD;
18 use fields qw(groups grouplist err out);
22 my $self = fields::new($class);
24 $self->{err} = \*STDERR;
25 $self->{out} = \*STDOUT;
26 $self->{grouplist} = [];
30 sub refresh_groups () {
32 require PublicInbox::Config;
33 my $pi_config = PublicInbox::Config->new;
36 foreach my $k (keys %$pi_config) {
37 $k =~ /\Apublicinbox\.([^\.]+)\.mainrepo\z/ or next;
39 my $git_dir = $pi_config->{$k};
40 my $addr = $pi_config->{"publicinbox.$g.address"};
41 my $ngname = $pi_config->{"publicinbox.$g.newsgroup"};
42 if (defined $ngname) {
43 next if ($ngname eq ''); # disabled
46 my $ng = PublicInbox::NewsGroup->new($g, $git_dir, $addr);
47 my $old_ng = $self->{groups}->{$g};
49 # Reuse the old one if possible since it can hold
50 # references to valid mm and gcf objects
56 # Only valid if Msgmap works
62 @list = sort { $a->{name} cmp $b->{name} } @list;
63 $self->{grouplist} = \@list;
64 # this will destroy old groups that got deleted
65 %{$self->{groups}} = %$new;