feat(server): the relay joins modems of different projects by a code (K3)
A modem that offers a connection to another project is found by six characters derived from its project and itself (modemCode): a copy of the project has another code, so no two modems offer the same one. The room names its modems of other projects to F's relay at a start and none at a stop; the relay pairs each offer with the first modem that joins its code, one to one as Java's server modem takes one client, and passes the frames between the rooms' threads. Every client hears how each modem stands (`modems`: connected, waiting, taken, unpaired, ambiguous, detached, or unavailable without F). The document keeps the connection and the code. Measured on F with two threads: a ping from one project's notebook to the other's goes through; a third project that wants the same code reads taken, and takes it when the second stops; a deleted project's modem leaves with its room. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -18,12 +18,15 @@ import {
|
||||
connect,
|
||||
createUndoManager,
|
||||
deviceSheet,
|
||||
docSnapshot,
|
||||
readProject,
|
||||
renameDevice,
|
||||
ROOTS,
|
||||
setDhcpClient,
|
||||
setHostAddress,
|
||||
setHostLabels,
|
||||
setModemCode,
|
||||
setModemConnection,
|
||||
setHostWireless,
|
||||
setIpForwarding,
|
||||
setModemPort,
|
||||
@@ -498,7 +501,7 @@ describe("a switch's and a modem's sheet", () => {
|
||||
it('pairs a modem by its port, and renames a router', () => {
|
||||
const doc = new Y.Doc();
|
||||
const modem = add(doc, 'remoteLink', 'Modem');
|
||||
expect(deviceSheet(doc, modem)).toEqual({ kind: 'remoteLink', name: 'Modem', port: 12_345 });
|
||||
expect(deviceSheet(doc, modem)).toEqual({ kind: 'remoteLink', name: 'Modem', port: 12_345, connection: 'inProject', code: '' });
|
||||
expect(setModemPort(doc, modem, '65536', 'me')).toEqual({ invalid: true });
|
||||
expect(setModemPort(doc, modem, ' 80', 'me')).toEqual({ value: '80' });
|
||||
expect(readProject(doc).remoteLinkConfigurations.get(modem)).toEqual({ pairIdentifier: 'java-modem-port-80', latencyMilliseconds: 20, isEnabled: true });
|
||||
@@ -510,6 +513,44 @@ describe("a switch's and a modem's sheet", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("a modem's connection to another project", () => {
|
||||
it('offers a code, joins one as typed, and goes back to the pair on its port', () => {
|
||||
const doc = new Y.Doc();
|
||||
const modem = add(doc, 'remoteLink', 'Modem');
|
||||
setModemConnection(doc, modem, 'offer', 'me');
|
||||
expect(deviceSheet(doc, modem)).toMatchObject({ connection: 'offer', code: '' });
|
||||
expect(readProject(doc).remoteLinkConfigurations.get(modem)).toMatchObject({ relay: { role: 'offer' } });
|
||||
expect(docSnapshot(doc).remoteLinkConfigurationsByNodeId.get(modem)).toMatchObject({ relay: { role: 'offer' } });
|
||||
setModemConnection(doc, modem, 'join', 'me');
|
||||
expect(deviceSheet(doc, modem)).toMatchObject({ connection: 'join', code: '' });
|
||||
expect(setModemCode(doc, modem, 'k7f-3qx', 'me')).toEqual({ value: 'K7F3QX' });
|
||||
expect(deviceSheet(doc, modem)).toMatchObject({ connection: 'join', code: 'K7F3QX' });
|
||||
expect(docSnapshot(doc).remoteLinkConfigurationsByNodeId.get(modem)).toMatchObject({ relay: { role: 'join', code: 'K7F3QX' } });
|
||||
// Misread characters (0, O, 1, I) and a wrong length are no code; the code stays.
|
||||
for (const text of ['K7F3Q0', 'K7F3QI', 'K7F3Q', 'K7F3QXY']) expect(setModemCode(doc, modem, text, 'me')).toEqual({ invalid: true });
|
||||
expect(deviceSheet(doc, modem)).toMatchObject({ code: 'K7F3QX' });
|
||||
setModemConnection(doc, modem, 'inProject', 'me');
|
||||
expect(deviceSheet(doc, modem)).toMatchObject({ connection: 'inProject', code: '', port: 12_345 });
|
||||
expect(readProject(doc).remoteLinkConfigurations.get(modem)).not.toHaveProperty('relay');
|
||||
});
|
||||
|
||||
it('is each one step of the undo, and touches nothing but a modem', () => {
|
||||
const doc = new Y.Doc();
|
||||
const modem = add(doc, 'remoteLink', 'Modem');
|
||||
const notebook = add(doc, 'notebook');
|
||||
const undo = createUndoManager(doc, 'me');
|
||||
setModemConnection(doc, modem, 'join', 'me');
|
||||
undo.stopCapturing();
|
||||
setModemCode(doc, modem, 'ABCDEF', 'me');
|
||||
undo.undo();
|
||||
expect(deviceSheet(doc, modem)).toMatchObject({ connection: 'join', code: '' });
|
||||
undo.undo();
|
||||
expect(deviceSheet(doc, modem)).toMatchObject({ connection: 'inProject' });
|
||||
setModemConnection(doc, notebook, 'offer', 'me');
|
||||
expect((doc.getMap<Y.Map<unknown>>(ROOTS.nodes).get(notebook)!.get('settings') as Y.Map<unknown>).has('remoteLink')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("the sheet's changes", () => {
|
||||
it('are each one step of the person’s undo, the wireless join with its connection', () => {
|
||||
const doc = new Y.Doc();
|
||||
|
||||
Reference in New Issue
Block a user