X-Git-Url: http://dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FThingy%2FHello.pm;h=7221d7898722fc58dd15a451b388211d5ada13fd;hb=7abfb64b58d106d8352eb365b63cec23669c4e0d;hp=111abf8b2a46cc48e05ff1b60a025193055b6d28;hpb=6f20114b034d329c1e2a4f91f0aba2f6ec4002d4;p=spider.git diff --git a/perl/Thingy/Hello.pm b/perl/Thingy/Hello.pm index 111abf8b..7221d789 100644 --- a/perl/Thingy/Hello.pm +++ b/perl/Thingy/Hello.pm @@ -1,6 +1,9 @@ # # Hello Thingy handling # +# Note that this is a generator of pc19n and pc16n/pc16u +# and a consumer of fpc19n and fpc16n +# # $Id$ # # Copyright (c) 2005 Dirk Koopman G1TLH @@ -11,37 +14,138 @@ use strict; package Thingy::Hello; use vars qw($VERSION $BRANCH); -$VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ ); -$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0)); -$main::build += $VERSION; -$main::branch += $BRANCH; + +main::mkver($VERSION = q$Revision$); use DXChannel; use DXDebug; use Verify; use Thingy; +use Thingy::RouteFilter; +use Thingy::Rt; -use vars qw(@ISA); -@ISA = qw(Thingy); +use vars qw(@ISA $verify_on_login); +@ISA = qw(Thingy Thingy::RouteFilter); + +$verify_on_login = 1; # make sure that a HELLO coming from + # the dxchan call is authentic sub gen_Aranea { my $thing = shift; + my $dxchan = shift; + unless ($thing->{Aranea}) { - my $auth = $thing->{auth} = Verify->new($main::mycall, $main::systime); - $thing->{Aranea} = Aranea::genmsg($thing, 'HELLO', sw=>'DXSpider', - v=>$main::version, - b=>$main::build, - auth=>$auth->challenge($main::me->user->passphrase) - ); + if ($thing->{user}) { + $thing->{h} ||= $dxchan->here; + } else { + $thing->{sw} ||= 'DXSp'; + $thing->{v} ||= $main::me->version; + $thing->{b} ||= $main::me->build; + $thing->{h} ||= $main::me->here; + $thing->add_auth; + } + + $thing->{Aranea} = Aranea::genmsg($thing, [qw(sw h v b s auth)]); } return $thing->{Aranea}; } -sub from_Aranea +sub handle { - my $line = shift; - my $thing = Aranea::input($line); - return unless $thing; + my $thing = shift; + my $dxchan = shift; + + my $origin = $thing->{origin}; + my $node = $dxchan->{call}; + + my $nref; + + $thing->{pc19n} ||= []; + + my $v = $thing->{v}; + if ($v) { + $v = $DXProt::myprot_version + int ($v*100) if $v > 2 && $v < 3; + $v = $DXProt::myprot_version + 150 unless $v >= 5400; + $v =~ s/\.\d+$//; + $thing->{pcv} = $v; + } + + # verify authenticity + if ($node eq $origin) { + + # for directly connected calls + if ($verify_on_login && !$thing->{user}) { + my $pp = $dxchan->user->passphrase; + unless ($pp) { + dbglog('err', "Thingy::Hello::handle: verify on and $origin has no passphrase"); + $dxchan->disconnect; + return; + } + my $auth = Verify->new("DXSp,$origin,$thing->{s},$thing->{v},$thing->{b}"); + unless ($auth->verify($thing->{auth}, $dxchan->user->passphrase)) { + dbglog('err', "Thingy::Hello::handle: verify on and $origin failed auth check"); + $dxchan->disconnect; + return; + } + } + if ($dxchan->{state} ne 'normal') { + $nref = $main::routeroot->add($origin, $thing->{pcv}, $thing->{h}); + push @{$thing->{pc19n}}, $nref if $nref; + $dxchan->start($dxchan->{conn}->{csort}, $dxchan->{conn}->{outbound} ? 'O' : 'A'); + if ($dxchan->{outbound}) { + my $thing = Thingy::Hello->new(); + $thing->send($dxchan); + + # broadcast our configuration to the world + $thing = Thingy::Rt->new_cf; + $thing->broadcast; + } + } + $nref = Route::Node::get($origin); + $nref->np(1); + } else { + + # for otherwise connected calls, that come in relayed from other nodes + # note that we cannot do any connections at this point + $nref = Route::Node::get($origin); + unless ($nref) { + my $v = $thing->{user} ? undef : $thing->{pcv}; + $nref = Route::Node->new($origin, $v, 1); + push @{$thing->{pc19n}}, $nref; + $nref->np(1); + } + } + + # handle "User" + if (my $user = $thing->{user}) { + my $ur = Route::get($user); + unless ($ur) { + my @ref; + my $uref = DXUser->get_current($user) || Thingy::Rt::_upd_user_rec($user, $origin)->put; + if ($uref->is_node || $uref->is_aranea) { + push @ref, $nref->add($user, $thing->{pcv} || 0, $thing->{h} || 0); + push @{$thing->{pc19n}}, @ref if @ref; + do $_->np(1) for @ref; + } else { + $thing->{pc16n} = $nref; + push @ref, $nref->add_user($user, $thing->{h} || 0); + $thing->{pc16u} = \@ref if @ref; + } + } + } else { + $nref->version($v) unless $nref->version; + $nref->build($thing->{b}) unless $nref->build; + $nref->sw($thing->{sw}) unless $nref->sw; + $nref->here($thing->{h}) if exists $thing->{h}; + } + + RouteDB::update($origin, $node, $thing->{hopsaway}); + RouteDB::update($thing->{user}, $node, $thing->{hopsaway}) if $thing->{user}; + + delete $thing->{pc19n} unless @{$thing->{pc19n}}; + + $thing->broadcast($dxchan); } + 1;