Fix the rendering of SEENBY/PATH lines in packets, which should have each new line prefixed with host

This commit is contained in:
Deon George 2023-11-27 09:00:32 +11:00
parent a19eaa3291
commit 8590bb8acc
3 changed files with 42 additions and 29 deletions

View File

@ -495,8 +495,8 @@ class Message extends FTNBase
} else { } else {
// Seenby & PATH - FSC-0068 // Seenby & PATH - FSC-0068
$return .= sprintf("SEEN-BY: %s\r",wordwrap(optimize_path($this->seenby)->join(' '),70,"\rSEEN-BY: ")); $return .= $this->optimise_path($this->seenby,'SEEN-BY:')."\r";
$return .= sprintf("\01PATH: %s\r",wordwrap(optimize_path($this->path)->join(' '),73,"\rPATH: ")); $return .= "\x01".$this->optimise_path($this->path,'PATH:')."\r";
} }
$return .= "\00"; $return .= "\00";
@ -514,6 +514,44 @@ class Message extends FTNBase
$this->decode($values); $this->decode($values);
} }
/**
* Reduce our PATH/SEEN-BY for messages as per FSC-0068
*
* @param Collection $path
* @param string $prefix
* @param int $len
* @param string $delim
* @return string
*/
function optimise_path(Collection $path,string $prefix,int $len=79,string $delim="\r"): string
{
$cur = NULL;
$result = $prefix;
$c = strlen($prefix);
foreach ($path as $address) {
[$host,$node] = explode('/',$address);
if (($c+strlen(' '.$host)) > $len) {
$result .= ($x=$delim.$prefix);
$c = strlen($x);
$cur = NULL;
}
if ($host !== $cur) {
$cur = $host;
$result .= ($x=' '.$address);
} else {
$result .= ($x=' '.$node);
}
$c += strlen($x);
}
return $result;
}
/** /**
* Parse a message from a packet * Parse a message from a packet
* *

View File

@ -163,28 +163,3 @@ if (! function_exists('wtime')) {
return Carbon::create($year,$month,$day,$hr,$min,$sec+$milli/10); return Carbon::create($year,$month,$day,$hr,$min,$sec+$milli/10);
} }
} }
if (! function_exists('optimize_path')) {
/**
* This will optimize an array of paths to show the smallest number of characters
*/
function optimize_path(Collection $path): Collection
{
$cur = NULL;
$result = collect();
foreach ($path as $address) {
[$host,$node] = explode('/',$address);
if ($host !== $cur) {
$cur = $host;
$result->push($address);
} else {
$result->push($node);
}
}
return $result;
}
}

View File

@ -42,7 +42,7 @@ use App\Classes\FTN\Message;
@if ($msg instanceof \App\Models\Echomail) @if ($msg instanceof \App\Models\Echomail)
<div class="row pb-2"> <div class="row pb-2">
<div class="col-8"> <div class="col-8">
SEENBY: <br><strong class="highlight">{!! optimize_path($msg->seenby->pluck('ftn2d'))->join('</strong>, <strong class="highlight">') !!}</strong> SEENBY: <br><strong class="highlight">{!! $msg->seenby->pluck('ftn2d')->join('</strong>, <strong class="highlight">') !!}</strong>
</div> </div>
@if ($msg->rogue_seenby->count()) @if ($msg->rogue_seenby->count())
@ -62,7 +62,7 @@ use App\Classes\FTN\Message;
<!-- @todo for the nodes we export to, highlight those that we have actually sent it, vs those that havent received it yet --> <!-- @todo for the nodes we export to, highlight those that we have actually sent it, vs those that havent received it yet -->
<div class="row pb-2"> <div class="row pb-2">
<div class="col-8"> <div class="col-8">
PATH: <br><strong class="highlight">{!! optimize_path($msg->pathorder())->join('</strong> -> <strong class="highlight">') !!}</strong> PATH: <br><strong class="highlight">{!! $msg->pathorder()->join('</strong> -> <strong class="highlight">') !!}</strong>
@if (($msg instanceof \App\Models\Echomail) && $msg->rogue_path->count()) @if (($msg instanceof \App\Models\Echomail) && $msg->rogue_path->count())
<br><small>[<strong>NOTE</strong>: Some path values couldnt be identified - ({{ $msg->rogue_path->join(',') }})]</small> <br><small>[<strong>NOTE</strong>: Some path values couldnt be identified - ({{ $msg->rogue_path->join(',') }})]</small>