Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
nomilous committed Oct 20, 2016
1 parent 316d4cb commit 9088729
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 9 deletions.
97 changes: 91 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,99 @@

# vertex-transport

**Requires node v6.0.0**

`npm install vertex-transport —save`

A server and socket for [vertex](https://github.com/nomilous/vertex).

Warning… watch socket `error` events… `VertexSocketDataError`s `terminate`
Uses [ws](https://www.npmjs.com/package/ws) underneath. They suggest installing binary addons for speed: [bufferutil](https://www.npmjs.com/package/bufferutil) and [utf-8-validate](https://www.npmjs.com/package/utf-8-validate)


Optional deps to speed things up...

### Quick Start

```javascript
const {VertexServer, VertexSocket} = require('vertex-transport');
```
"optionalDependencies": {
"bufferutil": "^1.2.1",
"utf-8-validate": "^1.2.1"
}

#### Start the server

[details](#Server Details)

```javascript
VertexServer.create()
.then(server => {})
.catch(error => {});
```





### Errors

In addition to regular socket errors.

```javascript
const {
VertexSocketDataError,
VertexSocketIdleError,
VertexSocketClosedError,
VertexSocketTimeoutError,
VertexSocketReplyError,
VertexSocketRemoteEncodeError
} = require('vertex-transport').errors;
```

**Emitted** in the socket error event handler.

```javascript
vertexSocket.on('error', error => {});
```

**Passed** into the `send()` rejection handler.

```javascript
vertexSocket.send({data: 1}).catch(error => {})
```

#### VertexSocketDataError

* **Emitted** on the server-side socket (usually when an attacker is probing the server port).
* **Emitted** on the client-side socket in the unlikely event that it sends or recieves unparsable data to the server.

The socket is immediately/aleady closed in both cases.

#### VertexSocketIdleError

* **Emitted** on the server-side socket when a new connection fails to send any data within `config.connectIdleTimeout`. Once the first frame is received no futher idle timeouts are applied.

The socket is immediately closed.

#### VertexSocketClosedError

* **Passed** in the `send()` promise rejection when the socket is already closed or when it closes while awaiting ACKs for already sent messages.

#### VertexSocketTimeoutError

* **Passed** in the `send(data, optionalTimeout)` promise rejection if an ACK or NAK is not received from the server in the specified time.

#### VertexSocketReplyError

* **Emitted** if an ACK or NAK arrives **after** the timeout that caused the `VertexSocketTimeoutError`.

#### VertexSocketRemoteEncodeError

* **Passed** in the `send()` promise rejection when the remote side assembled a response (ACK+data) that could not be encoded. This will usually only be encountered while developing.



### Server





### Client

2 changes: 2 additions & 0 deletions lib/VertexServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class VertexServer extends EventEmitter {
this._server = server;
this._config = config;

this._config.connectIdleTimeout = this._config.connectIdleTimeout || 20 * 1000;

this._onErrorListener = this._onError.bind(this);
this._onListeningListener = this._onListening.bind(this);
this._onConnectionListener = this._onConnection.bind(this);
Expand Down
6 changes: 3 additions & 3 deletions lib/errors/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module.exports = {
VertexSocketDataError: require('./VertexSocketDataError'),
VertexSocketRemoteEncodeError: require('./VertexSocketRemoteEncodeError'),
VertexSocketIdleError: require('./VertexSocketIdleError'),
VertexSocketClosedError: require('./VertexSocketClosedError'),
VertexSocketTimeoutError: require('./VertexSocketTimeoutError'),
VertexSocketReplyError: require('./VertexSocketReplyError'),
VertexSocketClosedError: require('./VertexSocketClosedError'),
VertexSocketIdleError: require('./VertexSocketIdleError')
VertexSocketRemoteEncodeError: require('./VertexSocketRemoteEncodeError')
};

0 comments on commit 9088729

Please sign in to comment.