/.settings
application/hub/config-local.php
db/node_data/*.serialized
+db/node_list/*.serialized
db/node_states/*.serialized
db/peer_states/*.serialized
docs/warn.log
$dataSetInstance->addCriteria(self::DB_COLUMN_PEER_SESSION_ID, $packageData[NetworkPackage::PACKAGE_DATA_SENDER]);
// Get peer name
- if (!@socket_getpeername($socketResource, $peerName, $peerPort)) {
+ if (!socket_getpeername($socketResource, $peerName, $peerPort)) {
// Get last error
$lastError = socket_last_error($socketResource);
*/
public function purgeOldEntriesBySocketResource ($socketResource) {
// Get peer name
- if (!@socket_getpeername($socketResource, $peerName, $peerPort)) {
+ if (!socket_getpeername($socketResource, $peerName, $peerPort)) {
// Get last error
$lastError = socket_last_error($socketResource);
$ownAddress = Registry::getRegistry()->getInstance('node')->getAddressPort($this);
// Does it match?
- // @TODO Numeric or alpha-numeric index?
$matches = ($ownAddress === $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
// Return result
$decodedData = false;
// Debug message
- //* NOISY-DEBUG: */ $this->debugOutput('HANDLER: Handling TCP package from peer ' . $resource);
+ /* NOISY-DEBUG: */ $this->debugOutput('TCP-HANDLER: Handling TCP package from peer ' . $resource . ',last error=' . socket_strerror(socket_last_error($resource)));
/*
* Read the raw data from socket. If you change PHP_BINARY_READ to
- * PHP_NORMAL_READ, this line will endless block. We only have
- * simultanous threads and no real threads.
+ * PHP_NORMAL_READ, this line will endless block. This script does only
+ * provide simultanous threads, not real.
*/
$rawData = socket_read($resource, $this->getConfigInstance()->getConfigEntry('tcp_buffer_length'), PHP_BINARY_READ);
// Debug output of read data length
- //* NOISY-DEBUG: */ $this->debugOutput('TCP-HANDLER: rawData[]=' . strlen($rawData));
+ /* NOISY-DEBUG: */ $this->debugOutput('TCP-HANDLER: rawData[' . gettype($rawData) . ']=' . strlen($rawData) . ',resource=' . $resource . ',error=' . socket_strerror(socket_last_error($resource)));
// Is it valid?
if (($rawData === false) || (socket_last_error($resource) > 0)) {
$this->setErrorCode(self::SOCKET_ERROR_EMPTY_DATA);
} else {
/*
- * Low-level checks of the raw data went all fine, we can now
- * decode the raw data. This may still fail because of invalid
- * encoded data.
+ * Low-level checks of the raw data went all fine, now decode the
+ * raw data. This may still fail because of invalid encoded data.
*/
$decodedData = $this->getInputStreamInstance()->streamData($rawData);
}
//* NOISY-DEBUG: */ $this->debugOutput('CONNECTION: Sending out ' . strlen($encodedData) . ' bytes,bufferSize=' . $bufferSize . ',diff=' . $this->diff);
if ($this->diff >= 0) {
// Send all out (encodedData is smaller than or equal buffer size)
- $sentBytes = @socket_write($socketResource, $encodedData, ($bufferSize - $this->diff));
+ $sentBytes = socket_write($socketResource, $encodedData, ($bufferSize - $this->diff));
} else {
// Send buffer size out
- $sentBytes = @socket_write($socketResource, $encodedData, $bufferSize);
+ $sentBytes = socket_write($socketResource, $encodedData, $bufferSize);
}
// If there was an error, we don't continue here
socket_clear_error($this->getSocketResource());
// Call the shutdown function on the currently set socket
- if (!@socket_shutdown($this->getSocketResource())) {
+ if (!socket_shutdown($this->getSocketResource())) {
// Could not shutdown socket, this is fine if e.g. the other side is not connected, so analyse it
if (socket_last_error($this->getSocketResource()) != 107) {
// Something bad happened while we shutdown a socket
// Handle it here, if not main socket
if ($currentSocket != $this->getSocketResource()) {
// ... or else it will raise warnings like 'Transport endpoint is not connected'
- //* NOISY-DEBUG: */ $this->debugOutput('TCP-LISTENER: currentSocket=' . $currentSocket);
+ //* NOISY-DEBUG: */ $this->debugOutput('TCP-LISTENER: currentSocket=' . $currentSocket . ',server=' . $this->getSocketResource());
$this->getHandlerInstance()->processRawDataFromResource($currentSocket);
} // END - if
*/
public function doListen() {
// Read a package and determine the peer
- $amount = @socket_recvfrom($this->getSocketResource(), $pkt, 1500, 0, $peer, $port);
+ $amount = @socket_recvfrom($this->getSocketResource(), $rawData, $this->getConfigInstance()->getConfigEntry('udp_buffer_length'), MSG_DONTWAIT, $peer, $port);
// Get last error
$lastError = socket_last_error($this->getSocketResource());
* This (resource temporary unavailable) can be safely ignored on
* "listening" UDP ports. If we don't clear the error here, our UDP
* "listener" won't read any packages except if the UDP sender
- * starts the transmission before this "listener came up...
+ * starts the transmission before this "listener" came up...
*/
socket_clear_error($this->getSocketResource());
// Skip further processing
return;
- } elseif ((empty($pkt)) || (trim($peer) == '')) {
+ } elseif ((empty($rawData)) || (trim($peer) == '')) {
// Zero sized packages/peer names are usual in non-blocking mode
return;
} // END - if
// Debug only
- $this->debugOutput('UDP-LISTENER: Handling UDP package with size ' . strlen($pkt) . ' from peer ' . $peer . ':' . $port);
+ $this->debugOutput('UDP-LISTENER: Handling UDP package with size ' . strlen($rawData) . ' from peer ' . $peer . ':' . $port);
}
/**
* Also make sure the error code is SOCKET_ERROR_UNHANDLED because we
* only want to handle unhandled packages here.
*/
- /* NOISY-DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: errorCode=' . $decodedData[BaseRawDataHandler::PACKAGE_ERROR_CODE]);
+ /* NOISY-DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: errorCode=' . $decodedData[BaseRawDataHandler::PACKAGE_ERROR_CODE] . '(' . BaseRawDataHandler::SOCKET_ERROR_UNHANDLED . ')');
assert($decodedData[BaseRawDataHandler::PACKAGE_ERROR_CODE] == BaseRawDataHandler::SOCKET_ERROR_UNHANDLED);
// Remove the last chunk SEPARATOR (because it is being added and we don't need it)
// The socket resource should not match server socket
if ($socketResource != $this->getListenerInstance()->getSocketResource()) {
// Try to determine the peer's IP number
- if (!@socket_getpeername($socketResource, $peerName)) {
+ if (!socket_getpeername($socketResource, $peerName)) {
// Handle the socket error with a faked recipientData array
$this->handleSocketError($socketResource, array('0.0.0.0', '0'));
/*
}
// Output error message
- $this->debugOutput('POOL: Adding peer ' . $peerName . ', socketResource=' . $socketResource);
+ $this->debugOutput('POOL: Adding peer ' . $peerName . ',socketResource=' . $socketResource);
// Add it finally to the pool
$this->addPoolEntry($socketResource);
} // END - if
// Try to get the "peer"'s name
- if (!@socket_getpeername($socket, $peerIp)) {
+ if (!socket_getpeername($socket, $peerIp)) {
// Handle the socket error with given package data
$this->handleSocketError($socket, explode(':', $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
} // END - if