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

Conversation

nicgirault
Copy link

@nicgirault nicgirault commented Feb 4, 2024

In order to use this package as a proxy without opening one backend socket per peer (and thus make the proxy scale above the number of available ports), being able to access peers per socket remote info is needed.

Here is the code I am writing in order to integrate this project with https://github.com/coapjs/node-coap (see coapjs/node-coap#253) and where we see this need of the method added in the pull request:

import { createServer } from "openssl-dtls"
import { EventEmitter } from "events"

export class DTLSSocket extends EventEmitter {
  constructor(options) {
    super()
    this.dtlsServer = createServer(options)

    this.dtlsServer.on("secureConnection", peer => {
      peer.on("message", msg => {
        this.emit("message", msg, peer.address())
      })
    })
  }

  send(message, port, host, callback) {
    // here I duplicate https://github.com/jue89/node-openssl-dtls/blob/7e16a03d504d72d0d7027a7111e6a21f79ca3692/server.js#L51
    const key = `${host} ${port}`
    const peer = this.dtlsServer.peers[key]

    if (peer) {
      peer.send(message)
      callback()
    } else {
      callback(new Error('No client connection stored at this address'))
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant