╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ serve_ssh_protocol.zig ───────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1974 const recipient_channel = try r.takeInt(u32, .big); 1975 if (recipient_channel != expected_channel) return error.UnknownChannel; 1976 if (extended) { 1977 const data_type = try r.takeInt(u32, .big); 1978 if (data_type != SSH_EXTENDED_DATA_STDERR) return error.UnsupportedExtendedData; 1979 } 1980 const data_len = try r.takeInt(u32, .big); 1981 // catches both data_len > remaining (would otherwise be a bounds-check 1982 // panic on the slice) and trailing junk after the declared payload. 1983 if (data_len != r.buffered().len) return error.InvalidChannelData; 1984 return r.buffered(); 1985 } 1986 1987 fn parseChannelId(packet: []const u8, expected_channel: u32) !void { 1988 if (packet.len < 1) return error.EmptyPacket; 1989 var r = std.Io.Reader.fixed(packet[1..]); 1990 const recipient_channel = try r.takeInt(u32, .big); 1991 if (recipient_channel != expected_channel) return error.UnknownChannel; 1992 if (r.buffered().len != 0) return error.InvalidChannelMessage; 1993 } 1994 1995 /// send a CHANNEL_WINDOW_ADJUST if our receive window has dipped below half 1996 /// of `budget`, the credit we're willing to have outstanding. used both for 1997 /// the pre-session discard path and by SessionCtx after it consumes a 1998 /// CHANNEL_DATA payload. 1999 fn maybeRefillRecvWindow(conn: *Conn, ch: *Channel, budget: u32) !void { 2000 if (ch.local_window >= budget / 2) return; 2001 const add = budget - ch.local_window; 2002 ch.local_window += add; 2003 var adj: std.ArrayList(u8) = .empty; 2004 defer adj.deinit(conn.allocator); 2005 try adj.append(conn.allocator, SSH_MSG_CHANNEL_WINDOW_ADJUST); 2006 try writeU32(&adj, conn.allocator, ch.remote_id); 2007 try writeU32(&adj, conn.allocator, add); 2008 try conn.sc_cipher.writePacket(conn.io, conn.writer, adj.items); 2009 } 2010 2011 pub fn writeU32(buf: *std.ArrayList(u8), allocator: std.mem.Allocator, value: u32) !void { 2012 var bytes: [4]u8 = undefined; 2013 std.mem.writeInt(u32, &bytes, value, .big); 2014 try buf.appendSlice(allocator, &bytes); 2015 } 2016