@libp2p/daemon-server 0.0.0
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/LICENSE +4 -0
- package/README.md +43 -0
- package/dist/src/client.d.ts +26 -0
- package/dist/src/client.d.ts.map +1 -0
- package/dist/src/client.js +43 -0
- package/dist/src/client.js.map +1 -0
- package/dist/src/dht.d.ts +18 -0
- package/dist/src/dht.d.ts.map +1 -0
- package/dist/src/dht.js +127 -0
- package/dist/src/dht.js.map +1 -0
- package/dist/src/index.d.ts +103 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +395 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/pubsub.d.ts +12 -0
- package/dist/src/pubsub.d.ts.map +1 -0
- package/dist/src/pubsub.js +39 -0
- package/dist/src/pubsub.js.map +1 -0
- package/dist/src/responses.d.ts +10 -0
- package/dist/src/responses.d.ts.map +1 -0
- package/dist/src/responses.js +22 -0
- package/dist/src/responses.js.map +1 -0
- package/dist/src/stream-handler.d.ts +28 -0
- package/dist/src/stream-handler.d.ts.map +1 -0
- package/dist/src/stream-handler.js +47 -0
- package/dist/src/stream-handler.js.map +1 -0
- package/dist/src/util/index.d.ts +13 -0
- package/dist/src/util/index.d.ts.map +1 -0
- package/dist/src/util/index.js +26 -0
- package/dist/src/util/index.js.map +1 -0
- package/package.json +165 -0
- package/src/client.ts +56 -0
- package/src/dht.ts +153 -0
- package/src/index.ts +513 -0
- package/src/pubsub.ts +57 -0
- package/src/responses.ts +23 -0
- package/src/stream-handler.ts +65 -0
- package/src/util/index.ts +30 -0
package/LICENSE
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
libp2p-daemon JavaScript implementation
|
|
2
|
+
======
|
|
3
|
+
|
|
4
|
+
<a href="http://libp2p.io/"><img src="https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square" /></a>
|
|
5
|
+
<a href="http://webchat.freenode.net/?channels=%23libp2p"><img src="https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square" /></a>
|
|
6
|
+
<a href="https://discuss.libp2p.io"><img src="https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg" /></a>
|
|
7
|
+
<a href="https://waffle.io/libp2p/libp2p"><img src="https://img.shields.io/badge/pm-waffle-yellow.svg?style=flat-square" /></a>
|
|
8
|
+
|
|
9
|
+
> A standalone deployment of a libp2p host, running in its own OS process and installing a set of virtual endpoints to enable co-local applications to: communicate with peers, handle protocols, interact with the DHT, participate in pubsub, etc. no matter the language they are developed in, nor whether a native libp2p implementation exists in that language.
|
|
10
|
+
|
|
11
|
+
## Lead Maintainer
|
|
12
|
+
|
|
13
|
+
[Jacob Heun](https://github.com/jacobheun)
|
|
14
|
+
|
|
15
|
+
## Specs
|
|
16
|
+
|
|
17
|
+
The specs for the daemon are currently housed in the go implementation. You can read them at [libp2p/go-libp2p-daemon](https://github.com/libp2p/go-libp2p-daemon/blob/master/specs/README.md)
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
npm i -g libp2p-daemon
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
For a full list of options, you can run help `jsp2pd --help`.
|
|
28
|
+
Running the defaults, `jsp2pd`, will start the daemon and bind it to a local unix socket path.
|
|
29
|
+
Daemon clients will be able to communicate with the daemon over that unix socket.
|
|
30
|
+
|
|
31
|
+
As an alternative, you can use this daemon with a different version of libp2p as the one specified in `package.json`. You just need to define its path through an environment variable as follows:
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
export LIBP2P_JS=./../../js-libp2p/src/index.js
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Contribute
|
|
38
|
+
|
|
39
|
+
This module is actively under development. Please check out the issues and submit PRs!
|
|
40
|
+
|
|
41
|
+
## License
|
|
42
|
+
|
|
43
|
+
MIT © Protocol Labs
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
2
|
+
import type { Connection } from '@libp2p/interfaces/connection';
|
|
3
|
+
import type { ConnectionHandler } from '@libp2p/interfaces/transport';
|
|
4
|
+
export declare class Client {
|
|
5
|
+
private multiaddr;
|
|
6
|
+
private tcp;
|
|
7
|
+
private listener?;
|
|
8
|
+
constructor(addr: Multiaddr);
|
|
9
|
+
/**
|
|
10
|
+
* Connects to a daemon at the unix socket path the client
|
|
11
|
+
* was created with
|
|
12
|
+
*/
|
|
13
|
+
connect(): Promise<Connection>;
|
|
14
|
+
/**
|
|
15
|
+
* Starts a server listening at `socketPath`. New connections
|
|
16
|
+
* will be sent to the `connectionHandler`.
|
|
17
|
+
*/
|
|
18
|
+
start(addr: Multiaddr, handler: ConnectionHandler): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Closes the socket
|
|
21
|
+
*
|
|
22
|
+
* @returns {Promise}
|
|
23
|
+
*/
|
|
24
|
+
close(): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAC/D,OAAO,KAAK,EAAE,iBAAiB,EAAY,MAAM,8BAA8B,CAAA;AAE/E,qBAAa,MAAM;IACjB,OAAO,CAAC,SAAS,CAAW;IAC5B,OAAO,CAAC,GAAG,CAAK;IAChB,OAAO,CAAC,QAAQ,CAAC,CAAU;gBAEd,IAAI,EAAE,SAAS;IAK5B;;;OAGG;IACH,OAAO,IAAK,OAAO,CAAC,UAAU,CAAC;IAM/B;;;OAGG;IACG,KAAK,CAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAaxE;;;;OAIG;IACG,KAAK;CAOZ"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { TCP } from '@libp2p/tcp';
|
|
2
|
+
import { passThroughUpgrader } from './util/index.js';
|
|
3
|
+
export class Client {
|
|
4
|
+
constructor(addr) {
|
|
5
|
+
this.multiaddr = addr;
|
|
6
|
+
this.tcp = new TCP();
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Connects to a daemon at the unix socket path the client
|
|
10
|
+
* was created with
|
|
11
|
+
*/
|
|
12
|
+
connect() {
|
|
13
|
+
return this.tcp.dial(this.multiaddr, {
|
|
14
|
+
upgrader: passThroughUpgrader
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Starts a server listening at `socketPath`. New connections
|
|
19
|
+
* will be sent to the `connectionHandler`.
|
|
20
|
+
*/
|
|
21
|
+
async start(addr, handler) {
|
|
22
|
+
if (this.listener != null) {
|
|
23
|
+
await this.close();
|
|
24
|
+
}
|
|
25
|
+
this.listener = this.tcp.createListener({
|
|
26
|
+
handler,
|
|
27
|
+
upgrader: passThroughUpgrader
|
|
28
|
+
});
|
|
29
|
+
await this.listener.listen(addr);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Closes the socket
|
|
33
|
+
*
|
|
34
|
+
* @returns {Promise}
|
|
35
|
+
*/
|
|
36
|
+
async close() {
|
|
37
|
+
if (this.listener != null) {
|
|
38
|
+
await this.listener.close();
|
|
39
|
+
}
|
|
40
|
+
this.listener = undefined;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAKrD,MAAM,OAAO,MAAM;IAKjB,YAAa,IAAe;QAC1B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAA;QACrB,IAAI,CAAC,GAAG,GAAG,IAAI,GAAG,EAAE,CAAA;IACtB,CAAC;IAED;;;OAGG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YACnC,QAAQ,EAAE,mBAAmB;SAC9B,CAAC,CAAA;IACJ,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,KAAK,CAAE,IAAe,EAAE,OAA0B;QACtD,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,EAAE;YACzB,MAAM,IAAI,CAAC,KAAK,EAAE,CAAA;SACnB;QAED,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC;YACtC,OAAO;YACP,QAAQ,EAAE,mBAAmB;SAC9B,CAAC,CAAA;QAEF,MAAM,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAClC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,KAAK;QACT,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,EAAE;YACzB,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAA;SAC5B;QAED,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAA;IAC3B,CAAC;CACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { PeerId } from '@libp2p/interfaces/peer-id';
|
|
2
|
+
import type { DualDHT } from '@libp2p/interfaces/dht';
|
|
3
|
+
import type { CID } from 'multiformats/cid';
|
|
4
|
+
export interface DHTOperationsInit {
|
|
5
|
+
dht: DualDHT;
|
|
6
|
+
}
|
|
7
|
+
export declare class DHTOperations {
|
|
8
|
+
private dht;
|
|
9
|
+
constructor(init: DHTOperationsInit);
|
|
10
|
+
provide(cid: CID): AsyncGenerator<Uint8Array, void, unknown>;
|
|
11
|
+
getClosestPeers(key: Uint8Array): AsyncGenerator<Uint8Array, void, undefined>;
|
|
12
|
+
getPublicKey(peerId: PeerId): AsyncGenerator<Uint8Array, void, unknown>;
|
|
13
|
+
getValue(key: Uint8Array): AsyncGenerator<Uint8Array, void, unknown>;
|
|
14
|
+
putValue(key: Uint8Array, value: Uint8Array): AsyncGenerator<Uint8Array, void, unknown>;
|
|
15
|
+
findPeer(peerId: PeerId): AsyncGenerator<Uint8Array, void, unknown>;
|
|
16
|
+
findProviders(cid: CID, count: number): AsyncGenerator<Uint8Array, void, unknown>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=dht.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dht.d.ts","sourceRoot":"","sources":["../../src/dht.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AACxD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AACrD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAG3C,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,OAAO,CAAA;CACb;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,GAAG,CAAS;gBAEP,IAAI,EAAE,iBAAiB;IAM5B,OAAO,CAAE,GAAG,EAAE,GAAG;IAKjB,eAAe,CAAE,GAAG,EAAE,UAAU;IAqBhC,YAAY,CAAE,MAAM,EAAE,MAAM;IAe5B,QAAQ,CAAE,GAAG,EAAE,UAAU;IAiBzB,QAAQ,CAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU;IAU5C,QAAQ,CAAE,MAAM,EAAE,MAAM;IAsBxB,aAAa,CAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM;CAsC/C"}
|
package/dist/src/dht.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/* eslint max-depth: ["error", 6] */
|
|
2
|
+
import { DHTResponse, } from '@libp2p/daemon-protocol';
|
|
3
|
+
import { ErrorResponse, OkResponse } from './responses.js';
|
|
4
|
+
import drain from 'it-drain';
|
|
5
|
+
export class DHTOperations {
|
|
6
|
+
constructor(init) {
|
|
7
|
+
const { dht } = init;
|
|
8
|
+
this.dht = dht;
|
|
9
|
+
}
|
|
10
|
+
async *provide(cid) {
|
|
11
|
+
await this.dht.provide(cid);
|
|
12
|
+
yield OkResponse();
|
|
13
|
+
}
|
|
14
|
+
async *getClosestPeers(key) {
|
|
15
|
+
yield OkResponse({
|
|
16
|
+
dht: {
|
|
17
|
+
type: DHTResponse.Type.BEGIN
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
for await (const event of this.dht.getClosestPeers(key)) {
|
|
21
|
+
if (event.name === 'PEER_RESPONSE') {
|
|
22
|
+
yield* event.closer.map(peer => DHTResponse.encode({
|
|
23
|
+
type: DHTResponse.Type.VALUE,
|
|
24
|
+
value: peer.id.toBytes()
|
|
25
|
+
}).finish());
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
yield DHTResponse.encode({
|
|
29
|
+
type: DHTResponse.Type.END
|
|
30
|
+
}).finish();
|
|
31
|
+
}
|
|
32
|
+
async *getPublicKey(peerId) {
|
|
33
|
+
yield ErrorResponse(new Error('FIX ME: not implemented'));
|
|
34
|
+
/*
|
|
35
|
+
const pubKey = await this.dht.getPublicKey(peerId)
|
|
36
|
+
|
|
37
|
+
yield OkResponse({
|
|
38
|
+
dht: {
|
|
39
|
+
type: DHTResponse.Type.VALUE,
|
|
40
|
+
value: pubKey.bytes
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
*/
|
|
44
|
+
}
|
|
45
|
+
async *getValue(key) {
|
|
46
|
+
try {
|
|
47
|
+
for await (const event of this.dht.getClosestPeers(key)) {
|
|
48
|
+
if (event.name === 'VALUE') {
|
|
49
|
+
yield OkResponse({
|
|
50
|
+
dht: {
|
|
51
|
+
type: DHTResponse.Type.VALUE,
|
|
52
|
+
value: event.value
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
yield ErrorResponse(err.message);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
async *putValue(key, value) {
|
|
63
|
+
try {
|
|
64
|
+
await drain(this.dht.put(key, value));
|
|
65
|
+
yield OkResponse();
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
yield ErrorResponse(err.message);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async *findPeer(peerId) {
|
|
72
|
+
try {
|
|
73
|
+
for await (const event of this.dht.findPeer(peerId)) {
|
|
74
|
+
if (event.name === 'FINAL_PEER') {
|
|
75
|
+
yield OkResponse({
|
|
76
|
+
dht: {
|
|
77
|
+
type: DHTResponse.Type.VALUE,
|
|
78
|
+
peer: {
|
|
79
|
+
id: event.peer.id.toBytes(),
|
|
80
|
+
addrs: event.peer.multiaddrs.map(m => m.bytes)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
throw new Error('Peer not found');
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
yield ErrorResponse(err);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async *findProviders(cid, count) {
|
|
93
|
+
yield OkResponse({
|
|
94
|
+
dht: {
|
|
95
|
+
type: DHTResponse.Type.BEGIN
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
try {
|
|
99
|
+
const maxNumProviders = count;
|
|
100
|
+
let found = 0;
|
|
101
|
+
for await (const event of this.dht.findProviders(cid)) {
|
|
102
|
+
if (event.name === 'PEER_RESPONSE') {
|
|
103
|
+
for (const provider of event.providers) {
|
|
104
|
+
found++;
|
|
105
|
+
yield DHTResponse.encode({
|
|
106
|
+
type: DHTResponse.Type.VALUE,
|
|
107
|
+
peer: {
|
|
108
|
+
id: provider.id.toBytes(),
|
|
109
|
+
addrs: (provider.multiaddrs || []).map(m => m.bytes)
|
|
110
|
+
}
|
|
111
|
+
}).finish();
|
|
112
|
+
}
|
|
113
|
+
if (maxNumProviders === found) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch (err) {
|
|
120
|
+
yield ErrorResponse(err);
|
|
121
|
+
}
|
|
122
|
+
yield DHTResponse.encode({
|
|
123
|
+
type: DHTResponse.Type.END
|
|
124
|
+
}).finish();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=dht.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dht.js","sourceRoot":"","sources":["../../src/dht.ts"],"names":[],"mappings":"AAAA,oCAAoC;AAEpC,OAAO,EACL,WAAW,GACZ,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAI1D,OAAO,KAAK,MAAM,UAAU,CAAA;AAM5B,MAAM,OAAO,aAAa;IAGxB,YAAa,IAAuB;QAClC,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA;QAEpB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;IAChB,CAAC;IAED,KAAK,CAAC,CAAE,OAAO,CAAE,GAAQ;QACvB,MAAM,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;QAC3B,MAAM,UAAU,EAAE,CAAA;IACpB,CAAC;IAED,KAAK,CAAC,CAAE,eAAe,CAAE,GAAe;QACtC,MAAM,UAAU,CAAC;YACf,GAAG,EAAE;gBACH,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,KAAK;aAC7B;SACF,CAAC,CAAA;QAEF,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,e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AClC,KAAK,MAAM,QAAQ,IAAI,KAAK,CAAC,SAAS,EAAE;wBACtC,KAAK,EAAE,CAAA;wBAEP,MAAM,WAAW,CAAC,MAAM,CAAC;4BACvB,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,KAAK;4BAC5B,IAAI,EAAE;gCACJ,EAAE,EAAE,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE;gCACzB,KAAK,EAAE,CAAC,QAAQ,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;6BACrD;yBACF,CAAC,CAAC,MAAM,EAAE,CAAA;qBACZ;oBAED,IAAI,eAAe,KAAK,KAAK,EAAE;wBAC7B,OAAM;qBACP;iBACF;aACF;SACF;QAAC,OAAO,GAAQ,EAAE;YACjB,MAAM,aAAa,CAAC,GAAG,CAAC,CAAA;SACzB;QAED,MAAM,WAAW,CAAC,MAAM,CAAC;YACvB,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,GAAG;SAC3B,CAAC,CAAC,MAAM,EAAE,CAAA;IACb,CAAC;CACF"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { Multiaddr } from '@multiformats/multiaddr';
|
|
2
|
+
import { IRequest, IStreamInfo, IPSRequest, IDHTRequest, IPeerstoreRequest } from '@libp2p/daemon-protocol';
|
|
3
|
+
import type { Connection, Stream } from '@libp2p/interfaces/connection';
|
|
4
|
+
import type { PeerId } from '@libp2p/interfaces/peer-id';
|
|
5
|
+
import type { AbortOptions } from '@libp2p/interfaces';
|
|
6
|
+
import type { StreamHandler as StreamCallback } from '@libp2p/interfaces/registrar';
|
|
7
|
+
import type { DualDHT } from '@libp2p/interfaces/dht';
|
|
8
|
+
import type { PubSub } from '@libp2p/interfaces/pubsub';
|
|
9
|
+
import type { PeerStore } from '@libp2p/interfaces/peer-store';
|
|
10
|
+
export interface OpenStream {
|
|
11
|
+
streamInfo: IStreamInfo;
|
|
12
|
+
connection: Stream;
|
|
13
|
+
}
|
|
14
|
+
export interface Libp2p {
|
|
15
|
+
peerId: PeerId;
|
|
16
|
+
peerStore: PeerStore;
|
|
17
|
+
pubsub?: PubSub;
|
|
18
|
+
dht?: DualDHT;
|
|
19
|
+
getConnections: (peerId?: PeerId) => Connection[];
|
|
20
|
+
getPeers: () => PeerId[];
|
|
21
|
+
dial: (peer: PeerId | Multiaddr, options?: AbortOptions) => Promise<Connection>;
|
|
22
|
+
handle: (protocol: string | string[], handler: StreamCallback) => Promise<void>;
|
|
23
|
+
start: () => void | Promise<void>;
|
|
24
|
+
stop: () => void | Promise<void>;
|
|
25
|
+
getMultiaddrs: () => Multiaddr[];
|
|
26
|
+
}
|
|
27
|
+
export interface DaemonInit {
|
|
28
|
+
multiaddr: Multiaddr;
|
|
29
|
+
libp2pNode: any;
|
|
30
|
+
}
|
|
31
|
+
export interface Libp2pServer {
|
|
32
|
+
start: () => Promise<void>;
|
|
33
|
+
stop: () => Promise<void>;
|
|
34
|
+
getMultiaddrs: () => Multiaddr[];
|
|
35
|
+
}
|
|
36
|
+
export declare class Server implements Libp2pServer {
|
|
37
|
+
private multiaddr;
|
|
38
|
+
private libp2p;
|
|
39
|
+
private tcp;
|
|
40
|
+
private listener;
|
|
41
|
+
private streamHandlers;
|
|
42
|
+
private dhtOperations?;
|
|
43
|
+
private pubsubOperations?;
|
|
44
|
+
constructor(init: DaemonInit);
|
|
45
|
+
/**
|
|
46
|
+
* Connects the daemons libp2p node to the peer provided
|
|
47
|
+
*/
|
|
48
|
+
connect(request: IRequest): Promise<Connection>;
|
|
49
|
+
/**
|
|
50
|
+
* Opens a stream on one of the given protocols to the given peer
|
|
51
|
+
*/
|
|
52
|
+
openStream(request: IRequest): Promise<OpenStream>;
|
|
53
|
+
/**
|
|
54
|
+
* Sends inbound requests for the given protocol
|
|
55
|
+
* to the unix socket path provided. If an existing handler
|
|
56
|
+
* is registered at the path, it will be overridden.
|
|
57
|
+
*
|
|
58
|
+
* @param {StreamHandlerRequest} request
|
|
59
|
+
* @returns {Promise<void>}
|
|
60
|
+
*/
|
|
61
|
+
registerStreamHandler(request: IRequest): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Listens for process exit to handle cleanup
|
|
64
|
+
*
|
|
65
|
+
* @private
|
|
66
|
+
* @returns {void}
|
|
67
|
+
*/
|
|
68
|
+
_listen(): void;
|
|
69
|
+
_onExit(): void;
|
|
70
|
+
/**
|
|
71
|
+
* Starts the daemon
|
|
72
|
+
*/
|
|
73
|
+
start(): Promise<void>;
|
|
74
|
+
getMultiaddrs(): Multiaddr[];
|
|
75
|
+
/**
|
|
76
|
+
* Stops the daemon
|
|
77
|
+
*
|
|
78
|
+
* @param {object} options
|
|
79
|
+
* @param {boolean} options.exit - If the daemon process should exit
|
|
80
|
+
* @returns {Promise<void>}
|
|
81
|
+
*/
|
|
82
|
+
stop(options?: {
|
|
83
|
+
exit: boolean;
|
|
84
|
+
}): Promise<void>;
|
|
85
|
+
handlePeerStoreRequest(request: IPeerstoreRequest): AsyncGenerator<Uint8Array, void, unknown>;
|
|
86
|
+
/**
|
|
87
|
+
* Parses and responds to PSRequests
|
|
88
|
+
*/
|
|
89
|
+
handlePubsubRequest(request: IPSRequest): AsyncGenerator<Uint8Array, void, undefined>;
|
|
90
|
+
/**
|
|
91
|
+
* Parses and responds to DHTRequests
|
|
92
|
+
*/
|
|
93
|
+
handleDHTRequest(request: IDHTRequest): AsyncGenerator<Uint8Array, void, undefined>;
|
|
94
|
+
/**
|
|
95
|
+
* Handles requests for the given connection
|
|
96
|
+
*/
|
|
97
|
+
handleConnection(connection: Connection): Promise<void>;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Creates a daemon from the provided Daemon Options
|
|
101
|
+
*/
|
|
102
|
+
export declare const createServer: (multiaddr: Multiaddr, libp2pNode: Libp2p) => Promise<Libp2pServer>;
|
|
103
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
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