/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { Logger::set(new NullLogger()); $this->input = $input; $this->output = $output; $this->config = $this->getContainer()->getParameter('voryx_thruway'); switch ($input->getArgument('action')) { case "start": $this->start(); break; case "stop": $this->stop(); break; case "restart": $this->restart(); break; case "status": $this->status(); break; case "add": $this->add(); break; default: $output->writeln("Expected an action: start, stop, status"); } }
/** * Start the transport * * @param boolean $startLoop * @throws \Exception */ public function start($debug = false, $startLoop = true) { if (!$debug) { Logger::set(new NullLogger()); } parent::start($startLoop); }
public function connect(\Closure $callback, array $options = []) { $options = array_merge(['logging' => $this->logging, 'loggingOutput' => $this->loggingOutput, 'connectionTimeout' => null, 'connectionOptions' => []], $options); if (!$options['logging']) { Logger::set(new NullLogger()); } if (!$options['loggingOutput']) { ob_start(); } $connection = $this->createConnection($options['connectionOptions']); $connection->once('open', function (ClientSession $session) use($connection, $callback) { call_user_func_array($callback, [$connection, $session]); }); if ($options['connectionTimeout'] !== null) { $loop = $connection->getClient()->getLoop(); $timer = $loop->addTimer($options['connectionTimeout'], function () use($loop) { $loop->stop(); }); $connection->once('close', function () use($timer) { $timer->cancel(); \Yii::warning('WAMP connection closed by timeout.'); }); } $connection->open(); if ($options['logging']) { \Yii::info(ob_get_contents()); } if (!$options['loggingOutput']) { ob_clean(); } }
/** * //@todo implement a non-blocking version of this * * @param $topicName * @param $arguments * @param array|null $argumentsKw * @param null $options * @return \React\Promise\Promise */ public function publish($topicName, $arguments, $argumentsKw = [], $options = null) { //Use the serializer to serialize and than deserialize. This is a hack because the serializer doesn't support the array format and we need to be able to handle Entities $arguments = json_decode($this->serializer->serialize($arguments, "json")); $argumentsKw = json_decode($this->serializer->serialize($argumentsKw, "json")); //If we already have a client open that we can use, use that if ($this->container->initialized('wamp_kernel') && ($client = $this->container->get('wamp_kernel')->getClient())) { $session = $this->container->get('wamp_kernel')->getSession(); return $session->publish($topicName, $arguments, $argumentsKw, $options); } if (is_array($options)) { $options = (object) $options; } if (!is_object($options)) { $options = (object) []; } Logger::set(new NullLogger()); //If we don't already have a long running client, get a short lived one. $client = $this->getShortClient(); $options->acknowledge = true; $deferrer = new Deferred(); $client->on("open", function (ClientSession $session, TransportInterface $transport) use($deferrer, $topicName, $arguments, $argumentsKw, $options) { $session->publish($topicName, $arguments, $argumentsKw, $options)->then(function () use($deferrer, $transport) { $transport->close(); $deferrer->resolve(); }); }); $client->on("error", function ($error) use($topicName) { $this->container->get('logger')->addError("Got the following error when trying to publish to '{$topicName}': {$error}"); }); $client->start(); return $deferrer->promise(); }
/** * TODO doc block */ public function __construct() { Logger::set(new NullLogger()); parent::__construct('realm1'); $ip = Configure::read('Websockets.ip'); $port = Configure::read('Websockets.port'); $this->addTransportProvider(new PawlTransportProvider("ws://" . $ip . ":" . $port . "/")); }
/** * Configure optional settings * * @param $config * @param ContainerBuilder $container */ protected function configureOptions(&$config, ContainerBuilder $container) { if ($config['enable_logging'] !== true) { Logger::set(new NullLogger()); } if (isset($config['router']['authentication']) && $config['router']['authentication'] !== false) { //Inject the authentication manager into the router $container->getDefinition('voryx.thruway.server')->addMethodCall('registerModule', [new Reference('voryx.thruway.authentication.manager')]); } if ($container->hasDefinition('security.user.provider.concrete.in_memory')) { $container->addAliases(['in_memory_user_provider' => 'security.user.provider.concrete.in_memory']); } //Topic State Handler if (isset($config['router']['enable_topic_state']) && $config['router']['enable_topic_state'] === true) { $container->getDefinition('voryx.thruway.server')->addMethodCall('registerModule', [new Reference('voryx.thruway.topic.state.handler')]); } }
/** * Configure optional settings * * @param $config * @param ContainerBuilder $container */ protected function configureOptions(&$config, ContainerBuilder $container) { //Add optional Manager if (isset($config['router']['enable_manager']) && $config['router']['enable_manager'] === true) { //Replace the dummy manager with the client manager $container->getDefinition('voryx.thruway.manager.client')->setClass('Thruway\\Manager\\ManagerClient'); //Inject the manager client into the router $container->getDefinition('voryx.thruway.server')->addMethodCall('addTransportProvider', [new Reference('voryx.thruway.internal.manager')]); } if ($config['enable_logging'] !== true) { Logger::set(new NullLogger()); } if (isset($config['router']['authentication']) && $config['router']['authentication'] !== false) { //Inject the authentication manager into the router $container->getDefinition('voryx.thruway.server')->addMethodCall('registerModule', [new Reference('voryx.thruway.authentication.manager')]); } if ($container->hasDefinition('security.user.provider.concrete.in_memory')) { $container->addAliases(['in_memory_user_provider' => 'security.user.provider.concrete.in_memory']); } //Topic State Handler if (isset($config['router']['enable_topic_state']) && $config['router']['enable_topic_state'] === true) { $container->getDefinition('voryx.thruway.server')->addMethodCall('registerModule', [new Reference('voryx.thruway.topic.state.handler')]); } }
public function setup() { \Thruway\Logging\Logger::set(new \Psr\Log\NullLogger()); $this->router = new \Thruway\Peer\Router(); }
## CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF ## SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ## INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN ## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ## POSSIBILITY OF SUCH DAMAGE. ## ############################################################################### use Psr\Log\NullLogger; use Thruway\ClientSession; use Thruway\ClientWampCraAuthenticator; use Thruway\Connection; use Thruway\Logging\Logger; use Thruway\Message\ChallengeMessage; require __DIR__ . '/vendor/autoload.php'; Logger::set(new NullLogger()); $userDb = ['joe' => ['secret' => 'secret2', 'role' => 'frontend'], 'peter' => ['secret' => 'prq7+YkJ1/KlW1X0YczMHw==', 'role' => 'frontend', 'salt' => 'salt123', 'iterations' => 100, 'keylen' => 16]]; $authenticate = function ($args) use($userDb) { $realm = array_shift($args); $authid = array_shift($args); $details = array_shift($args); echo "authenticate called: {$realm}, {$authid}, {$details}\n"; if (isset($userDb[$authid])) { return $userDb[$authid]; } echo "no such user: {$realm}, {$authid}\n"; }; $user = $argv[3]; $password = $argv[4]; $onChallenge = function (ClientSession $session, $method, ChallengeMessage $msg) use($user, $password) { if ("wampcra" !== $method) {
/** * @param $procedureName * @param $arguments * @return \React\Promise\Promise */ public function call($procedureName, $arguments, $argumentsKw = [], $options = null) { $arguments = $arguments ?: [$arguments]; $argumentsKw = $argumentsKw ?: [$argumentsKw]; $arguments = $this->serializer->toArray($arguments); $argumentsKw = $this->serializer->toArray($argumentsKw); //If we already have a client open that we can use, use that if ($this->container->initialized('wamp_kernel') && ($client = $this->container->get('wamp_kernel')->getClient())) { $session = $this->container->get('wamp_kernel')->getSession(); return $session->call($procedureName, $arguments, $argumentsKw, $options); } Logger::set(new NullLogger()); //So logs don't show up on the web page //If we don't already have a long running client, get a short lived one. $client = $this->getShortClient(); $deferrer = new Deferred(); $client->on("open", function (ClientSession $session, TransportInterface $transport) use($deferrer, $procedureName, $arguments, $argumentsKw, $options) { $session->call($procedureName, $arguments, $argumentsKw, $options)->then(function ($res) use($deferrer, $transport) { $transport->close(); $deferrer->resolve($res); }); }); $client->on("error", function ($error) use($procedureName) { $this->container->get('logger')->addError("Got the following error when trying to call '{$procedureName}': {$error}"); throw new \Exception("Got the following error when trying to call '{$procedureName}': {$error}"); }); $client->start(); return $deferrer->promise(); }