Skip to content

All your computers and your phone/iPhone, working as one desk. Screens, apps, files, clipboard, calls, texts, notifications, mouse and keyboard, shared between Mac, Windows, Linux , Android, Web and ios / ipados . Free and open source. No account, no cloud, and no shared network needed.

2.4 KB
Raw Blame
// TwinDesk — Copyright (C) 2026 inukaasith. GPL-3.0, see LICENSE.
// linux/discovery.js (#350): which address TwinDesk gives out first with Ethernet and Wi-Fi on
// separate networks (Overview, QR pairing, Wake), and General's Network for TwinDesk list.
// Run with: node shared/test/linux-iface-rank.js
'use strict';
const assert = require('assert');
const { rankAddresses, defaultIface, ifaceChoices } = require('../../linux/discovery');

// The reporter's laptop: a dedicated Ethernet link without a gateway, Wi-Fi with the default route.
const list = [
  { name: 'enp7s0', address: '192.168.77.1', netmask: '255.255.255.0' },
  { name: 'docker0', address: '172.17.0.1', netmask: '255.255.0.0' },
  { name: 'wlan0', address: '192.168.1.103', netmask: '255.255.255.0' },
];
const ROUTE = `Iface\tDestination\tGateway \tFlags\tRefCnt\tUse\tMetric\tMask\t\tMTU\tWindow\tIRTT
wlan0\t00000000\t0101A8C0\t0003\t0\t0\t100\t00000000\t0\t0\t0
wlan0\t0001A8C0\t00000000\t0001\t0\t0\t100\t00FFFFFF\t0\t0\t0
enp7s0\t004DA8C0\t00000000\t0001\t0\t0\t900\t00FFFFFF\t0\t0\t0
`;

// the default route, lowest metric first
assert.strictEqual(defaultIface(ROUTE), 'wlan0');
assert.strictEqual(defaultIface(ROUTE + 'enp7s0\t00000000\t01000000\t0003\t0\t0\t50\t00000000\t0\t0\t0\n'), 'enp7s0');
assert.strictEqual(defaultIface('Iface\tDestination\n'), '');
// automatic: the default route wins over a wired link with no gateway
assert.deepStrictEqual(rankAddresses(list, { def: defaultIface(ROUTE) }), ['192.168.1.103', '192.168.77.1', '172.17.0.1']);
// automatic without a default route: wired first, as before
assert.deepStrictEqual(rankAddresses(list, {}), ['192.168.77.1', '192.168.1.103', '172.17.0.1']);
// the connected device's network comes before the default route
assert.strictEqual(rankAddresses(list, { peer: '192.168.77.2', def: 'wlan0' })[0], '192.168.77.1');
// a picked interface comes first, even over the peer's network; the others stay
assert.deepStrictEqual(rankAddresses(list, { prefer: 'wlan0', peer: '192.168.77.2', def: 'enp7s0' }), ['192.168.1.103', '192.168.77.1', '172.17.0.1']);
// a picked interface that's gone changes nothing
assert.deepStrictEqual(rankAddresses(list, { prefer: 'wlp2s0', def: 'wlan0' }), ['192.168.1.103', '192.168.77.1', '172.17.0.1']);
// General's list: each interface once, with its kind
assert.deepStrictEqual(ifaceChoices(list).map((i) => `${i.name}:${i.kind}`), ['enp7s0:ethernet', 'docker0:virtual', 'wlan0:wifi']);
console.log('linux-iface-rank: ok');