NetworkSimulation
Network conditions to simulate on one link, for testing prediction and lag compensation on one machine.
Nebula · Packages/com.1by3.nebula/Runtime/Transport/SimulatedNetworkTransport.cspublic sealed class NetworkSimulationNetwork conditions to simulate on one link, for testing prediction and lag compensation on one machine. LatencyMs is the added round trip: half of it delays each packet the link sends and the other half delays each packet it receives. All values are clamped to a sensible range on use.
Constructors
NetworkSimulation
public NetworkSimulation();
public NetworkSimulation(float latencyMs, float jitterMs, float lossPercent);A simulation of latencyMs of added round trip, jitterMs of jitter and lossPercent of loss.
Fields
MaxMs
public const float MaxMs = 5000f;The most latency, jitter or loss the simulation accepts: 5 seconds, or 100 percent.
Properties
LatencyMs
public float LatencyMs { get; }Added round-trip time in milliseconds: LatencyMs / 2 in each direction. 0 adds none.
JitterMs
public float JitterMs { get; }Jitter in milliseconds: each packet's delay in each direction varies by a random amount between -JitterMs / 2 and +JitterMs / 2 around its half of LatencyMs, never below zero. A packet sent after another can therefore arrive first; a Delivery.Sequenced packet that is overtaken is dropped, as a real sequenced link does, and reliable packets stay in order.
LossPercent
public float LossPercent { get; }Percent of packets lost in each direction, 0 to 100. A lost Delivery.Sequenced packet never arrives. A lost reliable packet arrives one extra round trip late, as a retransmission would, and holds up the reliable packets behind it.
Active
public bool Active { get; }Whether any of the three values would change the link.
IsAvailable
public static bool IsAvailable { get; }Whether this build may simulate network conditions: the Editor and development builds can; release builds cannot.
Methods
Set
public void Set(float latencyMs, float jitterMs, float lossPercent);Sets all three values. Negative and non-numeric values count as 0; latency and jitter are capped at MaxMs and loss at 100. The change applies to packets sent or received from now on.
ToString
public override string ToString();A short description for logs and overlays, for example 100 ms round trip, 20 ms jitter, 2% loss; off when inactive.
NebulaCrypto
Provides random bytes, SHA-256 hashes, hash-based message authentication codes (HMAC), and key derivation for encrypted transport connections.
SimulatedNetworkTransport
An ITransport that adds the latency, jitter and packet loss of a NetworkSimulation to every link of another transport, in both directions, without touching the remote side.