npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

public-server

v2.0.1

Published

let's a client talk to `hidden-server` via `public-server`

Downloads

12

Readme

public-server

let's a client talk to hidden-server via public-server

use case: e.g. access server sitting behind firewalls with unknown ip-address via reverse tunnel on demand.

the public-server is the counter part of hidden-server.

how it works

the hidden-server consists of three parts: client --command--> public <--ping-- hidden

  • hidden the hidden server or device that sits behind a firewall and does not have a fixed ip-address.
  • public a publicly available server the client can connect to. tt acts as a reverse proxy.
  • client client Machine that want's to access the hidden server.

it uses http POST with JSON content. the hidden server sends out ping messages to the publicServer at the given pingInterval. in order to allow simultaneous user access, simultaneousPings are sent by the hidden server.

when the keepPingOpen option is true on the hidden and on the public server, the pings are kept open until a command is received, or the next pingInterval kicks in. pingInterval is in seconds btw. if the keepPingOpen option is false, the command request from the client will only be responded, after the public server could respond to an incomming ping request from the hidden server.

when a command request by the client was successful, both ends (public and hidden) receive a command event.

ah and yes, you can have as many hidden servers as you like and connect them to a single public server. the client can decide with wich hidden server it want's to talk.

scenarios

The following scenarios describe the combinations with the options: keepPingOpen and roundTripResponse

###Scenario: keepPingOpen and roundTripResponse

  • + Advantage: fast, deterministic command response time / feedback from hidden-server
  • - Disadvantage: many open ports on public-server with many hidden-servers
+--------+                   +--------+                     +--------+
| Client |                   | Public |                     | Hidden |
+----+---+                   +----+---+                     +----+---+
     |                            |             Ping             |
     |                            | <--------------------------+ |
     |                            | |                            |
     |                            | | keepPingOpen               |
     |                            | |                            |
     |                            | |         Response           |
     |                            | v--------------------------> |
     |                            |                              |
     |                            |             Ping             |
     |                            | <--------------------------+ |
     |          Command           | |                            |
     | +------------------------> | |         Response           |
     |                          | | v--------------------------> | +---->
     |                          | |                              |      |  handleRequest
     |                          | |             Ping             |      |
     |          Response        | | <--------------------------+ | <----v
     | <------------------------v | |                            |
     |                            | | keepPingOpen               |
     |                            | |                            |
     |                            | |         Response           |
     |                            | v--------------------------> |
     |                            |                              |
     |                            |                              |
     +                            +                              +

###Scenario: roundTripResponse

  • + Advantage: no open ports on public-server / feedback from hidden-server
  • - Disadvantage: long, non deterministic command response time
 +--------+                   +--------+                     +--------+
 | Client |                   | Public |                     | Hidden |
 +----+---+                   +----+---+                     +----+---+
      |                            |             Ping             |
      |                            | <--------------------------+ | +
      |                            | v--------------------------> | |
      |                            |           Response           | | pingInterval
      |                            |                              | |
      |                            |                              | |
      |                            |             Ping             | v
      |                            | <--------------------------+ |
      |                            | v--------------------------> | +
      |                            |           Response           | |
      |          Command           |                              | | pingInterval
      | +------------------------> |                              | |
      |                          | |                              | |
      |                          | |             Ping             | v
      |                          | | <--------------------------+ |
      |                          | | v--------------------------> | +---->
      |                          | |           Response           |      | handleRequest
      |                          | |             Ping             |      |
      |                          | | <--------------------------+ | <----v
      |          Response        | | v--------------------------> |
      | <------------------------v |           Response           |
      |                            |                              |
      |                            |                              |
      +                            +                              +

###Scenario: keepPingOpen

  • + Advantage: fast, deterministic command response time,
  • - Disadvantage: no feedback from hidden-server / many open ports on public-server with many hidden-servers
+--------+                   +--------+                     +--------+
| Client |                   | Public |                     | Hidden |
+----+---+                   +----+---+                     +----+---+
     |                            |             Ping             |
     |                            | <--------------------------+ |
     |                            | |                            |
     |                            | | keepPingOpen               |
     |                            | |                            |
     |                            | |         Response           |
     |                            | v--------------------------> |
     |                            |                              |
     |                            |             Ping             |
     |                            | <--------------------------+ |
     |                            | |                            |
     |          Command           | |         Response           |
     | +------------------------> | v--------------------------> |
     |          Response        | |                              |
     | <------------------------v |             Ping             |
     |                            | <--------------------------+ |
     |                            | |                            |
     |                            | | keepPingOpen               |
     |                            | |                            |
     |                            | |         Response           |
     |                            | v--------------------------> |
     |                            |                              |
     |                            |                              |
     +                            +                              +

###Scenario: no Options

  • + Advantage: not many... simple :-) ... no open ports on public-server
  • - Disadvantage: long, non deterministic command response time / no feedback from hidden-server
+--------+                   +--------+                     +--------+
| Client |                   | Public |                     | Hidden |
+----+---+                   +----+---+                     +----+---+
     |                            |             Ping             |
     |                            | <--------------------------+ | +
     |                            | v--------------------------> | |
     |                            |           Response           | | pingInterval
     |                            |                              | |
     |                            |                              | v
     |                            |             Ping             |
     |                            | <--------------------------+ | +
     |                            | v--------------------------> | |
     |          Command           |           Response           | | pingInterval
     | +------------------------> |                              | |
     |                          | |                              | v
     |                          | |             Ping             |
     |          Response        | | <--------------------------+ | +
     | <------------------------v | v--------------------------> | |
     |                            |           Response           | | pingInterval
     |                            |                              | |
     |                            |                              | v
     |                            |                              |
     |                            |                              |
     +                            +                              +

diagrams created with asciiflow

install

npm install public-server

test

npm install public-server -d
mocha

##usage

hidden

var HiddenServer = require('hidden-server');
var hidden = new HiddenServer({
  publicServer: 'http://localhost:3000',
  pingUri: '/ping/:hiddenServerName',
  simultaneousPings: 5,
  pingInterval: 3,
  keepPingOpen: true,
  roundTripResponse: false,
  hiddenServerName: 'server1'
}).start();


hidden.on('command', function(obj) {
  console.log('command', obj);
});

public

var PublicServer = require('public-server');
var public = PublicServer({
  commandUri: '/command/:hiddenServerName',
  pingUri: '/ping/:hiddenServerName',
  pingInterval: 3,
  keepPingOpen: true,
  roundTripResponse: false
});

public.on('command', function(obj) {
  console.log('command', obj);
});

public.listen(3000);

client

curl -H "Content-Type: application/json" -d '{"command":"newCommand","additional":"parameter"}' localhost:3000/command/server1

license

MIT License