BINKP responding to incoming netmail pings

This commit is contained in:
Deon George
2021-07-18 22:10:21 +10:00
parent 7bb3e12f66
commit 9dcfe6b17d
19 changed files with 145 additions and 54 deletions

View File

@@ -5,8 +5,13 @@ namespace App\Classes\File;
use Exception;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\Exception\FileException;
use App\Classes\FTN\Packet;
use App\Jobs\ProcessPacket;
use App\Models\Address;
/**
* Object representing the files we are receiving
*
@@ -16,12 +21,14 @@ use Symfony\Component\HttpFoundation\File\Exception\FileException;
*/
final class Receive extends Item
{
private Address $ao;
private Collection $list;
private ?Item $receiving;
private mixed $f; // File descriptor
private int $start; // Time we started receiving
private int $file_pos; // Current write pointer
private string $file; // Local filename for file received
public function __construct()
{
@@ -86,8 +93,29 @@ final class Receive extends Item
fclose($this->f);
$this->file_pos = 0;
$this->receiving = NULL;
$this->f = NULL;
// If we received a packet, we'll dispatch a job to process it
switch ($this->receiving->file_type) {
case self::IS_PKT:
Log::info(sprintf('%s: - Processing mail packet [%s]',__METHOD__,$this->file));
foreach (Packet::open(new File($this->file),$this->ao->zone->domain)->messages as $msg) {
Log::info(sprintf('%s: - Mail from [%s] to [%s]',__METHOD__,$msg->fftn,$msg->tftn));
// @todo Quick check that the packet should be processed by us.
// @todo validate that the packet's zone is in the domain.
// Dispatch job.
ProcessPacket::dispatchSync($msg);
}
break;
default:
Log::debug(sprintf('%s: - Leaving file [%s] in the inbound dir',__METHOD__,$this->file));
}
$this->receiving = NULL;
}
/**
@@ -97,7 +125,7 @@ final class Receive extends Item
* @return bool
* @throws Exception
*/
public function open(bool $check=FALSE): bool
public function open(Address $ao,bool $check=FALSE): bool
{
Log::debug(sprintf('%s: + Start [%d]',__METHOD__,$check));
@@ -112,11 +140,13 @@ final class Receive extends Item
if (! $this->receiving)
throw new Exception('No files currently receiving');
$this->ao = $ao;
$this->file_pos = 0;
$this->start = time();
$this->file = sprintf('storage/app/%s/%04X-%s',config('app.fido'),$this->ao->id,$this->receiving->recvas);
Log::debug(sprintf('%s: - Opening [%s]',__METHOD__,$this->receiving->recvas));
$this->f = fopen($this->receiving->recvas,'wb');
Log::debug(sprintf('%s: - Opening [%s]',__METHOD__,$this->file));
$this->f = fopen($this->file,'wb');
if (! $this->f) {
Log::error(sprintf('%s: ! Unable to open file [%s] for writing',__METHOD__,$this->receiving->file_name));
return 3; // @todo change to const