init fragmentation

Calculated the intended message length of HyBi-10 frame
Commented out socket recv buffer
Added onError to demonstration
This commit is contained in:
Chris Boden 2011-11-11 16:37:53 -05:00
parent d9283d9593
commit 021a185753
3 changed files with 20 additions and 0 deletions

View File

@ -53,6 +53,10 @@ class Chat implements SocketObserver {
public function onClose(SocketInterface $conn) { public function onClose(SocketInterface $conn) {
$this->_clients->detach($conn); $this->_clients->detach($conn);
} }
public function onError(SocketInterface $conn, \Exception $e) {
return $this->_factory->newCommand('CloseConnection', $conn);
}
} }
// Run the server application through the WebSocket protocol // Run the server application through the WebSocket protocol

View File

@ -96,12 +96,25 @@ class HyBi10 implements VersionInterface {
} }
if($payloadLength === 126) { if($payloadLength === 126) {
$msg_len = bindec(sprintf('%08b', ord($data[2])) . sprintf('%08b', ord($data[3])));
$mask = substr($data, 4, 4); $mask = substr($data, 4, 4);
$payloadOffset = 8; $payloadOffset = 8;
} elseif($payloadLength === 127) { } elseif($payloadLength === 127) {
$msg_len = bindec(
sprintf('%08b', ord($data[2]))
. sprintf('%08b', ord($data[3]))
. sprintf('%08b', ord($data[4]))
. sprintf('%08b', ord($data[5]))
. sprintf('%08b', ord($data[6]))
. sprintf('%08b', ord($data[7]))
. sprintf('%08b', ord($data[8]))
. sprintf('%08b', ord($data[9]))
);
$mask = substr($data, 10, 4); $mask = substr($data, 10, 4);
$payloadOffset = 14; $payloadOffset = 14;
} else { } else {
$msg_len = $payloadLength;
$mask = substr($data, 2, 4); $mask = substr($data, 2, 4);
$payloadOffset = 6; $payloadOffset = 6;
} }

View File

@ -105,11 +105,14 @@ class Server implements SocketObserver, \IteratorAggregate {
// This idea works* but... // This idea works* but...
// 1) A single DDOS attack will block the entire application (I think) // 1) A single DDOS attack will block the entire application (I think)
// 2) What if the last message in the frame is equal to $recv_bytes? Would loop until another msg is sent // 2) What if the last message in the frame is equal to $recv_bytes? Would loop until another msg is sent
// 3) This failed...an intermediary can set their buffer lower and this still propagates a fragment
// Need to 1) proc_open the recv() calls. 2) ??? // Need to 1) proc_open the recv() calls. 2) ???
/*
while ($bytes === $recv_bytes) { while ($bytes === $recv_bytes) {
$bytes = $conn->recv($buf, $recv_bytes, 0); $bytes = $conn->recv($buf, $recv_bytes, 0);
$data .= $buf; $data .= $buf;
} }
*/
$res = $this->onRecv($conn, $data); $res = $this->onRecv($conn, $data);
} else { } else {