+
+
+#
+# send a talk message to this thingy
+#
+sub talk
+{
+ my ($self, $from, $to, $via, $line, $origin) = @_;
+
+ $line =~ s/\^/\\5E/g; # remove any ^ characters
+ $self->send(DXProt::pc10($from, $to, $via, $line, $origin));
+ Log('talk', $self->call, $from, $via?$via:$main::mycall, $line) unless $origin && $origin ne $main::mycall;
+}
+
+# send it if it isn't the except list and isn't isolated and still has a hop count
+# taking into account filtering and so on
+sub send_route
+{
+ my $self = shift;
+ my $generate = shift;
+ my $no = shift; # the no of things to filter on
+ my $routeit;
+ my ($filter, $hops);
+ my @rin;
+
+ for (; @_ && $no; $no--) {
+ my $r = shift;
+
+ if (!$self->{isolate} && $self->{routefilter}) {
+ $filter = undef;
+ if ($r) {
+ ($filter, $hops) = $self->{routefilter}->it($self->{call}, $self->{dxcc}, $self->{itu}, $self->{cq}, $r->call, $r->dxcc, $r->itu, $r->cq);
+ if ($filter) {
+ push @rin, $r;
+ } else {
+ dbg("DXPROT: $self->{call}/" . $r->call . " rejected by output filter") if isdbg('chanerr');
+ }
+ } else {
+ dbg("was sent a null value") if isdbg('chanerr');
+ }
+ } else {
+ push @rin, $r unless $self->{isolate} && $r->call ne $main::mycall;
+ }
+ }
+ if (@rin) {
+ foreach my $line (&$generate(@rin, @_)) {
+ if ($hops) {
+ $routeit = $line;
+ $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
+ } else {
+ $routeit = adjust_hops($self, $line); # adjust its hop count by node name
+ next unless $routeit;
+ }
+ $self->send($routeit);
+ }
+ }
+}
+
+sub broadcast_route
+{
+ my $self = shift;
+ my $generate = shift;
+ my @dxchan = DXChannel::get_all_nodes();
+ my $dxchan;
+ my $line;
+
+ unless ($self->{isolate}) {
+ foreach $dxchan (@dxchan) {
+ next if $dxchan == $self;
+ next if $dxchan == $me;
+ $dxchan->send_route($generate, @_);
+ }
+ }
+}
+
+sub route_pc16
+{
+ my $self = shift;
+ broadcast_route($self, \&pc16, 1, @_);
+}
+
+sub route_pc17
+{
+ my $self = shift;
+ broadcast_route($self, \&pc17, 1, @_);
+}
+
+sub route_pc19
+{
+ my $self = shift;
+ broadcast_route($self, \&pc19, scalar @_, @_);
+}
+
+sub route_pc21
+{
+ my $self = shift;
+ broadcast_route($self, \&pc21, scalar @_, @_);
+}
+
+sub route_pc24
+{
+ my $self = shift;
+ broadcast_route($self, \&pc24, 1, @_);
+}
+
+sub route_pc41
+{
+ my $self = shift;
+ broadcast_route($self, \&pc41, 1, @_);
+}
+
+sub route_pc50
+{
+ my $self = shift;
+ broadcast_route($self, \&pc50, 1, @_);
+}
+
+sub in_filter_route
+{
+ my $self = shift;
+ my $r = shift;
+ my ($filter, $hops) = (1, 1);
+
+ if ($self->{inroutefilter}) {
+ ($filter, $hops) = $self->{inroutefilter}->it($self->{call}, $self->{dxcc}, $self->{itu}, $self->{cq}, $r->call, $r->dxcc, $r->itu, $r->cq);
+ dbg("PCPROT: $self->{call}/" . $r->call . ' rejected by in_filter_route') if !$filter && isdbg('chanerr');
+ }
+ return $filter;
+}
+
+sub eph_dup
+{
+ my $s = shift;
+ my $r;
+
+ # chop the end off
+ $s =~ s/\^H\d\d?\^?\~?$//;
+ $r = 1 if exists $eph{$s}; # pump up the dup if it keeps circulating
+ $eph{$s} = $main::systime;
+ return $r;
+}
+
+sub eph_del_regex
+{
+ my $regex = shift;
+ my ($key, $val);
+ while (($key, $val) = each %eph) {
+ if ($key =~ m{$regex}) {
+ delete $eph{$key};
+ }
+ }
+}
+
+sub eph_clean
+{
+ my ($key, $val);
+
+ while (($key, $val) = each %eph) {
+ if ($main::systime - $val > 180) {
+ delete $eph{$key};
+ }
+ }
+}
+