| 1 | # -*- perl -*- | ||
| 2 | |||
| 3 | # Copyright (c) 2009 AdCopy | ||
| 4 | # Author: Jeff Weisberg | ||
| 5 | # Created: 2009-Mar-30 10:19 (EDT) | ||
| 6 | # Function: | ||
| 7 | # | ||
| 8 | # $Id$ | ||
| 9 | |||
| 10 | package AC::Yenta::Kibitz::Status::Server; | ||
| 11 | use AC::Dumper; | ||
| 12 | use AC::Yenta::Debug 'status_server'; | ||
| 13 | use strict; | ||
| 14 | |||
| 15 | |||
| 16 | sub handler { | ||
| 17 | my $class = shift; | ||
| 18 | my $io = shift; | ||
| 19 | my $proto = shift; | ||
| 20 | my $gpb = shift; | ||
| 21 | my $content = shift; | ||
| 22 | |||
| 23 | if( $gpb ){ | ||
| 24 | AC::Yenta::Kibitz::Status::update_sceptical( $gpb, $io ); | ||
| 25 | } | ||
| 26 | |||
| 27 | unless( $proto->{want_reply} ){ | ||
| 28 | $io->shut(); | ||
| 29 | return; | ||
| 30 | } | ||
| 31 | |||
| 32 | AC::Yenta::NetMon::update( $io ); | ||
| 33 | |||
| 34 | # respond with all known peers | ||
| 35 | my $response = AC::Yenta::Kibitz::Status::response(); | ||
| 36 | my $yp = AC::Yenta::Protocol->new(); | ||
| 37 | |||
| 38 | my $hdr = $yp->encode_header( | ||
| 39 | type => 'yenta_status', | ||
| 40 | data_length => length($response), | ||
| 41 | content_length => 0, | ||
| 42 | msgid => $proto->{msgid}, | ||
| 43 | is_reply => 1, | ||
| 44 | ); | ||
| 45 | |||
| 46 | debug("sending status reply"); | ||
| 47 | $io->write_and_shut( $hdr . $response ); | ||
| 48 | } | ||
| 49 | |||
| 50 | 1; |