API documentation of Agoric SDK / Exports / @agoric/network / index
Module: index
Table of contents
Interfaces
Type Aliases
Variables
Functions
- base64ToBytes
- bytesToString
- crossoverConnection
- dataToBase64
- getPrefixes
- parse
- prepareEchoConnectionKit
- prepareLoopbackProtocolHandler
- prepareNetworkProtocol
- prepareRouter
- prepareRouterProtocol
- rethrowUnlessMissing
- toBytes
- unparse
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
| Name | Type | Description |
|---|---|---|
AttemptDescription | Matcher | - |
Bytes | Matcher | - |
Connection | Matcher | - |
ConnectionHandler | Matcher | - |
ConnectionI | { connection: InterfaceGuard<{ close: MethodGuard ; getLocalAddress: MethodGuard ; getRemoteAddress: MethodGuard ; send: MethodGuard }> ; openConnectionAckWatcher: InterfaceGuard<{ onFulfilled: MethodGuard }> ; rethrowUnlessMissingWatcher: InterfaceGuard<{ onRejected: MethodGuard }> ; sinkWatcher: InterfaceGuard<{ onFulfilled: MethodGuard }> } | - |
ConnectionI.connection | InterfaceGuard<{ close: MethodGuard ; getLocalAddress: MethodGuard ; getRemoteAddress: MethodGuard ; send: MethodGuard }> | - |
ConnectionI.openConnectionAckWatcher | InterfaceGuard<{ onFulfilled: MethodGuard }> | - |
ConnectionI.rethrowUnlessMissingWatcher | InterfaceGuard<{ onRejected: MethodGuard }> | - |
ConnectionI.sinkWatcher | InterfaceGuard<{ onFulfilled: MethodGuard }> | - |
Data | Matcher | Data is string | Buffer | ArrayBuffer but only string is passable |
Endpoint | Matcher | - |
InboundAttempt | Matcher | - |
InboundAttemptI | { inboundAttempt: InterfaceGuard<{ accept: MethodGuard ; close: MethodGuard ; getLocalAddress: MethodGuard ; getRemoteAddress: MethodGuard }> ; inboundAttemptAcceptWatcher: InterfaceGuard<{ onFulfilled: MethodGuard }> ; rethrowUnlessMissingWatcher: InterfaceGuard<{ onRejected: MethodGuard }> ; sinkWatcher: InterfaceGuard<{ onFulfilled: MethodGuard }> } | - |
InboundAttemptI.inboundAttempt | InterfaceGuard<{ accept: MethodGuard ; close: MethodGuard ; getLocalAddress: MethodGuard ; getRemoteAddress: MethodGuard }> | - |
InboundAttemptI.inboundAttemptAcceptWatcher | InterfaceGuard<{ onFulfilled: MethodGuard }> | - |
InboundAttemptI.rethrowUnlessMissingWatcher | InterfaceGuard<{ onRejected: MethodGuard }> | - |
InboundAttemptI.sinkWatcher | InterfaceGuard<{ onFulfilled: MethodGuard }> | - |
ListenHandler | Matcher | - |
Listener | Matcher | - |
Opts | Matcher | - |
Port | Matcher | - |
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.port | InterfaceGuard<{ addListener: MethodGuard ; connect: MethodGuard ; getLocalAddress: MethodGuard ; removeListener: MethodGuard ; revoke: MethodGuard }> | - |
PortI.portAddListenerWatcher | InterfaceGuard<{ onFulfilled: MethodGuard }> | - |
PortI.portConnectWatcher | InterfaceGuard<{ onFulfilled: MethodGuard }> | - |
PortI.portRemoveListenerWatcher | InterfaceGuard<{ onFulfilled: MethodGuard }> | - |
PortI.portRevokeCleanupWatcher | InterfaceGuard<{ onFulfilled: MethodGuard }> | - |
PortI.portRevokeWatcher | InterfaceGuard<{ onFulfilled: MethodGuard }> | - |
PortI.rethrowUnlessMissingWatcher | InterfaceGuard<{ onRejected: MethodGuard }> | - |
PortI.sinkWatcher | InterfaceGuard<{ onFulfilled: MethodGuard ; onRejected: MethodGuard }> | - |
ProtocolHandler | Matcher | - |
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.protocolHandler | InterfaceGuard<{ generatePortID: MethodGuard ; onBind: MethodGuard ; onConnect: MethodGuard ; onCreate: MethodGuard ; onInstantiate: MethodGuard ; onListen: MethodGuard ; onListenRemove: MethodGuard ; onRevoke: MethodGuard }> | - |
ProtocolHandlerI.protocolHandlerAcceptWatcher | InterfaceGuard<{ onFulfilled: MethodGuard }> | - |
ProtocolHandlerI.protocolHandlerConnectWatcher | InterfaceGuard<{ onFulfilled: MethodGuard }> | - |
ProtocolHandlerI.protocolHandlerInstantiateWatcher | InterfaceGuard<{ onFulfilled: MethodGuard }> | - |
ProtocolHandlerI.rethrowUnlessMissingWatcher | InterfaceGuard<{ onRejected: MethodGuard }> | - |
ProtocolImpl | Matcher | - |
ProtocolImplI | InterfaceGuard<{ bind: MethodGuard ; inbound: MethodGuard ; outbound: MethodGuard }> | - |
Vow | Matcher | - |
Vow$ | (shape: any) => Matcher | - |
Defined in
packages/network/src/shapes.js:38
Functions
base64ToBytes
▸ base64ToBytes(string): string
Decodes a base64 string into bytes.
Parameters
| Name | Type | Description |
|---|---|---|
string | string | Base64-encoded string |
Returns
string
decoded bytes
Defined in
packages/network/src/bytes.js:70
bytesToString
▸ bytesToString(bytes): string
Convert bytes to a String.
Parameters
| Name | Type |
|---|---|
bytes | string |
Returns
string
Defined in
packages/network/src/bytes.js:49
crossoverConnection
▸ crossoverConnection(zone, handler0, addr0, handler1, addr1, makeConnection, current?): Connection[]
Parameters
| Name | Type |
|---|---|
zone | Zone |
handler0 | Remote<Required<ConnectionHandler>, {}> |
addr0 | string |
handler1 | Remote<Required<ConnectionHandler>, {}> |
addr1 | string |
makeConnection | (opts: ConnectionOpts) => Connection |
current? | WeakSetStore<Closable> |
Returns
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
| Name | Type |
|---|---|
byteSource | ByteSource |
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
| Name | Type |
|---|---|
addr | string |
Returns
string[]
Defined in
packages/network/src/network.js:36
parse
▸ parse(ma): Multiaddr
Transform a text address to a parsed multiaddr
Parameters
| Name | Type |
|---|---|
ma | string |
Returns
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
| Name | Type |
|---|---|
zone | Zone |
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
| Name | Type |
|---|---|
...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
| Name | Type |
|---|---|
zone | Zone |
powers | Object |
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
| Name | Type |
|---|---|
instancePrefix | any |
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
| Name | Type |
|---|---|
zone | Zone |
powers | Object |
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
| Name | Type |
|---|---|
protocolHandler | Remote<ProtocolHandler> |
Returns
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
| Name | Type |
|---|---|
zone | Zone |
Returns
fn
▸ (...args): Guarded<{ getRoutes: (addr: string) => [string, T][] ; register: (prefix: string, route: T) => void ; unregister: (prefix: string, route: T) => void }>
Parameters
| Name | Type |
|---|---|
...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
| Name | Type | Default value | Description |
|---|---|---|---|
zone | Zone | undefined | - |
powers | Object | undefined | - |
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> | undefined | Shorten 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> } | defaultE | Eventual 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
| Name | Type |
|---|---|
...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
| Name | Type |
|---|---|
err | unknown |
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
| Name | Type |
|---|---|
byteSource | ByteSource |
Returns
string
Defined in
packages/network/src/bytes.js:36
unparse
▸ unparse(ma): string
Transform a parsed multiaddr to a string.
Parameters
| Name | Type |
|---|---|
ma | string | Multiaddr |
Returns
string