-
Notifications
You must be signed in to change notification settings - Fork 443
/
index.ts
69 lines (63 loc) · 1.87 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
/**
* @packageDocumentation
*
* The `circuitRelayTransport` allows libp2p to dial and listen on [Circuit Relay](https://docs.libp2p.io/concepts/nat/circuit-relay/)
* addresses.
*
* @example Use as a transport
*
* Configuring a transport will let you dial other circuit relay addresses.
*
* ```typescript
* import { createLibp2p } from 'libp2p'
* import { circuitRelayTransport } from '@libp2p/circuit-relay-v2'
*
* const node = await createLibp2p({
* transports: [
* circuitRelayTransport()
* ]
* })
* ```
*
* The `circuitRelayServer` function allows libp2p to function as a [Circuit Relay](https://docs.libp2p.io/concepts/nat/circuit-relay/)
* server. This will not work in browsers.
*
* @example Use as a server
*
* Configuring a server will let you function as a network relay for other
* nodes.
*
* ```typescript
* import { createLibp2p } from 'libp2p'
* import { circuitRelayServer } from '@libp2p/circuit-relay-v2'
*
* const node = await createLibp2p({
* services: {
* circuitRelay: circuitRelayServer()
* }
* })
* ```
*/
import type { Limit } from './pb/index.js'
import type { TypedEventEmitter } from '@libp2p/interface'
import type { PeerMap } from '@libp2p/peer-collections'
import type { Multiaddr } from '@multiformats/multiaddr'
export interface RelayReservation {
expire: Date
addr: Multiaddr
limit?: Limit
}
export interface CircuitRelayServiceEvents {
'relay:reservation': CustomEvent<RelayReservation>
'relay:advert:success': CustomEvent<unknown>
'relay:advert:error': CustomEvent<Error>
}
export interface CircuitRelayService extends TypedEventEmitter<CircuitRelayServiceEvents> {
reservations: PeerMap<RelayReservation>
}
export { circuitRelayServer } from './server/index.js'
export { circuitRelayTransport } from './transport/index.js'
export {
RELAY_V2_HOP_CODEC,
RELAY_V2_STOP_CODEC
} from './constants.js'