NSerf.Lighthouse.Client 1.0.0

dotnet add package NSerf.Lighthouse.Client --version 1.0.0
                    
NuGet\Install-Package NSerf.Lighthouse.Client -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NSerf.Lighthouse.Client" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NSerf.Lighthouse.Client" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="NSerf.Lighthouse.Client" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NSerf.Lighthouse.Client --version 1.0.0
                    
#r "nuget: NSerf.Lighthouse.Client, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package NSerf.Lighthouse.Client@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NSerf.Lighthouse.Client&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=NSerf.Lighthouse.Client&version=1.0.0
                    
Install as a Cake Tool

NSerf.Lighthouse.Client

.NET client library for consuming the NSerf Lighthouse API. This library provides a simple interface for cluster registration and node discovery in NSerf clusters.

Features

  • Cluster Registration: Register your cluster with the Lighthouse server
  • Node Discovery: Discover other nodes in your cluster version
  • Cryptographic Security: Built-in ECDSA signature verification and AES-256-GCM encryption
  • Resilience Policies: Automatic retry with exponential backoff and circuit breaker using Microsoft.Extensions.Http.Resilience
  • Comprehensive Logging: Structured logging for all operations and errors
  • Telemetry Support: Built-in metrics and observability
  • Easy Integration: Simple dependency injection setup

Installation

dotnet add package NSerf.Lighthouse.Client

Quick Start

1. Configure the Client

Add configuration to your appsettings.json:

{
  "LighthouseClient": {
    "BaseUrl": "https://lighthouse.example.com",
    "ClusterId": "your-cluster-guid",
    "PrivateKey": "base64-encoded-pkcs8-private-key",
    "AesKey": "base64-encoded-32-byte-aes-key",
    "TimeoutSeconds": 30
  }
}

2. Register the Client

In your Program.cs or Startup.cs:

using NSerf.Lighthouse.Client;

builder.Services.AddLighthouseClient(options =>
{
    builder.Configuration.GetSection(LighthouseClientOptions.SectionName).Bind(options);
});

3. Use the Client

public class MyService
{
    private readonly ILighthouseClient _lighthouseClient;

    public MyService(ILighthouseClient lighthouseClient)
    {
        _lighthouseClient = lighthouseClient;
    }

    public async Task RegisterAndDiscoverAsync()
    {
        // Register cluster (one-time setup)
        var publicKey = GetPublicKey(); // Your ECDSA public key
        await _lighthouseClient.RegisterClusterAsync(publicKey);

        // Discover nodes
        var currentNode = new NodeInfo
        {
            IpAddress = "192.168.1.100",
            Port = 7946,
            Metadata = new Dictionary<string, string>
            {
                ["region"] = "us-east-1",
                ["role"] = "worker"
            }
        };

        var peers = await _lighthouseClient.DiscoverNodesAsync(
            currentNode,
            versionName: "production",
            versionNumber: 1);

        foreach (var peer in peers)
        {
            Console.WriteLine($"Discovered peer: {peer.IpAddress}:{peer.Port}");
        }
    }
}

Key Generation

Generate ECDSA Key Pair (P-256)

using System.Security.Cryptography;

var ecdsa = ECDsa.Create(ECCurve.NamedCurves.nistP256);
var privateKey = ecdsa.ExportPkcs8PrivateKey();
var publicKey = ecdsa.ExportSubjectPublicKeyInfo();

var privateKeyBase64 = Convert.ToBase64String(privateKey);
var publicKeyBase64 = Convert.ToBase64String(publicKey);

Generate AES-256 Key

var aesKey = new byte[32];
RandomNumberGenerator.Fill(aesKey);
var aesKeyBase64 = Convert.ToBase64String(aesKey);

API Reference

ILighthouseClient

RegisterClusterAsync

Registers the cluster with the Lighthouse server.

Task<bool> RegisterClusterAsync(byte[] publicKey, CancellationToken cancellationToken = default)
DiscoverNodesAsync

Discovers other nodes in the cluster and registers the current node.

Task<List<NodeInfo>> DiscoverNodesAsync(
    NodeInfo currentNode,
    string versionName,
    long versionNumber,
    CancellationToken cancellationToken = default)

NodeInfo

Represents a node in the cluster:

public class NodeInfo
{
    public string IpAddress { get; set; }
    public int Port { get; set; }
    public Dictionary<string, string> Metadata { get; set; }
}

Resilience & Fault Tolerance

The client uses Microsoft.Extensions.Http.Resilience for handling transient failures with a standard resilience pipeline:

Retry Policy

  • 3 retries with exponential backoff (2s base delay)
  • Jitter enabled to prevent thundering herd
  • Handles transient HTTP errors (5xx, 408, network failures)
  • Automatic retry on timeout

Circuit Breaker

  • Opens at 50% failure ratio with minimum 5 requests
  • Stays open for 30 seconds
  • Sampling duration: 30 seconds
  • Prevents cascading failures
  • Automatic reset after break duration

Timeout

  • 10 seconds per attempt
  • Separate from overall HTTP client timeout

Logging

The client provides comprehensive structured logging:

services.AddLogging(builder =>
{
    builder.AddConsole();
    builder.SetMinimumLevel(LogLevel.Information);
});

Logged Events:

  • Client initialization
  • Cluster registration attempts (success/failure)
  • Node discovery operations
  • Decryption failures
  • HTTP errors and retries
  • Circuit breaker state changes

Log Levels:

  • Information: Successful operations, node counts
  • Warning: Failed decryptions, registration failures
  • Error: HTTP errors, unexpected exceptions
  • Debug: Individual node details, discovery start

Security

  • All node payloads are encrypted using AES-256-GCM
  • All requests are signed using ECDSA with P-256 curve
  • Nonce-based replay attack protection
  • Server never decrypts node payloads

License

MIT

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on NSerf.Lighthouse.Client:

Package Downloads
NSerf

A complete C# port of HashiCorp Serf for decentralized cluster membership, failure detection, and event dissemination. Includes ASP.NET Core integration, RPC client/server, and full SWIM-based gossip protocol implementation.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 441 11/12/2025

Initial release v1.0.0
     - Cluster registration with public key authentication
     - Node discovery with encrypted payloads (AES-256-GCM)
     - Digital signatures using ECDSA P-256
     - Built-in resilience with retry and circuit breaker policies
     - Dependency injection support
     - Comprehensive logging and telemetry