Skip to content

Commit 9db7fa7

Browse files
authored
Merge pull request #87 from clue-labs/socks5-uri
URI scheme socks5:// acts only as an alias for default socks:// scheme
2 parents f1003ea + cd4f80b commit 9db7fa7

4 files changed

Lines changed: 22 additions & 11 deletions

File tree

README.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,15 @@ a generic proxy allowing higher level application protocols to work through it.
311311
By default, the `Client` communicates via SOCKS5 with the SOCKS server.
312312
This is done because SOCKS5 is the latest version from the SOCKS protocol family
313313
and generally has best support across other vendors.
314+
You can also omit the default `socks://` URI scheme. Similarly, the `socks5://`
315+
URI scheme acts as an alias for the default `socks://` URI scheme.
316+
317+
```php
318+
// all three forms are equivalent
319+
$client = new Client('127.0.0.1', $connector);
320+
$client = new Client('socks://127.0.0.1', $connector);
321+
$client = new Client('socks5://127.0.0.1', $connector);
322+
```
314323

315324
If want to explicitly set the protocol version to SOCKS4(a), you can use the URI
316325
scheme `socks4://` as part of the SOCKS URI:
@@ -544,7 +553,7 @@ You can use the `sockss://` URI scheme or use an explicit
544553
```php
545554
$client = new Client('sockss://127.0.0.1:1080', new Connector($loop));
546555

547-
$client = new Client('socks5s://127.0.0.1:1080', new Connector($loop));
556+
$client = new Client('socks4s://127.0.0.1:1080', new Connector($loop));
548557
```
549558

550559
See also [example 32](examples).
@@ -587,7 +596,7 @@ You can use the `socks+unix://` URI scheme or use an explicit
587596
```php
588597
$client = new Client('socks+unix:///tmp/proxy.sock', new Connector($loop));
589598

590-
$client = new Client('socks5+unix:///tmp/proxy.sock', new Connector($loop));
599+
$client = new Client('socks4+unix:///tmp/proxy.sock', new Connector($loop));
591600
```
592601

593602
Similarly, you can also combine this with [authentication](#authentication)
@@ -661,7 +670,8 @@ Internally, the `Server` uses ReactPHP's normal
661670
[`connect()`](https://github.com/reactphp/socket#connect) method, but
662671
it also passes the original client IP as the `?source={remote}` parameter.
663672
The `source` parameter contains the full remote URI, including the protocol
664-
and any authentication details, for example `socks5://user:pass@1.2.3.4:5678`.
673+
and any authentication details, for example `socks://user:pass@1.2.3.4:5678`
674+
or `socks4://1.2.3.4:5678` for legacy SOCKS4(a).
665675
You can use this parameter for logging purposes or to restrict connection
666676
requests for certain clients by providing a custom implementation of the
667677
[`ConnectorInterface`](https://github.com/reactphp/socket#connectorinterface).
@@ -695,8 +705,9 @@ function that should return a `bool` value like this synchronous example:
695705

696706
```php
697707
$server = new Clue\React\Socks\Server($loop, null, function ($user, $pass, $remote) {
698-
// $remote is a full URI à la socks5://user:pass@192.168.1.1:1234
699-
// or socks5s://user:pass@192.168.1.1:1234 for SOCKS over TLS
708+
// $remote is a full URI à la socks://user:pass@192.168.1.1:1234
709+
// or sockss://user:pass@192.168.1.1:1234 for SOCKS over TLS
710+
// or may be null when remote is unknown (SOCKS over Unix Domain Sockets)
700711
// useful for logging or extracting parts, such as the remote IP
701712
$ip = parse_url($remote, PHP_URL_HOST);
702713

src/Server.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public function handleSocks5(ConnectionInterface $stream, $auth, StreamReader $r
218218
if (($pos = strpos($remote, '://')) !== false) {
219219
$remote = substr($remote, $pos + 3);
220220
}
221-
$remote = 'socks5' . ($secure ? 's' : '') . '://' . $remote;
221+
$remote = 'socks' . ($secure ? 's' : '') . '://' . $remote;
222222
}
223223

224224
$that = $this;

tests/FunctionalTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public function testConnectionAuthenticationCallback()
214214
++$called;
215215
$that->assertEquals('name', $name);
216216
$that->assertEquals('pass', $pass);
217-
$that->assertStringStartsWith('socks5://name:pass@127.0.0.1:', $remote);
217+
$that->assertStringStartsWith('socks://name:pass@127.0.0.1:', $remote);
218218

219219
return true;
220220
});

tests/ServerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ public function testConnectWillCreateConnectionWithSourceUri()
7979

8080
$promise = new Promise(function () { });
8181

82-
$this->connector->expects($this->once())->method('connect')->with('google.com:80?source=socks5%3A%2F%2F10.20.30.40%3A5060')->willReturn($promise);
82+
$this->connector->expects($this->once())->method('connect')->with('google.com:80?source=socks%3A%2F%2F10.20.30.40%3A5060')->willReturn($promise);
8383

84-
$promise = $this->server->connectTarget($stream, array('google.com', 80, 'socks5://10.20.30.40:5060'));
84+
$promise = $this->server->connectTarget($stream, array('google.com', 80, 'socks://10.20.30.40:5060'));
8585

8686
$this->assertInstanceOf('React\Promise\PromiseInterface', $promise);
8787
}
@@ -291,7 +291,7 @@ public function testHandleSocks5ConnectionWithIpv4AndSourceAddressWillEstablishO
291291

292292
$promise = new Promise(function () { });
293293

294-
$this->connector->expects($this->once())->method('connect')->with('127.0.0.1:80?source=socks5%3A%2F%2F10.20.30.40%3A5060')->willReturn($promise);
294+
$this->connector->expects($this->once())->method('connect')->with('127.0.0.1:80?source=socks%3A%2F%2F10.20.30.40%3A5060')->willReturn($promise);
295295

296296
$this->server->onConnection($connection);
297297

@@ -305,7 +305,7 @@ public function testHandleSocks5ConnectionWithSecureTlsIpv4AndSourceAddressWillE
305305

306306
$promise = new Promise(function () { });
307307

308-
$this->connector->expects($this->once())->method('connect')->with('127.0.0.1:80?source=socks5s%3A%2F%2F10.20.30.40%3A5060')->willReturn($promise);
308+
$this->connector->expects($this->once())->method('connect')->with('127.0.0.1:80?source=sockss%3A%2F%2F10.20.30.40%3A5060')->willReturn($promise);
309309

310310
$this->server->onConnection($connection);
311311

0 commit comments

Comments
 (0)