RandomRoutingStrategy
Overview
The RandomRoutingStrategy
selects gateways randomly from the available pool. This strategy provides simple load distribution without maintaining state or performing complex calculations, making it ideal for scenarios where unpredictability is desired or where simplicity is paramount.
How It Works
- Receive Gateway List: Accept the list of available gateways
- Generate Random Index: Create a random number within the gateway list range
- Select Gateway: Choose the gateway at the random index
- Apply Filters: Optionally filter out unhealthy or blocked gateways
- Return Selection: Return the randomly selected gateway
Basic Usage
import { RandomRoutingStrategy } from '@ar.io/wayfinder-core'
const strategy = new RandomRoutingStrategy()
// randomly selects a gateway from the provided list
const selectedGateway = strategy.selectGateway({
gateways: ['https://arweave.net', 'https://permagate.io', 'https://ardrive.net']
})
Parameters
Parameter | Type | Default | Description |
---|---|---|---|
logger | Logger | defaultLogger | Optional logger instance |
Related
- FastestPingRoutingStrategy: Network-based gateway discovery
- PreferredWithFallbackRoutingStrategy: Static gateway configuration
- RandomRoutingStrategy: Randomized gateway selection