summaryrefslogtreecommitdiff
path: root/src/detached
diff options
context:
space:
mode:
Diffstat (limited to 'src/detached')
-rw-r--r--src/detached/wire.zig29
1 files changed, 21 insertions, 8 deletions
diff --git a/src/detached/wire.zig b/src/detached/wire.zig
index 6090dedb..337211b7 100644
--- a/src/detached/wire.zig
+++ b/src/detached/wire.zig
@@ -9,6 +9,8 @@ const builtin = @import("builtin");
const pardes = @import("../pardes.zig");
const config = @import("pardes_config");
+/// 19: a client joining again names the view it had in its hello, and a
+/// bye says whether it joins again for it (views.away);
/// 18: a replica's input is stamped with its guess of the session's
/// clocks, the time its step reads (phase 6's instant interaction notes);
/// 17: a pointer's hit carries the place it was made on (Layer.Place) and
@@ -22,7 +24,7 @@ const config = @import("pardes_config");
/// part B); 14: the hello names a session and
/// carries the semantics hash, and a ping is answered (phase 5's
/// groundwork); 13: the frames went (phase 3).
-pub const version: u16 = 18;
+pub const version: u16 = 19;
/// The terminal's build and the window's step alike (`semantics`).
const family = switch (config.platform) {
@@ -134,12 +136,15 @@ pub const Hello = struct {
semantics: u64 = semantics,
/// Which session (its 9P name, as `--attach=` names it).
session: []const u8,
+ /// The view it had, joining again for it (a divergence's rejoin, an
+ /// Upgrade's): the daemon hands it on with the connection. 0xff: none.
+ view: ?u8 = null,
};
/// A session's name on the wire, as the daemon keeps it.
pub const max_name = 128;
/// The longest hello there is, header and all.
-pub const hello_max = header_len + 2 + 8 + 2 + max_name;
+pub const hello_max = header_len + 2 + 8 + 2 + max_name + 1;
/// Daemon or session -> client.
pub const ServerTag = enum(u8) {
@@ -268,7 +273,8 @@ pub fn helloVersion(payload: []const u8) Error!u16 {
/// one call and no longer.
pub const ClientMsg = union(enum) {
hello: Hello,
- bye,
+ /// The client's end: `again`, it joins again for its view at once.
+ bye: struct { again: bool = false },
/// A round trip's probe, answered `pong` with the same value.
ping: u64,
screen_ack: []const u8,
@@ -498,8 +504,9 @@ pub fn encodeClient(out: []u8, msg: ClientMsg) Error![]const u8 {
try w.writeInt(u64, h.semantics, .little);
if (h.session.len > max_name) return error.Overlong;
try putSlice16(&w, h.session);
+ try w.writeByte(h.view orelse 0xff);
},
- .bye => {},
+ .bye => |b| try w.writeByte(@intFromBool(b.again)),
.ping => |v| try w.writeInt(u64, v, .little),
.screen_ack, .want => |bytes| try w.writeAll(bytes),
.check => {},
@@ -573,8 +580,12 @@ pub fn decodeClient(tag: u8, payload: []const u8) Error!ClientMsg {
if (n > max_name) return error.BadValue;
break :blk try r.take(n);
},
+ .view = switch (try r.takeByte()) {
+ 0xff => null,
+ else => |k| k,
+ },
} },
- .bye => .bye,
+ .bye => .{ .bye = .{ .again = try getBool(&r) } },
.ping => .{ .ping = try r.takeInt(u64, .little) },
.screen_ack => return .{ .screen_ack = payload },
.check => .check,
@@ -693,7 +704,8 @@ test "detached wire: every Event variant round-trips" {
try testing.expectEqual(semantics, got.hello.semantics);
try testing.expectEqualStrings("work", got.hello.session);
}
- try testing.expectEqual(ClientMsg.bye, try roundClient(&buf, .bye));
+ try testing.expect((try roundClient(&buf, .{ .bye = .{ .again = true } })).bye.again);
+ try testing.expectEqual(@as(?u8, 2), (try roundClient(&buf, .{ .hello = .{ .session = "work", .view = 2 } })).hello.view);
try testing.expectEqual(@as(u64, 0xfeed_beef_0000_0001), (try roundClient(&buf, .{ .ping = 0xfeed_beef_0000_0001 })).ping);
{
// The other way: framed the same, its tag the ServerTag's number.
@@ -920,8 +932,9 @@ test "detached wire: values a field cannot mean are refused" {
std.mem.writeInt(u16, hello[10..12], max_name + 1, .little);
try testing.expectError(error.BadValue, decodeClient(@backingInt(ClientTag.hello), &hello));
std.mem.writeInt(u16, hello[10..12], max_name, .little);
- try testing.expectEqual(@as(usize, max_name), (try decodeClient(@backingInt(ClientTag.hello), hello[0 .. hello.len - 1])).hello.session.len);
- try testing.expect(header_len + hello.len - 1 == hello_max);
+ hello[hello.len - 1] = 0xff;
+ try testing.expectEqual(@as(usize, max_name), (try decodeClient(@backingInt(ClientTag.hello), &hello)).hello.session.len);
+ try testing.expect(header_len + hello.len == hello_max);
}
// A NaN scroll distance. `pinch` multiplies into a zoom the pane keeps.
{