Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add getPeer per rinfo #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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 <[email protected]>",
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