Skip to content
This repository was archived by the owner on Jun 26, 2023. It is now read-only.

fix: make connection upgrade and encryption abortable #121

Merged
merged 1 commit into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/libp2p-interfaces/src/crypto/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { PeerId } from '../peer-id'
import type { MultiaddrConnection } from '../transport'
import type { AbortOptions } from '../index'

/**
* A libp2p crypto module must be compliant to this interface
Expand All @@ -10,11 +11,11 @@ export interface Crypto {
/**
* Encrypt outgoing data to the remote party.
*/
secureOutbound: (localPeer: PeerId, connection: MultiaddrConnection, remotePeer: PeerId) => Promise<SecureOutbound>
secureOutbound: (localPeer: PeerId, connection: MultiaddrConnection, remotePeer: PeerId, options?: AbortOptions) => Promise<SecureOutbound>
/**
* Decrypt incoming data.
*/
secureInbound: (localPeer: PeerId, connection: MultiaddrConnection, remotePeer?: PeerId) => Promise<SecureOutbound>
secureInbound: (localPeer: PeerId, connection: MultiaddrConnection, remotePeer?: PeerId, options?: AbortOptions) => Promise<SecureOutbound>
}

export interface SecureOutbound {
Expand Down
9 changes: 3 additions & 6 deletions packages/libp2p-interfaces/src/transport/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import type events from 'events'
import type { Multiaddr } from 'multiaddr'
import type { Connection } from '../connection'

export interface AbortOptions {
signal?: AbortSignal
}
import type { AbortOptions } from '../index'

export interface TransportFactory<DialOptions extends { signal?: AbortSignal }, ListenerOptions> {
new(upgrader: Upgrader): Transport<DialOptions, ListenerOptions>
Expand Down Expand Up @@ -51,12 +48,12 @@ export interface Upgrader {
/**
* Upgrades an outbound connection on `transport.dial`.
*/
upgradeOutbound: (maConn: MultiaddrConnection) => Promise<Connection>
upgradeOutbound: (maConn: MultiaddrConnection, options?: AbortOptions) => Promise<Connection>

/**
* Upgrades an inbound connection on transport listener.
*/
upgradeInbound: (maConn: MultiaddrConnection) => Promise<Connection>
upgradeInbound: (maConn: MultiaddrConnection, options?: AbortOptions) => Promise<Connection>
}

export interface MultiaddrConnectionTimeline {
Expand Down