22#ifndef PROTOCORE_SSH_FLOW_CONTROL_H
23#define PROTOCORE_SSH_FLOW_CONTROL_H
void pc_ssh_flow_init(SshFlow *f, uint32_t local_window, uint32_t peer_window, uint32_t peer_max_pkt)
Start a channel's windows: ours at local_window, the peer's at what it advertised.
void pc_ssh_flow_local_credit(SshFlow *f, uint32_t add)
Credit our window by add, once that WINDOW_ADJUST has actually been sent.
int32_t pc_ssh_sig_build_window_adjust(uint32_t peer_id, uint32_t add, uint8_t *out, size_t cap, size_t *out_len)
CHANNEL_WINDOW_ADJUST granting add more bytes. Credit the window only once this is sent.
bool pc_ssh_flow_recv_take(SshFlow *f, uint32_t n)
Account n inbound bytes against our window.
int32_t pc_ssh_sig_build_open_confirm(const SshFlow *f, uint32_t peer_id, uint32_t local_id, uint8_t *out, size_t cap, size_t *out_len)
CHANNEL_OPEN_CONFIRMATION, advertising our current window and maximum packet size.
int32_t pc_ssh_sig_build_open_failure(uint8_t *out, size_t cap, uint32_t peer_id, uint32_t reason, size_t *out_len)
CHANNEL_OPEN_FAILURE. reason: 1 admin-prohibited, 2 connect-failed, 3 unknown-type,...
uint32_t pc_ssh_flow_send_cap(const SshFlow *f, uint32_t want)
Clamp a would-be send to what the peer currently permits.
int32_t pc_ssh_sig_build_data(SshFlow *f, uint32_t peer_id, const uint8_t *data, size_t len, uint8_t *out, size_t cap, size_t *out_len)
CHANNEL_DATA carrying len bytes, and account them against the peer's window.
bool pc_ssh_flow_send_allows(const SshFlow *f, size_t len)
True if len bytes fit both the peer's remaining window and its maximum packet size.
void pc_ssh_flow_send_take(SshFlow *f, uint32_t n)
Account n outbound bytes against the peer's window (call only after send_allows()).
uint32_t pc_ssh_flow_peer_window(const SshFlow *f)
Bytes we may still send the peer - the bound a producer sizes its next read to.
void pc_ssh_flow_peer_add(SshFlow *f, uint32_t add)
Credit the peer's window from an inbound WINDOW_ADJUST.
bool pc_ssh_flow_replenish_due(const SshFlow *f, uint32_t *add)
Decide whether a WINDOW_ADJUST is due, and for how much. Does not mutate.
int32_t pc_ssh_sig_build_close(uint32_t peer_id, uint8_t *out, size_t cap, size_t *out_len)
CHANNEL_EOF followed by CHANNEL_CLOSE, as one 10-byte pair.
One channel's flow-control state (RFC 4254 sec 5.2).
uint32_t peer_max_pkt
Peer's maximum packet size; caps a single send independently of the window.
uint32_t local_max
The window we advertised, and replenish back up to.
uint32_t peer_window
Bytes we may still send the peer.
uint32_t local_window
Bytes the peer may still send us before we WINDOW_ADJUST.