Skip to content

Commit 8eb8cfb

Browse files
authored
Merge pull request #25 from clue-labs/readme
Improve code examples and documentation
2 parents c12f07e + 8d5e166 commit 8eb8cfb

5 files changed

+57
-41
lines changed

README.md

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ This makes it fairly simple to add SSH proxy support to pretty much any
158158
higher-level component:
159159

160160
```diff
161-
- $client = new SomeClient($connector);
162-
+ $proxy = new SshProcessConnector('user@example.com', $loop);
163-
+ $client = new SomeClient($proxy);
161+
- $acme = new AcmeApi($connector);
162+
+ $proxy = new Clue\React\SshProxy\SshProcessConnector('user@example.com', $loop);
163+
+ $acme = new AcmeApi($proxy);
164164
```
165165

166166
### SshSocksConnector
@@ -242,9 +242,9 @@ This makes it fairly simple to add SSH proxy support to pretty much any
242242
higher-level component:
243243

244244
```diff
245-
- $client = new SomeClient($connector);
246-
+ $proxy = new SshSocksConnector('user@example.com', $loop);
247-
+ $client = new SomeClient($proxy);
245+
- $acme = new AcmeApi($connector);
246+
+ $proxy = new Clue\React\SshProxy\SshSocksConnector('user@example.com', $loop);
247+
+ $acme = new AcmeApi($proxy);
248248
```
249249

250250
## Usage
@@ -259,13 +259,13 @@ a streaming plain TCP/IP connection on the `SshProcessConnector` or `SshSocksCon
259259
and use any higher level protocol like so:
260260

261261
```php
262-
$proxy = new SshProcessConnector('user@example.com', $loop);
262+
$proxy = new Clue\React\SshProxy\SshProcessConnector('user@example.com', $loop);
263263
// or
264-
$proxy = new SshSocksConnector('user@example.com', $loop);
264+
$proxy = new Clue\React\SshProxy\SshSocksConnector('user@example.com', $loop);
265265

266-
$proxy->connect('tcp://smtp.googlemail.com:587')->then(function (ConnectionInterface $stream) {
267-
$stream->write("EHLO local\r\n");
268-
$stream->on('data', function ($chunk) use ($stream) {
266+
$proxy->connect('tcp://smtp.googlemail.com:587')->then(function (React\Socket\ConnectionInterface $connection) {
267+
$connection->write("EHLO local\r\n");
268+
$connection->on('data', function ($chunk) use ($connection) {
269269
echo $chunk;
270270
});
271271
});
@@ -275,14 +275,18 @@ You can either use the `SshProcessConnector` or `SshSocksConnector` directly or
275275
may want to wrap this connector in ReactPHP's [`Connector`](https://github.com/reactphp/socket#connector):
276276

277277
```php
278-
$connector = new Connector($loop, array(
278+
$proxy = new Clue\React\SshProxy\SshProcessConnector('user@example.com', $loop);
279+
// or
280+
$proxy = new Clue\React\SshProxy\SshSocksConnector('user@example.com', $loop);
281+
282+
$connector = new React\Socket\Connector($loop, array(
279283
'tcp' => $proxy,
280284
'dns' => false
281285
));
282286

283-
$connector->connect('tcp://smtp.googlemail.com:587')->then(function (ConnectionInterface $stream) {
284-
$stream->write("EHLO local\r\n");
285-
$stream->on('data', function ($chunk) use ($stream) {
287+
$connector->connect('tcp://smtp.googlemail.com:587')->then(function (React\Socket\ConnectionInterface $connection) {
288+
$connection->write("EHLO local\r\n");
289+
$connection->on('data', function ($chunk) use ($connection) {
286290
echo $chunk;
287291
});
288292
});
@@ -304,16 +308,16 @@ ReactPHP's [`Connector`](https://github.com/reactphp/socket#connector) or the
304308
low-level [`SecureConnector`](https://github.com/reactphp/socket#secureconnector):
305309

306310
```php
307-
$proxy = new SshSocksConnector('user@example.com', $loop);
311+
$proxy = new Clue\React\SshProxy\SshSocksConnector('user@example.com', $loop);
308312

309-
$connector = new Connector($loop, array(
313+
$connector = new React\Socket\Connector($loop, array(
310314
'tcp' => $proxy,
311315
'dns' => false
312316
));
313317

314-
$connector->connect('tls://smtp.googlemail.com:465')->then(function (ConnectionInterface $stream) {
315-
$stream->write("EHLO local\r\n");
316-
$stream->on('data', function ($chunk) use ($stream) {
318+
$connector->connect('tls://smtp.googlemail.com:465')->then(function (React\Socket\ConnectionInterface $connection) {
319+
$connection->write("EHLO local\r\n");
320+
$connection->on('data', function ($chunk) use ($connection) {
317321
echo $chunk;
318322
});
319323
});
@@ -336,7 +340,7 @@ In order to send HTTP requests, you first have to add a dependency for
336340
This allows you to send both plain HTTP and TLS-encrypted HTTPS requests like this:
337341

338342
```php
339-
$proxy = new Clue\React\SshProxy\SshSocksConnector('me@localhost:22', $loop);
343+
$proxy = new Clue\React\SshProxy\SshSocksConnector('user@example.com', $loop);
340344

341345
$connector = new React\Socket\Connector($loop, array(
342346
'tcp' => $proxy,
@@ -381,7 +385,7 @@ $factory = new React\MySQL\Factory($loop, $proxy);
381385
$connection = $factory->createLazyConnection($uri);
382386

383387
$connection->query('SELECT * FROM book')->then(
384-
function (QueryResult $command) {
388+
function (React\MySQL\QueryResult $command) {
385389
echo count($command->resultRows) . ' row(s) in set' . PHP_EOL;
386390
},
387391
function (Exception $error) {
@@ -422,13 +426,17 @@ It provides the same `connect()` method, but will automatically reject the
422426
underlying connection attempt if it takes too long:
423427

424428
```php
425-
$connector = new Connector($loop, array(
429+
$proxy = new Clue\React\SshProxy\SshProcessConnector('user@example.com', $loop);
430+
// or
431+
$proxy = new Clue\React\SshProxy\SshSocksConnector('user@example.com', $loop);
432+
433+
$connector = new React\Socket\Connector($loop, array(
426434
'tcp' => $proxy,
427435
'dns' => false,
428436
'timeout' => 3.0
429437
));
430438

431-
$connector->connect('tcp://google.com:80')->then(function ($stream) {
439+
$connector->connect('tcp://google.com:80')->then(function (React\Socket\ConnectionInterface $connection) {
432440
// connection succeeded within 3.0 seconds
433441
});
434442
```
@@ -464,7 +472,11 @@ Given that remote DNS resolution is assumed to be the preferred mode, all
464472
other examples explicitly disable DNS resolution like this:
465473

466474
```php
467-
$connector = new Connector($loop, array(
475+
$proxy = new Clue\React\SshProxy\SshProcessConnector('user@example.com', $loop);
476+
// or
477+
$proxy = new Clue\React\SshProxy\SshSocksConnector('user@example.com', $loop);
478+
479+
$connector = new React\Socket\Connector($loop, array(
468480
'tcp' => $proxy,
469481
'dns' => false
470482
));
@@ -473,8 +485,12 @@ $connector = new Connector($loop, array(
473485
If you want to explicitly use *local DNS resolution*, you can use the following code:
474486

475487
```php
488+
$proxy = new Clue\React\SshProxy\SshProcessConnector('user@example.com', $loop);
489+
// or
490+
$proxy = new Clue\React\SshProxy\SshSocksConnector('user@example.com', $loop);
491+
476492
// set up Connector which uses Google's public DNS (8.8.8.8)
477-
$connector = new Connector($loop, array(
493+
$connector = new React\Socket\Connector($loop, array(
478494
'tcp' => $proxy,
479495
'dns' => '8.8.8.8'
480496
));
@@ -508,9 +524,9 @@ If your SSH proxy server requires password authentication, you may pass the
508524
username and password as part of the SSH proxy server URL like this:
509525

510526
```php
511-
$proxy = new SshProcessConnector('user:pass@example.com', $loop);
527+
$proxy = new Clue\React\SshProxy\SshProcessConnector('user:pass@example.com', $loop);
512528
// or
513-
$proxy = new SshSocksConnector('user:pass@example.com', $loop);
529+
$proxy = new Clue\React\SshProxy\SshSocksConnector('user:pass@example.com', $loop);
514530
```
515531

516532
For this to work, you will have to have the `sshpass` binary installed. On
@@ -527,7 +543,7 @@ special characters:
527543
$user = 'he:llo';
528544
$pass = 'p@ss';
529545

530-
$proxy = new SshProcessConnector(
546+
$proxy = new Clue\React\SshProxy\SshProcessConnector(
531547
rawurlencode($user) . ':' . rawurlencode($pass) . '@example.com:2222',
532548
$loop
533549
);

examples/11-proxy-raw-http-protocol.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
'dns' => false
2626
));
2727

28-
$connector->connect('tcp://google.com:80')->then(function (React\Socket\ConnectionInterface $stream) {
29-
$stream->write("GET / HTTP/1.1\r\nHost: google.com\r\nConnection: close\r\n\r\n");
30-
$stream->on('data', function ($chunk) {
28+
$connector->connect('tcp://google.com:80')->then(function (React\Socket\ConnectionInterface $connection) {
29+
$connection->write("GET / HTTP/1.1\r\nHost: google.com\r\nConnection: close\r\n\r\n");
30+
$connection->on('data', function ($chunk) {
3131
echo $chunk;
3232
});
3333
}, function (Exception $e) {

examples/12-optional-proxy-raw-http-protocol.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
$connector = new React\Socket\Connector($loop);
3333
}
3434

35-
$connector->connect('tcp://google.com:80')->then(function (React\Socket\ConnectionInterface $stream) {
36-
$stream->write("GET / HTTP/1.1\r\nHost: google.com\r\nConnection: close\r\n\r\n");
37-
$stream->on('data', function ($chunk) {
35+
$connector->connect('tcp://google.com:80')->then(function (React\Socket\ConnectionInterface $connection) {
36+
$connection->write("GET / HTTP/1.1\r\nHost: google.com\r\nConnection: close\r\n\r\n");
37+
$connection->on('data', function ($chunk) {
3838
echo $chunk;
3939
});
4040
}, function (Exception $e) {

examples/21-proxy-raw-https-protocol.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
'dns' => false
2626
));
2727

28-
$connector->connect('tls://google.com:443')->then(function (React\Socket\ConnectionInterface $stream) {
29-
$stream->write("GET / HTTP/1.1\r\nHost: google.com\r\nConnection: close\r\n\r\n");
30-
$stream->on('data', function ($chunk) {
28+
$connector->connect('tls://google.com:443')->then(function (React\Socket\ConnectionInterface $connection) {
29+
$connection->write("GET / HTTP/1.1\r\nHost: google.com\r\nConnection: close\r\n\r\n");
30+
$connection->on('data', function ($chunk) {
3131
echo $chunk;
3232
});
3333
}, function (Exception $e) {

examples/22-optional-proxy-raw-https-protocol.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
$connector = new React\Socket\Connector($loop);
3333
}
3434

35-
$connector->connect('tls://google.com:443')->then(function (React\Socket\ConnectionInterface $stream) {
36-
$stream->write("GET / HTTP/1.1\r\nHost: google.com\r\nConnection: close\r\n\r\n");
37-
$stream->on('data', function ($chunk) {
35+
$connector->connect('tls://google.com:443')->then(function (React\Socket\ConnectionInterface $connection) {
36+
$connection->write("GET / HTTP/1.1\r\nHost: google.com\r\nConnection: close\r\n\r\n");
37+
$connection->on('data', function ($chunk) {
3838
echo $chunk;
3939
});
4040
}, function (Exception $e) {

0 commit comments

Comments
 (0)