-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(daemon): Move mail delivery to agent public facets (#2186)
Toward delivering mail over the network, this change introduces a `deliver` method on guest and host agents that accepts arbitrary messages into the agent’s inbox. Any other agent can send mail to any other local agent for whom they have a handle and cannot spoof their sender handle. This is a net simplification, since it reduces our dependence on the internal facet of agents and requires less machinery because it treats messages as capabilities on the wire, freely exposing and carrying identifiers. We no longer have separate internal and external representations of messages and pet name “dubbing” is deferred to the UI. This in turn enables us to defer to the UI the question of whether to query the name for each identifier once or watch for changes. Stacked on #2184
- Loading branch information
Showing
10 changed files
with
366 additions
and
412 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 |
---|---|---|
@@ -1,41 +1,73 @@ | ||
/* global process */ | ||
/* eslint-disable no-continue */ | ||
|
||
import os from 'os'; | ||
import { E } from '@endo/far'; | ||
import { makeRefIterator } from '@endo/daemon'; | ||
import { withEndoAgent } from '../context.js'; | ||
import { formatMessage } from '../message-format.js'; | ||
|
||
const { stringify: q } = JSON; | ||
|
||
export const inbox = async ({ follow, agentNames }) => | ||
withEndoAgent(agentNames, { os, process }, async ({ agent }) => { | ||
const selfId = await E(agent).identify('SELF'); | ||
const messages = follow | ||
? makeRefIterator(E(agent).followMessages()) | ||
: await E(agent).listMessages(); | ||
for await (const message of messages) { | ||
const { number, who, when } = message; | ||
const { number, type, from, to, date } = message; | ||
|
||
let verb = ''; | ||
if (type === 'request') { | ||
verb = 'requested'; | ||
} else if (type === 'package') { | ||
verb = 'sent'; | ||
} else { | ||
verb = 'sent an unrecognizable message'; | ||
} | ||
|
||
let provenance = 'unrecognizable message'; | ||
if (from === selfId && to === selfId) { | ||
provenance = `you ${verb} yourself `; | ||
} else if (from === selfId) { | ||
const [toName] = await E(agent).reverseIdentify(to); | ||
if (toName === undefined) { | ||
continue; | ||
} | ||
provenance = `${verb} ${q(toName)} `; | ||
} else if (to === selfId) { | ||
const [fromName] = await E(agent).reverseIdentify(from); | ||
if (fromName === undefined) { | ||
continue; | ||
} | ||
provenance = `${q(fromName)} ${verb} `; | ||
} else { | ||
const [toName] = await E(agent).reverseIdentify(to); | ||
const [fromName] = await E(agent).reverseIdentify(from); | ||
if (fromName === undefined || toName === undefined) { | ||
continue; | ||
} | ||
provenance = `${q(fromName)} ${verb} ${q(toName)} `; | ||
} | ||
|
||
if (message.type === 'request') { | ||
const { what } = message; | ||
const { description } = message; | ||
console.log( | ||
`${number}. ${JSON.stringify(who)} requested ${JSON.stringify( | ||
what, | ||
)} at ${JSON.stringify(when)}`, | ||
`${number}. ${provenance}${JSON.stringify( | ||
description, | ||
)} at ${JSON.stringify(date)}`, | ||
); | ||
} else if (message.type === 'package') { | ||
const { strings, names: edgeNames } = message; | ||
console.log( | ||
`${number}. ${JSON.stringify(who)} sent ${formatMessage( | ||
`${number}. ${provenance}${formatMessage( | ||
strings, | ||
edgeNames, | ||
)} at ${JSON.stringify(when)}`, | ||
)} at ${JSON.stringify(date)}`, | ||
); | ||
} else { | ||
console.log( | ||
`${number}. ${JSON.stringify( | ||
who, | ||
)} sent an unrecognizable message at ${JSON.stringify( | ||
when, | ||
)}. Consider upgrading.`, | ||
); | ||
console.log(`${number}. ${provenance}, consider upgrading.`); | ||
} | ||
} | ||
}); |
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
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
Oops, something went wrong.