From 5516b5dc233e3500e46e0d761e88fad8faa1ff92 Mon Sep 17 00:00:00 2001 From: Deon George Date: Tue, 11 Jul 2023 17:22:31 +1000 Subject: [PATCH] Fixes for BINKP, we were sending too many EOB's --- app/Classes/File/Receive.php | 4 ++-- app/Classes/Protocol/Binkp.php | 44 +++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/app/Classes/File/Receive.php b/app/Classes/File/Receive.php index d7fd882..3babbc1 100644 --- a/app/Classes/File/Receive.php +++ b/app/Classes/File/Receive.php @@ -254,11 +254,11 @@ final class Receive extends Item && (Storage::disk('local')->size($this->local_path($ao)) === $this->size)) { Log::alert(sprintf('%s:- File already exists - skipping [%s]', self::LOGKEY, $this->file)); - return Protocol::FOP_SKIP; + return Protocol::FOP_GOT; } elseif (file_exists($this->file) && (Storage::disk('local')->size($this->local_path($ao)) > 0)) { Log::alert(sprintf('%s:- File exists with different details - skipping [%s]',self::LOGKEY,$this->file)); - return Protocol::FOP_SUSPEND; + return Protocol::FOP_SKIP; } else { // @todo I dont think we are enabling resumable sessions - need to check diff --git a/app/Classes/Protocol/Binkp.php b/app/Classes/Protocol/Binkp.php index cc1a608..84d473c 100644 --- a/app/Classes/Protocol/Binkp.php +++ b/app/Classes/Protocol/Binkp.php @@ -2,7 +2,6 @@ namespace App\Classes\Protocol; -use App\Exceptions\FileGrewException; use Carbon\Carbon; use Illuminate\Support\Arr; use Illuminate\Support\Collection; @@ -13,6 +12,7 @@ use App\Classes\Crypt; use App\Classes\Protocol as BaseProtocol; use App\Classes\Sock\SocketClient; use App\Classes\Sock\SocketException; +use App\Exceptions\FileGrewException; use App\Models\Address; final class Binkp extends BaseProtocol @@ -247,7 +247,7 @@ final class Binkp extends BaseProtocol */ // No dupes mode is preferred on BINKP 1.1 - if ($this->capGet(self::F_NODUPE,self::O_WE) || ($this->originate && $this->capGet(self::F_NOREL,self::O_WANT) && $this->node->get_versionint() > 100)) { + if ($this->capGet(self::F_NODUPE,self::O_WE) || ($this->originate && $this->capGet(self::F_NOREL,self::O_WANT) && $this->node->get_versionint() > 101)) { Log::debug(sprintf('%s:/ NR mode enabled, because we are in NDA mode, or I want NDA and the remote is version [%d]',self::LOGKEY,$this->node->get_versionint())); $this->capSet(self::F_NOREL,self::O_YES); } @@ -264,14 +264,14 @@ final class Binkp extends BaseProtocol self::LOGKEY, $this->node->ver_major, $this->node->ver_minor, - $this->capGet(self::F_NOREL,0xFF), - $this->capGet(self::F_NODUPE,0xFF), - $this->capGet(self::F_NODUPEA,0xFF), - $this->capGet(self::F_MD,0xFF), - $this->capGet(self::F_MULTIBATCH,0xFF), - $this->capGet(self::F_CRYPT,0xFF), - $this->capGet(self::F_COMP,0xFF), - $this->capGet(self::F_CHAT,0xFF), + $this->capGet(self::F_NOREL,self::O_WE), + $this->capGet(self::F_NODUPE,self::O_WE), + $this->capGet(self::F_NODUPEA,self::O_WE), + $this->capGet(self::F_MD,self::O_WE), + $this->capGet(self::F_MULTIBATCH,self::O_WE), + $this->capGet(self::F_CRYPT,self::O_WE), + $this->capGet(self::F_COMP,self::O_WE), + $this->capGet(self::F_CHAT,self::O_WE), )); return TRUE; @@ -555,8 +555,6 @@ final class Binkp extends BaseProtocol } } elseif ($this->sessionGet(self::SE_SENDFILE) && $this->send->fd && (! $this->sessionGet(self::SE_WAITGET))) { - $data = ''; - try { $buf = $this->send->read(self::BLOCKSIZE); @@ -799,6 +797,7 @@ final class Binkp extends BaseProtocol $this->sessionSet(self::SE_RECVEOB); $this->sessionClear(self::SE_DELAYEOB); + // @todo Is this multibatch mode, if so we should check that MB hasn been agreed. if (! $this->send->total_count && $this->sessionGet(self::SE_NOFILES)) { // Add our mail to the queue if we have authenticated if ($this->node->aka_authed) @@ -836,7 +835,7 @@ final class Binkp extends BaseProtocol { Log::info(sprintf('%s:+ About to receive a file [%s]',self::LOGKEY,$buf)); - if ($this->sessionGet(self::SE_SENTEOB|self::SE_RECVEOB)) + if ($this->sessionGet(self::SE_SENTEOB) && $this->sessionGet(self::SE_RECVEOB)) $this->sessionClear(self::SE_SENTEOB); $this->sessionClear(self::SE_RECVEOB); @@ -898,13 +897,14 @@ final class Binkp extends BaseProtocol case self::FOP_OK: Log::debug(sprintf('%s:- Getting file from offset [%ld]',self::LOGKEY,$file['offs'])); - //$this->msgs(self::BPM_GET,sprintf('%s %ld',$this->recv->name_size_time,($file['offs'] < 0) ? 0 : $file['offs'])); if (((int)$file['offs'] === -1) && (! $this->capGet(self::F_NOREL,self::O_THEY))) { Log::debug(sprintf('%s:- Assuming the remote wants NR mode, since offset is [%d] and they didnt specify an OPT with it',self::LOGKEY,$file['offs'])); $this->capSet(self::F_NOREL,self::O_THEY); } + if ($this->capGet(self::F_NOREL,self::O_YES)) + $this->msgs(self::BPM_GET,sprintf('%s %ld',$this->recv->name_size_time,($file['offs'] < 0) ? 0 : $file['offs'])); break; } @@ -1302,7 +1302,12 @@ final class Binkp extends BaseProtocol if ($this->DEBUG) Log::debug(sprintf('%s: - protocol_session LOOP',self::LOGKEY)); - if (! $this->sessionGet(self::SE_INIT|self::SE_SENDFILE|self::SE_SENTEOB|self::SE_NOFILES) && ! $this->send->fd) { + if ((! $this->sessionGet(self::SE_INIT)) + && (! $this->sessionGet(self::SE_SENDFILE)) + && (! $this->sessionGet(self::SE_SENTEOB)) + && (! $this->sessionGet(self::SE_NOFILES)) + && (! $this->send->fd)) + { // Open our next file to send if ($this->send->total_count && ! $this->send->fd) $this->send->open(); @@ -1312,7 +1317,7 @@ final class Binkp extends BaseProtocol $this->sessionSet(self::SE_SENDFILE); // NR mode, we wait for an M_GET before sending - if ($this->capGet(self::F_NOREL,self::O_WE)) { + if ($this->capGet(self::F_NOREL,self::O_YES)) { $this->sessionSet(self::SE_WAITGET); Log::debug(sprintf('%s:- NR mode, waiting for M_GET',self::LOGKEY)); @@ -1334,7 +1339,12 @@ final class Binkp extends BaseProtocol } } - if (! $this->sessionGet(self::SE_INIT|self::SE_WAITGOT|self::SE_SENTEOB|self::SE_DELAYEOB) && $this->sessionGet(self::SE_NOFILES)) { + if ((! $this->sessionGet(self::SE_INIT)) + && (! $this->sessionGet(self::SE_WAITGOT)) + && (! $this->sessionGet(self::SE_SENTEOB)) + && (! $this->sessionGet(self::SE_DELAYEOB)) + && $this->sessionGet(self::SE_NOFILES)) + { $this->msgs(self::BPM_EOB,''); $this->sessionSet(self::SE_SENTEOB); }