New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@agoric/network

Package Overview
Dependencies
Maintainers
0
Versions
1072
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@agoric/network - npm Package Compare versions

Comparing version

to
0.1.1-dev-bfca51a.0

40

package.json
{
"name": "@agoric/network",
"version": "0.1.1-dev-bfa47d1.0+bfa47d1",
"version": "0.1.1-dev-bfca51a.0+bfca51a",
"description": "Agoric's network protocol API",

@@ -11,5 +11,5 @@ "type": "module",

"prepack": "tsc --build tsconfig.build.json",
"postpack": "git clean -f '*.d.ts*'",
"postpack": "git clean -f '*.d.ts*' '*.tsbuildinfo'",
"test": "ava",
"test:c8": "c8 $C8_OPTIONS ava",
"test:c8": "c8 --all $C8_OPTIONS ava",
"test:xs": "exit 0",

@@ -25,20 +25,20 @@ "lint-fix": "yarn lint:eslint --fix",

"dependencies": {
"@agoric/internal": "0.3.3-dev-bfa47d1.0+bfa47d1",
"@agoric/store": "0.9.3-dev-bfa47d1.0+bfa47d1",
"@agoric/vat-data": "0.5.3-dev-bfa47d1.0+bfa47d1",
"@endo/base64": "^1.0.5",
"@endo/errors": "^1.2.2",
"@endo/far": "^1.1.2",
"@endo/pass-style": "^1.4.0",
"@endo/patterns": "^1.4.0",
"@endo/promise-kit": "^1.1.2"
"@agoric/internal": "0.3.3-dev-bfca51a.0+bfca51a",
"@agoric/store": "0.9.3-dev-bfca51a.0+bfca51a",
"@agoric/vat-data": "0.5.3-dev-bfca51a.0+bfca51a",
"@endo/base64": "^1.0.9",
"@endo/errors": "^1.2.8",
"@endo/far": "^1.1.9",
"@endo/pass-style": "^1.4.7",
"@endo/patterns": "^1.4.7",
"@endo/promise-kit": "^1.1.8"
},
"devDependencies": {
"@agoric/swingset-liveslots": "0.10.3-dev-bfa47d1.0+bfa47d1",
"@agoric/swingset-vat": "0.32.3-dev-bfa47d1.0+bfa47d1",
"@agoric/vow": "0.1.1-dev-bfa47d1.0+bfa47d1",
"@agoric/zone": "0.2.3-dev-bfa47d1.0+bfa47d1",
"@endo/bundle-source": "^3.2.3",
"@agoric/swingset-liveslots": "0.10.3-dev-bfca51a.0+bfca51a",
"@agoric/swingset-vat": "0.32.3-dev-bfca51a.0+bfca51a",
"@agoric/vow": "0.1.1-dev-bfca51a.0+bfca51a",
"@agoric/zone": "0.2.3-dev-bfca51a.0+bfca51a",
"@endo/bundle-source": "^3.5.0",
"ava": "^5.3.0",
"c8": "^9.1.0"
"c8": "^10.1.2"
},

@@ -71,5 +71,5 @@ "exports": {

"typeCoverage": {
"atLeast": 89.7
"atLeast": 91.16
},
"gitHead": "bfa47d1ff808f5b752544a2b3c70a11aa8e7ddfc"
"gitHead": "bfca51a6114a29205a8ec05f793edee1249f8953"
}

@@ -12,14 +12,5 @@ /**

* @param {import('@agoric/base-zone').Zone} zone
* @param {ReturnType<import('@agoric/vow').prepareVowTools>} powers
* @param {VowTools} powers
*/
export function prepareLoopbackProtocolHandler(zone: import("@agoric/base-zone").Zone, { watch, allVows }: ReturnType<(zone: import("@agoric/base-zone").Zone, powers?: {
isRetryableReason?: import("@agoric/vow").IsRetryableReason | undefined;
} | undefined) => {
when: <T, TResult1 = import("@agoric/vow").EUnwrap<T>, TResult2 = never>(specimenP: T, onFulfilled?: ((value: import("@agoric/vow").EUnwrap<T>) => TResult1 | PromiseLike<TResult1>) | undefined, onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined) => Promise<TResult1 | TResult2>;
watch: <T = any, TResult1 = T, TResult2 = never, C extends any[] = any[]>(specimenP: import("@agoric/vow").EVow<T>, watcher?: import("@agoric/vow").Watcher<T, TResult1, TResult2, C> | undefined, ...watcherArgs: C) => import("@agoric/vow").Vow<Exclude<TResult1, void> | Exclude<TResult2, void> extends never ? TResult1 : Exclude<TResult1, void> | Exclude<TResult2, void>>;
makeVowKit: <T>() => import("@agoric/vow").VowKit<T>;
allVows: (maybeVows: import("@agoric/vow").EVow<unknown>[]) => import("@agoric/vow").Vow<any[]>;
asVow: <T extends unknown>(fn: (...args: any[]) => import("@agoric/vow").Vow<Awaited<T>> | Awaited<T> | import("@agoric/vow").PromiseVow<T>) => import("@agoric/vow").Vow<Awaited<T>>;
asPromise: import("@agoric/vow").AsPromiseFunction;
}>): (instancePrefix?: string | undefined) => import("@endo/exo").Guarded<{
export function prepareLoopbackProtocolHandler(zone: import("@agoric/base-zone").Zone, { watch, allVows }: VowTools): (instancePrefix?: string) => import("@endo/exo").Guarded<{
onCreate(_impl: any, _protocolHandler: any): Promise<void>;

@@ -38,14 +29,11 @@ generatePortID(_localAddr: any, _protocolHandler: any): Promise<string>;

/**
* @param {import('@agoric/vow').Remote<Port>} port
* @param {Remote<Port>} port
* @param {Endpoint} localAddr
* @param {import('@agoric/vow').Remote<ListenHandler>} listenHandler
* @param {Remote<ListenHandler>} listenHandler
* @param {*} _protocolHandler
*/
onListenRemove(port: import("@agoric/vow").Remote<Port>, localAddr: Endpoint, listenHandler: import("@agoric/vow").Remote<ListenHandler>, _protocolHandler: any): Promise<void>;
onListenRemove(port: Remote<Port>, localAddr: Endpoint, listenHandler: Remote<ListenHandler>, _protocolHandler: any): Promise<void>;
onRevoke(_port: any, _localAddr: any, _protocolHandler: any): Promise<void>;
}>;
/**
* @import {AttemptDescription, Bytes, Closable, CloseReason, Connection, ConnectionHandler, Endpoint, ListenHandler, Port, Protocol, ProtocolHandler, ProtocolImpl} from './types.js';
*/
/**
* Compatibility note: this must match what our peers use, so don't change it

@@ -55,14 +43,6 @@ * casually.

export const ENDPOINT_SEPARATOR: "/";
export const CLOSE_REASON_FINALIZER: "closed-by-finalizer";
export function rethrowUnlessMissing(err: unknown): undefined;
export function crossoverConnection(zone: import("@agoric/zone").Zone, handler0: import("@agoric/vow").Remote<Required<ConnectionHandler>>, addr0: Endpoint, handler1: import("@agoric/vow").Remote<Required<ConnectionHandler>>, addr1: Endpoint, makeConnection: (opts: ConnectionOpts) => Connection, current?: globalThis.WeakSetStore<Closable> | undefined): Connection[];
export function prepareNetworkProtocol(zone: import("@agoric/base-zone").Zone, powers: ReturnType<(zone: import("@agoric/base-zone").Zone, powers?: {
isRetryableReason?: import("@agoric/vow").IsRetryableReason | undefined;
} | undefined) => {
when: <T, TResult1 = import("@agoric/vow").EUnwrap<T>, TResult2 = never>(specimenP: T, onFulfilled?: ((value: import("@agoric/vow").EUnwrap<T>) => TResult1 | PromiseLike<TResult1>) | undefined, onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined) => Promise<TResult1 | TResult2>;
watch: <T = any, TResult1 = T, TResult2 = never, C extends any[] = any[]>(specimenP: import("@agoric/vow").EVow<T>, watcher?: import("@agoric/vow").Watcher<T, TResult1, TResult2, C> | undefined, ...watcherArgs: C) => import("@agoric/vow").Vow<Exclude<TResult1, void> | Exclude<TResult2, void> extends never ? TResult1 : Exclude<TResult1, void> | Exclude<TResult2, void>>;
makeVowKit: <T>() => import("@agoric/vow").VowKit<T>;
allVows: (maybeVows: import("@agoric/vow").EVow<unknown>[]) => import("@agoric/vow").Vow<any[]>;
asVow: <T extends unknown>(fn: (...args: any[]) => import("@agoric/vow").Vow<Awaited<T>> | Awaited<T> | import("@agoric/vow").PromiseVow<T>) => import("@agoric/vow").Vow<Awaited<T>>;
asPromise: import("@agoric/vow").AsPromiseFunction;
}>): (protocolHandler: import("@agoric/vow").Remote<ProtocolHandler>) => Protocol;
export function crossoverConnection(zone: import("@agoric/zone").Zone, handler0: Remote<Required<ConnectionHandler>>, addr0: Endpoint, handler1: Remote<Required<ConnectionHandler>>, addr1: Endpoint, makeConnection: (opts: ConnectionOpts) => Connection, finalizer: Finalizer, current?: WeakSetStore<Closable>): Connection[];
export function prepareNetworkProtocol(zone: import("@agoric/base-zone").Zone, powers: Powers): (protocolHandler: Remote<ProtocolHandler>) => Protocol;
export function prepareEchoConnectionKit(zone: import("@agoric/base-zone").Zone): () => import("@endo/exo").GuardedKit<{

@@ -78,6 +58,6 @@ handler: {

* @param {Connection} _connection
* @param {CloseReason} [_reason]
* @param {CloseReason} [reason]
* @param {ConnectionHandler} [_connectionHandler]
*/
onClose(_connection: Connection, _reason?: CloseReason, _connectionHandler?: ConnectionHandler | undefined): Promise<void>;
onClose(_connection: Connection, reason?: CloseReason, _connectionHandler?: ConnectionHandler): Promise<void>;
};

@@ -94,6 +74,6 @@ listener: {

* @param {Connection} _connection
* @param {CloseReason} [_reason]
* @param {CloseReason} [reason]
* @param {ConnectionHandler} [_connectionHandler]
*/
onClose(_connection: Connection, _reason?: CloseReason, _connectionHandler?: ConnectionHandler | undefined): Promise<void>;
onClose(_connection: Connection, reason?: CloseReason, _connectionHandler?: ConnectionHandler): Promise<void>;
}>>;

@@ -103,12 +83,3 @@ onListen(port: any, _listenHandler: any): Promise<void>;

}>;
export function preparePortAllocator(zone: import("@agoric/base-zone").Zone, { watch }: ReturnType<(zone: import("@agoric/base-zone").Zone, powers?: {
isRetryableReason?: import("@agoric/vow").IsRetryableReason | undefined;
} | undefined) => {
when: <T, TResult1 = import("@agoric/vow").EUnwrap<T>, TResult2 = never>(specimenP: T, onFulfilled?: ((value: import("@agoric/vow").EUnwrap<T>) => TResult1 | PromiseLike<TResult1>) | undefined, onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined) => Promise<TResult1 | TResult2>;
watch: <T = any, TResult1 = T, TResult2 = never, C extends any[] = any[]>(specimenP: import("@agoric/vow").EVow<T>, watcher?: import("@agoric/vow").Watcher<T, TResult1, TResult2, C> | undefined, ...watcherArgs: C) => import("@agoric/vow").Vow<Exclude<TResult1, void> | Exclude<TResult2, void> extends never ? TResult1 : Exclude<TResult1, void> | Exclude<TResult2, void>>;
makeVowKit: <T>() => import("@agoric/vow").VowKit<T>;
allVows: (maybeVows: import("@agoric/vow").EVow<unknown>[]) => import("@agoric/vow").Vow<any[]>;
asVow: <T extends unknown>(fn: (...args: any[]) => import("@agoric/vow").Vow<Awaited<T>> | Awaited<T> | import("@agoric/vow").PromiseVow<T>) => import("@agoric/vow").Vow<Awaited<T>>;
asPromise: import("@agoric/vow").AsPromiseFunction;
}>): (args_0: {
export function preparePortAllocator(zone: import("@agoric/base-zone").Zone, { watch }: Powers): (args_0: {
protocol: Protocol;

@@ -121,6 +92,10 @@ }) => import("@endo/exo").Guarded<{

}>;
export function prepareNetworkPowers(zone: import("@agoric/base-zone").Zone, vowTools: VowTools): Powers;
export type MakeEchoConnectionKit = ReturnType<typeof prepareEchoConnectionKit>;
export type Powers = VowTools & {
finalizer: Finalizer;
};
export type ConnectionOpts = {
addrs: Endpoint[];
handlers: import("@agoric/vow").Remote<Required<ConnectionHandler>>[];
handlers: Remote<Required<ConnectionHandler>>[];
conns: MapStore<number, Connection>;

@@ -132,5 +107,8 @@ current: WeakSetStore<Closable>;

export type PortAllocator = ReturnType<ReturnType<typeof preparePortAllocator>>;
export type Finalizer = ReturnType<typeof prepareFinalizer>;
import type { VowTools } from '@agoric/vow';
import type { Endpoint } from './types.js';
import type { AttemptDescription } from './types.js';
import type { Port } from './types.js';
import type { Remote } from '@agoric/vow';
import type { ListenHandler } from './types.js';

@@ -144,2 +122,36 @@ import type { ConnectionHandler } from './types.js';

import type { CloseReason } from './types.js';
/** @typedef {ReturnType<ReturnType<typeof preparePortAllocator>>} PortAllocator */
/**
* Return a package-specific singleton that pins objects until they are
* explicitly unpinned or finalized. It needs to pin objects only because they
* are resources that need to be released.
*
* The reason this functionality wasn't just baked into the other network exos
* is to maintain upgrade-compatible with minimal additional changes.
*
* @param {import('@agoric/base-zone').Zone} zone
* @param {VowTools} vowTools
*/
declare function prepareFinalizer(zone: import("@agoric/base-zone").Zone, { watch }: VowTools): import("@endo/exo").Guarded<{
has(obj: any): boolean;
/**
* Add a connection and handler for an `onClose` method to be called upon
* finalization.
* @param {Remote<Connection>} conn
* @param {Remote<Required<ConnectionHandler>>} handler
*/
initConnection(conn: Remote<Connection>, handler: Remote<Required<ConnectionHandler>>): void;
/**
* Add an object with a `close` method to be called (such as an
* `inboundAttempt`) upon finalization.
* @param {Remote<{ close(): PromiseVow<any> }>} closer
*/
initCloser(closer: Remote<{
close(): PromiseVow<any>;
}>): void;
finalize(obj: any): import("@agoric/vow").Vow<any> | undefined;
unpin(obj: any): void;
}>;
import type { PromiseVow } from '@agoric/vow';
export {};
//# sourceMappingURL=network.d.ts.map

@@ -13,5 +13,11 @@ // @ts-check

/**
* @import {AttemptDescription, Bytes, Closable, CloseReason, Connection, ConnectionHandler, Endpoint, ListenHandler, Port, Protocol, ProtocolHandler, ProtocolImpl} from './types.js';
* @import {AttemptDescription, Bytes, CloseReason, Closable, Connection, ConnectionHandler, Endpoint, ListenHandler, Port, Protocol, ProtocolHandler, ProtocolImpl} from './types.js';
* @import {PromiseVow, Remote, VowTools} from '@agoric/vow';
*/
/** @typedef {VowTools & { finalizer: Finalizer }} Powers */
const sink = () => {};
harden(sink);
/**

@@ -23,2 +29,5 @@ * Compatibility note: this must match what our peers use, so don't change it

// Mark the finalizer close reason.
export const CLOSE_REASON_FINALIZER = 'closed-by-finalizer';
/** @param {unknown} err */

@@ -65,3 +74,3 @@ export const rethrowUnlessMissing = err => {

if (!portNameRegex.test(specifiedName)) {
throw new Error(`Invalid IBC port name: ${specifiedName}`);
throw Error(`Invalid IBC port name: ${specifiedName}`);
}

@@ -73,3 +82,3 @@ }

* @property {Endpoint[]} addrs
* @property {import('@agoric/vow').Remote<Required<ConnectionHandler>>[]} handlers
* @property {Remote<Required<ConnectionHandler>>[]} handlers
* @property {MapStore<number, Connection>} conns

@@ -83,5 +92,5 @@ * @property {WeakSetStore<Closable>} current

* @param {import('@agoric/base-zone').Zone} zone
* @param {ReturnType<import('@agoric/vow').prepareVowTools>} powers
* @param {Powers} powers
*/
const prepareHalfConnection = (zone, { watch }) => {
const prepareHalfConnection = (zone, { watch, allVows, finalizer }) => {
const makeHalfConnectionKit = zone.exoClassKit(

@@ -131,3 +140,3 @@ 'Connection',

async close() {
const { closed, current, conns, l, handlers } = this.state;
const { closed, current, conns, l, r } = this.state;
if (closed) {

@@ -137,9 +146,11 @@ throw Error(closed);

this.state.closed = 'Connection closed';
current.delete(conns.get(l));
// Tear down both sides.
const lconn = conns.get(l);
const rconn = conns.get(r);
current.delete(lconn);
current.delete(rconn);
const innerVow = watch(
E(this.state.handlers[l]).onClose(
conns.get(l),
undefined,
handlers[l],
),
allVows([finalizer.finalize(lconn), finalizer.finalize(rconn)]),
this.facets.sinkWatcher,

@@ -186,7 +197,8 @@ );

* @param {import('@agoric/zone').Zone} zone
* @param {import('@agoric/vow').Remote<Required<ConnectionHandler>>} handler0
* @param {Remote<Required<ConnectionHandler>>} handler0
* @param {Endpoint} addr0
* @param {import('@agoric/vow').Remote<Required<ConnectionHandler>>} handler1
* @param {Remote<Required<ConnectionHandler>>} handler1
* @param {Endpoint} addr1
* @param {(opts: ConnectionOpts) => Connection} makeConnection
* @param {Finalizer} finalizer
* @param {WeakSetStore<Closable>} [current]

@@ -201,2 +213,3 @@ */

makeConnection,
finalizer,
current = zone.detached().weakSetStore('crossoverCurrentConnections'),

@@ -209,3 +222,3 @@ ) => {

/** @type {import('@agoric/vow').Remote<Required<ConnectionHandler>>[]} */
/** @type {Remote<Required<ConnectionHandler>>[]} */
const handlers = harden([handler0, handler1]);

@@ -228,5 +241,9 @@ /** @type {Endpoint[]} */

const openHalfConnection = (l, r) => {
current.add(conns.get(l));
const lconn = conns.get(l);
current.add(lconn);
if (!finalizer.has(lconn)) {
finalizer.initConnection(lconn, handlers[l]);
}
E(handlers[l])
.onOpen(conns.get(l), addrs[l], addrs[r], handlers[l])
.onOpen(lconn, addrs[l], addrs[r], handlers[l])
.catch(rethrowUnlessMissing);

@@ -247,5 +264,5 @@ };

* @param {(opts: ConnectionOpts) => Connection} makeConnection
* @param {ReturnType<import('@agoric/vow').prepareVowTools>} powers
* @param {Powers} powers
*/
const prepareInboundAttempt = (zone, makeConnection, { watch }) => {
const prepareInboundAttempt = (zone, makeConnection, { watch, finalizer }) => {
const makeInboundAttemptKit = zone.exoClassKit(

@@ -260,3 +277,3 @@ 'InboundAttempt',

* @param {string} opts.listenPrefix
* @param {MapStore<Endpoint, [Port, import('@agoric/vow').Remote<Required<ListenHandler>>]>} opts.listening
* @param {MapStore<Endpoint, [Port, Remote<Required<ListenHandler>>]>} opts.listening
*/

@@ -304,2 +321,3 @@ ({

current.delete(this.facets.inboundAttempt);
finalizer.unpin(this.facets.inboundAttempt);

@@ -317,3 +335,3 @@ const innerVow = watch(

* @param {string} [opts.remoteAddress]
* @param {import('@agoric/vow').Remote<ConnectionHandler>} opts.handler
* @param {Remote<ConnectionHandler>} opts.handler
*/

@@ -360,11 +378,8 @@ async accept({ localAddress, remoteAddress, handler: rchandler }) {

zone,
/** @type {import('@agoric/vow').Remote<Required<ConnectionHandler>>} */ (
lchandler
),
/** @type {Remote<Required<ConnectionHandler>>} */ (lchandler),
localAddress,
/** @type {import('@agoric/vow').Remote<Required<ConnectionHandler>>} */ (
rchandler
),
/** @type {Remote<Required<ConnectionHandler>>} */ (rchandler),
remoteAddress,
makeConnection,
finalizer,
current,

@@ -408,3 +423,3 @@ )[1];

/** @enum {number} */
/** @enum {typeof RevokeState[keyof typeof RevokeState]} */
const RevokeState = /** @type {const} */ ({

@@ -415,6 +430,7 @@ NOT_REVOKED: 0,

});
harden(RevokeState);
/**
* @param {import('@agoric/zone').Zone} zone
* @param {ReturnType<import('@agoric/vow').prepareVowTools>} powers
* @param {Powers} powers
*/

@@ -424,3 +440,3 @@ const preparePort = (zone, powers) => {

const { watch, allVows } = powers;
const { finalizer, watch, allVows } = powers;

@@ -430,8 +446,8 @@ /**

* @param {Endpoint} opts.localAddr
* @param {MapStore<Endpoint, [Port, import('@agoric/vow').Remote<Required<ListenHandler>>]>} opts.listening
* @param {SetStore<import('@agoric/vow').Remote<Connection>>} opts.openConnections
* @param {MapStore<Endpoint, [Port, Remote<Required<ListenHandler>>]>} opts.listening
* @param {SetStore<Remote<Connection>>} opts.openConnections
* @param {MapStore<Port, SetStore<Closable>>} opts.currentConnections
* @param {MapStore<string, Port>} opts.boundPorts
* @param {import('@agoric/vow').Remote<ProtocolHandler>} opts.protocolHandler
* @param {import('@agoric/vow').Remote<ProtocolImpl>} opts.protocolImpl
* @param {Remote<ProtocolHandler>} opts.protocolHandler
* @param {Remote<ProtocolImpl>} opts.protocolImpl
*/

@@ -466,3 +482,3 @@ const initPort = ({

},
/** @param {import('@agoric/vow').Remote<ListenHandler>} listenHandler */
/** @param {Remote<ListenHandler>} listenHandler */
async addListener(listenHandler) {

@@ -482,5 +498,3 @@ const { revoked, listening, localAddr, protocolHandler } = this.state;

this.facets.port,
/** @type {import('@agoric/vow').Remote<Required<ListenHandler>>} */ (
listenHandler
),
/** @type {Remote<Required<ListenHandler>>} */ (listenHandler),
]);

@@ -493,5 +507,3 @@ E(lhandler).onRemove(lport, lhandler).catch(rethrowUnlessMissing);

this.facets.port,
/** @type {import('@agoric/vow').Remote<Required<ListenHandler>>} */ (
listenHandler
),
/** @type {Remote<Required<ListenHandler>>} */ (listenHandler),
]),

@@ -515,3 +527,3 @@ );

},
/** @param {import('@agoric/vow').Remote<ListenHandler>} listenHandler */
/** @param {Remote<ListenHandler>} listenHandler */
async removeListener(listenHandler) {

@@ -538,7 +550,7 @@ const { listening, localAddr, protocolHandler } = this.state;

* @param {Endpoint} remotePort
* @param {import('@agoric/vow').Remote<ConnectionHandler>} [connectionHandler]
* @param {Remote<ConnectionHandler>} [connectionHandler]
*/
async connect(
remotePort,
connectionHandler = /** @type {import('@agoric/vow').Remote<ConnectionHandler>} */ (
connectionHandler = /** @type {Remote<ConnectionHandler>} */ (
makeIncapable()

@@ -555,3 +567,3 @@ ),

this.facets.portConnectWatcher,
{ revoked },
{ chandler: connectionHandler },
);

@@ -567,3 +579,2 @@ },

this.state.revoked = RevokeState.REVOKING;
const revokeVow = watch(

@@ -594,11 +605,12 @@ E(protocolHandler).onRevoke(

portConnectWatcher: {
onFulfilled(conn, watchContext) {
const { revoked } = watchContext;
const { openConnections } = this.state;
onFulfilled(conn, { chandler }) {
const { openConnections, revoked } = this.state;
if (!finalizer.has(conn)) {
finalizer.initConnection(conn, chandler);
}
if (revoked) {
void E(conn).close();
} else {
openConnections.add(conn);
return finalizer.finalize(conn);
}
openConnections.add(conn);
return conn;

@@ -617,4 +629,4 @@ },

ps.push(
...values.map(conn =>
watch(E(conn).close(), this.facets.sinkWatcher),
...values.map(obj =>
watch(finalizer.finalize(obj), this.facets.sinkWatcher),
),

@@ -682,3 +694,3 @@ );

* @param {import('@agoric/base-zone').Zone} zone
* @param {ReturnType<import('@agoric/vow').prepareVowTools>} powers
* @param {Powers} powers
*/

@@ -688,3 +700,3 @@ const prepareBinder = (zone, powers) => {

const { watch } = powers;
const { watch, finalizer } = powers;

@@ -764,4 +776,4 @@ const makeInboundAttempt = prepareInboundAttempt(

* @param {MapStore<string, Port>} opts.boundPorts
* @param {MapStore<Endpoint, [Port, import('@agoric/vow').Remote<Required<ListenHandler>>]>} opts.listening
* @param {import('@agoric/vow').Remote<ProtocolHandler>} opts.protocolHandler
* @param {MapStore<Endpoint, [Port, Remote<Required<ListenHandler>>]>} opts.listening
* @param {Remote<ProtocolHandler>} opts.protocolHandler
*/

@@ -812,3 +824,3 @@ ({ currentConnections, boundPorts, listening, protocolHandler }) => {

E(
/** @type {import('@agoric/vow').Remote<Required<ProtocolHandler>>} */ (
/** @type {Remote<Required<ProtocolHandler>>} */ (
protocolHandler

@@ -855,3 +867,3 @@ ),

E(
/** @type {import('@agoric/vow').Remote<Required<ProtocolHandler>>} */ (
/** @type {Remote<Required<ProtocolHandler>>} */ (
protocolHandler

@@ -941,2 +953,3 @@ ),

current.add(inboundAttempt);
finalizer.initCloser(inboundAttempt);
return inboundAttempt;

@@ -983,3 +996,3 @@ },

E(
/** @type {import('@agoric/vow').Remote<Required<ProtocolHandler>>} */ (
/** @type {Remote<Required<ProtocolHandler>>} */ (
protocolHandler

@@ -1047,11 +1060,8 @@ ),

zone,
/** @type {import('@agoric/vow').Remote<Required<ConnectionHandler>>} */ (
lchandler
),
/** @type {Remote<Required<ConnectionHandler>>} */ (lchandler),
negotiatedLocalAddress || requestedLocalAddress,
/** @type {import('@agoric/vow').Remote<Required<ConnectionHandler>>} */ (
rchandler
),
/** @type {Remote<Required<ConnectionHandler>>} */ (rchandler),
negotiatedRemoteAddress || requestedRemoteAddress,
makeConnection,
finalizer,
current,

@@ -1209,3 +1219,3 @@ )[0];

* @param {import('@agoric/base-zone').Zone} zone
* @param {ReturnType<import('@agoric/vow').prepareVowTools>} powers
* @param {Powers} powers
*/

@@ -1216,3 +1226,3 @@ export const prepareNetworkProtocol = (zone, powers) => {

/**
* @param {import('@agoric/vow').Remote<ProtocolHandler>} protocolHandler
* @param {Remote<ProtocolHandler>} protocolHandler
* @returns {Protocol}

@@ -1229,3 +1239,3 @@ */

/** @type {MapStore<Endpoint, [Port, import('@agoric/vow').Remote<Required<ListenHandler>>]>} */
/** @type {MapStore<Endpoint, [Port, Remote<Required<ListenHandler>>]>} */
const listening = detached.mapStore('listening');

@@ -1304,6 +1314,6 @@

* @param {Connection} _connection
* @param {CloseReason} [_reason]
* @param {CloseReason} [reason]
* @param {ConnectionHandler} [_connectionHandler]
*/
async onClose(_connection, _reason, _connectionHandler) {
async onClose(_connection, reason, _connectionHandler) {
const { closed } = this.state;

@@ -1315,3 +1325,3 @@

this.state.closed = 'Connection closed';
this.state.closed = reason || 'Connection closed';
},

@@ -1338,3 +1348,3 @@ },

* @param {import('@agoric/base-zone').Zone} zone
* @param {ReturnType<import('@agoric/vow').prepareVowTools>} powers
* @param {VowTools} powers
*/

@@ -1346,3 +1356,3 @@ export function prepareLoopbackProtocolHandler(zone, { watch, allVows }) {

const initHandler = (instancePrefix = 'nonce/') => {
/** @type {MapStore<string, [import('@agoric/vow').Remote<Port>, import('@agoric/vow').Remote<Required<ListenHandler>>]>} */
/** @type {MapStore<string, [Remote<Port>, Remote<Required<ListenHandler>>]>} */
const listeners = detached.mapStore('localAddr');

@@ -1426,3 +1436,3 @@

port,
/** @type {import('@agoric/vow').Remote<Required<ListenHandler>>} */ (
/** @type {Remote<Required<ListenHandler>>} */ (
listenHandler

@@ -1438,5 +1448,3 @@ ),

port,
/** @type {import('@agoric/vow').Remote<Required<ListenHandler>>} */ (
listenHandler
),
/** @type {Remote<Required<ListenHandler>>} */ (listenHandler),
]),

@@ -1447,5 +1455,5 @@ );

/**
* @param {import('@agoric/vow').Remote<Port>} port
* @param {Remote<Port>} port
* @param {Endpoint} localAddr
* @param {import('@agoric/vow').Remote<ListenHandler>} listenHandler
* @param {Remote<ListenHandler>} listenHandler
* @param {*} _protocolHandler

@@ -1503,3 +1511,3 @@ */

* @param {import('@agoric/base-zone').Zone} zone
* @param {ReturnType<import('@agoric/vow').prepareVowTools>} powers
* @param {Powers} powers
*/

@@ -1574,1 +1582,77 @@ export const preparePortAllocator = (zone, { watch }) =>

/** @typedef {ReturnType<ReturnType<typeof preparePortAllocator>>} PortAllocator */
/**
* Return a package-specific singleton that pins objects until they are
* explicitly unpinned or finalized. It needs to pin objects only because they
* are resources that need to be released.
*
* The reason this functionality wasn't just baked into the other network exos
* is to maintain upgrade-compatible with minimal additional changes.
*
* @param {import('@agoric/base-zone').Zone} zone
* @param {VowTools} vowTools
*/
const prepareFinalizer = (zone, { watch }) => {
/**
* @type {MapStore<{},
* { conn: Remote<Connection>, handler: Remote<Required<ConnectionHandler>>} |
* { closer: Remote<{ close(): PromiseVow<any> }> }
* >}
*/
const objToFinalizerInfo = zone.mapStore('objToFinalizerInfo');
return zone.exo('NetworkFinalizer', undefined, {
has(obj) {
return objToFinalizerInfo.has(obj);
},
/**
* Add a connection and handler for an `onClose` method to be called upon
* finalization.
* @param {Remote<Connection>} conn
* @param {Remote<Required<ConnectionHandler>>} handler
*/
initConnection(conn, handler) {
objToFinalizerInfo.init(conn, harden({ conn, handler }));
},
/**
* Add an object with a `close` method to be called (such as an
* `inboundAttempt`) upon finalization.
* @param {Remote<{ close(): PromiseVow<any> }>} closer
*/
initCloser(closer) {
objToFinalizerInfo.init(closer, harden({ closer }));
},
finalize(obj) {
if (!objToFinalizerInfo.has(obj)) {
return;
}
const disposeInfo = objToFinalizerInfo.get(obj);
if ('conn' in disposeInfo) {
// A connection+handler.
const { conn, handler } = disposeInfo;
objToFinalizerInfo.delete(obj);
return watch(E(handler).onClose(conn, CLOSE_REASON_FINALIZER, handler));
} else if ('closer' in disposeInfo) {
// Just something with a `close` method.
const { closer } = disposeInfo;
objToFinalizerInfo.delete(obj);
return watch(E(closer).close());
}
},
unpin(obj) {
objToFinalizerInfo.delete(obj);
},
});
};
harden(prepareFinalizer);
/**
* @param {import('@agoric/base-zone').Zone} zone
* @param {VowTools} vowTools
* @returns {Powers}
*/
export const prepareNetworkPowers = (zone, vowTools) => {
const finalizer = prepareFinalizer(zone, vowTools);
return harden({ ...vowTools, finalizer });
};
/** @typedef {ReturnType<typeof prepareFinalizer>} Finalizer */
/**
* @import {AttemptDescription, Bytes, Closable, CloseReason, Connection, ConnectionHandler, Endpoint, ListenHandler, Port, Protocol, ProtocolHandler, ProtocolImpl} from './types.js';
* @import {PromiseVow, Remote, VowKit, VowResolver, VowTools} from '@agoric/vow';
* @import {Endpoint, Port, Protocol, ProtocolHandler} from './types.js';
* @import {PromiseVow, Remote, VowTools} from '@agoric/vow';
*/

@@ -34,24 +34,3 @@ /**

}>;
export function prepareRouterProtocol(zone: import("@agoric/base-zone").Zone, powers: ReturnType<(zone: import("@agoric/base-zone").Zone, powers?: {
isRetryableReason?: import("@agoric/vow").IsRetryableReason | undefined;
} | undefined) => {
when: <T, TResult1 = import("@agoric/vow").EUnwrap<T>, TResult2 = never>(specimenP: T, onFulfilled?: ((value: import("@agoric/vow").EUnwrap<T>) => TResult1 | PromiseLike<TResult1>) | undefined, onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined) => Promise<TResult1 | TResult2>;
watch: <T = any, TResult1 = T, TResult2 = never, C extends any[] = any[]>(specimenP: import("@agoric/vow").EVow<T>, watcher?: import("@agoric/vow").Watcher<T, TResult1, TResult2, C> | undefined, ...watcherArgs: C) => import("@agoric/vow").Vow<Exclude<TResult1, void> | Exclude<TResult2, void> extends never ? TResult1 : Exclude<TResult1, void> | Exclude<TResult2, void>>;
makeVowKit: <T>() => VowKit<T>;
allVows: (maybeVows: import("@agoric/vow").EVow<unknown>[]) => import("@agoric/vow").Vow<any[]>;
asVow: <T extends unknown>(fn: (... /**
* @param {string} prefix
* @param {T} route
*/args: any[]) => import("@agoric/vow").Vow<Awaited<T>> | Awaited<T> | PromiseVow<T>) => import("@agoric/vow").Vow<Awaited<T>>;
asPromise: import("@agoric/vow").AsPromiseFunction;
}>, E?: ((<T>(x: T) => import("../../../node_modules/@endo/eventual-send/src/E.js").ECallableOrMethods<import("@endo/eventual-send").RemoteFunctions<T>>) & {
readonly get: <T_1>(x: T_1) => import("../../../node_modules/@endo/eventual-send/src/E.js").EGetters<import("@endo/eventual-send").LocalRecord<T_1>>;
readonly resolve: {
(): Promise<void>;
<T_2>(value: T_2): Promise<Awaited<T_2>>;
<T_3>(value: T_3 | PromiseLike<T_3>): Promise<Awaited<T_3>>;
};
readonly sendOnly: <T_4>(x: T_4) => import("../../../node_modules/@endo/eventual-send/src/E.js").ESendOnlyCallableOrMethods<import("@endo/eventual-send").RemoteFunctions<T_4>>;
readonly when: <T_5, U = T_5>(x: T_5 | PromiseLike<T_5>, onfulfilled?: ((value: T_5) => import("@endo/eventual-send").ERef<U>) | undefined, onrejected?: ((reason: any) => import("@endo/eventual-send").ERef<U>) | undefined) => Promise<U>;
}) | undefined): () => import("@endo/exo").Guarded<{
export function prepareRouterProtocol(zone: import("@agoric/base-zone").Zone, powers: import("./network.js").Powers, E?: typeof defaultE): () => import("@endo/exo").Guarded<{
/**

@@ -96,7 +75,7 @@ * @param {string[]} paths

import type { Endpoint } from './types.js';
import type { VowKit } from '@agoric/vow';
import type { PromiseVow } from '@agoric/vow';
import { E as defaultE } from '@endo/far';
import type { ProtocolHandler } from './types.js';
import type { Remote } from '@agoric/vow';
import type { Port } from './types.js';
import type { PromiseVow } from '@agoric/vow';
//# sourceMappingURL=router.d.ts.map

@@ -13,4 +13,4 @@ // @ts-check

/**
* @import {AttemptDescription, Bytes, Closable, CloseReason, Connection, ConnectionHandler, Endpoint, ListenHandler, Port, Protocol, ProtocolHandler, ProtocolImpl} from './types.js';
* @import {PromiseVow, Remote, VowKit, VowResolver, VowTools} from '@agoric/vow';
* @import {Endpoint, Port, Protocol, ProtocolHandler} from './types.js';
* @import {PromiseVow, Remote, VowTools} from '@agoric/vow';
*/

@@ -112,3 +112,3 @@

* @param {import('@agoric/base-zone').Zone} zone
* @param {ReturnType<import('@agoric/vow').prepareVowTools>} powers
* @param {import('./network.js').Powers} powers
* @param {typeof defaultE} [E] Eventual sender

@@ -115,0 +115,0 @@ */

@@ -161,3 +161,3 @@ // @ts-check

protocolHandlerAcceptWatcher: M.interface('ProtocolHandlerAcceptWatcher', {
onFulfilled: M.call(M.any()).rest(M.any()).returns(),
onFulfilled: M.call(M.any()).rest(M.any()).returns(M.any()),
}),

@@ -167,3 +167,3 @@ protocolHandlerInstantiateWatcher: M.interface(

{
onFulfilled: M.call(M.any()).rest(M.any()).returns(),
onFulfilled: M.call(M.any()).rest(M.any()).returns(M.any()),
},

@@ -174,3 +174,3 @@ ),

{
onFulfilled: M.call(M.any()).rest(M.any()).returns(),
onFulfilled: M.call(M.any()).rest(M.any()).returns(M.any()),
},

@@ -177,0 +177,0 @@ ),

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet