-
Notifications
You must be signed in to change notification settings - Fork 11
/
constants.js
99 lines (80 loc) · 3.3 KB
/
constants.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
'use strict'
const hypercoreid = require('hypercore-id-encoding')
const { platform, arch, isWindows, isLinux } = require('which-runtime')
const { pathToFileURL, fileURLToPath } = require('url-file-url')
const sodium = require('sodium-native')
const b4a = require('b4a')
const CHECKOUT = require('./checkout')
const { ERR_COULD_NOT_INFER_MODULE_PATH } = require('./errors')
const BIN = 'by-arch/' + platform + '-' + arch + '/bin/'
let url = module.url || electronModuleURL()
if (url.protocol === 'pear:' && url.host === 'dev') {
url = global.Pear.config.applink
if (url.slice(-1) !== '/') url += '/'
}
const mount = new URL('.', url)
const LOCALDEV = CHECKOUT.length === null
const swapURL = mount.pathname.endsWith('.bundle/') ? new URL('..', mount) : mount
const swapPath = toPath(swapURL)
const IPC_ID = 'pear'
const PLATFORM_URL = LOCALDEV ? new URL('pear/', swapURL) : new URL('../../../', swapURL)
const PLATFORM_DIR = toPath(PLATFORM_URL)
const PLATFORM_LOCK = toPath(new URL('corestores/platform/primary-key', PLATFORM_URL))
const DESKTOP_EXEC = isWindows
? 'pear-runtime-app/Pear Runtime.exe'
: isLinux
? 'pear-runtime-app/pear-runtime'
: 'Pear Runtime.app/Contents/MacOS/Pear Runtime'
const RUNTIME_EXEC = isWindows
? 'pear-runtime.exe'
: 'pear-runtime'
const WAKEUP_EXEC = isWindows
? 'pear.exe'
: isLinux
? 'pear'
: 'Pear.app/Contents/MacOS/Pear'
const ALIASES = {
keet: hypercoreid.decode('oeeoz3w6fjjt7bym3ndpa6hhicm8f8naxyk11z4iypeoupn6jzpo'),
runtime: hypercoreid.decode('nkw138nybdx6mtf98z497czxogzwje5yzu585c66ofba854gw3ro'),
doctor: hypercoreid.decode('3ih5k1t15xb9hrnz1mkd4jhamefis7ni4nwuus8f1w3j94yu831y')
}
const EOLS = {
keet: hypercoreid.decode('jc38t9nr7fasay4nqfxwfaawywfd3y14krnsitj67ymoubiezqdy')
}
exports.LOCALDEV = LOCALDEV
exports.CHECKOUT = CHECKOUT
exports.ALIASES = ALIASES
exports.EOLS = EOLS
exports.SWAP = swapPath
exports.PLATFORM_DIR = PLATFORM_DIR
exports.PLATFORM_LOCK = PLATFORM_LOCK
exports.GC = toPath(new URL('gc', PLATFORM_URL))
exports.PLATFORM_CORESTORE = toPath(new URL('corestores/platform', PLATFORM_URL))
exports.UPGRADE_LOCK = toPath(new URL('lock', PLATFORM_URL))
exports.APPLINGS_PATH = toPath(new URL('applings', PLATFORM_URL))
exports.MOUNT = mount.href.slice(0, -1)
exports.SOCKET_PATH = isWindows ? `\\\\.\\pipe\\${IPC_ID}-${pipeId(PLATFORM_DIR)}` : `${PLATFORM_DIR}/${IPC_ID}.sock`
exports.BOOT = require.main?.filename
exports.CONNECT_TIMEOUT = 20_000
exports.IDLE_TIMEOUT = 30_000
exports.SPINDOWN_TIMEOUT = 60_000
exports.WAKEUP = toPath(new URL(BIN + WAKEUP_EXEC, swapURL))
exports.RUNTIME = toPath(new URL(BIN + RUNTIME_EXEC, swapURL))
exports.DESKTOP_RUNTIME = toPath(new URL(BIN + DESKTOP_EXEC, swapURL))
exports.BARE_RESTART_EXIT_CODE = 75
exports.SALT = b4a.from('d134aa8b0631f1193b5031b356d82dbea214389208fa4a0bcdf5c2e062d8ced2', 'hex')
exports.KNOWN_NODES_LIMIT = 100
function electronModuleURL () {
const u = pathToFileURL(process.execPath)
const i = u.href.lastIndexOf(BIN)
if (i === -1) throw ERR_COULD_NOT_INFER_MODULE_PATH('Could not infer the actual module path')
return new URL(u.href.slice(0, i) + 'constants.js')
}
function toPath (u) {
return fileURLToPath(u).replace(/[/\\]$/, '') || '/'
}
function pipeId (s) {
const buf = b4a.allocUnsafe(32)
sodium.crypto_generichash(buf, b4a.from(s))
return b4a.toString(buf, 'hex')
}