docs(readme): update

This commit is contained in:
Micooz 2017-04-22 17:07:01 +08:00
parent e9642a3965
commit 2323cb82df
3 changed files with 53 additions and 51 deletions

@ -40,6 +40,7 @@ module.exports = {
port: 1080,
servers: [{
enabled: true,
transport: 'tcp',
host: "bs.example.com",
port: 6858,
key: "j+b3)I<h#c1_Jl^c",

@ -2,7 +2,7 @@
## Template
You can use blinksocks init to generate `blinksocks.client.js` and `blinksocks.server.js`:
You can use **blinksocks init** to generate `blinksocks.client.js` and `blinksocks.server.js`:
```
$ blinksocks init
@ -14,10 +14,8 @@ $ blinksocks init
module.exports = {
// local hostname or ip address
//
// @note
// 1. For client, act as a Socks5/Socks4/HTTP server.
// 2. For server, act as a blinksocks server.
// For client, act as a Socks5/Socks4/HTTP server.
// For server, act as a blinksocks server.
host: "localhost",
// local port to be listen on
@ -29,6 +27,9 @@ module.exports = {
// allow to use this server or not
enabled: true,
// the transport layer, "tcp" or "udp"
transport: 'tcp',
// server host name or ip address
host: "example.com",
@ -36,13 +37,11 @@ module.exports = {
port: 5678,
// a secret key for encryption/description
key: "j+b3)I<h#c1_Jl^c",
key: "qtPb2edK7yd7e]<K",
// presets to process data stream
//
// @note
// 1. DO NOT modify the first preset if you don't know what it is.
// 2. Take care the order of those presets, read the docs before changing them.
// DO NOT modify the first preset if you don't know what it is.
// Take care the order of those presets, read the docs before changing them.
presets: [
{
// preset name
@ -71,10 +70,7 @@ module.exports = {
// hot-reload when this file changed
watch: true,
// log at the level
//
// @note
// 1. should be one of [error, warn, info, verbose, debug, silly]
// log at the level, "error", "warn", "info", "verbose", "debug" or "silly"
log_level: "info"
};
@ -86,23 +82,22 @@ module.exports = {
module.exports = {
// local hostname or ip address
//
// @note
// 1. For client, act as a Socks5/Socks4/HTTP server.
// 2. For server, act as a blinksocks server.
// For client, act as a Socks5/Socks4/HTTP server.
// For server, act as a blinksocks server.
host: "0.0.0.0",
// local port to be listen on
port: 5678,
// the transport layer, "tcp" or "udp"
transport: 'tcp',
// a secret key for encryption/description
key: "j+b3)I<h#c1_Jl^c",
key: "qtPb2edK7yd7e]<K",
// presets to process data stream
//
// @note
// 1. DO NOT modify the first preset if you don't know what it is.
// 2. Take care the order of those presets, read the docs before changing them.
// DO NOT modify the first preset if you don't know what it is.
// Take care the order of those presets, read the docs before changing them.
presets: [
{
// preset name
@ -120,10 +115,8 @@ module.exports = {
}
],
// redirect data stream to here once preset fail to process(server side only)
//
// @note
// 1. Should be formed with "host:port".
// redirect data to here once preset fail to process(server side only)
// Should be formed with "host:port".
redirect: "",
// close inactive connection after timeout seconds
@ -135,10 +128,7 @@ module.exports = {
// hot-reload when this file changed
watch: true,
// log at the level
//
// @note
// 1. should be one of [error, warn, info, verbose, debug, silly]
// log at the level, "error", "warn", "info", "verbose", "debug" or "silly"
log_level: "info"
};

@ -91,6 +91,8 @@ Store target address for further use:
```js
// presets/ss-base.js
import {IPreset} from './defs';
export default class SSBasePreset extends IPreset {
_atyp = ATYP_V4;
@ -121,49 +123,52 @@ there are several built-in presets already.
### Custom Preset
A typical preset must implement four methods of IPreset interface:
A typical preset should extends **IPreset** interface:
```js
// custom.js
import {IPreset} from './defs';
export default class CustomPreset extends IPreset {
clientOut({buffer/* , next, broadcast, fail */}) {
clientOut({buffer/* , next, broadcast, direct, fail */}) {
// next(buffer); async
return buffer; // sync
}
serverIn({buffer/* , next, broadcast, fail */}) {
serverIn({buffer/* , next, broadcast, direct, fail */}) {
return buffer;
}
serverOut({buffer/* , next, broadcast, fail */}) {
serverOut({buffer/* , next, broadcast, direct, fail */}) {
return buffer;
}
clientIn({buffer/* , next, broadcast, fail */}) {
clientIn({buffer/* , next, broadcast, direct, fail */}) {
return buffer;
}
}
```
| METHODS | DESCRIPTION |
| :-------- | :----------------------------------- |
| clientOut | client will send data to server |
| serverIn | server received data from client |
| serverOut | server will send back data to client |
| clientIn | client received data from server |
| METHODS | DESCRIPTION |
| :-------- | :------------------------------------------------------------------------------- |
| clientOut | client received data from application, and ready to forward data to server |
| serverIn | server received data from client, and ready to forward data to real destination |
| serverOut | server received data from real destination, and ready to backward data to client |
| clientIn | client received data from server, and ready to backward data to application |
> NOTE: `server*` are used on the server side while `client*` are used on the client side.
Every method gets an object which contains three parameters you need:
| PARAM | DESCRIPTION |
| :-------- | :------------------------------------------------------------------------- |
| buffer | output from the previous middleware |
| next | call it with a new buffer once **async** process done |
| broadcast | call it with an action to notify other middlewares |
| fail | call it once handshake failed, connection will be closed in random seconds |
| PARAM | DESCRIPTION |
| :------------------------ | :------------------------------------------------------------------------- |
| buffer | output from the previous preset |
| next(buffer) | asynchronously process buffer to the next preset |
| broadcast(action) | broadcast an action to other middlewares |
| direct(buffer, isReverse) | ignore the following presets, send data directly to fsocket or bsocket |
| fail(message) | report that the preset is fail to process |
### Presets Decoupling
@ -175,7 +180,7 @@ Action is a plain object which only requires a `type` field:
// action
{
type: <string>,
payload: <any>
...
}
```
@ -183,6 +188,8 @@ Once broadcast, **all** other middlewares will receive the action in **onNotifie
```js
// custom.js
import {IPreset} from './defs';
export default class CustomPreset extends IPreset {
/**
@ -206,13 +213,15 @@ There are two hooks available:
```js
// custom.js
import {IPreset} from './defs';
export default class CustomPreset extends IPreset {
beforeOut({buffer/* , next, broadcast, fail */}) {
beforeOut({buffer/* , next, broadcast, direct, fail */}) {
return buffer;
}
beforeIn({buffer/* , next, broadcast, fail */}) {
beforeIn({buffer/* , next, broadcast, direct, fail */}) {
return buffer;
}
@ -231,6 +240,8 @@ export default class CustomPreset extends IPreset {
You can access user configuration from your preset:
```js
import {IPreset} from './defs';
export default class CustomPreset extends IPreset {
constructor() {