diff --git a/README.md b/README.md index 8b2f54d..567fc85 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/package.json b/package.json index cbf8c14..66693f8 100644 --- a/package.json +++ b/package.json @@ -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 ", diff --git a/server.js b/server.js index 2b50841..5125cb0 100644 --- a/server.js +++ b/server.js @@ -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]) { @@ -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);