2 # The RBN connection system
4 # Copyright (c) 2020 Dirk Koopman G1TLH
19 use Math::Round qw(nearest);
21 our @ISA = qw(DXChannel);
25 my $self = DXChannel::alloc(@_);
27 # routing, this must go out here to prevent race condx
31 DXProt::_add_thingy($main::routeroot, [$call, 0, 0, 1, undef, undef, $self->hostname], );
39 $self->{lasttime} = $main::systime;
40 $self->{minspottime} = 60*60;
41 $self->{showstats} = 0;
48 my ($self, $line, $sort) = @_;
49 my $user = $self->{user};
50 my $call = $self->{call};
51 my $name = $user->{name};
52 my $dref = $self->{d};
53 my $spotref = $self->{spot};
56 my $host = $self->{conn}->peerhost;
58 $self->{hostname} = $host;
60 $self->{name} = $name ? $name : $call;
61 $self->state('prompt'); # a bit of room for further expansion, passwords etc
62 $self->{lang} = $user->lang || $main::lang || 'en';
63 if ($line =~ /host=/) {
64 my ($h) = $line =~ /host=(\d+\.\d+\.\d+\.\d+)/;
65 $line =~ s/\s*host=\d+\.\d+\.\d+\.\d+// if $h;
67 ($h) = $line =~ /host=([\da..fA..F:]+)/;
68 $line =~ s/\s*host=[\da..fA..F:]+// if $h;
70 $self->{hostname} = $h if $h;
72 $self->{width} = 80 unless $self->{width} && $self->{width} > 80;
73 $self->{consort} = $line; # save the connection type
75 LogDbg('DXCommand', "$call connected from $self->{hostname}");
77 # set some necessary flags on the user if they are connecting
78 $self->{registered} = 1;
79 # sort out privilege reduction
86 $self->{spotsfilter} = Filter::read_in('spots', $call, 0)
87 || Filter::read_in('spots', $nossid, 0)
88 || Filter::read_in('spots', 'user_default', 0);
90 # clean up qra locators
92 $qra = undef if ($qra && !DXBearing::is_qra($qra));
95 my $long = $user->long;
96 $user->qra(DXBearing::lltoqra($lat, $long)) if (defined $lat && defined $long);
106 my $spot = $self->{spot};
108 # save this for them's that need it
111 # remove leading and trailing spaces
118 my $tim = $main::systime;
121 dbg "RBN:RAW,$line" if isdbg('rbnraw');
123 my ($origin, $qrg, $call, $mode, $s, $m, $spd, $u, $sort, $t, $tx) = split /[:\s]+/, $line;
125 dbg qq{0:$origin 1:$qrg 2:$call 3:$mode 4:$s 5:m 6:$spd 7:$u 8:$sort 9:$t 10:$tx} if $line =~ /DX/;
131 # fix up times for things like 'NXDXF B' etc
132 if ($tx && $t !~ /^\d{4}Z$/) {
133 if ($tx =~ /^\d{4}Z$/) {
142 # We have an RBN data line, dedupe it very simply on time, ignore QRG completely.
143 # This works because the skimmers are NTP controlled (or should be) and will receive
144 # the spot at the same time (velocity factor of the atmosphere and network delays
145 # carefully (not) taken into account :-)
147 # Note, there is no intelligence here, but there are clearly basic heuristics that could
148 # be applied at this point that reject (more likely rewrite) the call of a busted spot that would
149 # useful for a zonal hotspot requirement from the cluster node.
151 # In reality, this mechanism would be incorporated within the cluster code, utilising the dxqsl database,
152 # and other resources in DXSpider, thus creating a zone map for an emitted spot. This is then passed through the
153 # normal "to-user" spot system (where normal spots are sent to be displayed per user) and then be
154 # processed through the normal, per user, spot filtering system - like a regular spot.
156 # The key to this is deducing the true callsign by "majority voting" (the greater the number of spotters
157 # the more effective this is) together with some lexical analsys probably in conjuction with DXSpider
158 # data sources (for singleton spots) to then generate a "centre" from and to zone (whatever that will mean if it isn't the usual one)
159 # and some heuristical "Kwalitee" rating given distance from the zone centres of spotter, recipient user
160 # and spotted. A map can be generated once per user and spotter as they are essentially mostly static.
161 # The spotted will only get a coarse position unless other info is available. Programs that parse
162 # DX bulletins and the online data online databases could be be used and then cached.
164 # Obviously users have to opt in to receiving RBN spots and other users will simply be passed over and
167 # Clearly this will only work in the 'mojo' branch of DXSpider where it is possible to pass off external
168 # data requests to ephemeral or semi resident forked processes that do any grunt work and the main
169 # process to just the standard "message passing" which has been shown to be able to sustain over 5000
170 # per second (limited by the test program's output and network speed, rather than DXSpider's handling).
179 $qrg = sprintf('%.1f', nearest(.1, $qrg)); # to nearest 100Hz (to catch the odd multiple decpl QRG [eg '7002.07']).
180 if (isdbg('rbnraw')) {
181 my $ss = join(',', "RBN", $origin, $qrg, $call, $mode, $s, $m, $spd, $u, $sort, $t);
186 # Determine whether to "SPOT" it based on whether we have not seen it before (near this QRG) or,
187 # if we have, has it been a "while" since the last time we spotted it? If it has been spotted
188 # before then "RESPOT" it.
189 my $nqrg = nearest(1, $qrg); # normalised to nearest Khz
190 my $sp = "$call|$nqrg"; # hopefully the skimmers will be calibrated at least this well!
191 my $ts = $spot->{$sp};
193 if (!$ts || ($self->{minspottime} > 0 && $tim - $ts >= $self->{minspottime})) {
195 my $tag = $ts ? "RESPOT" : "SPOT";
197 dbg "RBN:" . join(',', $tag, $origin, $qrg, $call, $mode, $s, $m, $spd, $u, $sort, $t);
201 dbg "RBN:DATA,$line" if isdbg('rbn');
204 # periodic clearing out of the two caches
205 if (($tim % 60 == 0 && $tim > $self->{last}) || ($self->{last} && $tim >= $self->{last} + 60)) {
209 while (my ($k,$v) = each %{$d}) {
217 dbg "RBN:ADMIN,rbn cache: $removed removed $count remain" if isdbg('rbn');
218 $count = $removed = 0;
219 while (my ($k,$v) = each %{$spot}) {
220 if ($tim-$v > $self->{minspottime}*2) {
227 dbg "RBN:ADMIN,spot cache: $removed removed $count remain" if isdbg('rbn');
229 dbg "RBN:" . join(',', "STAT", $self->{noraw}, $self->{norbn}, $self->{nospot}) if $self->{showstats};
230 $self->{noraw} = $self->{norbn} = $self->{nospot} = 0;
232 $self->{last} = int($tim / 60) * 60;