From: Mark Bergsma Date: Wed, 6 Apr 2005 17:14:43 +0000 (+0000) Subject: HTCP Multicast Squid purging support X-Git-Tag: 1.5.0alpha1~381 X-Git-Url: http://git.cyclocoop.org/%28?a=commitdiff_plain;h=e2bf8490320c4a3bda8296fddee25be4257acffb;p=lhc%2Fweb%2Fwiklou.git HTCP Multicast Squid purging support Uses (UDP) HTCP packets to send 'CLR' (purge) requests to Squids, using a multicast group address. Needs a patched Squid (Squid doesn't support HTCP CLR): http://www.nedworks.org/~mark/patches/squid-htcp-clr.diff --- diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index da27ddaf88..fadfd72412 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -662,6 +662,10 @@ $wgSquidServersNoPurge = array(); /** Maximum number of titles to purge in any one client operation */ $wgMaxSquidPurgeTitles = 400; +/** HTCP multicast purging */ +$wgHTCPPort = 4827; +$wgHTCPMulticastTTL = 1; +# $wgHTCPMulticastAddress = "224.0.0.85"; # Cookie settings: # diff --git a/includes/SquidUpdate.php b/includes/SquidUpdate.php index 294fca4e43..d971d0a63b 100644 --- a/includes/SquidUpdate.php +++ b/includes/SquidUpdate.php @@ -91,13 +91,16 @@ class SquidUpdate { XXX report broken Squids per mail or log */ /* static */ function purge( $urlArr ) { - global $wgSquidServers; + global $wgSquidServers, $wgHTCPMulticastAddress, $wgHTCPPort; if ( $wgSquidServers == 'echo' ) { echo implode("
\n", $urlArr); return; } + if ( $wgHTCPMulticastAddress && $wgHTCPPort ) + SquidUpdate::HTCPPurge( $urlArr ); + $fname = 'SquidUpdate::purge'; wfProfileIn( $fname ); @@ -200,6 +203,59 @@ class SquidUpdate { wfProfileOut( $fname ); } + /* static */ function HTCPPurge( $urlArr ) { + global $wgHTCPMulticastAddress, $wgHTCPMulticastTTL, $wgHTCPPort; + $fname = 'SquidUpdate::HTCPPurge'; + wfProfileIn( $fname ); + + $htcpOpCLR = 4; // HTCP CLR + + // FIXME PHP doesn't support these socket constants (include/linux/in.h) + define( "IPPROTO_IP", 0 ); + define( "IP_MULTICAST_LOOP", 34 ); + define( "IP_MULTICAST_TTL", 33 ); + + // pfsockopen doesn't work because we need set_sock_opt + $conn = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP ); + if ( $conn ) { + // Set socket options + socket_set_option( $conn, IPPROTO_IP, IP_MULTICAST_LOOP, 0 ); + if ( $wgHTCPMulticastTTL != 1 ) + socket_set_option( $conn, IPPROTO_IP, IP_MULTICAST_TTL, + $wgHTCPMulticastTTL ); + + foreach ( $urlArr as $url ) { + // Construct a minimal HTCP request diagram + // as per RFC 2756 + // Opcode 'CLR', no response desired, no auth + $htcpTransID = rand(); + + $htcpSpecifier = pack( 'na4na*na8n', + 4, 'NONE', strlen( $url ), $url, + 8, 'HTTP/1.0', 0 ); + + $htcpDataLen = 8 + 2 + strlen( $htcpSpecifier ); + $htcpLen = 4 + $htcpDataLen + 2; + + // Note! Squid gets the bit order of the first + // word wrong, wrt the RFC. Apparently no other + // implementation exists, so adapt to Squid + $htcpPacket = pack( 'nxxnCxNxxa*n', + $htcpLen, $htcpDataLen, $htcpOpCLR, + $htcpTransID, $htcpSpecifier, 2); + + // Send out + debug( "Purging URL $url via HTCP\n" ); + socket_sendto( $conn, $htcpPacket, $htcpLen, 0, + $wgHTCPMulticastAddress, $wgHTCPPort ); + } + } else { + $errstr = socket_strerror( socket_last_error() ); + debug( "SquidUpdate::HTCPPurge(): Error opening UDP socket: $errstr\n" ); + } + wfProfileOut( $fname ); + } + function debug( $text ) { global $wgDebugSquid; if ( $wgDebugSquid ) {