This repository has been archived by the owner on Dec 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use (mostly numeric) vatID/deviceID everywhere within kernel
.. as the index for kernel state data structures, instead of user-provided vatName/deviceName strings. This will make it easier to use key/value state storage (#144), since the keys will be more uniform (and shorter, and not vulnerable to people using the separator string in their vat name). They look like "vNN" and "dNN", where NN is a positive integer. This will also make adding dynamic Vats easier (#19), as we'll just increment a counter instead of asking the user to invent a unique name. closes #146
- Loading branch information
Showing
10 changed files
with
587 additions
and
394 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import harden from '@agoric/harden'; | ||
import Nat from '@agoric/nat'; | ||
|
||
// Vats are identified by an integer index, which (for typechecking purposes) | ||
// is encoded as `vNN`. Devices are similarly identified as `dNN`. Both have | ||
// human-readable names, which are provided to controller.addGenesisVat(), | ||
// and usually come from the `vat-NAME.js` filenames processed in | ||
// loadBasedir(). These names also appear in the `vats` and `devices` | ||
// arguments to the bootstrap Vat's `bootstrap()` function, and in debug | ||
// messages. | ||
|
||
export function insistVatID(s) { | ||
try { | ||
if (s !== `${s}`) { | ||
throw new Error(`not a string`); | ||
} | ||
s = `${s}`; | ||
if (!s.startsWith(`v`)) { | ||
throw new Error(`does not start with 'v'`); | ||
} | ||
Nat(Number(s.slice(1))); | ||
} catch (e) { | ||
throw new Error(`'${s} is not a 'vNN'-style VatID: ${e.message}`); | ||
} | ||
} | ||
|
||
export function makeVatID(index) { | ||
return `v${Nat(index)}`; | ||
} | ||
|
||
export function insistDeviceID(s) { | ||
try { | ||
if (s !== `${s}`) { | ||
throw new Error(`not a string`); | ||
} | ||
s = `${s}`; | ||
if (!s.startsWith(`d`)) { | ||
throw new Error(`does not start with 'd'`); | ||
} | ||
Nat(Number(s.slice(1))); | ||
} catch (e) { | ||
throw new Error(`'${s} is not a 'dNN'-style DeviceID: ${e.message}`); | ||
} | ||
} | ||
|
||
export function makeDeviceID(index) { | ||
return `d${Nat(index)}`; | ||
} | ||
|
||
export function parseVatOrDeviceID(s) { | ||
if (s !== `${s}`) { | ||
throw new Error(`${s} is not a string, so cannot be a VatID/DevieID`); | ||
} | ||
s = `${s}`; | ||
let type; | ||
let idSuffix; | ||
if (s.startsWith('v')) { | ||
type = 'vat'; | ||
idSuffix = s.slice(1); | ||
} else if (s.startsWith('v')) { | ||
type = 'device'; | ||
idSuffix = s.slice(1); | ||
} else { | ||
throw new Error(`'${s}' is neither a VatID nor a DeviceID`); | ||
} | ||
return harden({ type, id: Nat(Number(idSuffix)) }); | ||
} |
Oops, something went wrong.