-
Notifications
You must be signed in to change notification settings - Fork 443
/
index.ts
71 lines (63 loc) · 2.11 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { CircuitRelayTransport } from './transport.js'
import type { RelayDiscoveryComponents } from './discovery.js'
import type { RelayStoreInit } from './reservation-store.js'
import type { Transport, Upgrader, Libp2pEvents, ConnectionGater, TypedEventTarget, PeerId, TopologyFilter } from '@libp2p/interface'
import type { AddressManager, Registrar } from '@libp2p/interface-internal'
export interface CircuitRelayTransportComponents extends RelayDiscoveryComponents {
peerId: PeerId
registrar: Registrar
upgrader: Upgrader
addressManager: AddressManager
connectionGater: ConnectionGater
events: TypedEventTarget<Libp2pEvents>
}
/**
* RelayConfig configures the circuit v2 relay transport.
*/
export interface CircuitRelayTransportInit extends RelayStoreInit {
/**
* The number of peers running diable relays to search for and connect to
*
* @default 0
*/
discoverRelays?: number
/**
* An optional filter used to prevent duplicate attempts to reserve relay
* slots on the same peer
*/
discoveryFilter?: TopologyFilter
/**
* The maximum number of simultaneous STOP inbound streams that can be open at
* once - each inbound relayed connection uses a STOP stream
*
* @default 300
*/
maxInboundStopStreams?: number
/**
* The maximum number of simultaneous STOP outbound streams that can be open
* at once. If this transport is used along with the relay server these
* settings should be set to the same value
*
* @default 300
*/
maxOutboundStopStreams?: number
/**
* Incoming STOP requests (e.g. when a remote peer wants to dial us via a
* relay) must finish the initial protocol negotiation within this timeout in
* ms
*
* @default 30000
*/
stopTimeout?: number
/**
* When creating a reservation it must complete within this number of ms
*
* @default 10000
*/
reservationCompletionTimeout?: number
}
export function circuitRelayTransport (init: CircuitRelayTransportInit = {}): (components: CircuitRelayTransportComponents) => Transport {
return (components) => {
return new CircuitRelayTransport(components, init)
}
}