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
38 unless ($thing->{Aranea}) {
40 $thing->{h} ||= $dxchan->here;
42 $thing->{sw} ||= 'DXSp';
43 $thing->{v} ||= $main::me->version;
44 $thing->{b} ||= $main::me->build;
45 $thing->{h} ||= $main::me->here;
49 $thing->{Aranea} = Aranea::genmsg($thing, [qw(sw h v b s auth)]);
51 return $thing->{Aranea};
59 my $origin = $thing->{origin};
60 my $node = $dxchan->{call};
64 $thing->{pc19n} ||= [];
68 $v = $DXProt::myprot_version + int ($v*100) if $v > 2 && $v < 3;
69 $v = $DXProt::myprot_version + 150 unless $v >= 5400;
75 if ($node eq $origin) {
77 # for directly connected calls
78 if ($verify_on_login && !$thing->{user}) {
79 my $pp = $dxchan->user->passphrase;
81 dbglog('err', "Thingy::Hello::handle: verify on and $origin has no passphrase");
85 my $auth = Verify->new("DXSp,$origin,$thing->{s},$thing->{v},$thing->{b}");
86 unless ($auth->verify($thing->{auth}, $dxchan->user->passphrase)) {
87 dbglog('err', "Thingy::Hello::handle: verify on and $origin failed auth check");
92 if ($dxchan->{state} ne 'normal') {
93 $nref = $main::routeroot->add($origin, $thing->{pcv}, $thing->{h});
94 push @{$thing->{pc19n}}, $nref if $nref;
95 $dxchan->start($dxchan->{conn}->{csort}, $dxchan->{conn}->{outbound} ? 'O' : 'A');
96 if ($dxchan->{outbound}) {
97 my $thing = Thingy::Hello->new();
98 $thing->send($dxchan);
100 # broadcast our configuration to the world
101 $thing = Thingy::Rt->new_cf;
105 $nref = Route::Node::get($origin);
109 # for otherwise connected calls, that come in relayed from other nodes
110 # note that we cannot do any connections at this point
111 $nref = Route::Node::get($origin);
113 my $v = $thing->{user} ? undef : $thing->{pcv};
114 $nref = Route::Node->new($origin, $v, 1);
115 push @{$thing->{pc19n}}, $nref;
121 if (my $user = $thing->{user}) {
122 my $ur = Route::get($user);
125 my $uref = DXUser->get_current($user) || Thingy::Rt::_upd_user_rec($user, $origin)->put;
126 if ($uref->is_node || $uref->is_aranea) {
127 push @ref, $nref->add($user, $thing->{pcv} || 0, $thing->{h} || 0);
128 push @{$thing->{pc19n}}, @ref if @ref;
129 do $_->np(1) for @ref;
131 $thing->{pc16n} = $nref;
132 push @ref, $nref->add_user($user, $thing->{h} || 0);
133 $thing->{pc16u} = \@ref if @ref;
137 $nref->version($v) unless $nref->version;
138 $nref->build($thing->{b}) unless $nref->build;
139 $nref->sw($thing->{sw}) unless $nref->sw;
140 $nref->here($thing->{h}) if exists $thing->{h};
143 RouteDB::update($origin, $node, $thing->{hopsaway});
144 RouteDB::update($thing->{user}, $node, $thing->{hopsaway}) if $thing->{user};
146 delete $thing->{pc19n} unless @{$thing->{pc19n}};
148 $thing->broadcast($dxchan);