BINKP responding to incoming netmail pings
This commit is contained in:
@@ -94,7 +94,7 @@ class Item
|
||||
throw new Exception('Invalid request for key: '.$key);
|
||||
|
||||
case 'recvas':
|
||||
return '/tmp/'.$this->file_name; // @todo this should be inbound temp
|
||||
return $this->file_name;
|
||||
|
||||
case 'sendas':
|
||||
return basename($this->file_name);
|
||||
@@ -114,6 +114,7 @@ class Item
|
||||
static $ext = ['su','mo','tu','we','th','fr','sa','req'];
|
||||
|
||||
$x = strrchr($this->file_name,'.');
|
||||
|
||||
if (! $x || (strlen(substr($x,1)) != 3))
|
||||
return self::IS_FILE;
|
||||
|
||||
|
@@ -20,7 +20,7 @@ class Mail extends Item
|
||||
switch ($action) {
|
||||
case self::I_SEND:
|
||||
$this->file = $mail;
|
||||
$this->file_name = sprintf('%08X.PKT',Carbon::now()->timestamp);
|
||||
$this->file_name = sprintf('%08x.pkt',Carbon::now()->timestamp);
|
||||
$this->file_size = strlen($mail);
|
||||
$this->file_mtime = Carbon::now()->timestamp; // @todo This timestamp should be consistent incase of retries
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -46,7 +46,7 @@ final class Send extends Item
|
||||
{
|
||||
switch ($key) {
|
||||
case 'fd':
|
||||
return is_resource($this->f);
|
||||
return is_resource($this->f) ?: $this->f;
|
||||
|
||||
case 'file_count':
|
||||
return $this->list
|
||||
@@ -228,8 +228,11 @@ final class Send extends Item
|
||||
public function mail(Address $ao): void
|
||||
{
|
||||
// Netmail
|
||||
if ($x=$ao->getNetmail())
|
||||
if ($x=$ao->getNetmail()) {
|
||||
Log::debug(sprintf('%s: - Netmail(s) added for sending to [%s]',__METHOD__,$ao->ftn));
|
||||
|
||||
$this->packets->push(new Mail($x,self::I_SEND));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user