Visitar URL original
NovaNet.TestNet
nova-net-0.3.0.0: General-purpose reliable UDP with C99 hot path and Haskell protocol logic
Safe HaskellNone
LanguageHaskell2010

NovaNet.TestNet

Description

A simulated network that runs entirely in pure code (State monad). Supports configurable latency, loss, jitter, duplicates, and reordering. Multi-peer world simulation for integration tests.

No real sockets — two NetPeer states in the same process with manual packet routing between them.

Synopsis

Test network monad

data TestNet a Source #

Pure deterministic network monad.

Instances

Instances details
Applicative TestNet Source # 
Instance details

Defined in NovaNet.TestNet

Methods

pure :: a -> TestNet a #

(<*>) :: TestNet (a -> b) -> TestNet a -> TestNet b #

liftA2 :: (a -> b -> c) -> TestNet a -> TestNet b -> TestNet c #

(*>) :: TestNet a -> TestNet b -> TestNet b #

(<*) :: TestNet a -> TestNet b -> TestNet a #

Functor TestNet Source # 
Instance details

Defined in NovaNet.TestNet

Methods

fmap :: (a -> b) -> TestNet a -> TestNet b #

(<$) :: a -> TestNet b -> TestNet a #

Monad TestNet Source # 
Instance details

Defined in NovaNet.TestNet

Methods

(>>=) :: TestNet a -> (a -> TestNet b) -> TestNet b #

(>>) :: TestNet a -> TestNet b -> TestNet b #

return :: a -> TestNet a #

MonadNetwork TestNet Source # 
Instance details

Defined in NovaNet.TestNet

MonadTime TestNet Source # 
Instance details

Defined in NovaNet.TestNet

MonadState TestNetState TestNet Source # 
Instance details

Defined in NovaNet.TestNet

runTestNet :: TestNet a -> TestNetState -> (a, TestNetState) Source #

Run a test network computation.

State

data TestNetConfig Source #

Test network configuration.

Instances

Instances details
Show TestNetConfig Source # 
Instance details

Defined in NovaNet.TestNet

data TestNetState Source #

State of the test network for one peer.

Instances

Instances details
Show TestNetState Source # 
Instance details

Defined in NovaNet.TestNet

MonadState TestNetState TestNet Source # 
Instance details

Defined in NovaNet.TestNet

data InFlightPacket Source #

A packet in transit.

Instances

Instances details
Show InFlightPacket Source # 
Instance details

Defined in NovaNet.TestNet

initialTestNetState :: SockAddr -> TestNetState Source #

Create initial state for a peer.

defaultTestNetConfig :: TestNetConfig Source #

Default: no latency, no loss, no jitter.

Operations

advanceTime :: MonoTime -> TestNet () Source #

Advance time and deliver packets that are ready.

simulateLatency :: Word64 -> TestNet () Source #

Set simulated one-way latency (milliseconds).

simulateLoss :: Double -> TestNet () Source #

Set simulated packet loss rate (0.0 to 1.0).

getPendingPackets :: TestNet [InFlightPacket] Source #

Get all packets currently in flight.

Multi-peer world

data TestWorld Source #

A world containing multiple peers for integration testing.

Instances

Instances details
Show TestWorld Source # 
Instance details

Defined in NovaNet.TestNet

newTestWorld :: TestWorld Source #

Create a new empty test world.

runPeerInWorld :: SockAddr -> TestNet a -> TestWorld -> (a, TestWorld) Source #

Run a TestNet action for a specific peer. Auto-creates if missing.

deliverPackets :: TestWorld -> TestWorld Source #

Deliver all ready packets between peers.

worldAdvanceTime :: MonoTime -> TestWorld -> TestWorld Source #

Advance time for all peers and deliver ready packets.