[Libwebsockets] Max connections

Andy Green andy at warmcat.com
Tue Oct 11 16:01:22 CEST 2016



On October 11, 2016 9:47:20 PM GMT+08:00, Srikar Vadlamani <SrikarVadlamani at trafficware.com> wrote:
>Hello,
>
>Is there a way to limit max number of connections?

You can just refuse connections as soon as they are accepted at the network level, if you don't want them to proceed as http[s]/ws[s] logical connections, for whatever reason.

https://github.com/warmcat/libwebsockets/blob/master/lib/libwebsockets.h#L770

LWS_CALLBACK_FILTER_NETWORK_CONNECTION			= 17,
	/**< called when a client connects to
	 * the server at network level; the connection is accepted but then
	 * passed to this callback to decide whether to hang up immediately
	 * or not, based on the client IP.  in contains the connection
	 * socket's descriptor. Since the client connection information is
	 * not available yet, wsi still pointing to the main server socket.
	 * Return non-zero to terminate the connection before sending or
	 * receiving anything. Because this happens immediately after the
	 * network connection from the client, there's no websocket protocol
	 * selected yet so this callback is issued only to protocol 0. */

Notice though an attacker can lock you out if his connections can be accepted first, and you refuse all after the first n connections.  You might want to make, eg, connections from 127.0.0.1 always accepted.

-Andy

>srikar
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Libwebsockets mailing list
>Libwebsockets at ml.libwebsockets.org
>http://libwebsockets.org/mailman/listinfo/libwebsockets




More information about the Libwebsockets mailing list