line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Gnutella::Client;
|
2
|
1
|
|
|
1
|
|
1592
|
use IO::Socket;
|
|
1
|
|
|
|
|
30605
|
|
|
1
|
|
|
|
|
6
|
|
3
|
1
|
|
|
1
|
|
544
|
use Carp;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
4
|
1
|
|
|
1
|
|
15
|
use strict;
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
5
|
1
|
|
|
1
|
|
5
|
use vars qw/$VERSION $AUTOLOAD/;
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
536
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
$VERSION = $VERSION = "0.1";
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# Use AUTOHANDLER to supply generic attribute methods
|
10
|
|
|
|
|
|
|
#
|
11
|
|
|
|
|
|
|
sub AUTOLOAD {
|
12
|
0
|
|
|
0
|
|
|
my $self = shift;
|
13
|
0
|
|
|
|
|
|
my $attr = $AUTOLOAD;
|
14
|
0
|
|
|
|
|
|
$attr =~ s/.*:://;
|
15
|
0
|
0
|
|
|
|
|
return unless $attr =~ /[^A-Z]/; # skip DESTROY and all-cap methods
|
16
|
0
|
0
|
|
|
|
|
croak sprintf "invalid attribute method: %s->%s()", ref($self), $attr unless exists $self->{_attr}->{lc $attr};
|
17
|
0
|
0
|
|
|
|
|
$self->{_attr}->{lc $attr} = shift if @_;
|
18
|
0
|
|
|
|
|
|
return $self->{_attr}->{lc $attr};
|
19
|
|
|
|
|
|
|
}
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new {
|
22
|
0
|
|
|
0
|
0
|
|
my $proto = shift;
|
23
|
0
|
|
|
|
|
|
my $parent = shift;
|
24
|
0
|
|
|
|
|
|
my %args = @_;
|
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
my $self = {
|
27
|
|
|
|
|
|
|
_attr => {
|
28
|
|
|
|
|
|
|
proto => $proto,
|
29
|
|
|
|
|
|
|
parent => $parent,
|
30
|
|
|
|
|
|
|
debug => $parent->debug,
|
31
|
|
|
|
|
|
|
timeout=> $parent->timeout,
|
32
|
|
|
|
|
|
|
error => '',
|
33
|
|
|
|
|
|
|
server => '',
|
34
|
|
|
|
|
|
|
port => 6346,
|
35
|
|
|
|
|
|
|
},
|
36
|
|
|
|
|
|
|
};
|
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
bless $self, $proto;
|
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
foreach my $key (keys %args) {
|
41
|
0
|
|
|
|
|
|
my $lkey = lc $key;
|
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
$self->$lkey($args{$key});
|
44
|
|
|
|
|
|
|
}
|
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
return $self->connect;
|
47
|
|
|
|
|
|
|
}
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub connect {
|
50
|
0
|
|
|
0
|
0
|
|
my $self = shift;
|
51
|
|
|
|
|
|
|
|
52
|
0
|
0
|
|
|
|
|
unless ($self->server) {
|
53
|
0
|
|
|
|
|
|
$self->error("No server specified!");
|
54
|
0
|
|
|
|
|
|
return $self;
|
55
|
|
|
|
|
|
|
}
|
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
my $sock = new IO::Socket::INET
|
58
|
|
|
|
|
|
|
PeerAddr => $self->server,
|
59
|
|
|
|
|
|
|
PeerPort => $self->port,
|
60
|
|
|
|
|
|
|
Proto => "tcp";
|
61
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
unless ($sock) {
|
63
|
0
|
|
|
|
|
|
$self->error("Connect failed: $!");
|
64
|
0
|
|
|
|
|
|
return $self;
|
65
|
|
|
|
|
|
|
}
|
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
my $conn = Net::Gnutella::Connection->new($self->parent,
|
68
|
|
|
|
|
|
|
Debug => $self->debug,
|
69
|
|
|
|
|
|
|
Timeout => $self->timeout,
|
70
|
|
|
|
|
|
|
Socket => $sock,
|
71
|
|
|
|
|
|
|
Ip => $sock->peerhost,
|
72
|
|
|
|
|
|
|
Connected => 1,
|
73
|
|
|
|
|
|
|
);
|
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
$conn->_write_wrapper("GNUTELLA CONNECT/0.4\n\n");
|
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
return $conn;
|
78
|
|
|
|
|
|
|
}
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |