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

Commit d31583d

Browse files
authored
fix: make connection upgrade and encryption abortable (#121)
Allow passing AbortSignals in to connection upgrading and encryption so the operations can be aborted if a timeout is reached.
1 parent c679729 commit d31583d

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

packages/libp2p-interfaces/src/crypto/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { PeerId } from '../peer-id'
22
import type { MultiaddrConnection } from '../transport'
3+
import type { AbortOptions } from '../index'
34

45
/**
56
* A libp2p crypto module must be compliant to this interface
@@ -10,11 +11,11 @@ export interface Crypto {
1011
/**
1112
* Encrypt outgoing data to the remote party.
1213
*/
13-
secureOutbound: (localPeer: PeerId, connection: MultiaddrConnection, remotePeer: PeerId) => Promise<SecureOutbound>
14+
secureOutbound: (localPeer: PeerId, connection: MultiaddrConnection, remotePeer: PeerId, options?: AbortOptions) => Promise<SecureOutbound>
1415
/**
1516
* Decrypt incoming data.
1617
*/
17-
secureInbound: (localPeer: PeerId, connection: MultiaddrConnection, remotePeer?: PeerId) => Promise<SecureOutbound>
18+
secureInbound: (localPeer: PeerId, connection: MultiaddrConnection, remotePeer?: PeerId, options?: AbortOptions) => Promise<SecureOutbound>
1819
}
1920

2021
export interface SecureOutbound {

packages/libp2p-interfaces/src/transport/index.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import type events from 'events'
22
import type { Multiaddr } from 'multiaddr'
33
import type { Connection } from '../connection'
4-
5-
export interface AbortOptions {
6-
signal?: AbortSignal
7-
}
4+
import type { AbortOptions } from '../index'
85

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

5653
/**
5754
* Upgrades an inbound connection on transport listener.
5855
*/
59-
upgradeInbound: (maConn: MultiaddrConnection) => Promise<Connection>
56+
upgradeInbound: (maConn: MultiaddrConnection, options?: AbortOptions) => Promise<Connection>
6057
}
6158

6259
export interface MultiaddrConnectionTimeline {

0 commit comments

Comments
 (0)