Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ srv.close([cb]);

Shuts down the server and calls `cb` once the underlying socket has been closed.

#### Method: getPeer(rinfo): peer

```js
srv.getPeer({address: ..., port: ...});
```

Returns a peer by address & port.

#### Event: connection

```js
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "openssl-dtls",
"version": "2.0.2",
"version": "2.1.0",
"description": "Bindings for OpenSSL DTLS1.2",
"main": "index.js",
"author": "Jue <me@jue.yt>",
Expand Down
11 changes: 10 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Server extends EventEmitter {

// Listen for datagrams
this.socket.on('message', (message, rinfo) => {
const key = `${rinfo.address} ${rinfo.port}`;
const key = this._peerKey(rinfo);

// New connection
if (!this.peers[key]) {
Expand All @@ -68,6 +68,15 @@ class Server extends EventEmitter {
});
}

_peerKey (rinfo) {
return `${rinfo.address} ${rinfo.port}`;
}

getPeer (rinfo) {
const key = this._peerKey(rinfo)
return this.peers[key]
}

bind () {
const args = Array.prototype.slice.call(arguments);
this.socket.bind.apply(this.socket, args);
Expand Down