From fc524249acbf05e21de9d8ddeb399d8bdc55503d Mon Sep 17 00:00:00 2001 From: Lee Aylward Date: Sun, 21 Feb 2010 18:39:41 -0600 Subject: [PATCH] Prepare 0.8 release, limit connection rate --- README.pod | 2 ++ lib/App/Alice.pm | 2 +- lib/App/Alice.pod | 2 ++ lib/App/Alice/IRC.pm | 8 ++++++- share/log.db | Bin 83968 -> 0 bytes share/proxy.psgi | 49 ------------------------------------------- 6 files changed, 12 insertions(+), 51 deletions(-) delete mode 100644 share/log.db delete mode 100755 share/proxy.psgi diff --git a/README.pod b/README.pod index fe4737cf..45dea3a3 100644 --- a/README.pod +++ b/README.pod @@ -129,6 +129,8 @@ Ryan Baumann Paul Robins Ealice@mon.gsE +Clint Ecker + =head1 COPYRIGHT Copyright 2009 by Lee Aylward Eleedo@cpan.orgE diff --git a/lib/App/Alice.pm b/lib/App/Alice.pm index bca87ac0..8bb85970 100644 --- a/lib/App/Alice.pm +++ b/lib/App/Alice.pm @@ -11,7 +11,7 @@ use App::Alice::Logger; use Any::Moose; use File::Copy; -our $VERSION = '0.06'; +our $VERSION = '0.08'; has cond => ( is => 'rw', diff --git a/lib/App/Alice.pod b/lib/App/Alice.pod index f0b64f7f..a9fd821a 100644 --- a/lib/App/Alice.pod +++ b/lib/App/Alice.pod @@ -129,6 +129,8 @@ Ryan Baumann Paul Robins Ealice@mon.gsE +Clint Ecker + =head1 COPYRIGHT Copyright 2009 by Lee Aylward Eleedo@cpan.orgE diff --git a/lib/App/Alice/IRC.pm b/lib/App/Alice/IRC.pm index 081f3159..845310ae 100644 --- a/lib/App/Alice/IRC.pm +++ b/lib/App/Alice/IRC.pm @@ -47,7 +47,7 @@ has 'reconnect_timer' => ( is => 'rw' ); -has 'reconnect_count' => ( +has [qw/reconnect_count connect_time/] => ( is => 'rw', isa => 'Int', default => 0, @@ -182,6 +182,7 @@ sub connected { } else { $self->reset_reconnect_count; + $self->connect_time(time); $self->is_connected(1); } } @@ -192,6 +193,11 @@ sub reconnect { $self->log_info("too many failed reconnects, giving up"); return; } + my $interval = time - $self->connect_time; + if ($interval < 30) { + $time = 30 - $interval; + $self->log_info("last attempt was within 30 seconds, delaying $time seconds") + } $time = 60 unless $time >= 0; $self->log_info("reconnecting in $time seconds"); $self->reconnect_timer( diff --git a/share/log.db b/share/log.db deleted file mode 100644 index b88f65947d350106347dae173da107591f63de3e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 83968 zcmeIzO-vkR9LMqHdDsFi^p%#r0S^TVw3I@jw57$eP+D4`w6M{tjdTjrvW1 zP4*o<7!SsS@t_`z2jjsQV>}oS#)I)-JQxr4(u*F9iHY%`7ytiKQYFTV*YAYiZHr((fu%$G9-Nj=L%d~9qiAsI^~{MnlI;o=>2ReG-FagR^d;o`BNrefuI z>FVRlGcDKSE%JG@`uKtumrKrgH+(PXal6*(z)do+X!XFwnZ~txuu%?%Rv%2x-0qr| zzuj^+S6db?uC3iVTv>lVo`}tRld|c2uP!FNKnD0nO2fsCb-gm+v(oL^ zXQdBj&q=psPe>og>J?kF`=s}0YozyOb)GF*{cLkaSJ#wDNbk*DlWxrD8XGbb()F1k z={=d_(sh{w(k`<{x;C>}x+bGO)oESt?zFCVSK5=_nT|>qr%y?T(|YwaX;m#r>!(W7 zM!GDeYh0VsHLgoNEnS{c)r!=h^!ikf^oEqKbYp6}^rlpa^yZXQXv>RIl{(|CI@N8X zQdPRt?K;C9dMm76Nw+b{4vC(lO0rF&a+MMl*KwO98zri;UQ!_`m#mYlmFOx>AD*vjgq~RCP}kISN8CZ$i7vgGjEd|l<2dePt_qw zr$hx0OZ4s^ksOsAlc6Z*h^ggKSX^B2ZdQZasynchronous(1); - -use AnyEvent::HTTP; -use Tatsumaki::HTTPClient; - -sub get { - my $self = shift; - my $url = "http://localhost:8081" . $self->request->request_uri; - - # do progressive update for stream - if ($self->request->request_uri =~ /^\/stream/) { - http_request(GET => $url, - on_body => sub { - my ($body, $headers) = @_; - $self->write($body); - $self->flush(0); - if (!$body) { - $self->finish; - return 0; - } - return 1; - }, - sub { - $self->finish; - } - ); - return; - } - - # use our own image proxy - elsif ($self->request->request_uri =~ /^\/get\/(.+)/) { - $url = $1; - } - - # proxy regular requests - Tatsumaki::HTTPClient->new->get($url, $self->async_cb(sub { - my $res = shift; - $self->write($res->content); - $self->finish; - })); -} - -package main; -use Tatsumaki::Application; -my $app = Tatsumaki::Application->new( - [ '/' => 'HTTPProxyHandler' ] -);