From 6fee83c989f1e7efc40a1fb235fa833e54cb8447 Mon Sep 17 00:00:00 2001 From: Jonathan Barrow Date: Fri, 16 Jan 2026 16:27:39 -0500 Subject: [PATCH] feat: add basic health check server --- README.md | 25 +++++++++++++------------ nex/authentication.go | 10 ++++++++-- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index f9c4718..35b8467 100644 --- a/README.md +++ b/README.md @@ -84,15 +84,16 @@ All configuration options are handled via environment variables `.env` files are supported -| Name | Description | Required | -|---------------------------------------------|------------------------------------------------------------------------------------------------------------------------|-------------------------------------| -| `PN_FRIENDS_CONFIG_DATABASE_URI` | Fully qualified URI to your Postgres server (Example `postgres://username:password@localhost/friends?sslmode=disable`) | Yes | -| `PN_FRIENDS_CONFIG_AES_KEY` | AES key used in tokens provided by the account server | Yes | -| `PN_FRIENDS_CONFIG_GRPC_API_KEY` | API key for your GRPC server | No (Assumed to be an open gRPC API) | -| `PN_FRIENDS_GRPC_SERVER_PORT` | Port for the GRPC server | Yes | -| `PN_FRIENDS_AUTHENTICATION_SERVER_PORT` | Port for the authentication server | Yes | -| `PN_FRIENDS_SECURE_SERVER_HOST` | Host name for the secure server (should point to the same address as the authentication server) | Yes | -| `PN_FRIENDS_SECURE_SERVER_PORT` | Port for the secure server | Yes | -| `PN_FRIENDS_ACCOUNT_GRPC_HOST` | Host name for your account server gRPC service | Yes | -| `PN_FRIENDS_ACCOUNT_GRPC_PORT` | Port for your account server gRPC service | Yes | -| `PN_FRIENDS_ACCOUNT_GRPC_API_KEY` | API key for your account server gRPC service | No (Assumed to be an open gRPC API) | +| Name | Description | Required | +| --------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- | ----------------------------------- | +| `PN_FRIENDS_CONFIG_DATABASE_URI` | Fully qualified URI to your Postgres server (Example `postgres://username:password@localhost/friends?sslmode=disable`) | Yes | +| `PN_FRIENDS_CONFIG_AES_KEY` | AES key used in tokens provided by the account server | Yes | +| `PN_FRIENDS_CONFIG_GRPC_API_KEY` | API key for your GRPC server | No (Assumed to be an open gRPC API) | +| `PN_FRIENDS_GRPC_SERVER_PORT` | Port for the GRPC server | Yes | +| `PN_FRIENDS_AUTHENTICATION_SERVER_PORT` | Port for the authentication server | Yes | +| `PN_FRIENDS_SECURE_SERVER_HOST` | Host name for the secure server (should point to the same address as the authentication server) | Yes | +| `PN_FRIENDS_SECURE_SERVER_PORT` | Port for the secure server | Yes | +| `PN_FRIENDS_ACCOUNT_GRPC_HOST` | Host name for your account server gRPC service | Yes | +| `PN_FRIENDS_ACCOUNT_GRPC_PORT` | Port for your account server gRPC service | Yes | +| `PN_FRIENDS_ACCOUNT_GRPC_API_KEY` | API key for your account server gRPC service | No (Assumed to be an open gRPC API) | +| `PN_FRIENDS_CONFIG_HEALTH_CHECK_PORT` | Port for the basic UDP health check server | No | diff --git a/nex/authentication.go b/nex/authentication.go index 0430b86..f26c03d 100644 --- a/nex/authentication.go +++ b/nex/authentication.go @@ -11,7 +11,13 @@ import ( var serverBuildString string func StartAuthenticationServer() { - port, _ := strconv.Atoi(os.Getenv("PN_FRIENDS_AUTHENTICATION_SERVER_PORT")) + prudpPort, _ := strconv.Atoi(os.Getenv("PN_FRIENDS_AUTHENTICATION_SERVER_PORT")) + + healthCheckPortString := os.Getenv("PN_FRIENDS_CONFIG_HEALTH_CHECK_PORT") + if healthCheckPortString != "" { + healthCheckPort, _ := strconv.Atoi(healthCheckPortString) + go nex.EnableBasicUDPHealthCheck(healthCheckPort) + } globals.AuthenticationServer = nex.NewPRUDPServer() globals.AuthenticationEndpoint = nex.NewPRUDPEndPoint(1) @@ -27,5 +33,5 @@ func StartAuthenticationServer() { globals.AuthenticationServer.SessionKeyLength = 16 globals.AuthenticationServer.AccessKey = "ridfebb9" globals.AuthenticationServer.BindPRUDPEndPoint(globals.AuthenticationEndpoint) - globals.AuthenticationServer.Listen(port) + globals.AuthenticationServer.Listen(prudpPort) }