@libp2p/circuit-relay-v2 1.0.24 → 1.0.25-44791342
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +5 -5
- package/dist/src/constants.d.ts +13 -12
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +13 -12
- package/dist/src/constants.js.map +1 -1
- package/dist/src/pb/index.d.ts +7 -7
- package/dist/src/pb/index.d.ts.map +1 -1
- package/dist/src/pb/index.js +94 -52
- package/dist/src/pb/index.js.map +1 -1
- package/dist/src/server/index.d.ts +1 -7
- package/dist/src/server/index.d.ts.map +1 -1
- package/dist/src/server/index.js +10 -19
- package/dist/src/server/index.js.map +1 -1
- package/dist/src/server/reservation-store.d.ts +2 -3
- package/dist/src/server/reservation-store.d.ts.map +1 -1
- package/dist/src/server/reservation-store.js.map +1 -1
- package/dist/src/transport/discovery.d.ts +15 -10
- package/dist/src/transport/discovery.d.ts.map +1 -1
- package/dist/src/transport/discovery.js +103 -51
- package/dist/src/transport/discovery.js.map +1 -1
- package/dist/src/transport/index.d.ts +27 -18
- package/dist/src/transport/index.d.ts.map +1 -1
- package/dist/src/transport/index.js +0 -3
- package/dist/src/transport/index.js.map +1 -1
- package/dist/src/transport/reservation-store.d.ts +7 -3
- package/dist/src/transport/reservation-store.d.ts.map +1 -1
- package/dist/src/transport/reservation-store.js +37 -13
- package/dist/src/transport/reservation-store.js.map +1 -1
- package/dist/src/transport/transport.d.ts +0 -1
- package/dist/src/transport/transport.d.ts.map +1 -1
- package/dist/src/transport/transport.js +20 -19
- package/dist/src/transport/transport.js.map +1 -1
- package/package.json +12 -13
- package/src/constants.ts +16 -15
- package/src/pb/index.ts +96 -53
- package/src/server/index.ts +11 -29
- package/src/server/reservation-store.ts +2 -4
- package/src/transport/discovery.ts +121 -56
- package/src/transport/index.ts +28 -18
- package/src/transport/reservation-store.ts +45 -13
- package/src/transport/transport.ts +21 -21
- package/dist/src/server/advert-service.d.ts +0 -44
- package/dist/src/server/advert-service.d.ts.map +0 -1
- package/dist/src/server/advert-service.js +0 -72
- package/dist/src/server/advert-service.js.map +0 -1
- package/dist/typedoc-urls.json +0 -12
- package/src/server/advert-service.ts +0 -107
@@ -1,72 +0,0 @@
|
|
1
|
-
import { TypedEventEmitter } from '@libp2p/interface';
|
2
|
-
import pRetry from 'p-retry';
|
3
|
-
import { DEFAULT_ADVERT_BOOT_DELAY, ERR_NO_ROUTERS_AVAILABLE, RELAY_RENDEZVOUS_NS } from '../constants.js';
|
4
|
-
import { namespaceToCid } from '../utils.js';
|
5
|
-
export class AdvertService extends TypedEventEmitter {
|
6
|
-
contentRouting;
|
7
|
-
timeout;
|
8
|
-
started;
|
9
|
-
bootDelay;
|
10
|
-
log;
|
11
|
-
/**
|
12
|
-
* Creates an instance of Relay
|
13
|
-
*/
|
14
|
-
constructor(components, init) {
|
15
|
-
super();
|
16
|
-
this.log = components.logger.forComponent('libp2p:circuit-relay:advert-service');
|
17
|
-
this.contentRouting = components.contentRouting;
|
18
|
-
this.bootDelay = init?.bootDelay ?? DEFAULT_ADVERT_BOOT_DELAY;
|
19
|
-
this.started = false;
|
20
|
-
}
|
21
|
-
isStarted() {
|
22
|
-
return this.started;
|
23
|
-
}
|
24
|
-
/**
|
25
|
-
* Start Relay service
|
26
|
-
*/
|
27
|
-
start() {
|
28
|
-
if (this.started) {
|
29
|
-
return;
|
30
|
-
}
|
31
|
-
// Advertise service if HOP enabled and advertising enabled
|
32
|
-
this.timeout = setTimeout(() => {
|
33
|
-
this._advertiseService().catch(err => {
|
34
|
-
this.log.error('could not advertise service', err);
|
35
|
-
});
|
36
|
-
}, this.bootDelay);
|
37
|
-
this.started = true;
|
38
|
-
}
|
39
|
-
/**
|
40
|
-
* Stop Relay service
|
41
|
-
*/
|
42
|
-
stop() {
|
43
|
-
try {
|
44
|
-
clearTimeout(this.timeout);
|
45
|
-
}
|
46
|
-
catch (err) { }
|
47
|
-
this.started = false;
|
48
|
-
}
|
49
|
-
/**
|
50
|
-
* Advertise hop relay service in the network.
|
51
|
-
*/
|
52
|
-
async _advertiseService() {
|
53
|
-
await pRetry(async () => {
|
54
|
-
try {
|
55
|
-
const cid = await namespaceToCid(RELAY_RENDEZVOUS_NS);
|
56
|
-
await this.contentRouting.provide(cid);
|
57
|
-
this.safeDispatchEvent('advert:success', { detail: undefined });
|
58
|
-
}
|
59
|
-
catch (err) {
|
60
|
-
this.safeDispatchEvent('advert:error', { detail: err });
|
61
|
-
if (err.code === ERR_NO_ROUTERS_AVAILABLE) {
|
62
|
-
this.log.error('a content router, such as a DHT, must be provided in order to advertise the relay service', err);
|
63
|
-
this.stop();
|
64
|
-
return;
|
65
|
-
}
|
66
|
-
this.log.error('could not advertise service', err);
|
67
|
-
throw err;
|
68
|
-
}
|
69
|
-
});
|
70
|
-
}
|
71
|
-
}
|
72
|
-
//# sourceMappingURL=advert-service.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"advert-service.js","sourceRoot":"","sources":["../../../src/server/advert-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,MAAM,MAAM,SAAS,CAAA;AAC5B,OAAO,EACL,yBAAyB,EACzB,wBAAwB,EACxB,mBAAmB,EACpB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAuB5C,MAAM,OAAO,aAAc,SAAQ,iBAAsC;IACtD,cAAc,CAAgB;IACvC,OAAO,CAAM;IACb,OAAO,CAAS;IACP,SAAS,CAAQ;IACjB,GAAG,CAAQ;IAE5B;;OAEG;IACH,YAAa,UAAmC,EAAE,IAAwB;QACxE,KAAK,EAAE,CAAA;QAEP,IAAI,CAAC,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC,qCAAqC,CAAC,CAAA;QAChF,IAAI,CAAC,cAAc,GAAG,UAAU,CAAC,cAAc,CAAA;QAC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AG,EAAE,CAAC,CAAA;gBAEvD,IAAI,GAAG,CAAC,IAAI,KAAK,wBAAwB,EAAE,CAAC;oBAC1C,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,2FAA2F,EAAE,GAAG,CAAC,CAAA;oBAChH,IAAI,CAAC,IAAI,EAAE,CAAA;oBACX,OAAM;gBACR,CAAC;gBAED,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAA;gBAClD,MAAM,GAAG,CAAA;YACX,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;CACF"}
|
package/dist/typedoc-urls.json
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"CircuitRelayService": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_circuit_relay_v2.CircuitRelayService.html",
|
3
|
-
".:CircuitRelayService": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_circuit_relay_v2.CircuitRelayService.html",
|
4
|
-
"CircuitRelayServiceEvents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_circuit_relay_v2.CircuitRelayServiceEvents.html",
|
5
|
-
".:CircuitRelayServiceEvents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_circuit_relay_v2.CircuitRelayServiceEvents.html",
|
6
|
-
"RelayReservation": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_circuit_relay_v2.RelayReservation.html",
|
7
|
-
".:RelayReservation": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_circuit_relay_v2.RelayReservation.html",
|
8
|
-
"RELAY_V2_HOP_CODEC": "https://libp2p.github.io/js-libp2p/variables/_libp2p_circuit_relay_v2.RELAY_V2_HOP_CODEC.html",
|
9
|
-
"RELAY_V2_STOP_CODEC": "https://libp2p.github.io/js-libp2p/variables/_libp2p_circuit_relay_v2.RELAY_V2_STOP_CODEC.html",
|
10
|
-
"circuitRelayServer": "https://libp2p.github.io/js-libp2p/functions/_libp2p_circuit_relay_v2.circuitRelayServer.html",
|
11
|
-
"circuitRelayTransport": "https://libp2p.github.io/js-libp2p/functions/_libp2p_circuit_relay_v2.circuitRelayTransport.html"
|
12
|
-
}
|
@@ -1,107 +0,0 @@
|
|
1
|
-
import { TypedEventEmitter } from '@libp2p/interface'
|
2
|
-
import pRetry from 'p-retry'
|
3
|
-
import {
|
4
|
-
DEFAULT_ADVERT_BOOT_DELAY,
|
5
|
-
ERR_NO_ROUTERS_AVAILABLE,
|
6
|
-
RELAY_RENDEZVOUS_NS
|
7
|
-
} from '../constants.js'
|
8
|
-
import { namespaceToCid } from '../utils.js'
|
9
|
-
import type { ComponentLogger, Logger, ContentRouting, Startable } from '@libp2p/interface'
|
10
|
-
|
11
|
-
export interface AdvertServiceInit {
|
12
|
-
/**
|
13
|
-
* How long to wait after startup to begin advertising the service
|
14
|
-
* - if some configured content routers take a while to warm up (for
|
15
|
-
* example, the DHT needs some peers to be able to publish) this
|
16
|
-
* value should be high enough that they will have warmed up
|
17
|
-
*/
|
18
|
-
bootDelay?: number
|
19
|
-
}
|
20
|
-
|
21
|
-
export interface AdvertServiceComponents {
|
22
|
-
contentRouting: ContentRouting
|
23
|
-
logger: ComponentLogger
|
24
|
-
}
|
25
|
-
|
26
|
-
export interface AdvertServiceEvents {
|
27
|
-
'advert:success': CustomEvent<unknown>
|
28
|
-
'advert:error': CustomEvent<Error>
|
29
|
-
}
|
30
|
-
|
31
|
-
export class AdvertService extends TypedEventEmitter<AdvertServiceEvents> implements Startable {
|
32
|
-
private readonly contentRouting: ContentRouting
|
33
|
-
private timeout?: any
|
34
|
-
private started: boolean
|
35
|
-
private readonly bootDelay: number
|
36
|
-
private readonly log: Logger
|
37
|
-
|
38
|
-
/**
|
39
|
-
* Creates an instance of Relay
|
40
|
-
*/
|
41
|
-
constructor (components: AdvertServiceComponents, init?: AdvertServiceInit) {
|
42
|
-
super()
|
43
|
-
|
44
|
-
this.log = components.logger.forComponent('libp2p:circuit-relay:advert-service')
|
45
|
-
this.contentRouting = components.contentRouting
|
46
|
-
this.bootDelay = init?.bootDelay ?? DEFAULT_ADVERT_BOOT_DELAY
|
47
|
-
this.started = false
|
48
|
-
}
|
49
|
-
|
50
|
-
isStarted (): boolean {
|
51
|
-
return this.started
|
52
|
-
}
|
53
|
-
|
54
|
-
/**
|
55
|
-
* Start Relay service
|
56
|
-
*/
|
57
|
-
start (): void {
|
58
|
-
if (this.started) {
|
59
|
-
return
|
60
|
-
}
|
61
|
-
|
62
|
-
// Advertise service if HOP enabled and advertising enabled
|
63
|
-
this.timeout = setTimeout(() => {
|
64
|
-
this._advertiseService().catch(err => {
|
65
|
-
this.log.error('could not advertise service', err)
|
66
|
-
})
|
67
|
-
}, this.bootDelay)
|
68
|
-
|
69
|
-
this.started = true
|
70
|
-
}
|
71
|
-
|
72
|
-
/**
|
73
|
-
* Stop Relay service
|
74
|
-
*/
|
75
|
-
stop (): void {
|
76
|
-
try {
|
77
|
-
clearTimeout(this.timeout)
|
78
|
-
} catch (err) { }
|
79
|
-
|
80
|
-
this.started = false
|
81
|
-
}
|
82
|
-
|
83
|
-
/**
|
84
|
-
* Advertise hop relay service in the network.
|
85
|
-
*/
|
86
|
-
async _advertiseService (): Promise<void> {
|
87
|
-
await pRetry(async () => {
|
88
|
-
try {
|
89
|
-
const cid = await namespaceToCid(RELAY_RENDEZVOUS_NS)
|
90
|
-
await this.contentRouting.provide(cid)
|
91
|
-
|
92
|
-
this.safeDispatchEvent('advert:success', { detail: undefined })
|
93
|
-
} catch (err: any) {
|
94
|
-
this.safeDispatchEvent('advert:error', { detail: err })
|
95
|
-
|
96
|
-
if (err.code === ERR_NO_ROUTERS_AVAILABLE) {
|
97
|
-
this.log.error('a content router, such as a DHT, must be provided in order to advertise the relay service', err)
|
98
|
-
this.stop()
|
99
|
-
return
|
100
|
-
}
|
101
|
-
|
102
|
-
this.log.error('could not advertise service', err)
|
103
|
-
throw err
|
104
|
-
}
|
105
|
-
})
|
106
|
-
}
|
107
|
-
}
|