Skip to content

Commit 4d4f86d

Browse files
committed
Improve formatting
1 parent 7856445 commit 4d4f86d

1 file changed

Lines changed: 74 additions & 31 deletions

File tree

README.md

Lines changed: 74 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,6 @@ $tcp->create('www.google.com',80)->then(function (React\Stream\Stream $stream) {
4141
});
4242
```
4343

44-
### HTTP requests
45-
46-
HTTP operates on a higher layer than this low-level SOCKS implementation.
47-
If you want to issue HTTP requests, you can add a dependency for
48-
[clue/buzz-react](https://github.com/clue/php-buzz-react).
49-
It can interact with this library by issuing all
50-
[http requests through a SOCKS server](https://github.com/clue/php-buzz-react/#via-socks-server).
51-
This works for both plain HTTP and SSL encrypted HTTPS requests.
52-
5344
### SSL/TLS encrypted
5445

5546
If you want to connect to arbitrary SSL/TLS servers, there sure too is an easy to use API available:
@@ -58,16 +49,30 @@ $ssl = $client->createSecureConnector();
5849

5950
// now create an SSL encrypted connection (notice the $ssl instead of $tcp)
6051
$ssl->create('www.google.com',443)->then(function (React\Stream\Stream $stream) {
61-
// proceed with just the plain text data and everything is encrypted/decrypted automatically
52+
// proceed with just the plain text data
53+
// everything is encrypted/decrypted automatically
6254
echo 'connected to SSL encrypted www.google.com';
6355
$stream->write("GET / HTTP/1.0\r\n\r\n");
6456
// ...
6557
});
6658
```
6759

60+
### HTTP requests
61+
62+
HTTP operates on a higher layer than this low-level SOCKS implementation.
63+
If you want to issue HTTP requests, you can add a dependency for
64+
[clue/buzz-react](https://github.com/clue/php-buzz-react).
65+
It can interact with this library by issuing all
66+
[http requests through a SOCKS server](https://github.com/clue/php-buzz-react/#via-socks-server).
67+
This works for both plain HTTP and SSL encrypted HTTPS requests.
68+
6869
## SOCKS Protocol versions & differences
6970

70-
While SOCKS4 already had (a somewhat limited) support for `SOCKS BIND` requests and SOCKS5 added generic UDP support (`SOCKS UDPASSOCIATE`), this library focuses on the most commonly used core feature of `SOCKS CONNECT`. In this mode, a SOCKS server acts as a generic proxy allowing higher level application protocols to work through it.
71+
While SOCKS4 already had (a somewhat limited) support for `SOCKS BIND` requests
72+
and SOCKS5 added generic UDP support (`SOCKS UDPASSOCIATE`), this library
73+
focuses on the most commonly used core feature of `SOCKS CONNECT`.
74+
In this mode, a SOCKS server acts as a generic proxy allowing higher level
75+
application protocols to work through it.
7176

7277
<table>
7378
<tr>
@@ -120,14 +125,20 @@ While SOCKS4 already had (a somewhat limited) support for `SOCKS BIND` requests
120125
</tr>
121126
</table>
122127

123-
Note, this is __not__ a full SOCKS5 implementation due to missing GSSAPI authentication (but it's unlikely you're going to miss it anyway).
128+
Note, this is __not__ a full SOCKS5 implementation due to missing GSSAPI
129+
authentication (but it's unlikely you're going to miss it anyway).
124130

125131
### Explicitly setting protocol version
126132

127133
This library supports the SOCKS4, SOCKS4a and SOCKS5 protocol versions.
128134
Usually, there's no need to worry about which protocol version is being used.
129-
Depending on which features you use (e.g. [remote DNS resolving](#remote-vs-local-dns-resolving) and [authentication](#username--password-authentication)), the `Socks/Client` automatically uses the _best_ protocol available. In general this library automatically switches to higher protocol versions when needed, but tries to keep things simple otherwise and sticks to lower protocol versions when possible.
130-
The `Socks/Server` supports all protocol versions by default.
135+
Depending on which features you use (e.g. [remote DNS resolving](#remote-vs-local-dns-resolving)
136+
and [authentication](#username--password-authentication)),
137+
the `Client` automatically uses the _best_ protocol available.
138+
In general this library automatically switches to higher protocol versions
139+
when needed, but tries to keep things simple otherwise and sticks to lower
140+
protocol versions when possible.
141+
The `Server` supports all protocol versions by default.
131142

132143
If want to explicitly set the protocol version, use the supported values `4`, `4a` or `5`:
133144

@@ -137,7 +148,8 @@ $client->setProtocolVersion('4a');
137148
$server->setProtocolVersion(5);
138149
```
139150

140-
In order to reset the protocol version to its default (i.e. automatic detection), use `null` as protocol version.
151+
In order to reset the protocol version to its default (i.e. automatic detection),
152+
use `null` as protocol version.
141153

142154
```PHP
143155
$client->setProcolVersion(null);
@@ -146,22 +158,25 @@ $server->setProtocolVersion(null);
146158

147159
### Remote vs. local DNS resolving
148160

149-
By default, the `Socks/Client` uses local DNS resolving to resolve target hostnames
161+
By default, the `Client` uses local DNS resolving to resolve target hostnames
150162
into IP addresses and only transmits the resulting target IP to the socks server.
151163

152164
Resolving locally usually results in better performance as for each outgoing
153165
request both resolving the hostname and initializing the connection to the
154166
SOCKS server can be done simultanously. So by the time the SOCKS connection is
155167
established (requires a TCP handshake for each connection), the target hostname
156-
will likely already be resolved ( _usually_ either already cached or requires a simple DNS query via UDP).
168+
will likely already be resolved ( _usually_ either already cached or requires a
169+
simple DNS query via UDP).
157170

158-
You may want to switch to remote DNS resolving if your local `Socks/Client` either can not
171+
You may want to switch to remote DNS resolving if your local `Client` either can not
159172
resolve target hostnames because it has no direct access to the internet or if
160173
it should not resolve target hostnames because its outgoing DNS traffic might
161-
be intercepted (in particular when using the [Tor network](#using-the-tor-anonymity-network-to-tunnel-socks-connections)).
174+
be intercepted (in particular when using the
175+
[Tor network](#using-the-tor-anonymity-network-to-tunnel-socks-connections)).
162176

163177
Local DNS resolving is available in all SOCKS protocol versions.
164-
Remote DNS resolving is only available for SOCKS4a and SOCKS5 (i.e. it is NOT available for SOCKS4).
178+
Remote DNS resolving is only available for SOCKS4a and SOCKS5
179+
(i.e. it is NOT available for SOCKS4).
165180

166181
Valid values are boolean `true`(default) or `false`.
167182

@@ -171,29 +186,47 @@ $client->setResolveLocal(false);
171186

172187
### Username / Password authentication
173188

174-
This library supports username/password authentication for SOCKS5 servers as defined in [RFC 1929](http://tools.ietf.org/html/rfc1929).
189+
This library supports username/password authentication for SOCKS5 servers as
190+
defined in [RFC 1929](http://tools.ietf.org/html/rfc1929).
175191

176-
On the client side, simply set your username and password to use for authentication (see below).
177-
For each further connection the client will merely send a flag to the server indicating authentication information is available. Only if the server requests authentication during the initial handshake, the actual authentication credentials will be transmitted to the server.
192+
On the client side, simply set your username and password to use for
193+
authentication (see below).
194+
For each further connection the client will merely send a flag to the server
195+
indicating authentication information is available.
196+
Only if the server requests authentication during the initial handshake,
197+
the actual authentication credentials will be transmitted to the server.
178198

179-
Note that the password is transmitted in cleartext to the SOCKS proxy server, so this methods should not be used on a network where you have to worry about eavesdropping.
180-
Authentication is only supported by protocol version 5 (SOCKS5), so setting authentication on the `Socks/Client` enforces communication with protocol version 5 and complains if you have explicitly set anything else.
199+
Note that the password is transmitted in cleartext to the SOCKS proxy server,
200+
so this methods should not be used on a network where you have to worry about eavesdropping.
201+
Authentication is only supported by protocol version 5 (SOCKS5),
202+
so setting authentication on the `Client` enforces communication with protocol
203+
version 5 and complains if you have explicitly set anything else.
181204

182205
```PHP
183206
$client->setAuth('username', 'password');
184207
```
185208

186-
Setting authentication on the `Socks/Server` enforces each further connected client to use protocol version 5. If a client tries to use any other protocol version, does not send along authentication details or if authentication details can not be verified, the connection will be rejected.
209+
Setting authentication on the `Server` enforces each further connected client
210+
to use protocol version 5.
211+
If a client tries to use any other protocol version, does not send along
212+
authentication details or if authentication details can not be verified,
213+
the connection will be rejected.
187214

188-
Because your authentication mechanism might take some time to actually check the provided authentication credentials (like querying a remote database or webservice), the server side uses a [Promise](https://github.com/reactphp/promise) based interface. While this might seem complex at first, it actually provides a very simple way to handle simultanous connections in a non-blocking fashion and increases overall performance.
215+
Because your authentication mechanism might take some time to actually check
216+
the provided authentication credentials (like querying a remote database or webservice),
217+
the server side uses a [Promise](https://github.com/reactphp/promise) based interface.
218+
While this might seem complex at first, it actually provides a very simple way
219+
to handle simultanous connections in a non-blocking fashion and increases overall performance.
189220

190221
```PHP
191222
$server->setAuth(function ($username, $password) {
192-
// either return a boolean success value right away or use promises for delayed authentication
223+
// either return a boolean success value right away
224+
// or use promises for delayed authentication
193225
});
194226
```
195227

196-
Or if you only accept static authentication details, you can use the simple array-based authentication method as a shortcut:
228+
Or if you only accept static authentication details, you can use the simple
229+
array-based authentication method as a shortcut:
197230

198231
```PHP
199232
$server->setAuthArray(array(
@@ -213,7 +246,10 @@ $server->unsetAuth();
213246

214247
### Using SSH as a SOCKS server
215248

216-
If you already have an SSH server set up, you can easily use it as a SOCKS tunnel end point. On your client, simply start your SSH client and use the `-D [port]` option to start a local SOCKS server (quoting the man page: a `local "dynamic" application-level port forwarding`) by issuing:
249+
If you already have an SSH server set up, you can easily use it as a SOCKS
250+
tunnel end point. On your client, simply start your SSH client and use
251+
the `-D [port]` option to start a local SOCKS server (quoting the man page:
252+
a `local "dynamic" application-level port forwarding`) by issuing:
217253

218254
`$ ssh -D 9050 ssh-server`
219255

@@ -223,7 +259,14 @@ $client = new Client($loop, '127.0.0.1', 9050);
223259

224260
### Using the Tor (anonymity network) to tunnel SOCKS connections
225261

226-
The [Tor anonymity network](http://www.torproject.org) client software is designed to encrypt your traffic and route it over a network of several nodes to conceal its origin. It presents a SOCKS4 and SOCKS5 interface on TCP port 9050 by default which allows you to tunnel any traffic through the anonymity network. In most scenarios you probably don't want your client to resolve the target hostnames, because you would leak DNS information to anybody observing your local traffic. Also, Tor provides hidden services through an `.onion` pseudo top-level domain which have to be resolved by Tor.
262+
The [Tor anonymity network](http://www.torproject.org) client software is designed
263+
to encrypt your traffic and route it over a network of several nodes to conceal its origin.
264+
It presents a SOCKS4 and SOCKS5 interface on TCP port 9050 by default
265+
which allows you to tunnel any traffic through the anonymity network.
266+
In most scenarios you probably don't want your client to resolve the target hostnames,
267+
because you would leak DNS information to anybody observing your local traffic.
268+
Also, Tor provides hidden services through an `.onion` pseudo top-level domain
269+
which have to be resolved by Tor.
227270

228271
```PHP
229272

0 commit comments

Comments
 (0)