named-data / YaNFD

Yet another Named Data Networking Forwarding Daemon
https://pkg.go.dev/github.com/named-data/YaNFD
MIT License
12 stars 10 forks source link

face: WebSocket listener and transport #12

Closed yoursunny closed 2 years ago

yoursunny commented 2 years ago

This change implements a WebSocket listener in YaNFD. It supports both unencrypted "ws" scheme and TLS-encrypted "wss" scheme.

This change has been tested with NDNts @ndn/ws-transport package.

Test instructions for "ws" scheme:

  1. In yanfd.toml, set faces.websocket.enabled=true.
  2. Start YaNFD.
  3. Start ndnpingserver and connect it to YaNFD.
  4. Checkout https://github.com/yoursunny/NDNts-starter/tree/webpack-js-simple revision 90371b8b3ccd5a2affb5b3f81c7347e3b941a8c8
  5. npm install
  6. Modify src/main.js:
    • Add at the top:
      import { WsTransport } from "@ndn/ws-transport";
    • Change await connectToNetwork(); to:
      const face = await WsTransport.createFace({}, "ws://localhost:9696");
      face.addRoute(new Name("/"));
  7. npm run serve and open http://localhost:3333
  8. Enter the name prefix of ndnpingserver and click ping button. You should see responses.

Test instructions for "wss" scheme are similar to above, but:

  1. You need a publicly accessible server and a trusted TLS certificate.
  2. In yanfd.toml, set faces.websocket.tls_enabled=true, and enter the path to TLS certificate (it should be the "fullchain" file from acme.sh or similar) and TLS key.
  3. Enter a "wss" URI in place of ws://localhost:9696.