From 07b5a335656be741353ab70c1d4717dacdbebc1b Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 18 Oct 2011 09:17:10 -0400 Subject: [PATCH] Warn when sending very large messages Depending on configuration, messages of a certain size sent through a Jabber server will cause the jabber server to disconnect the client. This change allows admins to configure a message size warning threshold. When a message meets or exceeds the size threshold, a warning is issued to the logs with the message size (in bytes) and the message recipient. It does not prevent the message from being delivered. It's purely informational. Use 1 800 000 as the default threhold. Signed-off-by: Bill Erickson Signed-off-by: Galen Charlton --- examples/opensrf_core.xml.example | 3 +++ src/perl/lib/OpenSRF/Transport/SlimJabber/Client.pm | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/examples/opensrf_core.xml.example b/examples/opensrf_core.xml.example index a1f2498..816a20c 100644 --- a/examples/opensrf_core.xml.example +++ b/examples/opensrf_core.xml.example @@ -41,6 +41,9 @@ vim:et:ts=2:sw=2: this should match one of the of the private router above --> router + + 1800000 + LOCALSTATEDIR/log/osrfsys.log diff --git a/src/perl/lib/OpenSRF/Transport/SlimJabber/Client.pm b/src/perl/lib/OpenSRF/Transport/SlimJabber/Client.pm index 2db8be7..a3f9233 100644 --- a/src/perl/lib/OpenSRF/Transport/SlimJabber/Client.pm +++ b/src/perl/lib/OpenSRF/Transport/SlimJabber/Client.pm @@ -109,7 +109,15 @@ sub send { my $msg = OpenSRF::Transport::SlimJabber::XMPPMessage->new(@_); $msg->osrf_xid($logger->get_osrf_xid); $msg->from($self->xmpp_id); - $self->reader->send($msg->to_xml); + my $xml = $msg->to_xml; + { + use bytes; + my $len = length($xml); + if ($len >= $self->{msg_size_warn}) { + $logger->warn("Sending large message of $len bytes to " . $msg->to) + } + } + $self->reader->send($xml); } =head2 initialize @@ -128,6 +136,8 @@ sub initialize { my $conf = OpenSRF::Utils::Config->current; + $self->{msg_size_warn} = $conf->bootstrap->msg_size_warn || 1800000; + my $tail = "_$$"; $tail = "" if !$conf->bootstrap->router_name and $username eq "router"; $resource = "$resource$tail"; -- 2.43.2