From fda536aef281e0f6fc68a02c537d18650bd5505f Mon Sep 17 00:00:00 2001 From: Dirk Koopman Date: Thu, 21 May 2020 16:32:30 +0100 Subject: [PATCH] fix call/call-ssid locking issue Fix the situation where GB7DXC exists and is locked out and $allowmultiple is active than GB7DXC-5 logs in and is locked by dint of GB7DXC's locked status and ignores GB7DXC-5's unlocked status. Run convert-users-v3-to-v4.pl automatically if there are no users.v4[.o/.n] files present in local_data or data. Then copy users.v4 to users.v4,n and do an export_users, creating users_json. File user export so that it actually works! --- cmd/export_users.pl | 2 +- perl/DXChannel.pm | 2 +- perl/DXUser.pm | 32 ++++++++++++++++++++++---------- perl/cluster.pl | 18 ++++++++++-------- 4 files changed, 34 insertions(+), 20 deletions(-) diff --git a/cmd/export_users.pl b/cmd/export_users.pl index 69cecc79..3a07d23a 100644 --- a/cmd/export_users.pl +++ b/cmd/export_users.pl @@ -15,7 +15,7 @@ unless ($fn && $fn eq 'user_json') { } my $strip = $flag eq 'strip'; -my @out = DXUser::export(undef, $strip); # for now +my @out = DXUser::export(); # for now return (1, @out); diff --git a/perl/DXChannel.pm b/perl/DXChannel.pm index 0e543e9c..d680251b 100644 --- a/perl/DXChannel.pm +++ b/perl/DXChannel.pm @@ -427,7 +427,7 @@ sub send # this is always later and always data my $call = $self->{call}; foreach my $l (@_) { - for (ref $l ? @$l : $l) { + for (ref($l) eq 'ARRAY' ? @$l : $l) { my @lines = split /\n/; for (@lines) { $conn->send_later("D$call|$_"); diff --git a/perl/DXUser.pm b/perl/DXUser.pm index 85a22195..3ad8d5c2 100644 --- a/perl/DXUser.pm +++ b/perl/DXUser.pm @@ -187,18 +187,28 @@ sub init { my $mode = shift; - my $ufn; - my $convert; - + my $convert = "$main::root/perl/convert-users-v3-to-v4.pl"; + my $export; + $json = JSON->new()->canonical(1); $filename = localdata("users.v4"); if (-e $filename || -e "$filename.n" || -e "$filename.o") { $v4 = 1; - readinjson(); } else { - die "User file $filename missing, please run convert-users-v3-to-v4.pl or copy a user_json backup from somewhere\n"; + if (-e localdata('users.v3')) { + LogDbg('DXUser', "Converting " . localdata('users.v3') . " to new json version of users file, please wait"); + if (-x $convert) { + system($convert); + ++$export; + } + } + + die "User file $filename missing, please run $convert or copy a user_json backup from somewhere\n" unless -e "$filename.n" || -s $filename; } + readinjson(); + copy $filename, "$filename.n" unless -e "$filename.n"; + export() if $export; } sub del_file @@ -508,6 +518,7 @@ sub export my $name = shift; my $fn = $name || localdata("user_json"); # force use of local_data + my $ta = [gettimeofday]; # save old ones move "$fn.oooo", "$fn.ooooo" if -e "$fn.oooo"; @@ -517,7 +528,7 @@ sub export move "$fn", "$fn.o" if -e "$fn"; my $json = JSON->new; - $json->canonical(1); + $json->canonical(1);; my $count = 0; my $err = 0; @@ -527,10 +538,10 @@ sub export my $key = 0; my $val = undef; foreach my $k (sort keys %u) { - my $r = $u{$k}; + my $r = get($k); if ($r->{sort} eq 'U' && !$r->{priv} && $main::systime > $r->{lastin}+$tooold ) { unless ($r->{lat} || $r->{long} || $r->{qra} || $r->{qth} || $r->{name}) { - LogDbg('DXUser', "DXUser::export deleting $k - too old, last in " . cldatetime($r->lastin) . " " . difft([$r->lastin, $main::systime])); + LogDbg('export', "DXUser::export deleting $k - too old, last in " . cldatetime($r->lastin) . " " . difft([$r->lastin, $main::systime])); delete $u{$k}; ++$del; next; @@ -538,7 +549,7 @@ sub export } eval {$val = json_encode($r);}; if ($@) { - LogDbg('DXUser', "DXUser::export error encoding call: $k $@"); + LogDbg('export', "DXUser::export error encoding call: $k $@"); ++$err; next; } @@ -547,7 +558,8 @@ sub export } $fh->close; } - my $s = qq{Exported users to $fn - $count Users $del Deleted $err Errors ('sh/log Export' for details)}; + my $t = _diffms($ta); + my $s = qq{Exported users to $fn - $count Users $del Deleted $err Errors in $t mS ('sh/log Export' for details)}; LogDbg('DXUser', $s); return $s; } diff --git a/perl/cluster.pl b/perl/cluster.pl index 9735aa30..3e57deb6 100755 --- a/perl/cluster.pl +++ b/perl/cluster.pl @@ -251,16 +251,18 @@ sub new_channel $basecall =~ s/-\d+$//; # remember this for later multiple user processing my $lock; if ($user) { - # we are a real user + # make sure we act on any locked status that the actual incoming call has. $lock = $user->lockout; - } elsif ($allowmultiple) { - # could we be a potential "pseudo" connection + } elsif ($allowmultiple && $call ne $basecall) { + # if we are allowing multiple connections and there is a basecall minus incoming ssid, use the basecall's lock status $user = DXUser::get_current($basecall); $lock = $user->lockout if $user; } + + # now deal with the lock if ($lock) { my $host = $conn->peerhost; - LogDbg('DXCommand', "$call on $host is locked out, disconnected"); + LogDbg('', "$call on $host is locked out, disconnected"); $conn->disconnect; return; } @@ -281,7 +283,7 @@ sub new_channel my $allow = 0; if (@lastconns >= $DXUser::maxconnlist) { $allow = $lastconns[-1]->[0] - $lastconns[0]->[0] < $min_reconnection_rate; - } + } # search for a spare ssid L1: for (my $count = $call =~ /-\d+$/?0:1; $allow && $count < $allowmultiple; ) { # remember we have one call already my $lastid = 1; @@ -303,7 +305,7 @@ sub new_channel if ($bumpexisting) { my $ip = $dxchan->hostname; $dxchan->send_now('D', DXM::msg($lang, 'conbump', $call, $ip)); - Log('', "$call bumped off by $ip, disconnected"); + LogDbg('', "$call bumped off by $ip, disconnected"); $dxchan->disconnect; } else { already_conn($conn, $call, DXM::msg($lang, 'conother', $call, $main::mycall)); @@ -327,7 +329,7 @@ sub new_channel $v = defined $c ? $c : $m; if ($v && @n >= $v+$allowmultiple) { my $nodes = join ',', @n; - LogDbg('DXCommand', "$call has too many connections ($v) at $nodes - disconnected"); + LogDbg('', "$call has too many connections ($v) at $nodes - disconnected"); already_conn($conn, $call, DXM::msg($lang, 'contomany', $call, $v, $nodes)); return; } @@ -354,7 +356,7 @@ sub new_channel # set callbacks - $conn->set_error(sub {my $err = shift; LogDbg('DXCommand', "Comms error '$err' received for call $dxchan->{call}"); $dxchan->disconnect(1);}); + $conn->set_error(sub {my $err = shift; LogDbg('', "Comms error '$err' received for call $dxchan->{call}"); $dxchan->disconnect(1);}); $conn->set_on_eof(sub {$dxchan->disconnect}); $conn->set_rproc(sub {my ($conn,$msg) = @_; $dxchan->rec($msg);}); if ($sort eq 'W') { -- 2.43.0