Пример #1
0
 public function testId()
 {
     #$id = (string)Uuid::uuid4();
     #$id = (string)Uuid::uuid5(Uuid::NAMESPACE_DNS, 'php.net');
     $key = sslKeyPubClean(static::SSL_KEY_PUB1);
     $keyBin = base64_decode($key);
     $id = (string) Uuid::uuid5(Uuid::NAMESPACE_X500, $keyBin);
     $this->assertEquals('d4773c00-6a11-540a-b72c-ed106ef8309b', $id);
     $id = (string) Uuid::uuid5(Uuid::NAMESPACE_X500, static::SSL_KEY_PUB1);
     $this->assertEquals('91a3d7b5-28fe-52d1-a56d-b09093c63c84', $id);
     $id = (string) Uuid::uuid5(Uuid::NAMESPACE_X500, 'hello world');
     $this->assertEquals('dbd9b896-6d7c-5852-895c-ecc5735cf874', $id);
     $id = (string) Uuid::uuid5(Uuid::NAMESPACE_DNS, 'hello world');
     $this->assertEquals('823a2f73-a936-56c3-b8b4-03641bd74f35', $id);
     $id = (string) Uuid::uuid5(Uuid::NAMESPACE_X500, 'my_name');
     $this->assertEquals('045fe53e-72be-5a76-8f58-783aed5c99d5', $id);
     $this->assertTrue(Uuid::isValid('91a3d7b5-28fe-52d1-a56d-b09093c63c84'));
     $this->assertFalse(Uuid::isValid('x1a3d7b5-28fe-52d1-a56d-b09093c63c84'));
     $id = '00000000-0000-4000-8000-000000000000';
     $this->assertTrue(Uuid::isValid($id));
     $id = '00000000-0000-4000-8000-00000000000x';
     $this->assertFalse(Uuid::isValid($id));
     $id = '00000000-0000-4000-8000-0000000000';
     $this->assertFalse(Uuid::isValid($id));
     $id = '00000000-0000-0000-0000-000000000000';
     $this->assertTrue(Uuid::isValid($id));
     $id = 'badfood0-0000-4000-a000-000000000000';
     $this->assertFalse(Uuid::isValid($id));
     $id = 'cafed00d-2131-4159-8e11-0b4dbadb1738';
     $this->assertTrue(Uuid::isValid($id));
 }
Пример #2
0
 /**
  */
 function __construct($uuid)
 {
     if (FALSE === UuidGenerator::isValid($uuid)) {
         throw new \InvalidArgumentException("Provided string '{$uuid}' is not valid UUID");
     }
     $this->_uuid = new String($uuid);
 }
Пример #3
0
 /**
  * @covers Alchemy\Phrasea\Border\File::getUUID
  */
 public function testNewUuid()
 {
     $file = __DIR__ . '/../../../../files/temporay.jpg';
     if (file_exists($file)) {
         unlink($file);
     }
     copy(__DIR__ . '/../../../../files/p4logo.jpg', $file);
     $borderFile = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess($file), self::$DI['collection']);
     $uuid = $borderFile->getUUID(true, false);
     $this->assertTrue(Uuid::isValid($uuid));
     $this->assertEquals($uuid, $borderFile->getUUID());
     $borderFile = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess($file), self::$DI['collection']);
     $newuuid = $borderFile->getUUID(true, true);
     $this->assertTrue(Uuid::isValid($newuuid));
     $this->assertNotEquals($uuid, $newuuid);
     $this->assertEquals($newuuid, $borderFile->getUUID());
     $borderFile = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess($file), self::$DI['collection']);
     $uuid = $borderFile->getUUID();
     $this->assertTrue(Uuid::isValid($uuid));
     $this->assertEquals($uuid, $newuuid);
     $this->assertEquals($uuid, $borderFile->getUUID());
     if (file_exists($file)) {
         unlink($file);
     }
 }
Пример #4
0
 /**
  * @test
  */
 public function testId()
 {
     $name = 'Douglas';
     $player = new HangmanPlayer(null, $name);
     $this->assertTrue(Uuid::isValid((string) $player->getId()));
     $this->assertEquals($name, $player->getName());
     $this->assertEquals(6, $player->getRemainingLives());
     $this->assertNull($player->getGame());
 }
Пример #5
0
 /**
  * Delete object from database
  * @param  string $document_id Identifier to delete document
  * @return boolean             Return TRUE if delete, else, FALSE
  */
 public function delete($document_id)
 {
     if (is_null($document_id) || !Uuid::isValid($document_id)) {
         return false;
     }
     if (file_exists($file = $this->dataPath . DIRECTORY_SEPARATOR . $document_id)) {
         return unlink($file);
     }
     return false;
 }
Пример #6
0
 /**
  * @param string
  */
 public final function __construct($uuid)
 {
     if (!is_string($uuid)) {
         throw new InvalidArgumentException('Uuid expected a string.');
     }
     if (!\Rhumsaa\Uuid\Uuid::isValid($uuid)) {
         throw new InvalidArgumentException('Invalid Uuid format.');
     }
     $this->uuid = \Rhumsaa\Uuid\Uuid::fromString($uuid);
 }
Пример #7
0
 /**
  * {@inheritdoc}
  *
  * @param Uuid|null                                 $value
  * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
  */
 public function convertToDatabaseValue($value, AbstractPlatform $platform)
 {
     if (empty($value)) {
         return null;
     }
     if ($value instanceof Uuid || Uuid::isValid($value)) {
         return (string) $value;
     }
     throw ConversionException::conversionFailed($value, self::NAME);
 }
 /**
  * Mutator for uuid attribute
  *
  * @throw InvalidUuidFormatException
  * @return string
  */
 public function setUuidAttribute($value)
 {
     //If it's a instance of Uuid, convert to string
     if ($value instanceof Uuid) {
         $value = $value->toString();
     }
     //If the uuid is not valid
     if (!Uuid::isValid($value)) {
         throw new InvalidUuidFormatException('The format of the uuid ' . $value . ' is not valid');
     }
     $this->attributes['uuid'] = UuidConverter::uuidToBinary($value);
 }
Пример #9
0
 /**
  * @param string $id article_id or permalink
  * @return Article
  * @throws ModelNotFoundException
  */
 public function findByIdentifier($id)
 {
     //if the id is a uuid, try that or fail.
     if (Uuid::isValid($id)) {
         return parent::findOrFail($id);
     }
     //otherwise attempt treat the id as a permalink and first try the model, then try the history
     try {
         return $this->where('permalink', '=', $id)->firstOrFail();
     } catch (ModelNotFoundException $e) {
         //id or permalink not found, try permalink history
         return ArticlePermalink::findOrFail($id)->article;
     }
 }
Пример #10
0
 /**
  * check if API-Key and WWW-Authorization valid
  * @param $token
  * @param $authentication
  * @return bool
  */
 public function isApiKeyUserPassValid($token, $authentication)
 {
     try {
         if (Uuid::isValid($token)) {
             $check = $this->getDB()->query()->where('email', '=', base64_decode($authentication))->where('token', '=', $token)->get()->count();
             if (!$check) {
                 return false;
             }
             return true;
         }
     } catch (\Exception $e) {
         $this->writeToJSON(['errmsg' => 'service unavailable'], 503);
     }
     return false;
 }
 /**
  * Fetch a resource
  *
  * @param  mixed $id
  * @return ApiProblem|mixed
  */
 public function fetch($id)
 {
     try {
         if (!Uuid::isValid($id)) {
             return new ApiProblem(400, 'Invalid identifier');
         }
         $repository = $this->entityManager->getRepository('Application\\V1\\Entity\\Pages');
         /* @var $pagesEntity PagesEntity */
         $pagesEntity = $repository->findOneByUuid($id);
         if (is_null($pagesEntity)) {
             return new ApiProblem(404, 'Requested site not found');
         }
         return $pagesEntity;
     } catch (\Exception $e) {
         return new ApiProblem(500, $e->getMessage());
     }
 }
 /**
  * Fetch all or a subset of resources
  *
  * @param  array $params
  * @return ApiProblem|mixed
  */
 public function fetchAll($params = array())
 {
     $pageId = $this->getEvent()->getRouteMatch()->getParam('page_id', null);
     if (!Uuid::isValid($pageId)) {
         return new ApiProblem(400, 'Invalid identifier');
     }
     /* @var $pageEntity PagesEntity */
     $pageEntity = $this->entityManager->getRepository('Application\\V1\\Entity\\Pages')->findOneByUuid($pageId);
     if (is_null($pageEntity)) {
         return new ApiProblem(404, 'Not found result of missed page');
     }
     if ($pageEntity->getStatusNumeric() !== PageInterface::STATUS_DONE) {
         return new ApiProblem(428, 'Not all images downloaded yet');
     }
     $qb = $this->entityManager->getRepository('Application\\V1\\Entity\\Images')->createQueryBuilder('i');
     $qb->where('i.page = :page')->setParameter('page', $pageEntity);
     return new Paginator(new DoctrineAdapter(new DoctrinePaginator($qb->getQuery())));
 }
Пример #13
0
 /**
  * {@inheritDoc}
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!Uuid::isValid($input->getArgument('uuid'))) {
         throw new Exception('Invalid UUID (' . $input->getArgument('uuid') . ')');
     }
     $uuid = Uuid::fromString($input->getArgument('uuid'));
     $table = $this->getHelperSet()->get('table');
     $table->setLayout(TableHelper::LAYOUT_BORDERLESS);
     $table->addRows(array(array('encode:', 'STR:', (string) $uuid), array('', 'INT:', (string) $uuid->getInteger())));
     if ($uuid->getVariant() != Uuid::RFC_4122) {
         $table->addRows(array(array('decode:', 'variant:', 'Not an RFC 4122 UUID')));
         $table->render($output);
         return;
     }
     switch ($uuid->getVersion()) {
         case 1:
             $version = '1 (time and node based)';
             break;
         case 2:
             $version = '2 (DCE security based)';
             break;
         case 3:
             $version = '3 (name based, MD5)';
             break;
         case 4:
             $version = '4 (random data based)';
             break;
         case 5:
             $version = '5 (name based, SHA-1)';
             break;
     }
     $table->addRows(array(array('decode:', 'variant:', 'RFC 4122'), array('', 'version:', $version)));
     if ($uuid->getVersion() == 1) {
         $table->addRows(array(array('', 'content:', 'time:  ' . $uuid->getDateTime()->format('c')), array('', '', 'clock: ' . $uuid->getClockSequence() . ' (usually random)'), array('', '', 'node:  ' . substr(chunk_split($uuid->getNodeHex(), 2, ':'), 0, -1))));
     }
     if ($uuid->getVersion() == 4) {
         $table->addRows(array(array('', 'content:', substr(chunk_split($uuid->getHex(), 2, ':'), 0, -1)), array('', '', '(no semantics: random data only)')));
     }
     if ($uuid->getVersion() == 3 || $uuid->getVersion() == 5) {
         $table->addRows(array(array('', 'content:', substr(chunk_split($uuid->getHex(), 2, ':'), 0, -1)), array('', '', '(not decipherable: MD5 message digest only)')));
     }
     $table->render($output);
 }
Пример #14
0
 protected function evaluateGoodStory($story)
 {
     $this->assertArrayHasKey('databox_id', $story);
     $this->assertTrue(is_int($story['databox_id']));
     $this->assertArrayHasKey('story_id', $story);
     $this->assertTrue(is_int($story['story_id']));
     $this->assertArrayHasKey('updated_on', $story);
     $this->assertDateAtom($story['updated_on']);
     $this->assertArrayHasKey('created_on', $story);
     $this->assertDateAtom($story['created_on']);
     $this->assertArrayHasKey('collection_id', $story);
     $this->assertTrue(is_int($story['collection_id']));
     $this->assertArrayHasKey('thumbnail', $story);
     $this->assertArrayHasKey('uuid', $story);
     $this->assertArrayHasKey('@entity@', $story);
     $this->assertEquals(V1::OBJECT_TYPE_STORY, $story['@entity@']);
     $this->assertTrue(Uuid::isValid($story['uuid']));
     if (!is_null($story['thumbnail'])) {
         $this->assertTrue(is_array($story['thumbnail']));
         $this->assertArrayHasKey('player_type', $story['thumbnail']);
         $this->assertTrue(is_string($story['thumbnail']['player_type']));
         $this->assertArrayHasKey('permalink', $story['thumbnail']);
         $this->assertArrayHasKey('mime_type', $story['thumbnail']);
         $this->assertTrue(is_string($story['thumbnail']['mime_type']));
         $this->assertArrayHasKey('height', $story['thumbnail']);
         $this->assertTrue(is_int($story['thumbnail']['height']));
         $this->assertArrayHasKey('width', $story['thumbnail']);
         $this->assertTrue(is_int($story['thumbnail']['width']));
         $this->assertArrayHasKey('filesize', $story['thumbnail']);
         $this->assertTrue(is_int($story['thumbnail']['filesize']));
     }
     $this->assertArrayHasKey('records', $story);
     $this->assertInternalType('array', $story['records']);
     foreach ($story['metadatas'] as $key => $metadata) {
         if (null !== $metadata) {
             $this->assertInternalType('string', $metadata);
         }
         if ($key === '@entity@') {
             continue;
         }
         $this->assertEquals(0, strpos($key, 'dc:'));
     }
     $this->assertArrayHasKey('@entity@', $story['metadatas']);
     $this->assertEquals(V1::OBJECT_TYPE_STORY_METADATA_BAG, $story['metadatas']['@entity@']);
     foreach ($story['records'] as $record) {
         $this->evaluateGoodRecord($record);
     }
 }
Пример #15
0
 /**
  * @covers Rhumsaa\Uuid\Console\Command\GenerateCommand::execute
  * @covers Rhumsaa\Uuid\Console\Command\GenerateCommand::createUuid
  * @covers Rhumsaa\Uuid\Console\Command\GenerateCommand::validateNamespace
  */
 public function testExecuteForUuidSpecifyVersion5WithCount()
 {
     $generate = new GenerateCommand();
     $input = new StringInput('5 ns:DNS "python.org" -c 21', $generate->getDefinition());
     $output = new TestOutput();
     $this->execute->invoke($generate, $input, $output);
     $this->assertCount(21, $output->messages);
     foreach ($output->messages as $uuid) {
         $this->assertTrue(Uuid::isValid($uuid));
         $this->assertEquals(5, Uuid::fromString($uuid)->getVersion());
         $this->assertEquals('886313e1-3b8a-5372-9b90-0c9aee199e5d', $uuid);
     }
 }
Пример #16
0
 public function msgHandle($msgName, $msgData)
 {
     #fwrite(STDOUT, 'msgHandle: /'.$msgRaw.'/'."\n");
     $msgHandleReturnValue = '';
     if ($msgName == 'noop') {
         $this->log('debug', 'no operation');
     } elseif ($msgName == 'test') {
         $len = 0;
         $test_data = 'N/A';
         if (array_key_exists('len', $msgData)) {
             $len = (int) $msgData['len'];
         }
         if (array_key_exists('test_data', $msgData)) {
             $test_data = $msgData['test_data'];
         }
         $this->log('debug', 'test: ' . $len . ' /' . $test_data . '/');
     } elseif ($msgName == 'hello') {
         if (array_key_exists('ip', $msgData)) {
             $ip = $msgData['ip'];
             if ($ip != '127.0.0.1' && strIsIp($ip)) {
                 $this->getSettings()->data['node']['uriPub'] = 'tcp://' . $ip;
                 $this->getSettings()->setDataChanged(true);
             }
         }
         $this->log('debug', 'actions execute: CRITERION_AFTER_HELLO');
         $this->actionsExecute(ClientAction::CRITERION_AFTER_HELLO);
         $msgHandleReturnValue .= $this->sendId();
     } elseif ($msgName == 'id') {
         #print __CLASS__.'->'.__FUNCTION__.': '.$msgName.', '.(int)$this->getStatus('hasId')."\n";
         if ($this->getTable()) {
             if (!$this->getStatus('hasId')) {
                 $release = 0;
                 $id = '';
                 $port = 0;
                 $strKeyPub = '';
                 $strKeyPubSign = '';
                 $strKeyPubFingerprint = '';
                 $bridgeServer = false;
                 $bridgeClient = false;
                 $isChannelPeer = false;
                 $hashcash = '';
                 if (array_key_exists('release', $msgData)) {
                     $release = (int) $msgData['release'];
                 }
                 if (array_key_exists('id', $msgData)) {
                     $id = $msgData['id'];
                 }
                 if (array_key_exists('port', $msgData)) {
                     $port = (int) $msgData['port'];
                 }
                 if (array_key_exists('sslKeyPub', $msgData)) {
                     $strKeyPub = base64_decode($msgData['sslKeyPub']);
                 }
                 if (array_key_exists('sslKeyPubSign', $msgData)) {
                     $strKeyPubSign = base64_decode($msgData['sslKeyPubSign']);
                 }
                 if (array_key_exists('bridgeServer', $msgData)) {
                     $bridgeServer = (bool) $msgData['bridgeServer'];
                 }
                 if (array_key_exists('bridgeClient', $msgData)) {
                     $bridgeClient = (bool) $msgData['bridgeClient'];
                 }
                 if (array_key_exists('isChannel', $msgData)) {
                     // isChannelPeer
                     $isChannelPeer = (bool) $msgData['isChannel'];
                 }
                 if ($isChannelPeer) {
                     $this->setStatus('isChannelPeer', true);
                 }
                 $this->log('debug', $this->getUri() . ' recv ' . $msgName . ': /' . $id . '/ /' . $port . '/ bs=' . (int) $bridgeServer . '');
                 $idOk = false;
                 $node = new Node();
                 if (Uuid::isValid($id) && $id != Uuid::NIL) {
                     $node->setIdHexStr($id);
                     $node->setUri('tcp://' . $this->getUri()->getHost() . ':' . $port);
                     $node->setBridgeServer($bridgeServer);
                     $node->setBridgeClient($bridgeClient);
                     $node->setTimeLastSeen(time());
                     $node = $this->getTable()->nodeEnclose($node);
                     #$this->log('debug', 'node ok: '.(int)is_object($node).' /'.$node->getIdHexStr().'/');
                     // Check if not Local Node
                     if (!$this->getLocalNode()->isEqual($node)) {
                         if ($strKeyPub) {
                             if ($strKeyPubSign) {
                                 if (openssl_verify($strKeyPub, $strKeyPubSign, $strKeyPub, OPENSSL_ALGO_SHA1)) {
                                     if (Node::genIdHexStr($strKeyPub) == $id) {
                                         // Check if a public key already exists.
                                         if ($node->getSslKeyPub()) {
                                             #$this->logColor('debug', 'SSL public key ok [Aa]', 'green');
                                             $idOk = true;
                                             if ($node->getSslKeyPub() == $strKeyPub) {
                                                 #$this->logColor('debug', 'SSL public key ok [Ab]', 'green');
                                                 $node->setSslKeyPubStatus('C');
                                                 $node->setDataChanged(true);
                                             }
                                         } else {
                                             // No public key found.
                                             $sslPubKey = openssl_pkey_get_public($strKeyPub);
                                             if ($sslPubKey !== false) {
                                                 $sslPubKeyDetails = openssl_pkey_get_details($sslPubKey);
                                                 if ($sslPubKeyDetails['bits'] >= Node::SSL_KEY_LEN_MIN) {
                                                     #$this->logColor('debug', 'SSL public key ok [B]', 'green');
                                                     $idOk = true;
                                                     $node->setSslKeyPub($strKeyPub);
                                                     $node->setSslKeyPubStatus('C');
                                                     $node->setDataChanged(true);
                                                 } else {
                                                     $msgHandleReturnValue .= $this->sendError(2020, $msgName);
                                                     $this->log('error', static::getErrorMsg(2020));
                                                 }
                                             } else {
                                                 $msgHandleReturnValue .= $this->sendError(2040, $msgName);
                                                 $this->log('error', static::getErrorMsg(2040));
                                             }
                                         }
                                     } else {
                                         $msgHandleReturnValue .= $this->sendError(1030, $msgName);
                                         $this->log('error', static::getErrorMsg(1030));
                                     }
                                 } else {
                                     $msgHandleReturnValue .= $this->sendError(2080, $msgName);
                                     $this->log('error', static::getErrorMsg(2080));
                                     while ($openSslErrorStr = openssl_error_string()) {
                                         $this->log('error', 'SSL: ' . $openSslErrorStr);
                                     }
                                 }
                             } else {
                                 $msgHandleReturnValue .= $this->sendError(2005, $msgName);
                                 $this->log('error', static::getErrorMsg(2005));
                             }
                         } else {
                             $msgHandleReturnValue .= $this->sendError(2000, $msgName);
                             $this->log('error', static::getErrorMsg(2000));
                         }
                     } else {
                         // It's the ID from the Local Node. Something is wrong.
                         $msgHandleReturnValue .= $this->sendError(1020, $msgName);
                         $this->log('error', static::getErrorMsg(1020));
                     }
                 } else {
                     $msgHandleReturnValue .= $this->sendError(9000, $msgName);
                     $this->log('error', static::getErrorMsg(9000));
                 }
                 if ($idOk) {
                     $this->setStatus('hasId', true);
                     $this->setNode($node);
                     if ($this->getStatus('isOutbound')) {
                         $this->getNode()->incConnectionsOutboundSucceed();
                     }
                     if ($this->getStatus('isInbound')) {
                         $this->getNode()->incConnectionsInboundSucceed();
                     }
                     if (!$this->debug && $node->getBridgeServer() && $this->getStatus('bridgeTargetUri')) {
                         $this->logColor('debug', 'bridge server: ' . $this->getStatus('bridgeServerUri'), 'yellow');
                         $this->logColor('debug', 'bridge target: ' . $this->getStatus('bridgeTargetUri'), 'yellow');
                         $actions = array();
                         $action = new ClientAction(ClientAction::CRITERION_AFTER_ID_SUCCESSFULL);
                         $action->setName('bridge_server_init_ssl');
                         $action->functionSet(function ($action, $client) {
                             $this->logColor('debug', 'init ssl because of bridge server', 'green');
                             $client->sendSslInit();
                         });
                         $actions[] = $action;
                         $action = new ClientAction(ClientAction::CRITERION_AFTER_HAS_SSL);
                         $action->setName('bridge_server_send_connect');
                         $action->functionSet(function ($action, $client) {
                             $this->logColor('debug', 'bridge ssl ok', 'yellow');
                             $client->sendBridgeConnect($client->getStatus('bridgeTargetUri'));
                         });
                         $actions[] = $action;
                         $this->actionsAdd($actions);
                     }
                     $msgHandleReturnValue .= $this->sendIdOk();
                     $this->log('debug', $this->getUri() . ' recv ' . $msgName . ': ID OK');
                 } else {
                     $msgHandleReturnValue .= $this->sendQuit();
                     $this->shutdown();
                 }
             } else {
                 $msgHandleReturnValue .= $this->sendError(1010, $msgName);
                 $this->log('error', static::getErrorMsg(1010));
             }
         } else {
             $msgHandleReturnValue .= $this->sendError(9010, $msgName);
             $this->log('error', static::getErrorMsg(9010));
         }
     } elseif ($msgName == 'id_ok') {
         $this->log('debug', $this->getUri() . ' recv ' . $msgName);
         $this->log('debug', 'actions execute: CRITERION_AFTER_ID_SUCCESSFULL');
         $this->actionsExecute(ClientAction::CRITERION_AFTER_ID_SUCCESSFULL);
         if ($this->getStatus('isChannelPeer')) {
             $this->consoleMsgAdd('New incoming channel connection from ' . $this->getUri() . '.', true, true, true);
         }
         if ($this->getStatus('isChannelPeer') || $this->getStatus('isChannelLocal')) {
             if ($this->getServer() && $this->getServer()->getKernel()) {
                 $contact = $this->getServer()->getKernel()->getAddressbook()->contactGetByNodeId($this->getNode()->getIdHexStr());
                 if ($contact) {
                     $text = 'You talked to ';
                     $text .= $this->getNode()->getIdHexStr() . ' (' . $contact->getUserNickname() . ')';
                     $text .= ' once before.';
                     $this->consoleMsgAdd($text, true, false);
                 } else {
                     $this->consoleMsgAdd('You never talked to ' . $this->getNode()->getIdHexStr() . ' before.', true, false);
                     $this->consoleMsgAdd('Verify the public keys with you conversation partner on another channel.', true, false);
                     $this->consoleMsgAdd('Public keys fingerprints:', true, false);
                     $this->consoleMsgAdd('  Yours: ' . $this->getLocalNode()->getSslKeyPubFingerprint(), true, false);
                     $this->consoleMsgAdd('  Peers: ' . $this->getNode()->getSslKeyPubFingerprint(), true, false);
                 }
             }
         }
     } elseif ($msgName == 'node_find') {
         if ($this->getStatus('hasId')) {
             $rid = '';
             $num = static::NODE_FIND_NUM;
             $nodeId = '';
             $hashcash = '';
             if (array_key_exists('rid', $msgData)) {
                 $rid = $msgData['rid'];
             }
             if (array_key_exists('num', $msgData)) {
                 $num = $msgData['num'];
             }
             if (array_key_exists('nodeId', $msgData)) {
                 $nodeId = $msgData['nodeId'];
             }
             if (array_key_exists('hashcash', $msgData)) {
                 $hashcash = $msgData['hashcash'];
             }
             $this->log('debug', $this->getUri() . ' recv ' . $msgName . ': ' . $rid);
             if ($rid) {
                 if ($hashcash && $this->hashcashVerify($hashcash, $this->getNode()->getIdHexStr(), static::HASHCASH_BITS_MIN)) {
                     if ($nodeId) {
                         $node = new Node();
                         $node->setIdHexStr($nodeId);
                         if ($node->isEqual($this->getLocalNode())) {
                             $this->log('debug', 'node find: find myself');
                             $msgHandleReturnValue .= $this->sendNodeFound($rid);
                         } elseif (!$node->isEqual($this->getNode()) && ($onode = $this->getTable()->nodeFind($node))) {
                             $this->log('debug', 'node find: find in table');
                             $msgHandleReturnValue .= $this->sendNodeFound($rid, array($onode));
                         } else {
                             $this->log('debug', 'node find: closest to "' . $node->getIdHexStr() . '"');
                             $nodes = $this->getTable()->nodeFindClosest($node, $num);
                             foreach ($nodes as $cnodeId => $cnode) {
                                 if ($cnode->isEqual($this->getNode())) {
                                     unset($nodes[$cnodeId]);
                                     break;
                                 }
                             }
                             $msgHandleReturnValue .= $this->sendNodeFound($rid, $nodes);
                         }
                     }
                 } else {
                     $msgHandleReturnValue .= $this->sendError(4000, $msgName);
                 }
             } else {
                 $msgHandleReturnValue .= $this->sendError(9000, $msgName);
                 $this->log('error', static::getErrorMsg(9000));
             }
         } else {
             $msgHandleReturnValue .= $this->sendError(1000, $msgName);
         }
     } elseif ($msgName == 'node_found') {
         if ($this->getStatus('hasId')) {
             $rid = '';
             $nodes = array();
             $hashcash = '';
             if (array_key_exists('rid', $msgData)) {
                 $rid = $msgData['rid'];
             }
             if (array_key_exists('nodes', $msgData)) {
                 $nodes = $msgData['nodes'];
             }
             if (array_key_exists('hashcash', $msgData)) {
                 $hashcash = $msgData['hashcash'];
             }
             if ($rid) {
                 $this->log('debug', $this->getUri() . ' recv ' . $msgName . ': ' . $rid);
                 $request = $this->requestGetByRid($rid);
                 if ($request) {
                     if ($hashcash && $this->hashcashVerify($hashcash, $this->getNode()->getIdHexStr(), static::HASHCASH_BITS_MAX)) {
                         $this->requestRemove($request);
                         $nodeId = $request['data']['nodeId'];
                         $nodesFoundIds = $request['data']['nodesFoundIds'];
                         $distanceOld = $request['data']['distance'];
                         $uri = '';
                         $this->log('debug', $this->getUri() . ' recv ' . $msgName . ': ' . $rid . ' nodes: ' . count($nodes));
                         if ($nodes) {
                             // Find the smallest distance.
                             foreach ($nodes as $nodeArId => $nodeAr) {
                                 $nodeArId = '';
                                 $nodeArSslPubKey = '';
                                 $nodeArBridgeServer = false;
                                 $nodeArBridgeClient = false;
                                 $nodeArBridgeDst = array();
                                 $node = new Node();
                                 if (isset($nodeAr['id'])) {
                                     $nodeArId = $nodeAr['id'];
                                 }
                                 if (isset($nodeAr['uri'])) {
                                     $node->setUri($nodeAr['uri']);
                                 }
                                 if (isset($nodeAr['sslKeyPub']) && $nodeAr['sslKeyPub']) {
                                     $nodeArSslPubKey = base64_decode($nodeAr['sslKeyPub']);
                                 }
                                 if (isset($nodeAr['bridgeServer'])) {
                                     $nodeArBridgeServer = $nodeAr['bridgeServer'];
                                 }
                                 if (isset($nodeAr['bridgeClient'])) {
                                     $nodeArBridgeClient = $nodeAr['bridgeClient'];
                                 }
                                 if (isset($nodeAr['bridgeDst'])) {
                                     # TODO
                                     $nodeArBridgeDst = $nodeAr['bridgeDst'];
                                 }
                                 $node->setBridgeServer($nodeArBridgeServer);
                                 $node->setBridgeServer($nodeArBridgeClient);
                                 $node->setTimeLastSeen(time());
                                 $distanceNew = $this->getLocalNode()->distanceHexStr($node);
                                 $this->log('debug', 'node found: ' . $nodeArId . ', do=/' . $distanceOld . '/ dn=/' . $distanceNew . '/');
                                 if ($nodeArId) {
                                     $node->setIdHexStr($nodeArId);
                                     if ($nodeArSslPubKey) {
                                         if (Node::genIdHexStr($nodeArSslPubKey) == $nodeArId) {
                                             if ($node->setSslKeyPub($nodeArSslPubKey)) {
                                                 if (!$this->getLocalNode()->isEqual($node)) {
                                                     if (!in_array($node->getIdHexStr(), $nodesFoundIds)) {
                                                         $nodesFoundIds[] = $nodeAr['id'];
                                                         if (count($nodesFoundIds) > static::NODE_FIND_MAX_NODE_IDS) {
                                                             array_shift($nodesFoundIds);
                                                         }
                                                         if ($nodeAr['id'] == $nodeId) {
                                                             $this->log('debug', 'node found: find completed');
                                                             $uri = '';
                                                         } else {
                                                             if ($distanceOld != $distanceNew) {
                                                                 $distanceMin = Node::idMinHexStr($distanceOld, $distanceNew);
                                                                 if ($distanceMin == $distanceNew) {
                                                                     // Is smaller then $distanceOld.
                                                                     $distanceOld = $distanceNew;
                                                                     $uri = $node->getUri();
                                                                 }
                                                             }
                                                         }
                                                         $this->getTable()->nodeEnclose($node);
                                                     } else {
                                                         $this->log('debug', 'node found: already known');
                                                     }
                                                 } else {
                                                     $this->log('debug', 'node found: myself, node equal');
                                                 }
                                             } else {
                                                 $this->log('debug', 'node found: public key invalid');
                                             }
                                         } else {
                                             $this->log('debug', 'node found: ID does not match public key');
                                         }
                                     } else {
                                         $this->log('debug', 'node found: no public key set');
                                     }
                                 } else {
                                     $this->log('debug', 'node found: no node id set');
                                 }
                             }
                         }
                         $this->log('debug', 'actions execute: CRITERION_AFTER_NODE_FOUND');
                         $this->actionsExecute(ClientAction::CRITERION_AFTER_NODE_FOUND);
                         if ((string) $uri) {
                             // Further search at the nearest node.
                             $this->log('debug', 'node found: uri (' . (string) $uri . ') ok');
                             $clientActions = array();
                             $action = new ClientAction(ClientAction::CRITERION_AFTER_ID_SUCCESSFULL);
                             $action->functionSet(function ($action, $client) use($nodeId, $distanceOld, $nodesFoundIds) {
                                 $client->sendNodeFind($nodeId, $distanceOld, $nodesFoundIds);
                             });
                             $clientActions[] = $action;
                             $this->getServer()->connect($uri, $clientActions);
                         }
                     } else {
                         $msgHandleReturnValue .= $this->sendError(4000, $msgName);
                     }
                 } else {
                     $msgHandleReturnValue .= $this->sendError(9000, $msgName);
                 }
                 $this->log('debug', $this->getUri() . ' recv ' . $msgName . ': ' . $rid . ' end');
             } else {
                 $msgHandleReturnValue .= $this->sendError(9000, $msgName);
             }
         } else {
             $msgHandleReturnValue .= $this->sendError(1000, $msgName);
         }
     } elseif ($msgName == 'msg') {
         if ($this->getStatus('hasId')) {
             if ($this->getMsgDb()) {
                 $rid = '';
                 $version = 0;
                 $id = '';
                 $srcNodeId = '';
                 $srcSslKeyPub = '';
                 $dstNodeId = '';
                 $subject = '';
                 $body = '';
                 $password = '';
                 $checksum = '';
                 $relayCount = 0;
                 $timeCreated = 0;
                 $hashcash = '';
                 if (array_key_exists('rid', $msgData)) {
                     $rid = $msgData['rid'];
                 }
                 if (array_key_exists('version', $msgData)) {
                     $version = (int) $msgData['version'];
                 }
                 if (array_key_exists('id', $msgData)) {
                     $id = $msgData['id'];
                 }
                 if (array_key_exists('srcNodeId', $msgData)) {
                     $srcNodeId = $msgData['srcNodeId'];
                 }
                 if (array_key_exists('srcSslKeyPub', $msgData)) {
                     $srcSslKeyPub = base64_decode($msgData['srcSslKeyPub']);
                 }
                 if (array_key_exists('dstNodeId', $msgData)) {
                     $dstNodeId = $msgData['dstNodeId'];
                 }
                 if (array_key_exists('body', $msgData)) {
                     $body = $msgData['body'];
                 }
                 if (array_key_exists('password', $msgData)) {
                     $password = $msgData['password'];
                 }
                 if (array_key_exists('checksum', $msgData)) {
                     $checksum = $msgData['checksum'];
                 }
                 if (array_key_exists('relayCount', $msgData)) {
                     $relayCount = (int) $msgData['relayCount'];
                 }
                 if (array_key_exists('timeCreated', $msgData)) {
                     $timeCreated = (int) $msgData['timeCreated'];
                 }
                 if (array_key_exists('hashcash', $msgData)) {
                     $hashcash = $msgData['hashcash'];
                 }
                 $this->log('debug', $this->getUri() . ' recv ' . $msgName . ': ' . $id);
                 #fwrite(STDOUT, __CLASS__.'->'.__FUNCTION__.' body: '.$body."\n");
                 #$this->log('debug', 'msg '.$id.' body: '.$body);
                 $status = 1;
                 // New
                 if ($this->getMsgDb()->getMsgById($id)) {
                     $status = 2;
                     // Reject
                 }
                 $srcNode = new Node();
                 $srcNode->setIdHexStr($srcNodeId);
                 $srcNode = $this->getTable()->nodeEnclose($srcNode);
                 #fwrite(STDOUT, __CLASS__.'->'.__FUNCTION__.': srcNode: '.$srcNode->getIdHexStr()."\n");
                 $this->log('debug', 'msg ' . $id . ' srcNode: ' . $srcNode->getIdHexStr());
                 if ($srcNode->getSslKeyPub()) {
                     if ($srcNode->getSslKeyPub() != $srcSslKeyPub) {
                         $status = 3;
                         // Error
                     }
                 } else {
                     if (Node::genIdHexStr($srcSslKeyPub) == $srcNodeId) {
                         if ($srcNode->setSslKeyPub($srcSslKeyPub)) {
                             $srcNode->setDataChanged(true);
                         }
                     } else {
                         $status = 3;
                         // Error
                     }
                 }
                 if ($hashcash && $this->hashcashVerify($hashcash, $this->getNode()->getIdHexStr(), static::HASHCASH_BITS_MAX)) {
                     $msgHandleReturnValue .= $this->sendMsgResponse($rid, $status);
                     if ($status == 1) {
                         $msg = new Msg();
                         $msg->setVersion($version);
                         $msg->setId($id);
                         $msg->setRelayNodeId($this->getNode()->getIdHexStr());
                         $msg->setSrcNodeId($srcNodeId);
                         $msg->setSrcSslKeyPub($srcSslKeyPub);
                         $msg->setDstNodeId($dstNodeId);
                         $msg->setBody($body);
                         $msg->setPassword($password);
                         $msg->setChecksum($checksum);
                         $msg->setRelayCount($relayCount);
                         $msg->setEncryptionMode('D');
                         $msg->setStatus('U');
                         $msg->setTimeCreated($timeCreated);
                         $msg->setTimeReceived(time());
                         if ($msg->getDstNodeId() == $this->getLocalNode()->getIdHexStr()) {
                             $msg->setDstSslPubKey($this->getLocalNode()->getSslKeyPub());
                             $msg->setSsl($this->getSsl());
                             try {
                                 if ($msg->decrypt()) {
                                     #fwrite(STDOUT, 'msg '.$id.': decrypt ok'."\n");
                                     $this->log('debug', 'msg ' . $id . ' decrypt ok');
                                     if (!$msg->getIgnore()) {
                                         #fwrite(STDOUT, 'msg '.$id.': not ignore'."\n");
                                         $this->log('debug', 'msg ' . $id . ' not ignore');
                                         $this->log('debug', 'msg ' . $id . ' subject: ' . $msg->getSubject());
                                         $this->getServer()->imapMailAdd($msg);
                                         $this->getServer()->consoleMsgAdd('You got mail.', true, true, true);
                                     } else {
                                         #fwrite(STDOUT, 'msg '.$id.': ignore'."\n");
                                         $this->log('debug', 'msg ' . $id . ' ignore');
                                     }
                                 } else {
                                     #fwrite(STDOUT, 'msg '.$id.': decrypt failed B'."\n");
                                     $this->log('debug', 'msg ' . $id . ' decrypt failed B');
                                 }
                             } catch (Exception $e) {
                                 #fwrite(STDOUT, 'msg '.$id.': decrypt failed A: '.$e->getMessage()."\n");
                                 $this->log('debug', 'msg ' . $id . ' decrypt failed A: ' . $e->getMessage());
                             }
                         } else {
                             #fwrite(STDOUT, 'msg '.$id.': msg not for me'."\n");
                             $this->log('debug', 'msg ' . $id . ' not for me');
                         }
                         $this->getMsgDb()->msgAdd($msg);
                         // Add all messages.
                     }
                 } else {
                     $msgHandleReturnValue .= $this->sendError(4000, $msgName);
                 }
             } else {
                 $msgHandleReturnValue .= $this->sendError(3090, $msgName);
             }
         } else {
             $msgHandleReturnValue .= $this->sendError(1000, $msgName);
         }
     } elseif ($msgName == 'msg_response') {
         if ($this->getStatus('hasId')) {
             $rid = '';
             $status = 0;
             if (array_key_exists('rid', $msgData)) {
                 $rid = $msgData['rid'];
             }
             if (array_key_exists('status', $msgData)) {
                 $status = (int) $msgData['status'];
             }
             $this->log('debug', $this->getUri() . ' recv ' . $msgName . ': ' . $rid . ', ' . $status);
             $request = $this->requestGetByRid($rid);
             if ($request) {
                 #ve($request);
                 $msg = $request['data']['msg'];
                 $msg->addSentNode($this->getNode()->getIdHexStr());
                 $msg->setStatus('S');
                 if ($this->getNode()->getIdHexStr() == $msg->getDstNodeId()) {
                     $msg->setStatus('D');
                 }
                 $this->log('debug', 'actions execute: CRITERION_AFTER_MSG_RESPONSE_SUCCESSFULL');
                 $this->actionsExecute(ClientAction::CRITERION_AFTER_MSG_RESPONSE_SUCCESSFULL);
             } else {
                 $msgHandleReturnValue .= $this->sendError(9000, $msgName);
             }
         } else {
             $msgHandleReturnValue .= $this->sendError(1000, $msgName);
         }
         $this->log('debug', 'actions execute: CRITERION_AFTER_MSG_RESPONSE');
         $this->actionsExecute(ClientAction::CRITERION_AFTER_MSG_RESPONSE);
     } elseif ($msgName == 'ssl_init') {
         #ve($this);
         if ($this->getSsl()) {
             if ($this->getStatus('hasId')) {
                 if (!$this->getStatus('hasSslInit')) {
                     $rid = '';
                     $hashcash = '';
                     if (array_key_exists('rid', $msgData)) {
                         $rid = $msgData['rid'];
                     }
                     if (array_key_exists('hashcash', $msgData)) {
                         $hashcash = $msgData['hashcash'];
                     }
                     $this->logColor('debug', 'SSL: init A: ' . $rid, 'green');
                     if ($hashcash && $this->hashcashVerify($hashcash, $this->getNode()->getIdHexStr(), static::HASHCASH_BITS_MIN)) {
                         $this->logColor('debug', 'SSL: init B', 'green');
                         $this->setStatus('hasSslInit', true);
                         $msgHandleReturnValue .= $this->sendSslInit();
                         $msgHandleReturnValue .= $this->sendSslInitResponse($rid, 1);
                         #fwrite(STDOUT, 'ssl init: /'.$msgHandleReturnValue.'/'."\n");
                         #ve($msgHandleReturnValue);
                     } else {
                         $this->resetStatusSsl();
                         #$msgHandleReturnValue .= $this->sendError(4000, $msgName);
                         $msgHandleReturnValue .= $this->sendSslInitResponse($rid, 4000);
                     }
                 }
             } else {
                 $this->resetStatusSsl();
                 #$msgHandleReturnValue .= $this->sendError(1000, $msgName);
                 $msgHandleReturnValue .= $this->sendSslInitResponse(null, 1000);
             }
         } else {
             $this->resetStatusSsl();
             #$msgHandleReturnValue .= $this->sendError(3090, $msgName);
             $msgHandleReturnValue .= $this->sendSslInitResponse(null, 3090);
         }
     } elseif ($msgName == 'ssl_init_response') {
         $rid = '';
         $status = 0;
         if (array_key_exists('rid', $msgData)) {
             $rid = $msgData['rid'];
         }
         if (array_key_exists('status', $msgData)) {
             $status = $msgData['status'];
         }
         $this->logColor('debug', 'SSL: init response: ' . $rid . ' ' . $status, 'green');
         if ($status) {
             if ($status == 1) {
                 // Ok
                 if ($this->getStatus('hasSslInit') && !$this->getStatus('hasSslInitOk')) {
                     $this->logColor('debug', 'SSL: init ok', 'green');
                     $this->setStatus('hasSslInitOk', true);
                     $msgHandleReturnValue .= $this->sendSslTest();
                 } else {
                     $this->logColor('warning', $msgName . ' SSL: you already initialized ssl', 'green');
                     $msgHandleReturnValue .= $this->sendError(2050, $msgName);
                 }
             } else {
                 $this->logColor('warning', $msgName . ' SSL: failed. status = ' . $status, 'green');
                 $this->resetStatusSsl();
                 $msgHandleReturnValue .= $this->sendError(3100, $msgName);
             }
         } else {
             $this->logColor('warning', $msgName . ' SSL: failed, invalid data', 'green');
             $this->resetStatusSsl();
             $msgHandleReturnValue .= $this->sendError(3100, $msgName);
         }
     } elseif ($msgName == 'ssl_test') {
         if ($this->getStatus('hasSslInitOk') && !$this->getStatus('hasSslTest')) {
             $msgData = $this->sslMsgDataPrivateDecrypt($msgData);
             if ($msgData) {
                 $token = '';
                 if (array_key_exists('token', $msgData)) {
                     $token = $msgData['token'];
                 }
                 if ($token) {
                     $this->logColor('debug', 'SSL: test', 'green');
                     $this->setStatus('hasSslTest', true);
                     $msgHandleReturnValue .= $this->sendSslVerify($token);
                 } else {
                     $msgHandleReturnValue .= $this->sendError(9000, $msgName);
                 }
             } else {
                 $msgHandleReturnValue .= $this->sendError(2070, $msgName);
                 $this->logColor('warning', $msgName . ' SSL: decryption failed', 'green');
             }
         } else {
             $msgHandleReturnValue .= $this->sendError(2060, $msgName);
             $logTmp = 'you need to initialize ssl /' . (int) $this->getStatus('hasSslInitOk') . '/';
             $logTmp .= ' /' . (int) $this->getStatus('hasSslTest') . '/';
             $this->logColor('warning', $msgName . ' SSL: ' . $logTmp, 'green');
         }
     } elseif ($msgName == 'ssl_verify') {
         if ($this->getStatus('hasSslTest') && !$this->getStatus('hasSslVerify')) {
             $msgData = $this->sslMsgDataPrivateDecrypt($msgData);
             if ($msgData) {
                 $token = '';
                 if (array_key_exists('token', $msgData)) {
                     $token = $msgData['token'];
                 }
                 if ($token && $this->sslTestToken && $token == $this->sslTestToken) {
                     $this->logColor('debug', 'SSL: verified', 'green');
                     #print __CLASS__.'->'.__FUNCTION__.': '.$msgName.' SSL: verified'."\n";
                     $this->setStatus('hasSslVerify', true);
                     $msgHandleReturnValue .= $this->sendSslPasswordPut();
                 } else {
                     $msgHandleReturnValue .= $this->sendError(2080, $msgName);
                 }
             } else {
                 $msgHandleReturnValue .= $this->sendError(2070, $msgName);
                 $this->logColor('warning', $msgName . ' SSL: decryption failed', 'green');
             }
         } else {
             $msgHandleReturnValue .= $this->sendError(2060, $msgName);
             $this->logColor('warning', $msgName . ' SSL: you need to initialize ssl', 'green');
         }
     } elseif ($msgName == 'ssl_password_put') {
         if ($this->getStatus('hasSslVerify') && !$this->getStatus('hasSslPasswortPut')) {
             $msgData = $this->sslMsgDataPrivateDecrypt($msgData);
             if ($msgData) {
                 $password = '';
                 if (array_key_exists('password', $msgData)) {
                     $password = $msgData['password'];
                 }
                 if ($password) {
                     $this->logColor('debug', 'SSL: password put', 'green');
                     $this->setStatus('hasSslPasswortPut', true);
                     $this->sslPasswordPeerCurrent = $password;
                     #$this->logColor('debug', 'SSL: peer password: '******'green');
                     $msgHandleReturnValue .= $this->sendSslPasswordTest();
                 } else {
                     $msgHandleReturnValue .= $this->sendError(9000, $msgName);
                 }
             } else {
                 $msgHandleReturnValue .= $this->sendError(2070, $msgName);
                 $this->logColor('warning', $msgName . ' SSL: decryption failed', 'green');
             }
         } else {
             $msgHandleReturnValue .= $this->sendError(2060, $msgName);
             $this->logColor('warning', $msgName . ' SSL: you need to initialize ssl', 'green');
         }
     } elseif ($msgName == 'ssl_password_test') {
         if ($this->getStatus('hasSslPasswortPut') && !$this->getStatus('hasSslPasswortTest')) {
             $msgData = $this->sslMsgDataPasswordDecrypt($msgData);
             if ($msgData) {
                 $token = '';
                 if (array_key_exists('token', $msgData)) {
                     $token = $msgData['token'];
                 }
                 if ($token) {
                     $this->setStatus('hasSslPasswortTest', true);
                     $msgHandleReturnValue .= $this->sendSslPasswordVerify($token);
                 } else {
                     $msgHandleReturnValue .= $this->sendError(9000, $msgName);
                 }
             } else {
                 $msgHandleReturnValue .= $this->sendError(2070, $msgName);
                 $this->logColor('warning', $msgName . ' SSL: decryption failed', 'green');
             }
         } else {
             $msgHandleReturnValue .= $this->sendError(2060, $msgName);
             $this->logColor('warning', $msgName . ' SSL: you need to initialize ssl', 'green');
         }
     } elseif ($msgName == 'ssl_password_verify') {
         if ($this->getStatus('hasSslPasswortTest')) {
             $msgData = $this->sslMsgDataPasswordDecrypt($msgData);
             if ($msgData) {
                 $token = '';
                 if (array_key_exists('token', $msgData)) {
                     $token = $msgData['token'];
                 }
                 #print __CLASS__.'->'.__FUNCTION__.': '.$msgName.' SSL: password token: '.$token."\n";
                 if ($token) {
                     $testToken = hash('sha512', $this->sslPasswordToken . '_' . $this->getNode()->getIdHexStr());
                     if ($this->sslPasswordToken && $token == $testToken) {
                         $this->logColor('debug', 'SSL: password verified', 'green');
                         $this->logColor('debug', 'SSL: OK', 'green');
                         $this->setStatus('hasSsl', true);
                         $this->log('debug', 'actions execute: CRITERION_AFTER_HAS_SSL');
                         $this->actionsExecute(ClientAction::CRITERION_AFTER_HAS_SSL);
                     } else {
                         $msgHandleReturnValue .= $this->sendError(2090, $msgName);
                     }
                 } else {
                     $msgHandleReturnValue .= $this->sendError(9000, $msgName);
                 }
             } else {
                 $msgHandleReturnValue .= $this->sendError(2070, $msgName);
                 $this->logColor('warning', $msgName . ' SSL: decryption failed', 'green');
             }
         } else {
             $msgHandleReturnValue .= $this->sendError(2060, $msgName);
             $this->logColor('warning', $msgName . ' SSL: you need to initialize ssl', 'green');
         }
         $this->sslTestToken = '';
         $this->sslPasswordToken = '';
     } elseif ($msgName == 'ssl_password_reput') {
         if ($this->getStatus('hasSsl')) {
             if (!$this->getStatus('hasReSslPasswortPut')) {
                 $msgData = $this->sslMsgDataPasswordDecrypt($msgData);
                 if ($msgData) {
                     $password = '';
                     if (array_key_exists('password', $msgData)) {
                         $password = $msgData['password'];
                     }
                     if ($password) {
                         $this->logColor('debug', 're-SSL: password reput 1A', 'green');
                         $this->setStatus('hasReSslPasswortPut', true);
                         $this->sslPasswordPeerNew = $password;
                         #$this->logColor('debug', 'SSL: peer password: '******'green');
                         #$this->logColor('debug', 'SSL: peer password new: '.substr($this->sslPasswordPeerNew, 0, 20), 'green');
                         if (!$this->getStatus('hasSendReSslPasswortPut')) {
                             $this->sslMsgCount = 0;
                             $this->sslPasswordToken = '';
                             $this->sslPasswordLocalNew = '';
                             #$this->sslPasswordPeerNew = '';
                             #$this->setStatus('hasSendReSslPasswortPut', true);
                             #$this->setStatus('hasReSslPasswortTest', false);
                             $this->logColor('debug', 're-SSL: password reput 1B', 'green');
                             $msgHandleReturnValue .= $this->sendSslPasswordReput();
                         }
                         $this->logColor('debug', 're-SSL: password reput 2', 'green');
                         $msgHandleReturnValue .= $this->sendSslPasswordRetest();
                     } else {
                         $msgHandleReturnValue .= $this->sendError(9000, $msgName);
                     }
                 } else {
                     $msgHandleReturnValue .= $this->sendError(2070, $msgName);
                     $this->logColor('warning', $msgName . ' re-SSL: decryption failed', 'green');
                 }
             }
         } else {
             $msgHandleReturnValue .= $this->sendError(2060, $msgName);
             $logMsg = $msgName . ' re-SSL: you need to initialize ssl, ';
             $logMsg .= 'hasSsl=/' . (int) $this->getStatus('hasSsl') . '/ ';
             $logMsg .= 'hasReSslPasswortPut=/' . (int) $this->getStatus('hasReSslPasswortPut') . '/';
             $this->logColor('warning', $logMsg, 'green');
         }
     } elseif ($msgName == 'ssl_password_retest') {
         if ($this->getStatus('hasReSslPasswortPut') && !$this->getStatus('hasReSslPasswortTest')) {
             $msgData = $this->sslMsgDataPasswordDecrypt($msgData, $this->sslPasswordLocalNew, $this->sslPasswordPeerNew);
             if ($msgData) {
                 $token = '';
                 if (array_key_exists('token', $msgData)) {
                     $token = $msgData['token'];
                 }
                 if ($token) {
                     $this->logColor('debug', 're-SSL: password retest', 'green');
                     $this->setStatus('hasReSslPasswortTest', true);
                     $msgHandleReturnValue .= $this->sendSslPasswordReverify($token);
                 } else {
                     $msgHandleReturnValue .= $this->sendError(9000, $msgName);
                 }
             } else {
                 $msgHandleReturnValue .= $this->sendError(2070, $msgName);
                 $this->logColor('warning', $msgName . ' re-SSL: decryption failed', 'green');
             }
         } else {
             $msgHandleReturnValue .= $this->sendError(2060, $msgName);
             $logMsg = $msgName . ' re-SSL: you need to initialize ssl, ';
             $logMsg .= 'hasReSslPasswortPut=/' . (int) $this->getStatus('hasReSslPasswortPut') . '/ ';
             $logMsg .= 'hasReSslPasswortTest=/' . (int) $this->getStatus('hasReSslPasswortTest') . '/';
             $this->logColor('warning', $logMsg, 'green');
         }
     } elseif ($msgName == 'ssl_password_reverify') {
         if ($this->getStatus('hasReSslPasswortTest')) {
             $msgData = $this->sslMsgDataPasswordDecrypt($msgData, $this->sslPasswordLocalNew, $this->sslPasswordPeerNew);
             if ($msgData) {
                 $token = '';
                 if (array_key_exists('token', $msgData)) {
                     $token = $msgData['token'];
                 }
                 #print __CLASS__.'->'.__FUNCTION__.': '.$msgName.' re-SSL: password token: '.$token."\n";
                 if ($token) {
                     $testToken = hash('sha512', $this->sslPasswordToken . '_' . $this->getNode()->getSslKeyPubFingerprint());
                     if ($this->sslPasswordToken && $token == $testToken) {
                         $this->logColor('debug', 're-SSL: password verified', 'green');
                         $this->logColor('debug', 're-SSL: OK', 'green');
                         $this->setStatus('hasSendReSslPasswortPut', false);
                         $this->setStatus('hasReSslPasswortPut', false);
                         $this->setStatus('hasReSslPasswortTest', false);
                         $this->sslPasswordLocalCurrent = $this->sslPasswordLocalNew;
                         $this->sslPasswordPeerCurrent = $this->sslPasswordPeerNew;
                         $this->logColor('debug', 'actions execute: CRITERION_AFTER_HAS_RESSL', 'green');
                         $this->actionsExecute(ClientAction::CRITERION_AFTER_HAS_RESSL);
                     } else {
                         $msgHandleReturnValue .= $this->sendError(2090, $msgName);
                     }
                 } else {
                     $msgHandleReturnValue .= $this->sendError(9000, $msgName);
                 }
             } else {
                 $msgHandleReturnValue .= $this->sendError(2070, $msgName);
                 $this->logColor('warning', $msgName . ' re-SSL: decryption failed', 'green');
             }
         } else {
             $msgHandleReturnValue .= $this->sendError(2060, $msgName);
             $logMsg = $msgName . ' re-SSL: you need to initialize ssl, ';
             $logMsg .= 'hasReSslPasswortTest=/' . (int) $this->getStatus('hasReSslPasswortTest') . '/';
             $this->logColor('warning', $logMsg, 'green');
         }
         $this->sslPasswordToken = '';
         $this->sslPasswordLocalNew = '';
         $this->sslPasswordLocalNew = '';
     } elseif ($msgName == 'talk_request') {
         if ($this->getStatus('hasSsl')) {
             $msgData = $this->sslMsgDataPasswordDecrypt($msgData);
             if ($msgData) {
                 $rid = '';
                 $userNickname = '[unknown]';
                 $hashcash = '';
                 if (array_key_exists('rid', $msgData)) {
                     $rid = $msgData['rid'];
                 }
                 if (array_key_exists('userNickname', $msgData) && $msgData['userNickname']) {
                     $userNickname = $msgData['userNickname'];
                 }
                 if (array_key_exists('hashcash', $msgData)) {
                     $hashcash = $msgData['hashcash'];
                 }
                 $this->log('debug', $this->getUri() . ' recv ' . $msgName . ': ' . $rid . ', ' . $userNickname);
                 if ($rid) {
                     if ($hashcash && $this->hashcashVerify($hashcash, $this->getNode()->getIdHexStr(), static::HASHCASH_BITS_MAX)) {
                         if ($this->getServer() && $this->getServer()->kernelHasConsole()) {
                             $this->setStatus('hasTalkRequest', true);
                             $this->consoleTalkRequestAdd($rid, $userNickname);
                         } else {
                             $msgHandleReturnValue .= $this->sendTalkResponse($rid, 4);
                             #$msgHandleReturnValue .= $this->sendQuit();
                             #$this->shutdown();
                             $action = new ClientAction(ClientAction::CRITERION_AFTER_PREVIOUS_ACTIONS);
                             $action->setName('talk_request_after_previous_actions_shutdown');
                             $action->functionSet(function ($action, $client) {
                                 $client->shutdown();
                             });
                             $this->actionAdd($action);
                         }
                     } else {
                         $msgHandleReturnValue .= $this->sendError(4000, $msgName);
                     }
                 } else {
                     $msgHandleReturnValue .= $this->sendError(9000, $msgName);
                 }
             } else {
                 $msgHandleReturnValue .= $this->sendError(9000, $msgName);
             }
         } else {
             $msgHandleReturnValue .= $this->sendError(2060, $msgName);
             $this->logColor('warning', $msgName . ' SSL: you need to initialize ssl', 'green');
         }
     } elseif ($msgName == 'talk_response') {
         if ($this->getStatus('hasSsl')) {
             $msgData = $this->sslMsgDataPasswordDecrypt($msgData);
             if ($msgData) {
                 $rid = '';
                 $status = 0;
                 $userNickname = '[unknown]';
                 if (array_key_exists('rid', $msgData)) {
                     $rid = $msgData['rid'];
                 }
                 if (array_key_exists('status', $msgData)) {
                     $status = (int) $msgData['status'];
                 }
                 if (array_key_exists('userNickname', $msgData) && $msgData['userNickname']) {
                     $userNickname = $msgData['userNickname'];
                 }
                 #$this->log('debug', $this->getUri().' recv '.$msgName.': '.$rid.', '.(int)$status.', '.$userNickname);
                 $this->log('debug', $this->getUri() . ' recv ' . $msgName . ': ' . $rid . ', ' . (int) $status);
                 $request = $this->requestGetByRid($rid);
                 if ($request) {
                     $this->requestRemove($request);
                     $this->log('debug', $this->getUri() . ' recv ' . $msgName . ': request ok (' . $status . ')');
                     //if($status == 0){} // Undefined
                     if ($status == 1) {
                         // Accepted
                         $this->setStatus('hasTalk', true);
                         $this->consoleMsgAdd('Talk request accepted.', true, false, true);
                         $this->consoleMsgAdd('Now talking to "' . $userNickname . '".', true, true);
                         $this->consoleSetModeChannel(true);
                         $this->consoleSetModeChannelClient($this);
                         if ($this->getServer() && $this->getServer()->getKernel()) {
                             // Add to addressbook.
                             $contact = new Contact();
                             $contact->setNodeId($this->getNode()->getIdHexStr());
                             $contact->setUserNickname($userNickname);
                             $this->getServer()->getKernel()->getAddressbook()->contactAdd($contact);
                         }
                     } elseif ($status == 2) {
                         // Declined
                         $this->consoleMsgAdd('Talk request declined.', true, true, true);
                     } elseif ($status == 3) {
                         // Timeout
                         $this->consoleMsgAdd('Talk request timed out.', true, true, true);
                     } elseif ($status == 4) {
                         // No console, standalone server.
                         $this->consoleMsgAdd($this->getUri() . ' has no user interface. Can\'t talk to you.', true, true, true);
                         #$msgHandleReturnValue .= $this->sendQuit();
                         #$this->shutdown();
                         $action = new ClientAction(ClientAction::CRITERION_AFTER_PREVIOUS_ACTIONS);
                         $action->setName('talk_request_after_previous_actions_shutdown');
                         $action->functionSet(function ($action, $client) {
                             $client->sendQuit();
                             $client->shutdown();
                         });
                         $this->actionAdd($action);
                         $this->log('debug', 'actions left: ' . count($this->actions));
                     }
                 } else {
                     $msgHandleReturnValue .= $this->sendError(9000, $msgName);
                 }
             }
         }
     } elseif ($msgName == 'talk_msg') {
         #$this->log('debug', $this->getUri().' recv '.$msgName);
         if ($this->getStatus('hasSsl')) {
             $msgData = $this->sslMsgDataPasswordDecrypt($msgData);
             if ($msgData) {
                 $rid = '';
                 $userNickname = '[unknown]';
                 $text = '';
                 $ignore = false;
                 if (array_key_exists('rid', $msgData)) {
                     $rid = $msgData['rid'];
                 }
                 if (array_key_exists('userNickname', $msgData) && $msgData['userNickname']) {
                     $userNickname = $msgData['userNickname'];
                 }
                 if (array_key_exists('text', $msgData)) {
                     $text = $msgData['text'];
                 }
                 if (array_key_exists('ignore', $msgData)) {
                     $ignore = $msgData['ignore'];
                 }
                 #$debugText = '/'.$rid.'/ /'.$userNickname.'/ '.(int)$ignore.' /'.$text.'/';
                 #$this->log('debug', $this->getUri().' recv '.$msgName.': '.$debugText);
                 $this->log('debug', $this->getUri() . ' recv ' . $msgName);
                 if (!$ignore) {
                     $this->consoleTalkMsgAdd($rid, $userNickname, $text);
                 }
             }
         }
     } elseif ($msgName == 'talk_user_nickname_change') {
         #$this->log('debug', $this->getUri().' recv '.$msgName);
         if ($this->getStatus('hasSsl')) {
             $msgData = $this->sslMsgDataPasswordDecrypt($msgData);
             if ($msgData) {
                 $userNicknameOld = '[unknown]';
                 $userNicknameNew = '';
                 if (array_key_exists('userNicknameOld', $msgData) && $msgData['userNicknameOld']) {
                     $userNicknameOld = $msgData['userNicknameOld'];
                 }
                 if (array_key_exists('userNicknameNew', $msgData)) {
                     $userNicknameNew = $msgData['userNicknameNew'];
                 }
                 if ($this->getServer() && $this->getServer()->getKernel()) {
                     $contact = $this->getServer()->getKernel()->getAddressbook()->contactGetByNodeId($this->getNode()->getIdHexStr());
                     if ($contact) {
                         if (!$userNicknameOld) {
                             $userNicknameOld = $contact->getUserNickname();
                         }
                         if ($userNicknameNew) {
                             $contact->setUserNickname($userNicknameNew);
                             $this->getServer()->getKernel()->getAddressbook()->setDataChanged(true);
                         }
                     }
                 }
                 if ($userNicknameNew) {
                     #$this->log('debug', $this->getUri().' recv '.$msgName.': '.$userNicknameOld.', '.$userNicknameNew);
                     $this->consoleMsgAdd('User "' . $userNicknameOld . '" is now known as "' . $userNicknameNew . '".', true, true, true);
                 }
             }
         }
     } elseif ($msgName == 'talk_close') {
         if ($this->getStatus('hasSsl')) {
             $msgData = $this->sslMsgDataPasswordDecrypt($msgData);
             if ($msgData) {
                 $rid = '';
                 $userNickname = '[unknown]';
                 if (array_key_exists('rid', $msgData)) {
                     $rid = $msgData['rid'];
                 }
                 if (array_key_exists('userNickname', $msgData) && $msgData['userNickname']) {
                     $userNickname = $msgData['userNickname'];
                 }
                 $this->log('debug', $this->getUri() . ' recv ' . $msgName . ': ' . $rid . ', ' . $userNickname);
                 $msgHandleReturnValue .= $this->sendQuit();
                 $this->setStatus('hasTalkClose', true);
                 $this->shutdown();
                 $this->consoleMsgAdd('Talk closed by "' . $userNickname . '".', true, true, true);
                 $this->consoleSetModeChannel(false);
                 $this->consoleSetModeChannelClient(null);
             }
         }
     } elseif ($msgName == 'bridge_connect') {
         if ($this->getSettings()->data['node']['bridge']['server']['enabled']) {
             if ($this->getStatus('hasSsl')) {
                 $msgData = $this->sslMsgDataPasswordDecrypt($msgData);
                 if ($msgData) {
                     $targetUri = '';
                     if (array_key_exists('uri', $msgData)) {
                         $targetUri = $msgData['uri'];
                         $targetUri = UriFactory::factory($targetUri);
                     }
                     $this->logColor('debug', $this->getUri() . ' recv ' . $msgName . ': target /' . $targetUri . '/', 'yellow');
                     $client = $this->getServer()->connect($targetUri);
                     if ($client !== null) {
                         $this->logColor('debug', 'bridge connected to target /' . $targetUri . '/', 'yellow');
                         $this->setBridgeClient($client);
                         $client->setBridgeClient($client);
                         $client->setStatus('bridgeTargetUri', $targetUri);
                         $msgHandleReturnValue .= $this->sendBridgeConnectResponse(1);
                     } else {
                         $this->logColor('debug', 'bridge connection to target /' . $targetUri . '/ failed', 'yellow');
                         $msgHandleReturnValue .= $this->sendBridgeConnectResponse(2);
                     }
                 } else {
                     $msgHandleReturnValue .= $this->sendError(9000, $msgName);
                 }
             } else {
                 $msgHandleReturnValue .= $this->sendError(2060, $msgName);
                 $this->log('warning', static::getErrorMsg(2060));
             }
         } else {
             $msgHandleReturnValue .= $this->sendError(5000, $msgName);
             $this->log('warning', static::getErrorMsg(5000));
         }
     } elseif ($msgName == 'bridge_connect_response') {
         if ($this->getSettings()->data['node']['bridge']['server']['enabled'] || $this->getSettings()->data['node']['bridge']['client']['enabled']) {
             if ($this->getStatus('hasSsl')) {
                 $msgData = $this->sslMsgDataPasswordDecrypt($msgData);
                 if ($msgData) {
                     $status = 0;
                     if (array_key_exists('status', $msgData)) {
                         $status = (int) $msgData['status'];
                     }
                     $this->logColor('debug', $this->getUri() . ' recv ' . $msgName . ': /' . $status . '/', 'yellow');
                     if ($status) {
                         if ($status == 1) {
                             $this->logColor('debug', 'bridge connection ok', 'yellow');
                             $this->bridgeActionsExecute(ClientAction::CRITERION_AFTER_HELLO);
                             $this->bridgeActionsExecute(ClientAction::CRITERION_AFTER_HAS_SSL);
                             /*foreach($this->bridgeActions as $bridgeActionId => $bridgeAction){
                             			$name = $bridgeAction->getName();
                             			$criteria = join(',', $bridgeAction->getCriteria());
                             			$this->logColor('debug', 'bridgeAction: /'.$name.'/ /'.$criteria.'/', 'yellow');
                             			#$this->bridgeActionRemove($bridgeAction);
                             			#$bridgeAction->functionExec($this);
                             		}*/
                         } elseif ($status == 2) {
                             $this->logColor('debug', 'bridge connection failed', 'yellow');
                         } else {
                             $this->logColor('debug', 'bridge connect response unknown status', 'yellow');
                         }
                     } else {
                         $msgHandleReturnValue .= $this->sendError(9000, $msgName);
                     }
                 } else {
                     $msgHandleReturnValue .= $this->sendError(9000, $msgName);
                 }
             } else {
                 $msgHandleReturnValue .= $this->sendError(2060, $msgName);
                 $this->log('warning', static::getErrorMsg(2060));
             }
         } else {
             $msgHandleReturnValue .= $this->sendError(5100, $msgName);
             $this->log('warning', static::getErrorMsg(5100));
         }
     } elseif ($msgName == 'bridge_msg') {
         if ($this->getSettings()->data['node']['bridge']['server']['enabled']) {
             if ($this->getStatus('hasSsl')) {
                 $msgData = $this->sslMsgDataPasswordDecrypt($msgData);
                 if ($msgData) {
                     $data = '';
                     if (array_key_exists('data', $msgData)) {
                         $data = $msgData['data'];
                     }
                     $this->logColor('debug', $this->getUri() . ' recv ' . $msgName . ': /' . $data . '/', 'yellow');
                     $this->logColor('debug', 'bridge server: ' . $this->getStatus('bridgeServerUri'), 'yellow');
                     $this->logColor('debug', 'bridge target: ' . $this->getStatus('bridgeTargetUri'), 'yellow');
                     $this->logColor('debug', 'bridge client: ' . (int) ($this->bridgeClient !== null), 'yellow');
                     # TODO
                     if ($this->bridgeClient) {
                     }
                 } else {
                     $msgHandleReturnValue .= $this->sendError(9000, $msgName);
                 }
             } else {
                 $msgHandleReturnValue .= $this->sendError(2060, $msgName);
                 $this->log('warning', static::getErrorMsg(2060));
             }
         } else {
             $msgHandleReturnValue .= $this->sendError(5200, $msgName);
             $this->log('warning', static::getErrorMsg(5200));
         }
     } elseif ($msgName == 'ping') {
         $rid = '';
         if (array_key_exists('rid', $msgData)) {
             $rid = $msgData['rid'];
         }
         $msgHandleReturnValue .= $this->sendPong($rid);
     } elseif ($msgName == 'pong') {
         $rid = '';
         if (array_key_exists('rid', $msgData)) {
             $rid = $msgData['rid'];
         }
         $this->pongTime = time();
     } elseif ($msgName == 'error') {
         $code = 0;
         $msg = '';
         $name = '';
         if (array_key_exists('msg', $msgData)) {
             $code = (int) $msgData['code'];
         }
         if (array_key_exists('msg', $msgData)) {
             $msg = $msgData['msg'];
         }
         if (array_key_exists('msg', $msgData)) {
             $name = $msgData['name'];
         }
         if ($code >= 2000 && $code <= 3999) {
             // SSL
             $this->logColor('debug', $this->getUri() . ' recv ' . $msgName . ': ' . $code . ', ' . $msg . ', ' . $name, 'green');
         } elseif ($code >= 5000 && $code <= 5999) {
             // Bridge
             $this->logColor('debug', $this->getUri() . ' recv ' . $msgName . ': ' . $code . ', ' . $msg . ', ' . $name, 'yellow');
         } else {
             $this->log('debug', $this->getUri() . ' recv ' . $msgName . ': ' . $code . ', ' . $msg . ', ' . $name);
         }
     } elseif ($msgName == 'quit') {
         $this->shutdown();
     } else {
         $this->log('debug', $this->getUri() . ' recv /' . $msgName . '/: not implemented.');
         $msgHandleReturnValue .= $this->sendError(9020, $msgName);
     }
     return $msgHandleReturnValue;
 }
 /**
  * @param string $id
  * @return bool
  */
 public function delete($id)
 {
     if (!Uuid::isValid($id)) {
         throw new DomainException('Invalid identifier provided', 404);
     }
     $result = $this->table->delete(['id' => $id]);
     if (!$result) {
         return false;
     }
     return true;
 }
 /**
  * Convert UUID string to binary
  *
  * @param string $uuid
  * @throw throw
  * @return string
  */
 protected function convertUuid($uuid)
 {
     //If the UUID is not valid, we assume the model is not found
     if (!Uuid::isValid($uuid)) {
         throw with(new ModelNotFoundException())->setEntity($this->model);
     }
     //Convert the UUID first
     $uuid = UuidConverter::uuidToBinary($uuid);
     return $uuid;
 }
Пример #19
0
 private function guard($value)
 {
     if (!Uuid::isValid($value)) {
         throw new AccountOwnerNotValidException($value);
     }
 }
Пример #20
0
 public function testGet_uuid()
 {
     $this->assertTrue(Uuid::isValid(self::$DI['record_1']->get_uuid()));
 }
Пример #21
0
 public function validateUuid($attribute, $value, $parameters)
 {
     return Uuid::isValid($value);
 }
Пример #22
0
 /**
  * @param string $id 
  * @return bool
  */
 public function delete($id)
 {
     if (!Uuid::isValid($id)) {
         throw new DomainException('Invalid identifier provided', 404);
     }
     if (!array_key_exists($id, $this->data)) {
         throw new DomainException('Cannot delete; no such status message', 404);
     }
     unset($this->data[$id]);
     $this->persistData();
     return true;
 }
Пример #23
0
 /**
  * @test
  */
 public function itShouldGenerateUuid()
 {
     $id = MiniGameId::create();
     $this->assertTrue(Uuid::isValid((string) $id));
 }
Пример #24
0
 public function testSendNodeFind()
 {
     list($client1, $client2) = $this->sendGenTestDataDefault();
     // Node Find before ID should cause an error.
     $raw = $client1->sendNodeFind($client1->getSettings()->data['node']['id']);
     #ve('testSend raw A'); ve($raw);
     $raw = $client2->dataRecv($raw);
     #ve('testSend raw B'); ve($raw);
     $json = $this->rawMsgToJson($raw);
     #ve('testSend json'); ve($json);
     $this->assertEquals('error', $json[0]['name']);
     $this->assertEquals(1000, $json[0]['data']['code']);
     // Node Find before ID should cause an error.
     $raw = $client1->sendNodeFind($client1->getSettings()->data['node']['id']);
     $json = $this->rawMsgToJson($raw);
     #ve($json);
     $raw = $client2->dataRecv($raw);
     $json = $this->rawMsgToJson($raw);
     #ve($json);
     $this->assertEquals('error', $json[0]['name']);
     $this->assertEquals(1000, $json[0]['data']['code']);
     $this->sendClientsId($client1, $client2);
     // Node Find
     $raw = $client1->sendNodeFind($client1->getSettings()->data['node']['id']);
     $json = $this->rawMsgToJson($raw);
     #ve($json);
     $this->assertEquals('node_find', $json[0]['name']);
     $this->assertEquals(8, $json[0]['data']['num']);
     $this->assertEquals('264bfdaf-e558-5547-b4b2-a7c1ce75478c', $json[0]['data']['nodeId']);
     $raw = $client2->dataRecv($raw);
     $json = $this->rawMsgToJson($raw);
     #ve($json);
     $this->assertEquals('node_found', $json[0]['name']);
     $this->assertTrue(Uuid::isValid($json[0]['data']['rid']));
     $this->assertEquals('10000000-1000-4000-8000-100000000008', $json[0]['data']['nodes'][0]['id']);
     $this->assertEquals('10000000-1000-4000-8000-100000000009', $json[0]['data']['nodes'][1]['id']);
     $this->assertEquals('10000000-1000-4000-8000-100000000005', $json[0]['data']['nodes'][2]['id']);
     $this->assertEquals('10000000-1000-4000-8000-100000000006', $json[0]['data']['nodes'][3]['id']);
     $this->assertEquals('10000000-1000-4000-8000-100000000007', $json[0]['data']['nodes'][4]['id']);
     $this->assertEquals('tcp://192.168.241.8', $json[0]['data']['nodes'][0]['uri']);
     $this->assertEquals('tcp://192.168.241.9', $json[0]['data']['nodes'][1]['uri']);
     $this->assertEquals('tcp://192.168.241.5', $json[0]['data']['nodes'][2]['uri']);
     $this->assertEquals('tcp://192.168.241.6', $json[0]['data']['nodes'][3]['uri']);
     $this->assertEquals('tcp://192.168.241.7', $json[0]['data']['nodes'][4]['uri']);
     $this->assertTrue(array_key_exists('sslKeyPub', $json[0]['data']['nodes'][0]));
     $this->assertTrue(array_key_exists('sslKeyPub', $json[0]['data']['nodes'][1]));
     $this->assertTrue(array_key_exists('sslKeyPub', $json[0]['data']['nodes'][2]));
     $this->assertTrue(array_key_exists('sslKeyPub', $json[0]['data']['nodes'][3]));
     $this->assertTrue(array_key_exists('sslKeyPub', $json[0]['data']['nodes'][4]));
     $raw = $client1->dataRecv($raw);
     $json = $this->rawMsgToJson($raw);
     #ve($json);
     $this->assertEquals(null, $json[0]);
     // Node Find without Hashcash should cause an error.
     $raw = $client1->sendNodeFind($client1->getSettings()->data['node']['id'], null, null, false);
     $raw = $client2->dataRecv($raw);
     $json = $this->rawMsgToJson($raw);
     #ve($json);
     $this->assertEquals('error', $json[0]['name']);
     $this->assertEquals(4000, $json[0]['data']['code']);
     // Found Node with wrong RID should cause an error.
     $raw = $client1->sendNodeFound('wrong_rid', array(), false);
     $json = $this->rawMsgToJson($raw);
     #ve($json);
     $this->assertEquals('node_found', $json[0]['name']);
     $raw = $client2->dataRecv($raw);
     $json = $this->rawMsgToJson($raw);
     #ve($json);
     $this->assertEquals('error', $json[0]['name']);
     $this->assertEquals(9000, $json[0]['data']['code']);
     $client1->getServer()->getKernel()->shutdown();
     $client2->getServer()->getKernel()->shutdown();
 }
Пример #25
0
 /**
  * @param string $uuid
  */
 private function assertIsValidUuid($uuid)
 {
     if (!\Rhumsaa\Uuid\Uuid::isValid($uuid)) {
         throw new \InvalidArgumentException('Invalid Uuid format.');
     }
 }
Пример #26
0
 /**
  * Checks for UUID in metadatas
  *
  * @todo Check if a file exists with the same checksum
  * @todo Check if an UUID is contained in the attributes, replace It if
  *              necessary
  *
  * @param  boolean $generate if true, if no uuid found, a valid one is generated
  * @param  boolean $write    if true, writes uuid in all available metadatas
  * @return File
  */
 public function getUUID($generate = false, $write = false)
 {
     if ($this->uuid && !$write) {
         return $this->uuid;
     }
     $availableUUIDs = ['XMP-exif:ImageUniqueID', 'SigmaRaw:ImageUniqueID', 'IPTC:UniqueDocumentID', 'ExifIFD:ImageUniqueID', 'Canon:ImageUniqueID'];
     if (!$this->uuid) {
         $metadatas = $this->media->getMetadatas();
         $uuid = null;
         foreach ($availableUUIDs as $meta) {
             if ($metadatas->containsKey($meta)) {
                 $candidate = $metadatas->get($meta)->getValue()->asString();
                 if (Uuid::isValid($candidate)) {
                     $uuid = $candidate;
                     break;
                 }
             }
         }
         if (!$uuid && $generate) {
             $uuid = Uuid::uuid4();
         }
         $this->uuid = $uuid;
     }
     if ($write) {
         $value = new MonoValue($this->uuid);
         $metadatas = new ExiftoolMetadataBag();
         foreach ($availableUUIDs as $tagname) {
             $metadatas->add(new Metadata(TagFactory::getFromRDFTagname($tagname), $value));
         }
         /**
          * PHPExiftool throws exception on some files not supported
          */
         try {
             $this->app['exiftool.writer']->reset();
             $this->app['exiftool.writer']->write($this->getFile()->getRealPath(), $metadatas);
         } catch (PHPExiftoolException $e) {
         }
     }
     return $this->uuid;
 }
 /**
  * @Given the :property property is a valid uuid
  */
 public function thePropertyIsAValidUuid($property)
 {
     $payload = $this->getScopePayload();
     $actualValue = $this->arrayGet($payload, $property);
     PHPUnit_Framework_Assert::assertTrue(Uuid::isValid($actualValue), "Asserting the [{$property}] property is a valid UUID.");
 }
Пример #28
0
 /**
  * Assert string is a valid UUID.
  *
  * @param $uuid
  * @return bool
  */
 public function assertUuid($uuid)
 {
     $this->assertTrue(Uuid::isValid($uuid), 'Valid UUID');
     return $this;
 }
Пример #29
0
 public function testId()
 {
     $msg = new Msg();
     $this->assertTrue(Uuid::isValid($msg->getId()));
 }
Пример #30
0
 /**
  * @inheritdoc
  */
 public function supportsDenormalization($data, $type, $format = null)
 {
     return Uuid::class === $type && ($data === null || is_string($data) && Uuid::isValid($data));
 }