Fix seenby/path addresses, fix when eom signature is split over the readbuf
This commit is contained in:
parent
0834288a28
commit
403dde0d35
@ -208,8 +208,23 @@ class Message extends FTNBase
|
||||
{
|
||||
$o = new self($domain);
|
||||
|
||||
try {
|
||||
$o->header = unpack(self::unpackheader(self::header),substr($msg,0,self::HEADER_LEN));
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error(sprintf('%s:! Error bad packet header',self::LOGKEY));
|
||||
$validator = Validator::make([
|
||||
'header' => substr($msg,0,self::HEADER_LEN),
|
||||
],[
|
||||
'header' => [function ($attribute,$value,$fail) use ($e) { return $fail($e->getMessage()); }]
|
||||
]);
|
||||
|
||||
if ($validator->fails())
|
||||
$o->errors = $validator;
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
||||
$ptr = 0;
|
||||
// To User
|
||||
$o->user_to = strstr(substr($msg,self::HEADER_LEN+$ptr),"\x00",TRUE);
|
||||
@ -577,7 +592,7 @@ class Message extends FTNBase
|
||||
if ($aos->has($ftn))
|
||||
$ao = $aos->get($ftn);
|
||||
else
|
||||
$aos->put($ftn,$ao=(bool)Address::findFTN($ftn));
|
||||
$aos->put($ftn,($ao=(Address::findFTN($ftn))?->id));
|
||||
|
||||
if (! $ao) {
|
||||
Log::alert(sprintf('%s:! Undefined Node [%s] in %s.',self::LOGKEY,$ftn,$type));
|
||||
|
@ -154,16 +154,10 @@ class Packet extends FTNBase implements \Iterator, \Countable
|
||||
$buf_ptr = 0;
|
||||
$message = '';
|
||||
$readbuf = '';
|
||||
$last = '';
|
||||
|
||||
while ($buf_ptr || (! feof($f) && ($readbuf=fread($f,self::BLOCKSIZE)))) {
|
||||
// A message header is atleast 0x22 chars long
|
||||
if (strlen($readbuf) < self::PACKED_MSG_HEADER_LEN) {
|
||||
$message .= $readbuf;
|
||||
$buf_ptr = 0;
|
||||
|
||||
continue;
|
||||
|
||||
} elseif (strlen($message) < self::PACKED_MSG_HEADER_LEN) {
|
||||
if (strlen($message) < self::PACKED_MSG_HEADER_LEN) {
|
||||
$addchars = self::PACKED_MSG_HEADER_LEN-strlen($message);
|
||||
$message .= substr($readbuf,$buf_ptr,$addchars);
|
||||
$buf_ptr += $addchars;
|
||||
@ -175,8 +169,35 @@ class Packet extends FTNBase implements \Iterator, \Countable
|
||||
}
|
||||
}
|
||||
|
||||
// If we didnt find a packet end, perhaps there are no more
|
||||
// Take 2 chars from the buffer and check if we have our end packet signature
|
||||
if ($last && ($buf_ptr == 0)) {
|
||||
$last .= substr($readbuf,0,2);
|
||||
|
||||
if (($end=strpos($last,"\x00\x02\x00",$buf_ptr)) !== FALSE) {
|
||||
$o->parseMessage(substr($message,0,$end-2),$domain);
|
||||
$last = '';
|
||||
$message = '';
|
||||
$buf_ptr = 1+$end;
|
||||
|
||||
// Loop to rebuild our header for the next message
|
||||
continue;
|
||||
}
|
||||
|
||||
$last = '';
|
||||
}
|
||||
|
||||
if (($end=strpos($readbuf,"\x00\x02\x00",$buf_ptr)) === FALSE) {
|
||||
// In case our packet break is at the end of the buffer
|
||||
$last = substr($readbuf,-2);
|
||||
|
||||
if ((str_contains($last,"\x00")) && ($fstat['size']-ftell($f) > 2)) {
|
||||
$message .= substr($readbuf,$buf_ptr);
|
||||
$buf_ptr = 0;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$last = '';
|
||||
$end = strpos($readbuf,"\x00\x00\x00",$buf_ptr);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user