Nebula
Orchestrator

OrchestratorHttpServer

The orchestrator's tiny web server: serves the dashboard page and a JSON state document, and forwards commands (POST) to the main thread.

generated from the sources
public sealed class OrchestratorHttpServer : IDisposable

The orchestrator's tiny web server: serves the dashboard page and a JSON state document, and forwards commands (POST) to the main thread. Runs on Mono's managed HttpListener, so it needs no URL ACLs and no external dependencies. Reads are answered from the listener thread with the last published state; writes are queued and executed by Pump from the orchestrator's Update, and the HTTP response waits for that.

Constructors

OrchestratorHttpServer

public OrchestratorHttpServer(string bind, ushort port, string page, string artifactDir = null);
ParameterDescription
bind"localhost" (default), "+" / "*" for every interface, or one address.
artifactDirDirectory served read-only under /build/ (the Linux server tarball worker VMs fetch); null disables.

Fields

MaxBodyBytes

public const long MaxBodyBytes = 8L * 1024 * 1024;

Largest request body accepted, in bytes (worker telemetry is the biggest thing posted).

Properties

Url

public string Url { get; }

Methods

QueryValue

public static string QueryValue(string query, string name);

One parameter of a query string, URL-decoded; "" when absent.

Start

public void Start();

PublishState

public void PublishState(string json);

Replace the state document served by GET /api/state. Call from the main thread whenever something changed.

AddPage

public void AddPage(string path, string html);

Serve html at path (/map). A trailing slash on the request is ignored.

MapDirect

public void MapDirect(string method, string path, Func<Request, Response> handler);

Answer method path on the listener thread instead of queueing it for the main thread (Pump). For endpoints that are hit often and touch nothing Unity owns, such as worker telemetry and the World map document; handler must be thread-safe.

MapDirectPrefix

public void MapDirectPrefix(string prefix, long maxBodyBytes, Func<Request, Response> handler);

Answer every request whose path starts with prefix + "/" on the listener thread, with the body as raw bytes (Request.BodyBytes) up to maxBodyBytes (larger is answered 413) instead of the general limit. For binary endpoints such as the shared cache; handler must be thread-safe and must not touch anything Unity owns.

Pump

public void Pump(Func<Request, Response> handler);

Main thread: execute queued commands. Each waiting HTTP response is released with the handler's result.

Dispose

public void Dispose();

TryGetInt

public static bool TryGetInt(string body, string key, out int value);

Reads an integer property from a flat JSON object body (the dashboard only ever sends {"key": value}).

GetString

public static string GetString(string body, string key);

Reads a string property from a flat JSON object body; "" when absent.

TryGetBool

public static bool TryGetBool(string body, string key, out bool value);

Reads a boolean property from a flat JSON object body; false (and false) when absent.

Nested types

Request

public sealed class Request

Provides the request API.

Fields

Method
public string Method;
Path
public string Path;
Body
public string Body;
Query
public string Query = "";

The query string without its leading '?' ("" when there is none).

Token
public string Token = "";

Value of the X-Nebula-Token header, or "" (the mesh token workers and gateways present).

BodyBytes
public byte[] BodyBytes;

The raw request body of a request answered by a prefix handler (MapDirectPrefix); null for every other request, whose Body is text.

Checksum
public string Checksum = "";

Value of the X-Nebula-Checksum header, or "" (the shared cache's integrity check).

Methods

GetQuery
public string GetQuery(string name);

One query parameter, URL-decoded; "" when absent.

Complete
public void Complete(Response response);

Answer a request whose handler returned Response.Pending. Main thread, any later tick.

Response

public struct Response

Stores the values used by response.

Fields

Status
public int Status;
ContentType
public string ContentType;
Body
public string Body;
Bytes
public byte[] Bytes;

When set, sent as the response body instead of Body.

Checksum
public string Checksum;

Sent as the X-Nebula-Checksum header when set.

Properties

Pending
public static Response Pending { get; }

Returned by a pumped handler that answers later through Request.Complete (a store lookup that lands on the next tick).

IsPending
public bool IsPending { get; }

Methods

Binary
public static Response Binary(int status, byte[] bytes, string checksum);

A binary response (application/octet-stream) carrying checksum in X-Nebula-Checksum.

Json
public static Response Json(int status, string body);
Error
public static Response Error(int status, string message);

On this page