Move the send DB updates out of the protocol and into Send::class
This commit is contained in:
parent
7584e3e44e
commit
f4fc6c24a4
@ -2,9 +2,12 @@
|
|||||||
|
|
||||||
namespace App\Classes\File;
|
namespace App\Classes\File;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
|
use App\Classes\Node;
|
||||||
use App\Models\File as FileModel;
|
use App\Models\File as FileModel;
|
||||||
|
|
||||||
final class File extends Send
|
final class File extends Send
|
||||||
@ -49,11 +52,22 @@ final class File extends Send
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function close(bool $successful): void
|
public function close(bool $successful,Node $node): void
|
||||||
{
|
{
|
||||||
if ($successful)
|
if ($successful) {
|
||||||
$this->complete = TRUE;
|
$this->complete = TRUE;
|
||||||
|
|
||||||
|
if (($this->type === Send::T_FILE)
|
||||||
|
&& ($x=$this->dbids)->count()
|
||||||
|
&& $node->aka_remote_authed->count())
|
||||||
|
DB::table('file_seenby')
|
||||||
|
->whereIn('file_id',$x)
|
||||||
|
->whereIn('address_id',$node->aka_remote_authed->pluck('id'))
|
||||||
|
->update([
|
||||||
|
'sent_at'=>Carbon::now(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
fclose($this->fd);
|
fclose($this->fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,10 @@ namespace App\Classes\File;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
|
||||||
use App\Classes\FTN\Packet;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
use App\Classes\Node;
|
||||||
|
use App\Classes\FTN\{Message,Packet};
|
||||||
|
|
||||||
final class Mail extends Send
|
final class Mail extends Send
|
||||||
{
|
{
|
||||||
@ -48,10 +51,35 @@ final class Mail extends Send
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function close(bool $successful): void
|
public function close(bool $successful,Node $node): void
|
||||||
{
|
{
|
||||||
if ($successful)
|
if ($successful) {
|
||||||
$this->complete = TRUE;
|
$this->complete = TRUE;
|
||||||
|
|
||||||
|
// Update netmail table
|
||||||
|
if (($this->type === Send::T_NETMAIL)
|
||||||
|
&& ($x=$this->dbids)->count())
|
||||||
|
DB::table('netmails')
|
||||||
|
->whereIn('id',$x)
|
||||||
|
->update([
|
||||||
|
'sent_at'=>Carbon::now(),
|
||||||
|
'sent_pkt'=>$this->name,
|
||||||
|
'sent_id'=>$node->address->id,
|
||||||
|
'flags'=>DB::raw('flags | '.Message::FLAG_SENT),
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Update echomails table
|
||||||
|
elseif (($this->type === Send::T_ECHOMAIL)
|
||||||
|
&& ($x=$this->dbids)->count()
|
||||||
|
&& $node->aka_remote_authed->count())
|
||||||
|
DB::table('echomail_seenby')
|
||||||
|
->whereIn('echomail_id',$x)
|
||||||
|
->whereIn('address_id',$node->aka_remote_authed->pluck('id'))
|
||||||
|
->update([
|
||||||
|
'sent_at'=>Carbon::now(),
|
||||||
|
'sent_pkt'=>$this->name,
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function feof(): bool
|
public function feof(): bool
|
||||||
|
@ -6,6 +6,7 @@ use Exception;
|
|||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use League\Flysystem\UnreadableFileEncountered;
|
use League\Flysystem\UnreadableFileEncountered;
|
||||||
|
|
||||||
|
use App\Classes\Node;
|
||||||
use App\Models\Address;
|
use App\Models\Address;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -72,7 +73,6 @@ class Send extends Base
|
|||||||
->filter(function($item) { return $item->isType(self::IS_ARC|self::IS_PKT); })
|
->filter(function($item) { return $item->isType(self::IS_ARC|self::IS_PKT); })
|
||||||
->sum(function($item) { return $item->size; });
|
->sum(function($item) { return $item->size; });
|
||||||
|
|
||||||
case 'dbids':
|
|
||||||
case 'name':
|
case 'name':
|
||||||
case 'nameas':
|
case 'nameas':
|
||||||
case 'mtime':
|
case 'mtime':
|
||||||
@ -112,19 +112,20 @@ class Send extends Base
|
|||||||
* Close the file descriptor of the file we are sending
|
* Close the file descriptor of the file we are sending
|
||||||
*
|
*
|
||||||
* @param bool $successful
|
* @param bool $successful
|
||||||
|
* @param Node $node
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function close(bool $successful): void
|
public function close(bool $successful,Node $node): void
|
||||||
{
|
{
|
||||||
if (! $this->fd)
|
if (! $this->fd)
|
||||||
throw new Exception('No file to close');
|
throw new Exception('No file to close');
|
||||||
|
|
||||||
if ($successful) {
|
if ($successful) {
|
||||||
$end = time()-$this->start;
|
$end = time()-$this->start;
|
||||||
Log::debug(sprintf('%s: - Closing [%s], sent in [%d]',self::LOGKEY,$this->sending->nameas,$end));
|
Log::debug(sprintf('%s: - Closing [%s], sent in [%d] with [%s] items',self::LOGKEY,$this->sending->nameas,$end,$this->sending->dbids->count()));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->sending->close($successful);
|
$this->sending->close($successful,$node);
|
||||||
$this->index = NULL;
|
$this->index = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -573,7 +573,7 @@ final class Binkp extends BaseProtocol
|
|||||||
$buf = $this->send->read(self::BLOCKSIZE);
|
$buf = $this->send->read(self::BLOCKSIZE);
|
||||||
|
|
||||||
} catch (UnreadableFileEncountered) {
|
} catch (UnreadableFileEncountered) {
|
||||||
$this->send->close(FALSE);
|
$this->send->close(FALSE,$this->node);
|
||||||
$this->sessionClear(self::SE_SENDFILE);
|
$this->sessionClear(self::SE_SENDFILE);
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@ -863,7 +863,7 @@ final class Binkp extends BaseProtocol
|
|||||||
$this->msgs(self::BPM_ERR,sprintf('M_FILE: unparsable file info: "%s", what are you on?',$buf));
|
$this->msgs(self::BPM_ERR,sprintf('M_FILE: unparsable file info: "%s", what are you on?',$buf));
|
||||||
|
|
||||||
if ($this->sessionGet(self::SE_SENDFILE))
|
if ($this->sessionGet(self::SE_SENDFILE))
|
||||||
$this->send->close(FALSE);
|
$this->send->close(FALSE,$this->node);
|
||||||
|
|
||||||
$this->rc = self::S_FAILURE;
|
$this->rc = self::S_FAILURE;
|
||||||
|
|
||||||
@ -957,7 +957,7 @@ final class Binkp extends BaseProtocol
|
|||||||
Log::error(sprintf('%s:! Cannot send file from requested offset [%d]',self::LOGKEY,$file['offs']));
|
Log::error(sprintf('%s:! Cannot send file from requested offset [%d]',self::LOGKEY,$file['offs']));
|
||||||
|
|
||||||
$this->msgs(self::BPM_ERR,'Can\'t send file from requested offset');
|
$this->msgs(self::BPM_ERR,'Can\'t send file from requested offset');
|
||||||
$this->send->close(FALSE);
|
$this->send->close(FALSE,$this->node);
|
||||||
$this->sessionClear(self::SE_SENDFILE);
|
$this->sessionClear(self::SE_SENDFILE);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -998,45 +998,10 @@ final class Binkp extends BaseProtocol
|
|||||||
Log::error(sprintf('%s:! M_got[skip] for unknown file [%s]',self::LOGKEY,$buf));
|
Log::error(sprintf('%s:! M_got[skip] for unknown file [%s]',self::LOGKEY,$buf));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Log::info(sprintf('%s:= Packet/File [%s], type [%d] sent with [%d] items.',self::LOGKEY,$this->send->nameas,$this->send->type,$this->send->dbids->count()));
|
Log::info(sprintf('%s:= Packet/File [%s], type [%d] sent.',self::LOGKEY,$this->send->nameas,$this->send->type));
|
||||||
$this->sessionClear(self::SE_WAITGOT|self::SE_SENDFILE);
|
$this->sessionClear(self::SE_WAITGOT|self::SE_SENDFILE);
|
||||||
|
|
||||||
// Update netmail table
|
$this->send->close(TRUE,$this->node);
|
||||||
if (($this->send->type === Send::T_NETMAIL)
|
|
||||||
&& ($x=$this->send->dbids)->count())
|
|
||||||
DB::table('netmails')
|
|
||||||
->whereIn('id',$x)
|
|
||||||
->update([
|
|
||||||
'sent_at'=>Carbon::now(),
|
|
||||||
'sent_pkt'=>$this->send->name,
|
|
||||||
'sent_id'=>$this->node->address->id,
|
|
||||||
'flags'=>DB::raw('flags | '.Message::FLAG_SENT),
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Update echomails table
|
|
||||||
elseif (($this->send->type === Send::T_ECHOMAIL)
|
|
||||||
&& ($x=$this->send->dbids)->count()
|
|
||||||
&& $this->node->aka_remote_authed->count())
|
|
||||||
DB::table('echomail_seenby')
|
|
||||||
->whereIn('echomail_id',$x)
|
|
||||||
->whereIn('address_id',$this->node->aka_remote_authed->pluck('id'))
|
|
||||||
->update([
|
|
||||||
'sent_at'=>Carbon::now(),
|
|
||||||
'sent_pkt'=>$this->send->name,
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Update the file seenby
|
|
||||||
elseif (($this->send->type === Send::T_FILE)
|
|
||||||
&& ($x=$this->send->dbids)->count()
|
|
||||||
&& $this->node->aka_remote_authed->count())
|
|
||||||
DB::table('file_seenby')
|
|
||||||
->whereIn('file_id',$x)
|
|
||||||
->whereIn('address_id',$this->node->aka_remote_authed->pluck('id'))
|
|
||||||
->update([
|
|
||||||
'sent_at'=>Carbon::now(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->send->close(TRUE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1211,7 +1211,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
|
|||||||
$z = new Zmodem;
|
$z = new Zmodem;
|
||||||
|
|
||||||
if (! $z->zmodem_sendinit($this->client,$zap) && $this->send->togo_count)
|
if (! $z->zmodem_sendinit($this->client,$zap) && $this->send->togo_count)
|
||||||
$z->zmodem_sendfile($this->send);
|
$z->zmodem_sendfile($this->send,$this->node);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send files
|
// Send files
|
||||||
@ -1219,7 +1219,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
|
|||||||
$z = new Zmodem;
|
$z = new Zmodem;
|
||||||
|
|
||||||
if (! $z->zmodem_sendinit($this->client,$zap) && $this->send->togo_count)
|
if (! $z->zmodem_sendinit($this->client,$zap) && $this->send->togo_count)
|
||||||
$z->zmodem_sendfile($this->send);
|
$z->zmodem_sendfile($this->send,$this->node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ namespace App\Classes\Protocol;
|
|||||||
|
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
use App\Classes\Protocol;
|
use App\Classes\{Node,Protocol};
|
||||||
use App\Classes\Protocol\Zmodem as ZmodemClass;
|
use App\Classes\Protocol\Zmodem as ZmodemClass;
|
||||||
use App\Classes\File\{Receive,Send};
|
use App\Classes\File\{Receive,Send};
|
||||||
use App\Classes\Sock\{SocketClient,SocketException};
|
use App\Classes\Sock\{SocketClient,SocketException};
|
||||||
@ -509,7 +509,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
|
|||||||
* @param Send $send
|
* @param Send $send
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function zmodem_sendfile(Send $send): int
|
public function zmodem_sendfile(Send $send,Node $node): int
|
||||||
{
|
{
|
||||||
Log::debug(sprintf('%s:+ zmodem_sendfile',self::LOGKEY));
|
Log::debug(sprintf('%s:+ zmodem_sendfile',self::LOGKEY));
|
||||||
|
|
||||||
@ -519,16 +519,16 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
|
|||||||
|
|
||||||
switch ($rc) {
|
switch ($rc) {
|
||||||
case self::OK:
|
case self::OK:
|
||||||
$send->close(TRUE);
|
case self::ZSKIP:
|
||||||
|
$send->close(TRUE,$node);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case self::ZSKIP:
|
|
||||||
case self::ZFERR:
|
case self::ZFERR:
|
||||||
$send->close(FALSE);
|
$send->close(FALSE,$node);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
$send->close(FALSE);
|
$send->close(FALSE,$node);
|
||||||
$this->ls_zabort();
|
$this->ls_zabort();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -2152,6 +2152,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
|
|||||||
/* Skip it */
|
/* Skip it */
|
||||||
case self::ZSKIP:
|
case self::ZSKIP:
|
||||||
/* Suspend it */
|
/* Suspend it */
|
||||||
|
// @todo Should ZFERR be next to ZABORT?
|
||||||
case self::ZFERR:
|
case self::ZFERR:
|
||||||
// @todo Mark the file as skipped
|
// @todo Mark the file as skipped
|
||||||
Log::debug(sprintf('%s: - ls_zsendfile ZSKIP/ZFERR',self::LOGKEY));
|
Log::debug(sprintf('%s: - ls_zsendfile ZSKIP/ZFERR',self::LOGKEY));
|
||||||
|
Loading…
Reference in New Issue
Block a user