Sign in

    moonbitstack/moonrpc/balance does not have a README file

    ConnectionPool

    pub struct ConnectionPool {
    order : Array[String]
    subconns : Map[String, SubConn]
    policy : LbPolicy
    cursor : Int
    }

    A pool of sub-connections, one per resolved address (in resolver order), that picks a READY one per an LbPolicy.

    ConnectionPool::new

    fn ConnectionPool::new(addresses : Array[String], policy? : LbPolicy) -> ConnectionPool

    A pool over addresses (each a host:port), each sub-connection starting IDLE, choosing among the READY ones with policy (default PickFirst).

    ConnectionPool::pick

    fn ConnectionPool::pick(self : ConnectionPool) -> String?

    Pick a READY sub-connection's address for the next call, applying the LB policy over just the ready ones (← gRPC picker). None when no sub-connection is ready.

    ConnectionPool::ready_addresses

    fn ConnectionPool::ready_addresses(self : ConnectionPool) -> Array[String]

    The addresses of every READY sub-connection, in resolver order.

    ConnectionPool::subconn

    fn ConnectionPool::subconn(self : ConnectionPool, address : String) -> SubConn?

    The sub-connection for address, if the pool has one — the handle the Channel drives.

    ConnectivityState

    pub(all) enum ConnectivityState {
    Idle
    Connecting
    Ready
    TransientFailure
    Shutdown
    } derive(Eq,
    Debug
    )

    A sub-connection's connectivity state (← gRPC connectivity.State).

    ConnectivityState::equal

    ConnectivityState::not_equal

    fn ConnectivityState::not_equal(x : ConnectivityState, y : ConnectivityState) -> Bool

    DnsRecord

    pub(all) struct DnsRecord {
    name : String
    rtype : Int
    ttl : Int
    address : String
    } derive(Eq,
    Debug
    )

    One answer resource record, carrying the textual address for A/AAAA records (empty for other types).

    DnsRecord::equal

    fn DnsRecord::equal(DnsRecord, DnsRecord) -> Bool

    DnsRecord::not_equal

    fn DnsRecord::not_equal(x : DnsRecord, y : DnsRecord) -> Bool

    DnsResponse

    pub(all) struct DnsResponse {
    id : Int
    rcode : Int
    answers : Array[DnsRecord]
    } derive(Eq,
    Debug
    )

    A decoded DNS response: the transaction id echoed back, the response code (0 = NOERROR), and the answer records.

    DnsResponse::addresses

    fn DnsResponse::addresses(self : DnsResponse) -> Array[String]

    Every resolved A/AAAA address in the response, in record order.

    DnsResponse::equal

    fn DnsResponse::equal(DnsResponse, DnsResponse) -> Bool

    DnsResponse::not_equal

    fn DnsResponse::not_equal(x : DnsResponse, y : DnsResponse) -> Bool

    HedgingPolicy

    pub(all) struct HedgingPolicy {
    max_attempts : Int
    hedging_delay_millis : Int
    non_fatal : Array[Int]
    }

    A method's hedging policy. max_attempts counts every parallel attempt (gRPC caps it at 5); a new attempt originates every hedging_delay_millis while attempts remain. A finished attempt commits the whole call unless its status is one of non_fatal, in which case hedging continues.

    HedgingPolicy::attempt_cap

    fn HedgingPolicy::attempt_cap(self : HedgingPolicy) -> Int

    The effective attempt cap: the configured max_attempts, but never above gRPC's ceiling of 5.

    HedgingPolicy::can_start_another

    fn HedgingPolicy::can_start_another(self : HedgingPolicy, attempts_started : Int) -> Bool

    Whether another hedged attempt may originate given attempts_started (the number already launched): only while attempts remain under the cap.

    HedgingPolicy::default

    fn HedgingPolicy::default() -> HedgingPolicy

    A conventional default: up to 3 parallel attempts, a fresh one every 500 ms, treating only UNAVAILABLE as non-fatal — so a transient transport failure keeps hedging while a real application error commits at once.

    HedgingPolicy::delay_millis

    fn HedgingPolicy::delay_millis(self : HedgingPolicy) -> Int

    The delay between originating hedged attempts. The async driver waits this long before launching the next parallel attempt; 0 fires them all at once.

    HedgingPolicy::should_commit

    fn HedgingPolicy::should_commit(self : HedgingPolicy, status_code : Int) -> Bool

    Whether a finished attempt with status_code commits the whole call — stopping hedging and returning this result. OK commits (success), and so does any error not listed as non-fatal (a real failure retrying won't fix). A non-fatal error does not commit; hedging continues.

    LbPolicy

    pub(all) enum LbPolicy {
    PickFirst
    RoundRobin
    } derive(Eq,
    Debug
    )

    A client-side load-balancing policy (← gRPC loadBalancingConfig).

    LbPolicy::equal

    fn LbPolicy::equal(LbPolicy, LbPolicy) -> Bool

    LbPolicy::not_equal

    fn LbPolicy::not_equal(x : LbPolicy, y : LbPolicy) -> Bool

    LbPolicy::to_repr

    LoadBalancer

    pub struct LoadBalancer {
    addresses : Array[String]
    policy : LbPolicy
    cursor : Int
    }

    A load balancer over a resolver's addresses, applying an LbPolicy to choose the next one.

    LoadBalancer::new

    fn LoadBalancer::new(addresses : Array[String], policy? : LbPolicy) -> LoadBalancer

    A balancer over addresses (each a host:port) using policy (default PickFirst).

    LoadBalancer::pick

    fn LoadBalancer::pick(self : LoadBalancer) -> String?

    The address the next call should use, or None when the resolver produced none. PickFirst always returns the first address; RoundRobin returns each in turn, wrapping around.

    LoadBalancer::size

    fn LoadBalancer::size(self : LoadBalancer) -> Int

    The number of addresses the balancer is choosing among.

    RetryPolicy

    pub(all) struct RetryPolicy {
    max_attempts : Int
    initial_backoff_millis : Int
    max_backoff_millis : Int
    backoff_multiplier : Double
    retryable : Array[Int]
    }

    A method's retry policy. max_attempts counts the first try plus every retry (gRPC caps it at 5); a call is retried only while attempts remain and its status is in retryable. Backoff starts at initial_backoff_millis and grows by backoff_multiplier each retry, capped at max_backoff_millis.

    RetryPolicy::backoff_millis

    fn RetryPolicy::backoff_millis(self : RetryPolicy, retry_index : Int) -> Int

    The backoff cap before the retry_index-th retry (the first retry is 1): min(initial * multiplier^(retry_index-1), max). gRPC sleeps a value drawn uniformly from [0, cap]; the async driver applies that jitter, so this returns the deterministic upper bound (which is also what a jitter-free driver sleeps).

    RetryPolicy::default

    fn RetryPolicy::default() -> RetryPolicy

    A conventional default: up to 3 attempts, 100 ms initial backoff doubling to a 1 s cap, retrying only UNAVAILABLE — the code a transient, safe-to-retry transport failure carries.

    RetryPolicy::should_retry

    fn RetryPolicy::should_retry(self : RetryPolicy, status_code : Int, attempts_made : Int) -> Bool

    Whether a call that has made attempts_made attempts (the first is 1) and got status_code should be tried again: attempts must remain, and the status must be non-OK and listed as retryable.

    SubConn

    pub struct SubConn {
    address : String
    state : ConnectivityState
    }

    One address the Channel dials, tracking its connectivity state.

    SubConn::connect

    fn SubConn::connect(self : SubConn) -> Unit

    Begin connecting (IDLE or TRANSIENT_FAILURE → CONNECTING). A no-op once SHUTDOWN or already connecting/ready.

    SubConn::is_ready

    fn SubConn::is_ready(self : SubConn) -> Bool

    Whether this sub-connection can carry RPCs right now.

    SubConn::new

    fn SubConn::new(address : String) -> SubConn

    A fresh sub-connection to address, starting IDLE.

    SubConn::on_connected

    fn SubConn::on_connected(self : SubConn) -> Unit

    The connection attempt succeeded (CONNECTING → READY).

    SubConn::on_failure

    fn SubConn::on_failure(self : SubConn) -> Unit

    A connection attempt or an established connection failed (→ TRANSIENT_FAILURE), unless shut down.

    SubConn::on_idle

    fn SubConn::on_idle(self : SubConn) -> Unit

    A READY connection went idle (READY → IDLE).

    SubConn::shutdown

    fn SubConn::shutdown(self : SubConn) -> Unit

    Shut the sub-connection down permanently (→ SHUTDOWN, a terminal state).

    dns_decode_response

    fn dns_decode_response(msg : Bytes) -> DnsResponse

    Decode a DNS response: echoed id, response code, and every answer record (A/AAAA records carry their textual address). Questions are skipped; authority and additional sections are ignored.

    dns_encode_query

    fn dns_encode_query(id : Int, name : String, qtype : Int) -> Bytes

    Encode a standard recursion-desired query for name of type qtype (dns_type_a or dns_type_aaaa) in class IN, with transaction id id.

    dns_type_a

    let dns_type_a : Int

    The DNS record type for an IPv4 address.

    dns_type_aaaa

    let dns_type_aaaa : Int

    The DNS record type for an IPv6 address.