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
10
Versions
993
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 0.1.1-dev-9553675.0 to 0.1.1-dev-9555ae0.0

48

package.json
{
"name": "@agoric/network",
"version": "0.1.1-dev-9553675.0+9553675",
"version": "0.1.1-dev-9555ae0.0+9555ae0",
"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,23 +25,23 @@ "lint-fix": "yarn lint:eslint --fix",

"dependencies": {
"@agoric/assert": "0.6.1-dev-9553675.0+9553675",
"@agoric/internal": "0.3.3-dev-9553675.0+9553675",
"@agoric/store": "0.9.3-dev-9553675.0+9553675",
"@agoric/vat-data": "0.5.3-dev-9553675.0+9553675",
"@endo/base64": "^1.0.5",
"@endo/far": "^1.1.2",
"@endo/patterns": "^1.4.0",
"@endo/promise-kit": "^1.1.2"
"@agoric/internal": "0.3.3-dev-9555ae0.0+9555ae0",
"@agoric/store": "0.9.3-dev-9555ae0.0+9555ae0",
"@agoric/vat-data": "0.5.3-dev-9555ae0.0+9555ae0",
"@endo/base64": "^1.0.9",
"@endo/errors": "^1.2.9",
"@endo/far": "^1.1.10",
"@endo/pass-style": "^1.4.8",
"@endo/patterns": "^1.4.8",
"@endo/promise-kit": "^1.1.9"
},
"devDependencies": {
"@agoric/swingset-liveslots": "0.10.3-dev-9553675.0+9553675",
"@agoric/swingset-vat": "0.32.3-dev-9553675.0+9553675",
"@agoric/vow": "0.1.1-dev-9553675.0+9553675",
"@agoric/zone": "0.2.3-dev-9553675.0+9553675",
"@endo/bundle-source": "^3.2.3",
"@agoric/swingset-liveslots": "0.10.3-dev-9555ae0.0+9555ae0",
"@agoric/swingset-vat": "0.32.3-dev-9555ae0.0+9555ae0",
"@agoric/vow": "0.1.1-dev-9555ae0.0+9555ae0",
"@agoric/zone": "0.2.3-dev-9555ae0.0+9555ae0",
"@endo/bundle-source": "^3.5.1",
"ava": "^5.3.0",
"c8": "^9.1.0"
"c8": "^10.1.2"
},
"exports": {
".": "./src/index.js",
"./exported.js": "./exported.js"
".": "./src/index.js"
},

@@ -52,6 +52,3 @@ "files": [

"scripts/",
"tools/",
"*.json",
"globals.d.ts",
"exported.js"
"tools/"
],

@@ -66,3 +63,2 @@ "publishConfig": {

"files": [
"test/**/test-*.*",
"test/**/*.test.*"

@@ -77,5 +73,5 @@ ],

"typeCoverage": {
"atLeast": 89.5
"atLeast": 91.16
},
"gitHead": "9553675cd136d389c427e024fc4da78558344779"
"gitHead": "9555ae03e9761b77c876197ef70c96380eeae5b4"
}
/**
* @import {Bytes} from './types.js';
*/
/** @typedef {Bytes | Buffer | Uint8Array | Iterable<number>} ByteSource */
/**
* This function is a coercer instead of an asserter because in a future where
* binary data has better support across vats and potentially its own type, we
* might allow more `specimen`s than just `ByteSource`.
*
* @param {unknown} specimen
* @returns {ByteSource}
*/
export function coerceToByteSource(specimen: unknown): ByteSource;
/**
* Convert a Uint8Array or other sequence of octets to a string representation

@@ -8,3 +21,3 @@ * that `@endo/marshal` accepts as Passable.

*/
export function toBytes(byteSource: ByteSource): string;
export function toBytes(byteSource: ByteSource): Bytes;
/**

@@ -16,3 +29,3 @@ * Convert bytes to a String.

*/
export function bytesToString(bytes: string): string;
export function bytesToString(bytes: Bytes): string;
/**

@@ -24,3 +37,3 @@ * Base64, as specified in https://tools.ietf.org/html/rfc4648#section-4

*/
export function dataToBase64(byteSource: ByteSource): string;
export function byteSourceToBase64(byteSource: ByteSource): string;
/**

@@ -32,4 +45,6 @@ * Decodes a base64 string into bytes.

*/
export function base64ToBytes(string: string): string;
export type ByteSource = string | Iterable<number> | Buffer | Uint8Array;
export function base64ToBytes(string: string): Bytes;
export type ByteSource = Bytes | Buffer | Uint8Array | Iterable<number>;
import type { Bytes } from './types.js';
import type { Bytes as Bytes_1 } from './types.js';
//# sourceMappingURL=bytes.d.ts.map
// @ts-check
/// <reference path="./types.js" />
import { Fail } from '@agoric/assert';
import { X, Fail } from '@endo/errors';
import { encodeBase64, decodeBase64 } from '@endo/base64';
import { isObject } from '@endo/pass-style';

@@ -13,2 +13,26 @@ /**

/**
* This function is a coercer instead of an asserter because in a future where
* binary data has better support across vats and potentially its own type, we
* might allow more `specimen`s than just `ByteSource`.
*
* @param {unknown} specimen
* @returns {ByteSource}
*/
export function coerceToByteSource(specimen) {
if (typeof specimen === 'string') {
return specimen;
}
isObject(specimen) ||
assert.fail(X`non-object ${specimen} is not a ByteSource`, TypeError);
const obj = /** @type {{}} */ (specimen);
typeof obj[Symbol.iterator] === 'function' ||
assert.fail(X`non-iterable ${specimen} is not a ByteSource`, TypeError);
// Good enough... it's iterable and can be converted later.
return /** @type {ByteSource} */ (specimen);
}
/**
* @param {ByteSource} contents

@@ -64,3 +88,3 @@ */

*/
export function dataToBase64(byteSource) {
export function byteSourceToBase64(byteSource) {
const bytes = coerceToByteArray(byteSource);

@@ -67,0 +91,0 @@ return encodeBase64(bytes);

@@ -7,2 +7,3 @@ /**

export function getPrefixes(addr: string): string[];
/** @typedef {ReturnType<typeof prepareEchoConnectionKit>} MakeEchoConnectionKit */
/**

@@ -12,12 +13,5 @@ * Create a protocol handler that just connects to itself.

* @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?: ((reason: any) => boolean) | undefined;
} | undefined) => {
when: <T, TResult1 = import("@agoric/vow").Unwrap<T>, TResult2 = never>(specimenP: T, onFulfilled?: ((value: import("@agoric/vow").Unwrap<T>) => TResult1 | PromiseLike<TResult1>) | undefined, onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined) => Promise<TResult1 | TResult2>;
watch: <T_1 = unknown, TResult1_1 = T_1, TResult2_1 = T_1, C = unknown>(specimenP: import("@agoric/vow").ERef<T_1 | import("@agoric/vow").Vow<T_1>>, watcher?: import("@agoric/vow").Watcher<T_1, TResult1_1, TResult2_1> | undefined, watcherContext?: C | undefined) => import("@agoric/vow").Vow<TResult1_1 | TResult2_1>;
makeVowKit: <T_2>() => import("@agoric/vow").VowKit<T_2>;
allVows: (vows: any) => import("@agoric/vow").Vow<any>;
}>): (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>;

@@ -32,36 +26,15 @@ generatePortID(_localAddr: any, _protocolHandler: any): Promise<string>;

*/
onConnect(_port: any, localAddr: string, remoteAddr: string): import("@agoric/vow").PromiseVow<AttemptDescription>;
onConnect(_port: any, localAddr: Endpoint, remoteAddr: Endpoint): import("@agoric/vow").PromiseVow<AttemptDescription>;
onInstantiate(_port: any, _localAddr: any, _remote: any, _protocol: any): Promise<string>;
onListen(port: any, localAddr: any, listenHandler: any, _protocolHandler: any): Promise<void>;
/**
* @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: string, listenHandler: import("@agoric/vow").Remote<ListenHandler, {
/**
* The listener has been registered
*/
onListen?: undefined;
/**
* The connection was rejected
*/
onReject?: undefined;
/**
* There was an error while listening
*/
onError?: undefined;
/**
* The
* listener has been removed
*/
onRemove?: undefined;
}>, _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

@@ -71,17 +44,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: string, handler1: import("@agoric/vow").Remote<Required<ConnectionHandler>, {}>, addr1: string, 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?: ((reason: any) => boolean) | undefined;
} | undefined) => {
when: <T, TResult1 = import("@agoric/vow").Unwrap<T>, TResult2 = never>(specimenP: T, onFulfilled?: ((value: import("@agoric/vow").Unwrap<T>) => TResult1 | PromiseLike<TResult1>) | undefined, onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined) => Promise<TResult1 | TResult2>;
watch: <T_1 = unknown, TResult1_1 = T_1, TResult2_1 = T_1, C = unknown>(specimenP: import("@agoric/vow").ERef<T_1 | import("@agoric/vow").Vow<T_1>>, watcher?: import("@agoric/vow").Watcher<T_1, TResult1_1, TResult2_1> | undefined, watcherContext?: C | undefined) => import("@agoric/vow").Vow<TResult1_1 | TResult2_1>;
makeVowKit: <T_2>() => import("@agoric/vow").VowKit<T_2>;
allVows: (vows: any) => import("@agoric/vow").Vow<any>;
}>): (protocolHandler: import("@agoric/vow").Remote<ProtocolHandler, {
/**
* Return unique suffix for local address
*/
onInstantiate?: undefined;
}>) => 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<{

@@ -94,9 +56,9 @@ handler: {

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

@@ -110,9 +72,9 @@ listener: {

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

@@ -122,25 +84,30 @@ 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?: ((reason: any) => boolean) | undefined;
} | undefined) => {
when: <T, TResult1 = import("@agoric/vow").Unwrap<T>, TResult2 = never>(specimenP: T, onFulfilled?: ((value: import("@agoric/vow").Unwrap<T>) => TResult1 | PromiseLike<TResult1>) | undefined, onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined) => Promise<TResult1 | TResult2>;
watch: <T_1 = unknown, TResult1_1 = T_1, TResult2_1 = T_1, C = unknown>(specimenP: import("@agoric/vow").ERef<T_1 | import("@agoric/vow").Vow<T_1>>, watcher?: import("@agoric/vow").Watcher<T_1, TResult1_1, TResult2_1> | undefined, watcherContext?: C | undefined) => import("@agoric/vow").Vow<TResult1_1 | TResult2_1>;
makeVowKit: <T_2>() => import("@agoric/vow").VowKit<T_2>;
allVows: (vows: any) => import("@agoric/vow").Vow<any>;
}>): (args_0?: any) => import("@endo/exo").Guarded<{
allocateCustomIBCPort(specifiedName?: string): import("@agoric/vow").Vow<any>;
allocateICAControllerPort(): import("@agoric/vow").Vow<any>;
allocateICQControllerPort(): import("@agoric/vow").Vow<any>;
allocateCustomLocalPort(specifiedName?: string): import("@agoric/vow").Vow<any>;
export function preparePortAllocator(zone: import("@agoric/base-zone").Zone, { watch }: Powers): (args_0: {
protocol: Protocol;
}) => import("@endo/exo").Guarded<{
allocateCustomIBCPort(specifiedName?: string): Promise<import("@agoric/vow").Vow<Port>>;
allocateICAControllerPort(): Promise<import("@agoric/vow").Vow<Port>>;
allocateICQControllerPort(): Promise<import("@agoric/vow").Vow<Port>>;
allocateCustomLocalPort(specifiedName?: string): Promise<import("@agoric/vow").Vow<Port>>;
}>;
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: string[];
handlers: import("@agoric/vow").Remote<Required<ConnectionHandler>, {}>[];
conns: globalThis.MapStore<number, Connection>;
current: globalThis.WeakSetStore<Closable>;
addrs: Endpoint[];
handlers: Remote<Required<ConnectionHandler>>[];
conns: MapStore<number, Connection>;
current: WeakSetStore<Closable>;
l: 0 | 1;
r: 0 | 1;
};
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';

@@ -152,2 +119,38 @@ import type { ConnectionHandler } from './types.js';

import type { Protocol } from './types.js';
import type { Bytes } 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
// @ts-check
/// <reference types="@agoric/store/exported.js" />
import { Fail } from '@endo/errors';
import { E } from '@endo/far';
import { M } from '@endo/patterns';
import { Fail } from '@agoric/assert';
import { toBytes } from './bytes.js';
import { Shape } from './shapes.js';
import '@agoric/store/exported.js';
/// <reference path="./types.js" />
/**
* @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);
/**

@@ -21,2 +28,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 */

@@ -63,3 +73,3 @@ export const rethrowUnlessMissing = err => {

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

@@ -71,3 +81,3 @@ }

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

@@ -81,5 +91,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(

@@ -129,3 +139,3 @@ 'Connection',

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

@@ -135,9 +145,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,

@@ -184,7 +196,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]

@@ -199,2 +212,3 @@ */

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

@@ -207,3 +221,3 @@ ) => {

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

@@ -226,5 +240,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);

@@ -245,5 +263,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(

@@ -258,3 +276,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
*/

@@ -302,2 +320,3 @@ ({

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

@@ -315,3 +334,3 @@ const innerVow = watch(

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

@@ -358,11 +377,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,

@@ -406,3 +422,3 @@ )[1];

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

@@ -413,6 +429,7 @@ NOT_REVOKED: 0,

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

@@ -422,3 +439,3 @@ const preparePort = (zone, powers) => {

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

@@ -428,8 +445,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
*/

@@ -464,3 +481,3 @@ const initPort = ({

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

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

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

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

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

@@ -513,3 +526,3 @@ );

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

@@ -536,7 +549,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()

@@ -553,3 +566,3 @@ ),

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

@@ -565,3 +578,2 @@ },

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

@@ -592,11 +604,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;

@@ -613,8 +626,6 @@ },

/** @type {import('@agoric/vow').Specimen[]} */
const ps = [];
ps.push(
...values.map(conn =>
watch(E(conn).close(), this.facets.sinkWatcher),
...values.map(obj =>
watch(finalizer.finalize(obj), this.facets.sinkWatcher),
),

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

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

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

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

@@ -764,4 +775,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 +823,3 @@ ({ currentConnections, boundPorts, listening, protocolHandler }) => {

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

@@ -855,3 +866,3 @@ ),

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

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

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

@@ -983,3 +995,3 @@ },

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

@@ -1047,11 +1059,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 +1218,3 @@ )[0];

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

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

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

@@ -1229,3 +1238,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 +1313,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 +1324,3 @@

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

@@ -1332,2 +1341,3 @@ },

};
/** @typedef {ReturnType<typeof prepareEchoConnectionKit>} MakeEchoConnectionKit */

@@ -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
*/

@@ -1519,5 +1527,10 @@ export const preparePortAllocator = (zone, { watch }) =>

}),
/**
*
* @param {object} opts
* @param {Protocol} opts.protocol
*/
({ protocol }) => ({ protocol, lastICAPortNum: 0n, lastICQPortNum: 0n }),
{
allocateCustomIBCPort(specifiedName = '') {
async allocateCustomIBCPort(specifiedName = '') {
const { state } = this;

@@ -1535,3 +1548,3 @@ let localAddr = `/ibc-port/`;

},
allocateICAControllerPort() {
async allocateICAControllerPort() {
const { state } = this;

@@ -1545,3 +1558,3 @@ state.lastICAPortNum += 1n;

},
allocateICQControllerPort() {
async allocateICQControllerPort() {
const { state } = this;

@@ -1555,3 +1568,3 @@ state.lastICQPortNum += 1n;

},
allocateCustomLocalPort(specifiedName = '') {
async allocateCustomLocalPort(specifiedName = '') {
const { state } = this;

@@ -1572,1 +1585,78 @@

);
/** @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';
*/

@@ -22,3 +22,3 @@ /**

/** @param {Endpoint} addr */
getRoutes(addr: string): [string, T][];
getRoutes(addr: Endpoint): [string, T][];
/**

@@ -35,19 +35,3 @@ * @param {string} prefix

}>;
export function prepareRouterProtocol(zone: import("@agoric/base-zone").Zone, powers: ReturnType<(zone: import("@agoric/base-zone").Zone, powers?: {
isRetryableReason?: ((reason: any) => boolean) | undefined;
} | undefined) => {
when: <T, TResult1 = import("@agoric/vow").Unwrap<T>, TResult2 = never>(specimenP: T, onFulfilled?: ((value: import("@agoric/vow").Unwrap<T>) => TResult1 | PromiseLike<TResult1>) | undefined, onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined) => Promise<TResult1 | TResult2>;
watch: <T_1 = unknown, TResult1_1 = T_1, TResult2_1 = T_1, C = unknown>(specimenP: import("@agoric/vow").ERef<T_1 | import("@agoric/vow").Vow<T_1>>, watcher?: import("@agoric/vow").Watcher<T_1, TResult1_1, TResult2_1> | undefined, watcherContext?: C | undefined) => import("@agoric/vow").Vow<TResult1_1 | TResult2_1>;
makeVowKit: <T_2>() => VowKit<T_2>;
allVows: (vows: any) => import("@agoric/vow").Vow<any>;
}>, E?: ((<T_3>(x: T_3) => import("../../../node_modules/@endo/eventual-send/src/E.js").ECallableOrMethods<import("@endo/eventual-send").RemoteFunctions<T_3>>) & {
readonly get: <T_1_1>(x: T_1_1) => import("../../../node_modules/@endo/eventual-send/src/E.js").EGetters<import("@endo/eventual-send").LocalRecord<T_1_1>>;
readonly resolve: {
(): Promise<void>;
<T_2_1>(value: T_2_1): Promise<Awaited<T_2_1>>;
<T_3_1>(value: T_3_1 | PromiseLike<T_3_1>): Promise<Awaited<T_3_1>>;
};
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("../../../node_modules/@endo/eventual-send/src/E.js").ERef<U>) | undefined, onrejected?: ((reason: any) => import("../../../node_modules/@endo/eventual-send/src/E.js").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<{
/**

@@ -64,3 +48,3 @@ * @param {string[]} paths

/** @param {Endpoint} localAddr */
bindPort(localAddr: string): Promise<Port | import("@agoric/vow").Vow<Port>>;
bindPort(localAddr: Endpoint): Promise<Port | import("@agoric/vow").Vow<Port>>;
}>;

@@ -92,3 +76,4 @@ /**

};
import type { VowKit } from '@agoric/vow';
import type { Endpoint } from './types.js';
import { E as defaultE } from '@endo/far';
import type { ProtocolHandler } from './types.js';

@@ -95,0 +80,0 @@ import type { Remote } from '@agoric/vow';

// @ts-check
/// <reference types="@agoric/store/exported.js" />
/// <reference path="./types.js" />
import { Fail } from '@endo/errors';
import { E as defaultE } from '@endo/far';
import { M } from '@endo/patterns';
import { Fail } from '@agoric/assert';
import { ENDPOINT_SEPARATOR, prepareNetworkProtocol } from './network.js';
import { Shape } from './shapes.js';
// XXX ambient types runtime imports until https://github.com/Agoric/agoric-sdk/issues/6512
import '@agoric/store/exported.js';
/// <reference path="./types.js" />
/**
* @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';
*/

@@ -110,3 +111,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

@@ -113,0 +114,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 @@ ),

@@ -53,3 +53,3 @@ /**

*/
connect: (remote: Endpoint, connectionHandler?: Remote<ConnectionHandler> | undefined) => PromiseVow<Connection>;
connect: (remote: Endpoint, connectionHandler?: Remote<ConnectionHandler>) => PromiseVow<Connection>;
/**

@@ -95,3 +95,3 @@ * Remove the currently-bound listener

*/
send: (packetBytes: Bytes, opts?: Record<string, any>) => PromiseVow<string>;
send: (packetBytes: Bytes, opts?: Record<string, any>) => PromiseVow<Bytes>;
/**

@@ -123,7 +123,7 @@ * Close both ends of the connection

*/
onReceive?: ((connection: Remote<Connection>, ack: Bytes, c: Remote<ConnectionHandler>, opts?: Record<string, any>) => PromiseVow<string>) | undefined;
onReceive?: ((connection: Remote<Connection>, ack: Bytes, c: Remote<ConnectionHandler>, opts?: Record<string, any>) => PromiseVow<Bytes>) | undefined;
/**
* The connection has been closed
*/
onClose?: ((connection: Remote<Connection>, reason?: CloseReason, c?: Remote<ConnectionHandler> | undefined) => PromiseVow<void>) | undefined;
onClose?: ((connection: Remote<Connection>, reason?: CloseReason, c?: Remote<ConnectionHandler>) => PromiseVow<void>) | undefined;
};

@@ -167,3 +167,3 @@ /**

*/
onInstantiate?: ((port: Remote<Port>, localAddr: Endpoint, remote: Endpoint, p: Remote<ProtocolHandler>) => PromiseVow<string>) | undefined;
onInstantiate?: ((port: Remote<Port>, localAddr: Endpoint, remote: Endpoint, p: Remote<ProtocolHandler>) => PromiseVow<Endpoint>) | undefined;
/**

@@ -219,3 +219,2 @@ * A port initiates an outbound connection

};
export type PortAllocator = ReturnType<ReturnType<typeof import("@agoric/network").preparePortAllocator>>;
import type { PromiseVow } from '@agoric/vow';

@@ -222,0 +221,0 @@ import type { RemotableObject } from '@endo/pass-style';

@@ -203,3 +203,1 @@ // @ts-check

*/
/** @typedef {ReturnType<ReturnType<typeof import('@agoric/network').preparePortAllocator>>} PortAllocator */

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc