Skip to content

API documentation of Agoric SDK / Exports / @agoric/network / index

Module: index

Table of contents

Interfaces

Type Aliases

Variables

Functions

Type Aliases

ByteSource

Ƭ ByteSource: Bytes | Buffer | Uint8Array | Iterable<number>

Defined in

packages/network/src/bytes.js:6


Multiaddr

Ƭ Multiaddr: [string, string][]

Defined in

packages/network/src/multiaddr.js:22


Textaddr

Ƭ Textaddr: string

An address string formatted as in https://github.com/multiformats/multiaddr

Defined in

packages/network/src/multiaddr.js:24

Variables

ENDPOINT_SEPARATOR

Const ENDPOINT_SEPARATOR: "/"

Compatibility note: this must match what our peers use, so don't change it casually.

Defined in

packages/network/src/network.js:16


Shape

Const Shape: Object

Type declaration

NameTypeDescription
AttemptDescriptionMatcher-
BytesMatcher-
ConnectionMatcher-
ConnectionHandlerMatcher-
ConnectionI{ connection: InterfaceGuard<{ close: MethodGuard ; getLocalAddress: MethodGuard ; getRemoteAddress: MethodGuard ; send: MethodGuard }> ; openConnectionAckWatcher: InterfaceGuard<{ onFulfilled: MethodGuard }> ; rethrowUnlessMissingWatcher: InterfaceGuard<{ onRejected: MethodGuard }> ; sinkWatcher: InterfaceGuard<{ onFulfilled: MethodGuard }> }-
ConnectionI.connectionInterfaceGuard<{ close: MethodGuard ; getLocalAddress: MethodGuard ; getRemoteAddress: MethodGuard ; send: MethodGuard }>-
ConnectionI.openConnectionAckWatcherInterfaceGuard<{ onFulfilled: MethodGuard }>-
ConnectionI.rethrowUnlessMissingWatcherInterfaceGuard<{ onRejected: MethodGuard }>-
ConnectionI.sinkWatcherInterfaceGuard<{ onFulfilled: MethodGuard }>-
DataMatcherData is string | Buffer | ArrayBuffer but only string is passable
EndpointMatcher-
InboundAttemptMatcher-
InboundAttemptI{ inboundAttempt: InterfaceGuard<{ accept: MethodGuard ; close: MethodGuard ; getLocalAddress: MethodGuard ; getRemoteAddress: MethodGuard }> ; inboundAttemptAcceptWatcher: InterfaceGuard<{ onFulfilled: MethodGuard }> ; rethrowUnlessMissingWatcher: InterfaceGuard<{ onRejected: MethodGuard }> ; sinkWatcher: InterfaceGuard<{ onFulfilled: MethodGuard }> }-
InboundAttemptI.inboundAttemptInterfaceGuard<{ accept: MethodGuard ; close: MethodGuard ; getLocalAddress: MethodGuard ; getRemoteAddress: MethodGuard }>-
InboundAttemptI.inboundAttemptAcceptWatcherInterfaceGuard<{ onFulfilled: MethodGuard }>-
InboundAttemptI.rethrowUnlessMissingWatcherInterfaceGuard<{ onRejected: MethodGuard }>-
InboundAttemptI.sinkWatcherInterfaceGuard<{ onFulfilled: MethodGuard }>-
ListenHandlerMatcher-
ListenerMatcher-
OptsMatcher-
PortMatcher-
PortI{ port: InterfaceGuard<{ addListener: MethodGuard ; connect: MethodGuard ; getLocalAddress: MethodGuard ; removeListener: MethodGuard ; revoke: MethodGuard }> ; portAddListenerWatcher: InterfaceGuard<{ onFulfilled: MethodGuard }> ; portConnectWatcher: InterfaceGuard<{ onFulfilled: MethodGuard }> ; portRemoveListenerWatcher: InterfaceGuard<{ onFulfilled: MethodGuard }> ; portRevokeCleanupWatcher: InterfaceGuard<{ onFulfilled: MethodGuard }> ; portRevokeWatcher: InterfaceGuard<{ onFulfilled: MethodGuard }> ; rethrowUnlessMissingWatcher: InterfaceGuard<{ onRejected: MethodGuard }> ; sinkWatcher: InterfaceGuard<{ onFulfilled: MethodGuard ; onRejected: MethodGuard }> }-
PortI.portInterfaceGuard<{ addListener: MethodGuard ; connect: MethodGuard ; getLocalAddress: MethodGuard ; removeListener: MethodGuard ; revoke: MethodGuard }>-
PortI.portAddListenerWatcherInterfaceGuard<{ onFulfilled: MethodGuard }>-
PortI.portConnectWatcherInterfaceGuard<{ onFulfilled: MethodGuard }>-
PortI.portRemoveListenerWatcherInterfaceGuard<{ onFulfilled: MethodGuard }>-
PortI.portRevokeCleanupWatcherInterfaceGuard<{ onFulfilled: MethodGuard }>-
PortI.portRevokeWatcherInterfaceGuard<{ onFulfilled: MethodGuard }>-
PortI.rethrowUnlessMissingWatcherInterfaceGuard<{ onRejected: MethodGuard }>-
PortI.sinkWatcherInterfaceGuard<{ onFulfilled: MethodGuard ; onRejected: MethodGuard }>-
ProtocolHandlerMatcher-
ProtocolHandlerI{ protocolHandler: InterfaceGuard<{ generatePortID: MethodGuard ; onBind: MethodGuard ; onConnect: MethodGuard ; onCreate: MethodGuard ; onInstantiate: MethodGuard ; onListen: MethodGuard ; onListenRemove: MethodGuard ; onRevoke: MethodGuard }> ; protocolHandlerAcceptWatcher: InterfaceGuard<{ onFulfilled: MethodGuard }> ; protocolHandlerConnectWatcher: InterfaceGuard<{ onFulfilled: MethodGuard }> ; protocolHandlerInstantiateWatcher: InterfaceGuard<{ onFulfilled: MethodGuard }> ; rethrowUnlessMissingWatcher: InterfaceGuard<{ onRejected: MethodGuard }> }-
ProtocolHandlerI.protocolHandlerInterfaceGuard<{ generatePortID: MethodGuard ; onBind: MethodGuard ; onConnect: MethodGuard ; onCreate: MethodGuard ; onInstantiate: MethodGuard ; onListen: MethodGuard ; onListenRemove: MethodGuard ; onRevoke: MethodGuard }>-
ProtocolHandlerI.protocolHandlerAcceptWatcherInterfaceGuard<{ onFulfilled: MethodGuard }>-
ProtocolHandlerI.protocolHandlerConnectWatcherInterfaceGuard<{ onFulfilled: MethodGuard }>-
ProtocolHandlerI.protocolHandlerInstantiateWatcherInterfaceGuard<{ onFulfilled: MethodGuard }>-
ProtocolHandlerI.rethrowUnlessMissingWatcherInterfaceGuard<{ onRejected: MethodGuard }>-
ProtocolImplMatcher-
ProtocolImplIInterfaceGuard<{ bind: MethodGuard ; inbound: MethodGuard ; outbound: MethodGuard }>-
VowMatcher-
Vow$(shape: any) => Matcher-

Defined in

packages/network/src/shapes.js:38

Functions

base64ToBytes

base64ToBytes(string): string

Decodes a base64 string into bytes.

Parameters

NameTypeDescription
stringstringBase64-encoded string

Returns

string

decoded bytes

Defined in

packages/network/src/bytes.js:70


bytesToString

bytesToString(bytes): string

Convert bytes to a String.

Parameters

NameType
bytesstring

Returns

string

Defined in

packages/network/src/bytes.js:49


crossoverConnection

crossoverConnection(zone, handler0, addr0, handler1, addr1, makeConnection, current?): Connection[]

Parameters

NameType
zoneZone
handler0Remote<Required<ConnectionHandler>, {}>
addr0string
handler1Remote<Required<ConnectionHandler>, {}>
addr1string
makeConnection(opts: ConnectionOpts) => Connection
current?WeakSetStore<Closable>

Returns

Connection[]

Defined in

packages/network/src/network.js:168


dataToBase64

dataToBase64(byteSource): string

Base64, as specified in https://tools.ietf.org/html/rfc4648#section-4

Parameters

NameType
byteSourceByteSource

Returns

string

base64 encoding

Defined in

packages/network/src/bytes.js:59


getPrefixes

getPrefixes(addr): string[]

Get the list of prefixes from longest to shortest.

Parameters

NameType
addrstring

Returns

string[]

Defined in

packages/network/src/network.js:36


parse

parse(ma): Multiaddr

Transform a text address to a parsed multiaddr

Parameters

NameType
mastring

Returns

Multiaddr

Defined in

packages/network/src/multiaddr.js:34


prepareEchoConnectionKit

prepareEchoConnectionKit(zone): (...args: []) => GuardedKit<{ handler: { onClose: (_connection: Connection, _reason?: any, _connectionHandler?: ConnectionHandler) => Promise<void> ; onReceive: (_connection: Connection, bytes: string, _connectionHandler: ConnectionHandler) => Promise<string> } ; listener: { onAccept: (_port: any, _localAddr: any, _remoteAddr: any, _listenHandler: any) => Promise<Guarded<{ onClose: (_connection: Connection, _reason?: any, _connectionHandler?: ConnectionHandler) => Promise<void> ; onReceive: (_connection: Connection, bytes: string, _connectionHandler: ConnectionHandler) => Promise<string> }>> ; onListen: (port: any, _listenHandler: any) => Promise<void> } }>

Create a ConnectionHandler that just echoes its packets.

Parameters

NameType
zoneZone

Returns

fn

▸ (...args): GuardedKit<{ handler: { onClose: (_connection: Connection, _reason?: any, _connectionHandler?: ConnectionHandler) => Promise<void> ; onReceive: (_connection: Connection, bytes: string, _connectionHandler: ConnectionHandler) => Promise<string> } ; listener: { onAccept: (_port: any, _localAddr: any, _remoteAddr: any, _listenHandler: any) => Promise<Guarded<{ onClose: (_connection: Connection, _reason?: any, _connectionHandler?: ConnectionHandler) => Promise<void> ; onReceive: (_connection: Connection, bytes: string, _connectionHandler: ConnectionHandler) => Promise<string> }>> ; onListen: (port: any, _listenHandler: any) => Promise<void> } }>

Parameters
NameType
...args[]
Returns

GuardedKit<{ handler: { onClose: (_connection: Connection, _reason?: any, _connectionHandler?: ConnectionHandler) => Promise<void> ; onReceive: (_connection: Connection, bytes: string, _connectionHandler: ConnectionHandler) => Promise<string> } ; listener: { onAccept: (_port: any, _localAddr: any, _remoteAddr: any, _listenHandler: any) => Promise<Guarded<{ onClose: (_connection: Connection, _reason?: any, _connectionHandler?: ConnectionHandler) => Promise<void> ; onReceive: (_connection: Connection, bytes: string, _connectionHandler: ConnectionHandler) => Promise<string> }>> ; onListen: (port: any, _listenHandler: any) => Promise<void> } }>

Defined in

packages/network/src/network.js:1181


prepareLoopbackProtocolHandler

prepareLoopbackProtocolHandler(zone, powers): (instancePrefix: any) => Guarded<{ generatePortID: (_localAddr: any, _protocolHandler: any) => Promise<string> ; onBind: (_port: any, _localAddr: any, _protocolHandler: any) => Promise<void> ; onConnect: (_port: any, localAddr: string, remoteAddr: string) => PromiseVow<AttemptDescription> ; onCreate: (_impl: any, _protocolHandler: any) => Promise<void> ; onInstantiate: (_port: any, _localAddr: any, _remote: any, _protocol: any) => Promise<string> ; onListen: (port: any, localAddr: any, listenHandler: any, _protocolHandler: any) => Promise<void> ; onListenRemove: (port: Remote<Port>, localAddr: string, listenHandler: Remote<ListenHandler>, _protocolHandler: any) => Promise<void> ; onRevoke: (_port: any, _localAddr: any, _protocolHandler: any) => Promise<void> }>

Create a protocol handler that just connects to itself.

Parameters

NameType
zoneZone
powersObject
powers.allVows(vows: any) => Vow<any>
powers.makeVowKit<T>() => VowKit<T>
powers.watch<T, TResult1, TResult2>(specimenP: ERef<T | Vow<T>>, watcher?: Watcher<T, TResult1, TResult2>, watcherContext?: unknown) => Vow<TResult1 | TResult2>
powers.when<T, TResult1, TResult2>(specimenP: T, onFulfilled?: (value: Unwrap<T>) => TResult1 | PromiseLike<TResult1>, onRejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>

Returns

fn

▸ (instancePrefix): Guarded<{ generatePortID: (_localAddr: any, _protocolHandler: any) => Promise<string> ; onBind: (_port: any, _localAddr: any, _protocolHandler: any) => Promise<void> ; onConnect: (_port: any, localAddr: string, remoteAddr: string) => PromiseVow<AttemptDescription> ; onCreate: (_impl: any, _protocolHandler: any) => Promise<void> ; onInstantiate: (_port: any, _localAddr: any, _remote: any, _protocol: any) => Promise<string> ; onListen: (port: any, localAddr: any, listenHandler: any, _protocolHandler: any) => Promise<void> ; onListenRemove: (port: Remote<Port>, localAddr: string, listenHandler: Remote<ListenHandler>, _protocolHandler: any) => Promise<void> ; onRevoke: (_port: any, _localAddr: any, _protocolHandler: any) => Promise<void> }>

Parameters
NameType
instancePrefixany
Returns

Guarded<{ generatePortID: (_localAddr: any, _protocolHandler: any) => Promise<string> ; onBind: (_port: any, _localAddr: any, _protocolHandler: any) => Promise<void> ; onConnect: (_port: any, localAddr: string, remoteAddr: string) => PromiseVow<AttemptDescription> ; onCreate: (_impl: any, _protocolHandler: any) => Promise<void> ; onInstantiate: (_port: any, _localAddr: any, _remote: any, _protocol: any) => Promise<string> ; onListen: (port: any, localAddr: any, listenHandler: any, _protocolHandler: any) => Promise<void> ; onListenRemove: (port: Remote<Port>, localAddr: string, listenHandler: Remote<ListenHandler>, _protocolHandler: any) => Promise<void> ; onRevoke: (_port: any, _localAddr: any, _protocolHandler: any) => Promise<void> }>

Defined in

packages/network/src/network.js:1265


prepareNetworkProtocol

prepareNetworkProtocol(zone, powers): (protocolHandler: Remote<ProtocolHandler>) => Protocol

Parameters

NameType
zoneZone
powersObject
powers.allVows(vows: any) => Vow<any>
powers.makeVowKit<T>() => VowKit<T>
powers.watch<T, TResult1, TResult2>(specimenP: ERef<T | Vow<T>>, watcher?: Watcher<T, TResult1, TResult2>, watcherContext?: unknown) => Vow<TResult1 | TResult2>
powers.when<T, TResult1, TResult2>(specimenP: T, onFulfilled?: (value: Unwrap<T>) => TResult1 | PromiseLike<TResult1>, onRejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>

Returns

fn

▸ (protocolHandler): Protocol

Parameters
NameType
protocolHandlerRemote<ProtocolHandler>
Returns

Protocol

Defined in

packages/network/src/network.js:1142


prepareRouter

prepareRouter<T>(zone): (...args: []) => Guarded<{ getRoutes: (addr: string) => [string, T][] ; register: (prefix: string, route: T) => void ; unregister: (prefix: string, route: T) => void }>

Type parameters

Name
T

Parameters

NameType
zoneZone

Returns

fn

▸ (...args): Guarded<{ getRoutes: (addr: string) => [string, T][] ; register: (prefix: string, route: T) => void ; unregister: (prefix: string, route: T) => void }>

Parameters
NameType
...args[]
Returns

Guarded<{ getRoutes: (addr: string) => [string, T][] ; register: (prefix: string, route: T) => void ; unregister: (prefix: string, route: T) => void }>

Defined in

packages/network/src/router.js:32


prepareRouterProtocol

prepareRouterProtocol(zone, powers, E?): (...args: []) => Guarded<{ bind: (localAddr: string) => Promise<Port | Vow<Port>> ; registerProtocolHandler: (paths: string[], protocolHandler: Remote<ProtocolHandler>) => void ; unregisterProtocolHandler: (prefix: string, protocolHandler: Remote<ProtocolHandler>) => void }>

Create a router that behaves like a Protocol.

Parameters

NameTypeDefault valueDescription
zoneZoneundefined-
powersObjectundefined-
powers.allVows(vows: any) => Vow<any>undefined-
powers.makeVowKit<T>() => VowKit<T>undefined-
powers.watch<T, TResult1, TResult2>(specimenP: ERef<T | Vow<T>>, watcher?: Watcher<T, TResult1, TResult2>, watcherContext?: unknown) => Vow<TResult1 | TResult2>undefined-
powers.when<T, TResult1, TResult2>(specimenP: T, onFulfilled?: (value: Unwrap<T>) => TResult1 | PromiseLike<TResult1>, onRejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>undefinedShorten specimenP until we achieve a final result.
E?<T>(x: T) => ECallableOrMethods<RemoteFunctions<T>> & { get: <T_1>(x: T_1) => EGetters<LocalRecord<T_1>> ; resolve: () => Promise<void><T_2>(value: T_2) => Promise<Awaited<T_2>><T_3>(value: T_3 | PromiseLike<T_3>) => Promise<Awaited<T_3>> ; sendOnly: <T_4>(x: T_4) => ESendOnlyCallableOrMethods<RemoteFunctions<T_4>> ; when: <T_5, U>(x: T_5 | PromiseLike<T_5>, onfulfilled?: (value: T_5) => ERef<U>, onrejected?: (reason: any) => ERef<U>) => Promise<U> }defaultEEventual sender

Returns

fn

▸ (...args): Guarded<{ bind: (localAddr: string) => Promise<Port | Vow<Port>> ; registerProtocolHandler: (paths: string[], protocolHandler: Remote<ProtocolHandler>) => void ; unregisterProtocolHandler: (prefix: string, protocolHandler: Remote<ProtocolHandler>) => void }>

Parameters
NameType
...args[]
Returns

Guarded<{ bind: (localAddr: string) => Promise<Port | Vow<Port>> ; registerProtocolHandler: (paths: string[], protocolHandler: Remote<ProtocolHandler>) => void ; unregisterProtocolHandler: (prefix: string, protocolHandler: Remote<ProtocolHandler>) => void }>

Defined in

packages/network/src/router.js:108


rethrowUnlessMissing

rethrowUnlessMissing(err): undefined

Parameters

NameType
errunknown

Returns

undefined

Defined in

packages/network/src/network.js:19


toBytes

toBytes(byteSource): string

Convert a Uint8Array or other sequence of octets to a string representation that @endo/marshal accepts as Passable.

Parameters

NameType
byteSourceByteSource

Returns

string

Defined in

packages/network/src/bytes.js:36


unparse

unparse(ma): string

Transform a parsed multiaddr to a string.

Parameters

NameType
mastring | Multiaddr

Returns

string

Defined in

packages/network/src/multiaddr.js:66