+ # Populate the routing table
+ $self->populate_routing_table($pc->[7], $pc->[6], $pc->[8]);
+ my $r = Route::User::get($pc->[6]);
+ if ($pcno == 61) {
+ unless ($pc->[8] && is_ipaddr($pc->[8])) {
+ dbg("PCPROT: ROUTE $self->{call} NO IP ADDRESS in '$line'!");
+ }
+ }
+
+ # this is where we decide to delay PC11s in the hope that a PC61 will be along soon.
+ my $key = join '|', @spot[0..2,4,7]; # not including text
+
+ unless ($recurse) {
+
+ if ($pcno == 61) {
+
+ if ($pc11_saved{$key}) {
+ # before we promote because it's a better pc61, check that it's not a dupe (but don't insert it).
+ if (Spot::dup_find(@spot[0..4,7])) {
+ dbg("PCPROT: Duplicate Spot $self->{call}: $pc->[0] $key ignored\n") if isdbg('chanerr') || isdbg('dupespot') || isdbg('pc11');
+ delete $pc11_saved{$key};
+ return;
+ }
+
+ ++$pc11_to_61;
+
+ my $percent = $pc11_rx ? $pc11_to_61 * 100 / $pc11_rx : 0;
+ dbg(sprintf("PROMOTED $self->{call}: BETTER $pc->[0] $key, using pc61, WAITING pc11 DUMPED: $pc61_rx pc11: $pc11_rx better pc61: $pc11_to_61 (%0.1f%%)", $percent)) if isdbg("pc11");
+
+ delete $pc11_saved{$key}; # because we have promoted it, no longer needed.
+
+ # so unlike the promotion by route, there is a stored, but uncounted PC11
+ # which have discarded. But we have chosen to use better PC61 that's just come in
+ # so we allow the PC61 to be counted later, but count the now discarded PC11
+ # because it *did* come in.
+ ++$pc11_rx;
+ }
+ }
+
+ if ($pcno == 11) {
+
+ # if this fires then we have already had one or more PC11s but no PC61 for this spot
+ if ($pc11_saved{$key}) {
+ dbg("DUPE $self->{call} $pc->[0] key: $key is saved, ignored") if isdbg("pc11");
+ return; # because it's a dup
+ }
+
+ # before we promote by route, check that it's not been preceded by a previous PC61
+ if (Spot::dup_find(@spot[0..4,7])) {
+ my $s = exists $pc11_saved{$key} ? " stored $key removed" : "";
+ dbg("PCPROT: Duplicate Spot $self->{call}: PC11$s, recurse: $recurse, ignored\n") if isdbg('chanerr') || isdbg('dupespot') || isdbg('pc11');
+ delete $pc11_saved{$key};
+ return;
+ }
+
+
+ # If we have an ip address we can promote by route
+ if ($r && $r->ip) {
+ $pcno = 61;
+ $pc->[0] = 'PC61';
+ my $hops = $pc->[8];
+ $pc->[8] = $spot[14] = $r->ip;
+ ++$rpc11_to_61;
+ my $percent = $pc11_rx ? $rpc11_to_61 * 100 / $pc11_rx : 0;
+ dbg(sprintf("PROMOTED $self->{call}: ROUTE pc11 $key PROMOTED to pc61 with IP $spot[14] pc61: $pc61_rx pc11: $pc11_rx route->pc61 $rpc11_to_61 (%0.1f%%)", $percent)) if isdbg("pc11");
+ $line = join '^', @$pc, $hops, '~';
+
+ # update the stats (NOTE, thie record was a PC11, it has now become a PC61
+ # this is NOT the same choosing a better PC61, that is a separate record.
+ ++$pc11_rx; # 'cos we received as a PC11 it and it won't be a pc11 anymore
+ --$pc61_rx; # 'cos we'll increment it later as it's now a pc61, no double counting
+
+# dbg("CHANGED saved key: $key PC11 line to $line") if isdbg('pc11');
+ delete $pc11_saved{$key};
+ }
+
+ # if it is STILL (despite all efforts to change it) a PC11
+ # save it and wait - it will be called from pc11_process
+ if ($pcno == 11) {
+ $pc11_saved{$key} = [$main::systime, $self, $pcno, $line, $origin, $pc];
+ dbg("WAITING $self->{call}: NEW $pc->[0] spot $key waiting for a better offer") if isdbg("pc11");
+ return;
+ }
+ }
+ }
+