# because it has to be used before a channel is fully initialised).
#
+sub formathead
+{
+ my $mycall = shift;
+ my $dts = shift;
+ my $hop = shift;
+ my $user = shift;
+ my $group = shift;
+
+ my $s = "$mycall,$dts,$hop";
+ $s .= ",$user" if $user;
+ if ($group) {
+ $s .= "," unless $user;
+ $s .= ",$group" if $group;
+ }
+ return $s;
+}
+
sub genheader
{
my $mycall = shift;
my $from = shift;
my $date = ((($dayno << 1) | $ntpflag) << 18) | ($main::systime % 86400);
- my $r = "$mycall," . sprintf('%6X%04X,0', $date, $seqno);
- $r .= ",$to" if $to;
- $r .= "," if $from && !$to;
- $r .= ",$from" if $from;
+ my $r = formathead($mycall, sprintf('%6X%04X', $date, $seqno), 0, $from, $to);
$seqno++;
$seqno = 0 if $seqno > 0x0ffff;
return $r;
my ($head, $data) = split /\|/, $line, 2;
return unless $head && $data;
- my ($origin, $dts, $hop, $group, $user) = split /,/, $head;
+ my ($origin, $dts, $hop, $user, $group) = split /,/, $head;
return if DXDupe::check("Ara,$origin,$dts", $dupeage);
my $err;
$err .= "incomplete header," unless $origin && $dts && defined $hop;
$thing = $class->new();
# reconstitute the header but wth hop increased by one
- $head = join(',', $origin, $dts, ++$hop);
- $head .= ",$group" if $group;
- $head .= ",$user" if $user;
+ $head = formathead($origin, $dts, ++$hop, $user, $group);
$thing->{Aranea} = "$head|$data";
# store useful data
my $dxchan = shift;
# verify authenticity
- if ($dxchan->call eq $thing->{origin}) {
+ if ($dxchan->{call} eq $thing->{origin}) {
+
+ # for directly connected calls
if ($verify_on_login) {
my $pp = $dxchan->user->passphrase;
unless ($pp) {
$thing->send($dxchan);
}
}
+ } else {
+
+ # for otherwise connected calls, that come in relayed from other nodes
+ # note that we cannot do any connections at this point
+ my $nref = Route::Node::get($thing->{origin});
+ unless ($nref) {
+ my $v = $thing->{user} ? undef : $thing->{v};
+ $nref = Route::Node->new($thing->{origin}, $v, 1);
+ }
+ if (my $user = $thing->{user}) {
+ my $ur = Route::get($user);
+ unless ($ur) {
+ my $uref = DXUser->get_current($user);
+ if ($uref->is_node || $uref->is_aranea) {
+ $nref->add($user, $thing->{v}, 1);
+ } else {
+ $nref->add_user($user, 1);
+ }
+ }
+ }
}
+ RouteDB::update($thing->{origin}, $dxchan->{call}, $thing->{hopsaway});
+ RouteDB::update($thing->{user}, $dxchan->{call}, $thing->{hopsaway}) if $thing->{user};
+
$thing->broadcast($dxchan);
}
my $thing = shift;
unless ($thing->{Aranea}) {
my @items;
- push @items, 't', $thing->{t} if $thing->{t};
- push @items, 'd', $thing->{d} if $thing->{d};
+ push @items, 's', $thing->{'s'} if $thing->{'s'};
+ push @items, 'n', $thing->{n} if $thing->{n};
+ push @items, 'v', $thing->{v} if $thing->{v};
+ push @items, 'u', $thing->{u} if $thing->{u};
$thing->{Aranea} = Aranea::genmsg($thing, 'RT', @items) if @items;
}
return $thing->{Aranea};
{
my $thing = shift;
my $dxchan = shift;
+ my $s = $thing->{'s'};
+ if ($s eq 'au') {
+ my $n = $thing->{n} || $thing->{user};
+ my @out;
+ if ($n && (my $u = $thing->{u})) {
+ my $s = '';
+ for (split /:/, $u) {
+ my ($here, $call) = unpack "A1 A*", $_;
+ my $str = sprintf "^%s * %d", $call, $here;
+ if (length($s) + length($str) > $DXProt::sentencelth) {
+ push @out, "PC16^$n" . $s . sprintf "^%s^", DXProt::get_hops(16);
+ $s = '';
+ }
+ $s .= $str;
+ }
+ push @out, "PC16^$n" . $s . sprintf "^%s^", DXProt::get_hops(16);
+ $thing->{DXProt} = @out > 1 ? \@out : $out[0];
+ }
+ } elsif ($s eq 'du') {
+ my $n = $thing->{n} || $thing->{user};
+ my $hops = DXProt::get_hops(17);
+ if ($n && (my $u = $thing->{u})) {
+ $thing->{DXProt} = "PC17^$u^$n^$hops^";
+ }
+ } elsif ($s eq 'an') {
+ } elsif ($s eq 'dn') {
+ }
return $thing->{DXProt};
}
}
}
-sub handle_eau
+# these contain users and either a node (for externals) or the from address
+sub handle_au
{
my $thing = shift;
my $dxchan = shift;
- if (my $d = $thing->{d}) {
- my $nref;
- for (split /:/, $d) {
- my ($type, $here, $call) = unpack "A1 A1 A*", $_;
- if ($type eq 'U') {
- unless ($nref) {
- dbg("Thingy::Rt::ea need a node before $call");
- return;
- }
+ my $node = $thing->{n} || $thing->{user};
+ my $nref = Route::Node::get($node);
+
+ if ($nref) {
+ if (my $u = $thing->{u}) {
+ for (split /:/, $u) {
+ my ($here, $call) = unpack "A1 A*", $_;
add_user($nref, $call, $here);
my $h = $dxchan->{call} eq $nref->{call} ? 3 : ($thing->{hops} || 99);
RouteDB::update($call, $dxchan->{call}, $h);
- } elsif ($type eq 'N') {
- $nref = Route::Node::get($call);
- unless ($nref) {
- dbg("Thingy::Rt::ea need a definition for $call");
- return;
- }
- my $h = $dxchan->{call} eq $nref->{call} ? 2 : ($thing->{hops} || 99);
- RouteDB::update($nref->{call}, $dxchan->{call}, $h);
- } else {
- dbg("Thingy::Rt::ea invalid type $type");
- return;
}
}
+ } else {
+ dbg("Thingy::Rt::au: $node not found") if isdbg('chanerr');
+ return;
}
return $thing;
}
-sub handle_edu
+sub handle_du
{
my $thing = shift;
my $dxchan = shift;
- if (my $d = $thing->{d}) {
- my $nref;
- for (split /:/, $d) {
- my ($type, $here, $call) = unpack "A1 A1 A*", $_;
- if ($type eq 'U') {
- unless ($nref) {
- dbg("Thingy::Rt::edu need a node before $call");
- return;
- }
+ my $node = $thing->{n} || $thing->{user};
+ my $nref = Route::Node::get($node);
+
+ if ($nref) {
+ if (my $u = $thing->{u}) {
+ for (split /:/, $u) {
+ my ($here, $call) = unpack "A1 A*", $_;
my $uref = Route::User::get($call);
unless ($uref) {
- dbg("Thingy::Rt::edu $call not a user") if isdbg('chanerr');
+ dbg("Thingy::Rt::du $call not a user") if isdbg('chanerr');
next;
}
$nref->del_user($uref);
RouteDB::delete($call, $dxchan->{call});
- } elsif ($type eq 'N') {
- $nref = Route::Node::get($call);
- unless ($nref) {
- dbg("Thingy::Rt::ed need a definition for $call");
- return;
- }
- RouteDB::update($nref->{call}, $dxchan->{call}, $dxchan->{call} eq $nref->{call} ? 2 : ($thing->{hops} || 99));
- } else {
- dbg("Thingy::Rt::ed invalid type $type");
- return;
}
+ RouteDB::update($nref->{call}, $dxchan->{call}, $dxchan->{call} eq $nref->{call} ? 2 : ($thing->{hops} || 99));
}
+ } else {
+ dbg("Thingy::Rt::du: $node not found") if isdbg('chanerr');
+ return;
}
+
return $thing;
}