Sign inSign up

asanrom/hls-websocket-cdn

By asanrom

•Updated over 1 year ago

This the main backend component for HLS Websocket CDN, implemented in golang.

Image
0

1.5K

asanrom/hls-websocket-cdn repository overview

⁠HLS Websocket CDN - Server

This the main backend component for HLS Websocket CDN⁠, implemented in golang.

⁠Configuration

You can configure the server using environment variables.

⁠Log configuration
VariableDescription
LOG_INFOCan be YES or NO. Set it to YES in order to enable logging INFO messages
LOG_DEBUGCan be YES or NO. Set it to YES in order to enable logging DEBUG messages
⁠Server configuration (HTTP)
VariableDescription
HTTP_ENABLEDCan be YES or NO. Set it to YES in order to enable the HTTP server (enabled by default).
HTTP_PORTThe port number for the HTTP server (80 by default)
HTTP_BIND_ADDRESSThe bind address for the HTTP server (Leave empty to listen on all network interfaces)
⁠Server configuration (HTTPS, HTTP over TLS)
VariableDescription
TLS_ENABLEDCan be YES or NO. Set it to YES in order to enable the HTTPS server (enabled by default).
TLS_PORTThe port number for the HTTPS server (443 by default)
TLS_BIND_ADDRESSThe bind address for the HTTPS server (Leave empty to listen on all network interfaces)
TLS_CERTIFICATEPath to the X.509 certificate for TLS
TLS_PRIVATE_KEYPath to the private key for TLS
TLS_CHECK_RELOAD_SECONDSNumber of seconds to check for changes in the certificate or key (for auto renewal)
⁠Websocket protocol configuration
VariableDescription
EXTERNAL_WEBSOCKET_URLExternal websocket URL of the server, for other servers to connect with it. If empty, it will be automatically detected from the network interfaces.
WEBSOCKET_PREFIXPath clients must use to connect to the server. By default: /.
MAX_BINARY_MESSAGE_SIZEWhen handling binary messages, what is the limit for them, in bytes. Default: 50 MB.
⁠Publish registry (Redis)
VariableDescription
PUB_REG_REDIS_ENABLEDCan be YES or NO. Set it to YES in order to enable the redis publish registry.
PUB_REG_REDIS_HOSTRedis host. Default: 127.0.0.1
PUB_REG_REDIS_PORTRedis port. Default: 6379
PUB_REG_REDIS_PASSWORDPassword to authenticate to the Redis server.
PUB_REG_REDIS_USE_TLSCan be YES or NO. Set it to YES in order to use TLS to connect to Redis.
PUB_REG_REFRESH_INTERVAL_SECONDSNumber of seconds to refresh publish registry entries. Default 60 seconds.
⁠Relay
VariableDescription
RELAY_FROM_ENABLEDCan be YES or NO. Set it to YES to enable relaying streams from another server.
RELAY_FROM_URLWebsocket URL of another server to relay HLS streams from.
⁠Authentication
VariableDescription
PULL_SECRETSecret to sign and validate the authentication tokens for pulling the streams.
PUSH_SECRETSecret to sign and validate the authentication tokens for pushing the streams.
PUSH_ALLOWEDCan be YES or NO. Set it to YES to allow pushing streams to the server.
⁠Rate limit

In order to prevent DoS attacks, a measure you can take is to limit the rate of requests per client IP address.

Note: Only use if the CDN server is exposed to the internet. If you are using a proxy. Do the rate limiting in the proxy, since it is the backend element closer to the client and probably has better rate limiting capabilities.

VariableDescription
RATE_LIMIT_ENABLEDCan be YES or NO. Set it to YES to enable rate limiting.
RATE_LIMIT_WHITELISTList of IP ranges not affected by the rate limit. Split by commas. Example: 127.0.0.1,10.0.0.0/8
RATE_LIMIT_CONNECTIONSMax number of active connections per unique client IP address. 0 means no limit.
RATE_LIMIT_REQ_PER_SECMax number of request per second per unique client IP address. 0 means no limit
RATE_LIMIT_REQ_BURSTExcess requests a client can make. If the client sends exceeds requests, it must wait more time.
RATE_LIMIT_REQ_CLEANUPInterval (seconds) to perform cleanup in the request counter. 10 by default.
⁠Memory limiter

By default, the server will store fragments in a buffer to send to new clients immediately. However, this can increase the memory usage, and result in a crash if the machine memory is fully used.

To prevent, that, the server allows you to configure a limit. When this limit is reached, the buffering will be degraded, but the CDN will still work. The impact on the user will be only a later wait time to play the stream when they connect.

Make sure to not set the limit too close to the total memory of the machine, as memory is also needed for other tasks and processes.

VariableDescription
BUFFER_MEMORY_LIMITER_ENABLEDCan be YES or NO. Set it to YES to enable the memory limiter.
BUFFER_MEMORY_LIMIT_MBMemory limit for fragment buffers in megabytes. Default: 256

⁠Other options

VariableDescription
FRAGMENT_BUFFER_MAX_LENGTHMax number of fragments to keep in the buffer for new pull connections. Default: 10
RELAY_INACTIVITY_PERIOD_SECRelay inactivity period (seconds). After double this period, a relay is closed if inactive. Default: 30

⁠Health check

You can check for the server health by sending an HTTP GET request to any other path that is not the websocket path. The server will return a 200 OK response with the body OK - HLS Websocket CDN.

Tag summary

Content type

Image

Digest

sha256:a871cb6ae…

Size

8.8 MB

Last updated

over 1 year ago

docker pull asanrom/hls-websocket-cdn