clavarium 0.2.381-next.1 → 0.2.382-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/deploy/online.mjs CHANGED
@@ -58,6 +58,7 @@ import { doctor, servedCert, DOCTOR_PATHS } from './doctor.mjs';
58
58
  export const PATHS = {
59
59
  access: '/var/lib/clavarium-relay-access',
60
60
  tunnel: '/var/lib/clavarium-tunnel',
61
+ tunnelUnit: TUNNEL_UNIT,
61
62
  relayConf: '/etc/clavarium/relay.conf',
62
63
  updateConf: '/etc/clavarium/update.conf',
63
64
  unit: '/etc/systemd/system/clavarium.service',
@@ -207,6 +208,15 @@ export function readRelayConf(P = PATHS) {
207
208
  try { for (const line of readFileSync(P.relayConf, 'utf8').split('\n')) { const m = /^([A-Z_]+)=(.*)$/.exec(line.trim()); if (m) conf[m[1]] = m[2]; } } catch { return null; }
208
209
  return conf.HOST ? conf : null;
209
210
  }
211
+ /* The relay of a machine put online before relay.conf existed (07-11, found on a test machine): only
212
+ its tunnel unit says it. Read there, as the updater does (tunnel.mjs, relayOfUnit); never written back. */
213
+ export function relayOf(P = PATHS) {
214
+ const conf = readRelayConf(P);
215
+ if (conf) return conf;
216
+ let unit = null;
217
+ try { unit = relayOfUnit(readFileSync(P.tunnelUnit ?? TUNNEL_UNIT, 'utf8')); } catch { return null; }
218
+ return unit ? { HOST: unit.relay, PORT: unit.port } : null;
219
+ }
210
220
  function writeRelayConf(P, conf) {
211
221
  mkdirSync(join(P.relayConf, '..'), { recursive: true });
212
222
  writeFileSync(`${P.relayConf}.new`, `# The relay of this Clavarium. Written by clavarium online.\n${Object.entries(conf).map(([k, v]) => `${k}=${v}`).join('\n')}\n`, { mode: 0o644 });
@@ -662,7 +672,7 @@ function writeInvites(P, v) {
662
672
  }
663
673
  /* Only the principal adds homes: the machine that holds the relay's maintenance key, online. */
664
674
  function principal(P) {
665
- const conf = readRelayConf(P);
675
+ const conf = relayOf(P);
666
676
  if (!conf) throw new Refused('this machine has no relay (sudo clavarium online --relay HOST --domain NAME)');
667
677
  if (conf.ROLE === 'home') throw new Refused(`this machine is a home of the relay ${conf.HOST}: only its principal${conf.PRINCIPAL ? ` (${conf.PRINCIPAL})` : ''} adds or removes homes`);
668
678
  const domain = serverModeOf(P);
@@ -729,7 +739,7 @@ export async function joinWithCode(sys, P, given, key) {
729
739
 
730
740
  /* `sudo clavarium relay VERB` */
731
741
  export async function relayCommand(args, sys, P = PATHS) {
732
- const conf = readRelayConf(P);
742
+ const conf = relayOf(P);
733
743
  if (!conf) throw new Refused('this machine has no relay (sudo clavarium online --relay HOST --domain NAME)');
734
744
  const [verb, ...rest] = args;
735
745
  if (conf.ROLE === 'home') throw new Refused(`this machine is a home of the relay ${conf.HOST}: the relay is kept by its principal${conf.PRINCIPAL ? `, ${conf.PRINCIPAL}` : ''}`);
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.381-next.1",
3
+ "version": "0.2.382-next.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.381-next.1",
9
+ "version": "0.2.382-next.1",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@xterm/addon-fit": "^0.11.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.381-next.1",
3
+ "version": "0.2.382-next.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "A conversation is a VM with a terminal in it. Everything else is a folder.",