line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Gnutella::Server;
|
2
|
1
|
|
|
1
|
|
649
|
use Net::Gnutella::Connection;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
34
|
|
3
|
1
|
|
|
1
|
|
10
|
use IO::Socket;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
11
|
|
4
|
1
|
|
|
1
|
|
771
|
use Carp;
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
61
|
|
5
|
1
|
|
|
1
|
|
4
|
use strict;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
6
|
1
|
|
|
1
|
|
6
|
use vars qw/$VERSION $AUTOLOAD/;
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
560
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
$VERSION = $VERSION = "0.1";
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# Use AUTOHANDLER to supply generic attribute methods
|
11
|
|
|
|
|
|
|
#
|
12
|
|
|
|
|
|
|
sub AUTOLOAD {
|
13
|
0
|
|
|
0
|
|
|
my $self = shift;
|
14
|
0
|
|
|
|
|
|
my $attr = $AUTOLOAD;
|
15
|
0
|
|
|
|
|
|
$attr =~ s/.*:://;
|
16
|
0
|
0
|
|
|
|
|
return unless $attr =~ /[^A-Z]/; # skip DESTROY and all-cap methods
|
17
|
0
|
0
|
|
|
|
|
croak sprintf "invalid attribute method: %s->%s()", ref($self), $attr unless exists $self->{_attr}->{lc $attr};
|
18
|
0
|
0
|
|
|
|
|
$self->{_attr}->{lc $attr} = shift if @_;
|
19
|
0
|
|
|
|
|
|
return $self->{_attr}->{lc $attr};
|
20
|
|
|
|
|
|
|
}
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub accept {
|
23
|
0
|
|
|
0
|
0
|
|
my $self = shift;
|
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
my $server = IO::Socket::INET->new(
|
26
|
|
|
|
|
|
|
Listen => SOMAXCONN,
|
27
|
|
|
|
|
|
|
LocalAddr => $self->server,
|
28
|
|
|
|
|
|
|
LocalPort => $self->port,
|
29
|
|
|
|
|
|
|
Reuse => 1,
|
30
|
|
|
|
|
|
|
);
|
31
|
|
|
|
|
|
|
|
32
|
0
|
0
|
|
|
|
|
unless (defined $server) {
|
33
|
0
|
|
|
|
|
|
$self->error("Couldn't bind to port: $!");
|
34
|
0
|
|
|
|
|
|
return;
|
35
|
|
|
|
|
|
|
}
|
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
$self->socket($server);
|
38
|
0
|
|
|
|
|
|
$self->server($server->sockhost);
|
39
|
0
|
|
|
|
|
|
$self->port($server->sockport);
|
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
$self->parent->_add_fh($self->socket, $self->can("_accept"), "r", $self);
|
42
|
|
|
|
|
|
|
}
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub connections {
|
45
|
0
|
|
|
0
|
0
|
|
my $self = shift;
|
46
|
0
|
|
|
|
|
|
my @ret;
|
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
foreach my $key (keys %{ $self->{_connhash} }) {
|
|
0
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
my $conn = $self->{_connhash}->{$key};
|
50
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
next unless $conn->connected;
|
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
push @ret, $conn;
|
54
|
|
|
|
|
|
|
}
|
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
return @ret;
|
57
|
|
|
|
|
|
|
}
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub new {
|
60
|
0
|
|
|
0
|
0
|
|
my $proto = shift;
|
61
|
0
|
|
|
|
|
|
my $parent = shift;
|
62
|
0
|
|
|
|
|
|
my %args = @_;
|
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
my $self = {
|
65
|
|
|
|
|
|
|
_attr => {
|
66
|
|
|
|
|
|
|
parent => $parent,
|
67
|
|
|
|
|
|
|
debug => $parent->debug,
|
68
|
|
|
|
|
|
|
timeout => $parent->timeout,
|
69
|
|
|
|
|
|
|
error => '',
|
70
|
|
|
|
|
|
|
socket => '',
|
71
|
|
|
|
|
|
|
server => undef,
|
72
|
|
|
|
|
|
|
port => 6346,
|
73
|
|
|
|
|
|
|
allow => 0,
|
74
|
|
|
|
|
|
|
},
|
75
|
|
|
|
|
|
|
};
|
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
bless $self, $proto;
|
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
foreach my $key (keys %args) {
|
80
|
0
|
|
|
|
|
|
my $lkey = lc $key;
|
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
$self->$lkey($args{$key});
|
83
|
|
|
|
|
|
|
}
|
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
$self->accept;
|
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
return $self;
|
88
|
|
|
|
|
|
|
}
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub _accept {
|
91
|
0
|
|
|
0
|
|
|
my $self = shift;
|
92
|
0
|
|
0
|
|
|
|
my $sock = $self->socket->accept || return;
|
93
|
|
|
|
|
|
|
|
94
|
0
|
0
|
|
|
|
|
printf STDERR "+ Accepted connection from '%s'\n", $sock->peerhost if $self->debug;
|
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
my $conn = Net::Gnutella::Connection->new($self->parent,
|
97
|
|
|
|
|
|
|
Debug => $self->debug,
|
98
|
|
|
|
|
|
|
Timeout => $self->timeout,
|
99
|
|
|
|
|
|
|
Allow => $self->allow,
|
100
|
|
|
|
|
|
|
Socket => $sock,
|
101
|
|
|
|
|
|
|
Ip => $sock->peerhost,
|
102
|
|
|
|
|
|
|
Connected => 2,
|
103
|
|
|
|
|
|
|
);
|
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
$self->{_connhash}->{$sock} = $conn;
|
106
|
|
|
|
|
|
|
}
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1;
|