2 # Hello Thingy handling
4 # Note that this is a generator of pc19n and pc16n/pc16u
5 # and a consumer of fpc19n and fpc16n
9 # Copyright (c) 2005 Dirk Koopman G1TLH
14 package Thingy::Hello;
16 use vars qw($VERSION $BRANCH);
18 main::mkver($VERSION = q$Revision$);
24 use Thingy::RouteFilter;
27 use vars qw(@ISA $verify_on_login);
28 @ISA = qw(Thingy Thingy::RouteFilter);
30 $verify_on_login = 1; # make sure that a HELLO coming from
31 # the dxchan call is authentic
36 unless ($thing->{Aranea}) {
39 $thing->{sw} ||= 'DXSp';
40 $thing->{v} ||= $main::version;
41 $thing->{b} ||= $main::build;
43 $thing->{Aranea} = Aranea::genmsg($thing, [qw(sw v b s auth)]);
45 return $thing->{Aranea};
53 my $origin = $thing->{origin};
54 my $node = $dxchan->{call};
58 $thing->{pc19n} ||= [];
61 if ($node eq $origin) {
63 # for directly connected calls
64 if ($verify_on_login) {
65 my $pp = $dxchan->user->passphrase;
67 dbglog('err', "Thingy::Hello::handle: verify on and $origin has no passphrase");
71 my $auth = Verify->new("DXSp,$origin,$thing->{s},$thing->{v},$thing->{b}");
72 unless ($auth->verify($thing->{auth}, $dxchan->user->passphrase)) {
73 dbglog('err', "Thingy::Hello::handle: verify on and $origin failed auth check");
78 if ($dxchan->{state} ne 'normal') {
79 $nref = $main::routeroot->add($origin, $thing->{v}, 1);
80 push @{$thing->{pc19n}}, $nref if $nref;
81 $dxchan->start($dxchan->{conn}->{csort}, $dxchan->{conn}->{outbound} ? 'O' : 'A');
82 if ($dxchan->{outbound}) {
83 my $thing = Thingy::Hello->new();
84 $thing->send($dxchan);
86 # broadcast our configuration to the world
87 $thing = Thingy::Rt->new_lcf;
91 $nref = Route::Node::get($origin);
94 # for otherwise connected calls, that come in relayed from other nodes
95 # note that we cannot do any connections at this point
96 $nref = Route::Node::get($origin);
98 my $v = $thing->{user} ? undef : $thing->{v};
99 $nref = Route::Node->new($origin, $v, 1);
100 push @{$thing->{pc19n}}, $nref;
105 if (my $user = $thing->{user}) {
106 my $ur = Route::get($user);
108 my $uref = DXUser->get_current($user);
109 if ($uref->is_node || $uref->is_aranea) {
110 my $u = $nref->add($user, $thing->{v}, 1);
111 push @{$thing->{pc19n}}, $u if $u;
113 $thing->{pc16n} = $nref;
114 $thing->{pc16u} = [$nref->add_user($user, 1)];
118 RouteDB::update($origin, $node, $thing->{hopsaway});
119 RouteDB::update($thing->{user}, $node, $thing->{hopsaway}) if $thing->{user};
121 delete $thing->{pc19n} unless @{$thing->{pc19n}};
123 $thing->broadcast($dxchan);