From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id C48C31F725 for ; Thu, 9 Nov 2023 10:09:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1699524587; bh=kmW617wjHRuHmlwq+mDUcJ2bzV0cQMhZhNluPB6DaSM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=3F4NgCgC4pS4q2Lmm6nvC90im03oHz1Tpd4rWyZaeVCoxhhrA3Mh09TaN8HRprgBk R+hTpO4LY7zVattOs6n66EwJQWznB05L5WYrBD9CPPwkCBurK9RFU+MxiNb6uVcjxi o0PGyx4hXEaRrF6GwTrZdv9QiAFil8bs75Sas6lE= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 05/13] net_nntp_socks: more comments around how it works Date: Thu, 9 Nov 2023 10:09:38 +0000 Message-ID: <20231109100946.1440611-6-e@80x24.org> In-Reply-To: <20231109100946.1440611-1-e@80x24.org> References: <20231109100946.1440611-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This is convoluted as hell but I can't figure out a better way to make Net::NNTP work with SOCKS. --- lib/PublicInbox/NetNNTPSocks.pm | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/PublicInbox/NetNNTPSocks.pm b/lib/PublicInbox/NetNNTPSocks.pm index 5b15dd59..306dcacb 100644 --- a/lib/PublicInbox/NetNNTPSocks.pm +++ b/lib/PublicInbox/NetNNTPSocks.pm @@ -1,13 +1,13 @@ # Copyright (C) all contributors # License: AGPL-3.0+ -# wrap Net::NNTP client with SOCKS support +# wrap Net::NNTP client with SOCKS support. Convoluted, but AFAIK this +# is the only way to get SOCKS working with Net::NNTP w/o LD_PRELOAD. package PublicInbox::NetNNTPSocks; use v5.12; use Net::NNTP; -our %OPT; +our %OPT; # used to pass options between ->new_socks and our ->new our @ISA = qw(IO::Socket::Socks); -my @SOCKS_KEYS = qw(ProxyAddr ProxyPort SocksVersion SocksDebug SocksResolve); # use this instead of Net::NNTP->new if using Proxy* sub new_socks { @@ -16,9 +16,10 @@ sub new_socks { local @Net::NNTP::ISA = (qw(Net::Cmd), __PACKAGE__); local %OPT = map {; defined($opt{$_}) ? ($_ => $opt{$_}) : () - } @SOCKS_KEYS; + } qw(ProxyAddr ProxyPort SocksVersion SocksDebug SocksResolve); no warnings 'uninitialized'; # needed for $SOCKS_ERROR - Net::NNTP->new(%opt) // die "errors: \$!=$! SOCKS=", + my $ret = Net::NNTP->new(%opt); # calls PublicInbox::NetNNTPSocks::new + $ret // die "errors: \$!=$! SOCKS=", eval('$IO::Socket::Socks::SOCKS_ERROR // ""'), ', SSL=', (eval('IO::Socket::SSL->errstr') // ''), "\n";