~sircmpwn/hare-ssh

06cf8df1545b8503cf028492675ba0fe3cf41aa3 — Drew DeVault a month ago 5daf8fb
net::ssh: decode packets without EAGAIN round-trip
1 files changed, 7 insertions(+), 4 deletions(-)

M net/ssh/client.ha
M net/ssh/client.ha => net/ssh/client.ha +7 -4
@@ 149,13 149,13 @@ export fn client_read(client: *client) (packet | io::EOF | error) = {
	if (len(client.rbuf) >= MAX_PACKETSIZE) {
		return protoerror;
	};
	// TODO: We could try to decode the packet right here if we already have
	// enough
	return errors::again;
	return client_decode(client);
};

fn client_decode(client: *client) (packet | error) = {
	assert(len(client.rbuf) >= 5);
	if (len(client.rbuf) < 5) {
		return errors::again;
	};
	const pktlen = endian::begetu32(client.rbuf[..4]);
	const padlen = client.rbuf[4];
	const maclen = match (client.mac) {


@@ 165,6 165,9 @@ fn client_decode(client: *client) (packet | error) = {
		yield mac_digestsz(mac);
	};
	const msglen = pktlen + maclen + 4;
	if (len(client.rbuf) < msglen) {
		return errors::again;
	};

	// TODO: Verify MAC
	const reader = bufio::fixed(client.rbuf[5..pktlen-6], io::mode::READ);