line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
#=============================================================================== |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# FILE: SignalLine.pm |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# DESCRIPTION: Register the available nodes. |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# FILES: --- |
9
|
|
|
|
|
|
|
# BUGS: --- |
10
|
|
|
|
|
|
|
# NOTES: --- |
11
|
|
|
|
|
|
|
# AUTHOR: Felipe da Veiga Leprevost (Leprevost, F.V.), leprevost@cpan.org |
12
|
|
|
|
|
|
|
# ORGANIZATION: |
13
|
|
|
|
|
|
|
# CREATED: 07/07/2012 11:59:39 AM |
14
|
|
|
|
|
|
|
# REVISION: --- |
15
|
|
|
|
|
|
|
#=============================================================================== |
16
|
|
|
|
|
|
|
package Cobweb::SignalLine; |
17
|
1
|
|
|
1
|
|
1601
|
use 5.10.0; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
67
|
|
18
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
49
|
|
19
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
34
|
|
20
|
1
|
|
|
1
|
|
1009
|
use autodie; |
|
1
|
|
|
|
|
24694
|
|
|
1
|
|
|
|
|
8
|
|
21
|
1
|
|
|
1
|
|
6593
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
use File::HomeDir; |
23
|
|
|
|
|
|
|
use File::Path qw(make_path); |
24
|
|
|
|
|
|
|
use IO::Socket::Multicast; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 NAME |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Cobweb::SignalLine - class for detection of nodes in the network. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 DESCRIPTION |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
CobWeb::SignalLine is the class responsible for detecting all the ode ins the networ thru |
33
|
|
|
|
|
|
|
a multicast channel. All responsive nodes will be memorized in a text file located at |
34
|
|
|
|
|
|
|
HOME/.cobweb directory. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head2 group |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
is rw |
41
|
|
|
|
|
|
|
isa Str |
42
|
|
|
|
|
|
|
default set to 230.1.2.3 |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head2 port |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
is rw |
47
|
|
|
|
|
|
|
isa Int |
48
|
|
|
|
|
|
|
default set to 6001 |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 interface |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
is rw |
53
|
|
|
|
|
|
|
isa Str |
54
|
|
|
|
|
|
|
default set to 'eth0' |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head2 lookup |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
is rw |
59
|
|
|
|
|
|
|
isa Str |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 METHODS AND MODIFIERS |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 start |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
This methos instantiate the multicast function. The responsive nodes will have their IP |
66
|
|
|
|
|
|
|
stored in the nodes.cw file under the HOME/.cobweb directory. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 before start modifier |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
This modifier is responsible for the set up of the .cobweb directory. The modifier will look |
71
|
|
|
|
|
|
|
for a directory with this name, if doesnt find one, it creates a new one. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
has 'group' => ( |
76
|
|
|
|
|
|
|
is => 'rw', |
77
|
|
|
|
|
|
|
isa => 'Str', |
78
|
|
|
|
|
|
|
default => '230.1.2.3', |
79
|
|
|
|
|
|
|
); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
has 'port' => ( |
82
|
|
|
|
|
|
|
is => 'rw', |
83
|
|
|
|
|
|
|
isa => 'Int', |
84
|
|
|
|
|
|
|
default => '6001', |
85
|
|
|
|
|
|
|
); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
has 'interface' => ( |
88
|
|
|
|
|
|
|
is => 'rw', |
89
|
|
|
|
|
|
|
isa => 'Str', |
90
|
|
|
|
|
|
|
default => 'eth0', |
91
|
|
|
|
|
|
|
); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
has 'lookup' => ( |
94
|
|
|
|
|
|
|
is => 'rw', |
95
|
|
|
|
|
|
|
isa => 'Str', |
96
|
|
|
|
|
|
|
); |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
before 'start' => sub { |
100
|
|
|
|
|
|
|
my $self = shift; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
$self->lookup(File::HomeDir->my_home); |
103
|
|
|
|
|
|
|
unless (-e $self->lookup.'/.cobweb') { |
104
|
|
|
|
|
|
|
make_path($self->lookup.'/.cobweb'); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
}; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub start { |
109
|
|
|
|
|
|
|
my $self = shift; |
110
|
|
|
|
|
|
|
my $beacon = IO::Socket::Multicast->new(LocalPort => $self->port); |
111
|
|
|
|
|
|
|
$beacon->mcast_add($self->group,$self->interface); |
112
|
|
|
|
|
|
|
my %cache; |
113
|
|
|
|
|
|
|
my $data; |
114
|
|
|
|
|
|
|
while(1) { |
115
|
|
|
|
|
|
|
$beacon->recv($data,1024); |
116
|
|
|
|
|
|
|
$cache{$data} = 1 if !exists $cache{$data}; |
117
|
|
|
|
|
|
|
open (my $fh2, '>', $self->lookup.'/.cobweb/nodes.cw'); |
118
|
|
|
|
|
|
|
for my $k (keys %cache) { |
119
|
|
|
|
|
|
|
say $k; |
120
|
|
|
|
|
|
|
print $fh2 $k if defined $k; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
no Moose; |
126
|
|
|
|
|
|
|
1; |