Optimised our sending and receiving of items
This commit is contained in:
@@ -11,6 +11,7 @@ use League\Flysystem\UnreadableFileEncountered;
|
||||
|
||||
use App\Classes\Crypt;
|
||||
use App\Classes\Protocol as BaseProtocol;
|
||||
use App\Classes\File\Send;
|
||||
use App\Classes\FTN\Message;
|
||||
use App\Classes\Sock\SocketClient;
|
||||
use App\Classes\Sock\SocketException;
|
||||
@@ -429,7 +430,7 @@ final class Binkp extends BaseProtocol
|
||||
$msg = ord(substr($this->rx_buf,0,1));
|
||||
|
||||
if ($msg > self::BPM_MAX) {
|
||||
Log::error(sprintf('%s:! Unknown message received [%d] (%d-%s)',self::LOGKEY,$rc,strlen($this->rx_buf),$this->rx_buf));
|
||||
Log::error(sprintf('%s:! Unknown message received [%d] (%d-%s)',self::LOGKEY,$msg,strlen($this->rx_buf),$this->rx_buf));
|
||||
$rc = TRUE;
|
||||
|
||||
} else {
|
||||
@@ -487,7 +488,7 @@ final class Binkp extends BaseProtocol
|
||||
break;
|
||||
|
||||
default:
|
||||
Log::error(sprintf('%s:! BINKP command not implemented [%d]',self::LOGKEY,$rc));
|
||||
Log::error(sprintf('%s:! BINKP command not implemented [%d]',self::LOGKEY,$msg));
|
||||
$rc = TRUE;
|
||||
}
|
||||
}
|
||||
@@ -500,7 +501,7 @@ final class Binkp extends BaseProtocol
|
||||
} catch (FileGrewException $e) {
|
||||
// Retry the file without compression
|
||||
Log::error(sprintf('%s:! %s',self::LOGKEY,$e->getMessage()));
|
||||
$this->msgs(self::BPM_GET,sprintf('%s %ld NZ',$this->recv->name_size_time,$this->recv->filepos));
|
||||
$this->msgs(self::BPM_GET,sprintf('%s %ld NZ',$this->recv->name_size_time,$this->recv->pos));
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error(sprintf('%s:! %s',self::LOGKEY,$e->getMessage()));
|
||||
@@ -511,8 +512,8 @@ final class Binkp extends BaseProtocol
|
||||
|
||||
$rc = TRUE;
|
||||
|
||||
if ($this->recv->filepos === $this->recv->size) {
|
||||
Log::info(sprintf('%s:- Finished receiving file [%s] with size [%d]',self::LOGKEY,$this->recv->name,$this->recv->size));
|
||||
if ($this->recv->pos === $this->recv->size) {
|
||||
Log::info(sprintf('%s:- Finished receiving file [%s] with size [%d]',self::LOGKEY,$this->recv->nameas,$this->recv->size));
|
||||
|
||||
$this->msgs(self::BPM_GOTSKIP,$this->recv->name_size_time);
|
||||
$this->recv->close();
|
||||
@@ -577,6 +578,8 @@ final class Binkp extends BaseProtocol
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error(sprintf('%s:! BINKP send unexpected ERROR [%s]',self::LOGKEY,$e->getMessage()));
|
||||
|
||||
throw new \Exception($e->getMessage());
|
||||
}
|
||||
|
||||
if ($buf) {
|
||||
@@ -596,7 +599,7 @@ final class Binkp extends BaseProtocol
|
||||
}
|
||||
|
||||
// @todo should this be less than BLOCKSIZE? Since a read could return a blocksize and it could be the end of the file?
|
||||
if ($this->send->filepos === $this->send->size) {
|
||||
if ($this->send->pos === $this->send->size) {
|
||||
$this->sessionSet(self::SE_WAITGOT);
|
||||
$this->sessionClear(self::SE_SENDFILE);
|
||||
}
|
||||
@@ -810,7 +813,7 @@ final class Binkp extends BaseProtocol
|
||||
$this->sessionSet(self::SE_RECVEOB);
|
||||
$this->sessionClear(self::SE_DELAYEOB);
|
||||
|
||||
if (! $this->send->total_count && $this->sessionGet(self::SE_NOFILES) && $this->capGet(self::F_MULTIBATCH,self::O_YES)) {
|
||||
if (! $this->send->togo_count && $this->sessionGet(self::SE_NOFILES) && $this->capGet(self::F_MULTIBATCH,self::O_YES)) {
|
||||
// Add our mail to the queue if we have authenticated
|
||||
if ($this->node->aka_authed)
|
||||
foreach ($this->node->aka_remote_authed as $ao) {
|
||||
@@ -819,8 +822,8 @@ final class Binkp extends BaseProtocol
|
||||
$this->send->files($ao);
|
||||
}
|
||||
|
||||
Log::debug(sprintf('%s:- We have [%d] items to send to [%s]',self::LOGKEY,$this->send->total_count,$ao->ftn));
|
||||
if ($this->send->total_count)
|
||||
Log::debug(sprintf('%s:- We have [%d] items to send to [%s]',self::LOGKEY,$this->send->togo_count,$ao->ftn));
|
||||
if ($this->send->togo_count)
|
||||
$this->sessionClear(self::SE_NOFILES|self::SE_SENTEOB);
|
||||
}
|
||||
|
||||
@@ -852,10 +855,10 @@ final class Binkp extends BaseProtocol
|
||||
|
||||
$this->sessionClear(self::SE_RECVEOB);
|
||||
|
||||
if ($this->recv->fd)
|
||||
$this->recv->close();
|
||||
//if ($this->recv->fd)
|
||||
// $this->recv->close();
|
||||
|
||||
if (! $file=$this->file_parse($buf)) {
|
||||
if (! ($file=$this->file_parse($buf))) {
|
||||
Log::error(sprintf('%s:! UNPARSABLE file info [%s]',self::LOGKEY,$buf));
|
||||
$this->msgs(self::BPM_ERR,sprintf('M_FILE: unparsable file info: "%s", what are you on?',$buf));
|
||||
|
||||
@@ -868,20 +871,22 @@ final class Binkp extends BaseProtocol
|
||||
}
|
||||
|
||||
// In NR mode, when we got -1 for the file offsite, the reply to our get will confirm our requested offset.
|
||||
if ($this->recv->name && ! strncasecmp(Arr::get($file,'file.name'),$this->recv->name,self::MAX_PATH)
|
||||
if ($this->recv->ready
|
||||
&& $this->recv->nameas
|
||||
&& (! strncasecmp(Arr::get($file,'file.name'),$this->recv->nameas,self::MAX_PATH))
|
||||
&& $this->recv->mtime === Arr::get($file,'file.mtime')
|
||||
&& $this->recv->size === Arr::get($file,'file.size')
|
||||
&& $this->recv->filepos === $file['offs'])
|
||||
&& $this->recv->pos === $file['offs'])
|
||||
{
|
||||
$this->recv->open($this->node->address,$file['offs']<0,$file['flags']);
|
||||
$this->recv->open($file['offs']<0,$file['flags']);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
$this->recv->new($file['file']);
|
||||
$this->recv->new($file['file'],$this->node->address);
|
||||
|
||||
try {
|
||||
switch ($this->recv->open($this->node->address,$file['offs']<0,$file['flags'])) {
|
||||
switch ($this->recv->open($file['offs']<0,$file['flags'])) {
|
||||
case self::FOP_ERROR:
|
||||
Log::error(sprintf('%s:! File ERROR',self::LOGKEY));
|
||||
|
||||
@@ -943,8 +948,8 @@ final class Binkp extends BaseProtocol
|
||||
|
||||
if ($file=$this->file_parse($buf)) {
|
||||
if ($this->sessionGet(self::SE_SENDFILE)
|
||||
&& $this->send->sendas
|
||||
&& ! strncasecmp(Arr::get($file,'file.name'),$this->send->sendas,self::MAX_PATH)
|
||||
&& $this->send->nameas
|
||||
&& ! strncasecmp(Arr::get($file,'file.name'),$this->send->nameas,self::MAX_PATH)
|
||||
&& $this->send->mtime === Arr::get($file,'file.mtime')
|
||||
&& $this->send->size === Arr::get($file,'file.size'))
|
||||
{
|
||||
@@ -957,8 +962,8 @@ final class Binkp extends BaseProtocol
|
||||
|
||||
} else {
|
||||
$this->sessionClear(self::SE_WAITGET);
|
||||
Log::debug(sprintf('%s:Sending file [%s] as [%s]',self::LOGKEY,$this->send->name,$this->send->sendas));
|
||||
$this->msgs(self::BPM_FILE,sprintf('%s %lu %ld %lu %s',$this->send->sendas,$this->send->size,$this->send->mtime,$file['offs'],$file['flags']));
|
||||
Log::debug(sprintf('%s:Sending file [%s] as [%s]',self::LOGKEY,$this->send->name,$this->send->nameas));
|
||||
$this->msgs(self::BPM_FILE,sprintf('%s %lu %ld %lu %s',$this->send->nameas,$this->send->size,$this->send->mtime,$file['offs'],$file['flags']));
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -984,8 +989,8 @@ final class Binkp extends BaseProtocol
|
||||
Log::debug(sprintf('%s:+ Remote confirms receipt for file [%s]',self::LOGKEY,$buf));
|
||||
|
||||
if ($file = $this->file_parse($buf)) {
|
||||
if ($this->send->sendas
|
||||
&& ! strncasecmp(Arr::get($file,'file.name'),$this->send->sendas,self::MAX_PATH)
|
||||
if ($this->send->nameas
|
||||
&& ! strncasecmp(Arr::get($file,'file.name'),$this->send->nameas,self::MAX_PATH)
|
||||
&& $this->send->mtime === Arr::get($file,'file.mtime')
|
||||
&& $this->send->size === Arr::get($file,'file.size'))
|
||||
{
|
||||
@@ -993,11 +998,12 @@ final class Binkp extends BaseProtocol
|
||||
Log::error(sprintf('%s:! M_got[skip] for unknown file [%s]',self::LOGKEY,$buf));
|
||||
|
||||
} else {
|
||||
Log::info(sprintf('%s:= Packet/File [%s] sent with [%s].',self::LOGKEY,$this->send->name,$this->send->dbids->join(',')));
|
||||
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()));
|
||||
$this->sessionClear(self::SE_WAITGOT|self::SE_SENDFILE);
|
||||
|
||||
// Update netmail table
|
||||
if ($x=$this->send->dbids->filter(function($item) { return (! $item); })->keys()->filter())
|
||||
if (($this->send->type === Send::T_NETMAIL)
|
||||
&& ($x=$this->send->dbids)->count())
|
||||
DB::table('netmails')
|
||||
->whereIn('id',$x)
|
||||
->update([
|
||||
@@ -1008,15 +1014,28 @@ final class Binkp extends BaseProtocol
|
||||
]);
|
||||
|
||||
// Update echomails table
|
||||
if ($x=$this->send->dbids->filter(function($item) { return $item; })->keys()->filter())
|
||||
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)
|
||||
->where('address_id',$this->node->address->id)
|
||||
->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);
|
||||
}
|
||||
}
|
||||
@@ -1299,7 +1318,7 @@ final class Binkp extends BaseProtocol
|
||||
$this->send->files($ao);
|
||||
}
|
||||
|
||||
$this->msgs(self::BPM_NUL,sprintf('TRF %lu %lu',$this->send->mail_size,$this->send->size));
|
||||
$this->msgs(self::BPM_NUL,sprintf('TRF %lu %lu',$this->send->mail_size,$this->send->files_size));
|
||||
$this->msgs(self::BPM_OK,sprintf('%ssecure',$have_pwd ? '' : 'non-'));
|
||||
|
||||
return $this->binkp_hsdone();
|
||||
@@ -1332,7 +1351,7 @@ final class Binkp extends BaseProtocol
|
||||
&& (! $this->send->fd))
|
||||
{
|
||||
// Open our next file to send
|
||||
if ($this->send->total_count && ! $this->send->fd) {
|
||||
if ($this->send->togo_count && ! $this->send->fd) {
|
||||
Log::info(sprintf('%s:- Opening next file to send',self::LOGKEY));
|
||||
$this->send->open();
|
||||
}
|
||||
@@ -1350,7 +1369,7 @@ final class Binkp extends BaseProtocol
|
||||
|
||||
$this->msgs(self::BPM_FILE,
|
||||
sprintf('%s %lu %lu %ld %s',
|
||||
$this->send->sendas,
|
||||
$this->send->nameas,
|
||||
$this->send->size,
|
||||
$this->send->mtime,
|
||||
$this->sessionGet(self::SE_WAITGET) ? -1 : 0,
|
||||
@@ -1360,7 +1379,7 @@ final class Binkp extends BaseProtocol
|
||||
|
||||
// We dont have anything to send
|
||||
} else {
|
||||
Log::info(sprintf('%s:- Nothing else to send',self::LOGKEY));
|
||||
Log::info(sprintf('%s:- Nothing left to send in this batch',self::LOGKEY));
|
||||
$this->sessionSet(self::SE_NOFILES);
|
||||
}
|
||||
}
|
||||
@@ -1389,6 +1408,7 @@ final class Binkp extends BaseProtocol
|
||||
|
||||
$this->mib = 0;
|
||||
$this->sessionClear(self::SE_RECVEOB|self::SE_SENTEOB);
|
||||
$this->sessionSet(self::SE_DELAYEOB);
|
||||
}
|
||||
|
||||
$wd = ($this->mqueue->count() || $this->tx_left || ($this->sessionGet(self::SE_SENDFILE) && $this->send->fd && ! $this->sessionGet(self::SE_WAITGET)));
|
||||
@@ -1424,7 +1444,7 @@ final class Binkp extends BaseProtocol
|
||||
break;
|
||||
}
|
||||
|
||||
if (($this->mqueue->count() || $wd) && ! $this->binkp_send() && (! $this->send->total_count)) {
|
||||
if (($this->mqueue->count() || $wd) && ! $this->binkp_send() && (! $this->send->togo_count)) {
|
||||
Log::info(sprintf('%s:- BINKP finished sending',self::LOGKEY));
|
||||
|
||||
break;
|
||||
|
Reference in New Issue
Block a user