@libp2p/daemon 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/index.d.ts +6 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +125 -0
- package/dist/src/index.js.map +1 -0
- package/package.json +145 -0
- package/src/index.ts +138 -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,6 @@
|
|
|
1
|
+
#! /usr/bin/env node
|
|
2
|
+
import { Multiaddr } from '@multiformats/multiaddr';
|
|
3
|
+
import type { Libp2pServer } from '@libp2p/daemon-server';
|
|
4
|
+
export default function main(processArgs: string[]): Promise<void>;
|
|
5
|
+
export declare function createLibp2pServer(listenAddr: Multiaddr, argv: any): Promise<Libp2pServer>;
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAInD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AASzD,wBAA8B,IAAI,CAAE,WAAW,EAAE,MAAM,EAAE,iBA0GxD;AAED,wBAAsB,kBAAkB,CAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,YAAY,CAAC,CAKjG"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
#! /usr/bin/env node
|
|
2
|
+
/* eslint no-console: ["error", { allow: ["log", "warn", "error"] }] */
|
|
3
|
+
import { Multiaddr } from '@multiformats/multiaddr';
|
|
4
|
+
import yargs from 'yargs';
|
|
5
|
+
// @ts-expect-error no types
|
|
6
|
+
import YargsPromise from 'yargs-promise';
|
|
7
|
+
// @ts-expect-error no types
|
|
8
|
+
import esMain from 'es-main';
|
|
9
|
+
const args = process.argv.slice(2);
|
|
10
|
+
const parser = new YargsPromise(yargs);
|
|
11
|
+
const log = console.log;
|
|
12
|
+
export default async function main(processArgs) {
|
|
13
|
+
parser.yargs
|
|
14
|
+
.option('listen', {
|
|
15
|
+
desc: 'daemon control listen multiaddr',
|
|
16
|
+
type: 'string',
|
|
17
|
+
default: '/unix/tmp/p2pd.sock'
|
|
18
|
+
})
|
|
19
|
+
.option('quiet', {
|
|
20
|
+
alias: 'q',
|
|
21
|
+
desc: 'be quiet',
|
|
22
|
+
type: 'boolean',
|
|
23
|
+
default: false
|
|
24
|
+
})
|
|
25
|
+
.option('id', {
|
|
26
|
+
desc: 'peer identity; private key file',
|
|
27
|
+
type: 'string',
|
|
28
|
+
default: ''
|
|
29
|
+
})
|
|
30
|
+
.option('hostAddrs', {
|
|
31
|
+
desc: 'Comma separated list of multiaddrs the host should listen on',
|
|
32
|
+
type: 'string',
|
|
33
|
+
default: ''
|
|
34
|
+
})
|
|
35
|
+
.option('announceAddrs', {
|
|
36
|
+
desc: 'Comma separated list of multiaddrs the host should announce to the network',
|
|
37
|
+
type: 'string',
|
|
38
|
+
default: ''
|
|
39
|
+
})
|
|
40
|
+
.option('bootstrap', {
|
|
41
|
+
alias: 'b',
|
|
42
|
+
desc: 'Connects to bootstrap peers and bootstraps the dht if enabled',
|
|
43
|
+
type: 'boolean',
|
|
44
|
+
default: false
|
|
45
|
+
})
|
|
46
|
+
.option('bootstrapPeers', {
|
|
47
|
+
desc: 'Comma separated list of bootstrap peers; defaults to the IPFS DHT peers',
|
|
48
|
+
type: 'string',
|
|
49
|
+
default: ''
|
|
50
|
+
})
|
|
51
|
+
.option('dht', {
|
|
52
|
+
desc: 'Enables the DHT in full node mode',
|
|
53
|
+
type: 'boolean',
|
|
54
|
+
default: false
|
|
55
|
+
})
|
|
56
|
+
.option('dhtClient', {
|
|
57
|
+
desc: '(Not yet supported) Enables the DHT in client mode',
|
|
58
|
+
type: 'boolean',
|
|
59
|
+
default: false
|
|
60
|
+
})
|
|
61
|
+
.option('nat', {
|
|
62
|
+
desc: 'Enables UPnP NAT hole punching',
|
|
63
|
+
type: 'boolean',
|
|
64
|
+
default: false
|
|
65
|
+
})
|
|
66
|
+
.option('connMgr', {
|
|
67
|
+
desc: '(Not yet supported) Enables the Connection Manager',
|
|
68
|
+
type: 'boolean',
|
|
69
|
+
default: false
|
|
70
|
+
})
|
|
71
|
+
.option('connMgrLo', {
|
|
72
|
+
desc: 'Number identifying the number of peers below which this node will not activate preemptive disconnections',
|
|
73
|
+
type: 'number'
|
|
74
|
+
})
|
|
75
|
+
.option('connMgrHi', {
|
|
76
|
+
desc: 'Number identifying the maximum number of peers the current peer is willing to be connected to before is starts disconnecting',
|
|
77
|
+
type: 'number'
|
|
78
|
+
})
|
|
79
|
+
.option('pubsub', {
|
|
80
|
+
desc: 'Enables pubsub',
|
|
81
|
+
type: 'boolean',
|
|
82
|
+
default: false
|
|
83
|
+
})
|
|
84
|
+
.option('pubsubRouter', {
|
|
85
|
+
desc: 'Specifies the pubsub router implementation',
|
|
86
|
+
type: 'string',
|
|
87
|
+
default: 'gossipsub'
|
|
88
|
+
})
|
|
89
|
+
.fail((msg, err, yargs) => {
|
|
90
|
+
if (err != null) {
|
|
91
|
+
throw err; // preserve stack
|
|
92
|
+
}
|
|
93
|
+
if (args.length > 0) {
|
|
94
|
+
// eslint-disable-next-line
|
|
95
|
+
log(msg);
|
|
96
|
+
}
|
|
97
|
+
yargs.showHelp();
|
|
98
|
+
});
|
|
99
|
+
const { data, argv } = await parser.parse(processArgs);
|
|
100
|
+
if (data != null) {
|
|
101
|
+
// Log help and exit
|
|
102
|
+
// eslint-disable-next-line
|
|
103
|
+
log(data);
|
|
104
|
+
process.exit(0);
|
|
105
|
+
}
|
|
106
|
+
const daemon = await createLibp2pServer(new Multiaddr(argv.listen), argv);
|
|
107
|
+
await daemon.start();
|
|
108
|
+
if (argv.quiet !== true) {
|
|
109
|
+
// eslint-disable-next-line
|
|
110
|
+
log('daemon has started');
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
export async function createLibp2pServer(listenAddr, argv) {
|
|
114
|
+
// const libp2p = await createLibp2p(argv)
|
|
115
|
+
// const daemon = await createServer(new Multiaddr(argv.listen), libp2p)
|
|
116
|
+
throw new Error('Not implemented yet');
|
|
117
|
+
}
|
|
118
|
+
if (esMain(import.meta) === true) {
|
|
119
|
+
main(process.argv)
|
|
120
|
+
.catch((err) => {
|
|
121
|
+
console.error(err);
|
|
122
|
+
process.exit(1);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AACA,uEAAuE;AAEvE,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,4BAA4B;AAC5B,OAAO,YAAY,MAAM,eAAe,CAAA;AAExC,4BAA4B;AAC5B,OAAO,MAAM,MAAM,SAAS,CAAA;AAE5B,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AAClC,MAAM,MAAM,GAAG,IAAI,YAAY,CAAC,KAAK,CAAC,CAAA;AAEtC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAA;AAEvB,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,IAAI,CAAE,WAAqB;IACvD,MAAM,CAAC,KAAK;SACT,MAAM,CAAC,QAAQ,EAAE;QAChB,IAAI,EAAE,iCAAiC;QACvC,IAAI,EAAE,QAA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1B;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAE,UAAqB,EAAE,IAAS;IACxE,0CAA0C;IAC1C,wEAAwE;IAExE,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;AACxC,CAAC;AAED,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE;IAChC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;SACf,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;QACb,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAClB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC,CAAC,CAAA;CACL"}
|
package/package.json
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@libp2p/daemon",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "libp2p-daemon JavaScript implementation",
|
|
5
|
+
"license": "Apache-2.0 OR MIT",
|
|
6
|
+
"homepage": "https://github.com/libp2p/js-libp2p-daemon/tree/master/packages/libp2p-daemon#readme",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/libp2p/js-libp2p-daemon.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/libp2p/js-libp2p-daemon/issues"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"libp2p"
|
|
16
|
+
],
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=16.0.0",
|
|
19
|
+
"npm": ">=7.0.0"
|
|
20
|
+
},
|
|
21
|
+
"bin": {
|
|
22
|
+
"jsp2pd": "src/cli/bin.js"
|
|
23
|
+
},
|
|
24
|
+
"type": "module",
|
|
25
|
+
"types": "./dist/src/index.d.ts",
|
|
26
|
+
"files": [
|
|
27
|
+
"src",
|
|
28
|
+
"dist/src",
|
|
29
|
+
"!dist/test",
|
|
30
|
+
"!**/*.tsbuildinfo"
|
|
31
|
+
],
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"import": "./dist/src/index.js"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"eslintConfig": {
|
|
38
|
+
"extends": "ipfs",
|
|
39
|
+
"parserOptions": {
|
|
40
|
+
"sourceType": "module"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"release": {
|
|
44
|
+
"branches": [
|
|
45
|
+
"master"
|
|
46
|
+
],
|
|
47
|
+
"plugins": [
|
|
48
|
+
[
|
|
49
|
+
"@semantic-release/commit-analyzer",
|
|
50
|
+
{
|
|
51
|
+
"preset": "conventionalcommits",
|
|
52
|
+
"releaseRules": [
|
|
53
|
+
{
|
|
54
|
+
"breaking": true,
|
|
55
|
+
"release": "major"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"revert": true,
|
|
59
|
+
"release": "patch"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"type": "feat",
|
|
63
|
+
"release": "minor"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"type": "fix",
|
|
67
|
+
"release": "patch"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"type": "chore",
|
|
71
|
+
"release": "patch"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"type": "docs",
|
|
75
|
+
"release": "patch"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"type": "test",
|
|
79
|
+
"release": "patch"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"scope": "no-release",
|
|
83
|
+
"release": false
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
],
|
|
88
|
+
[
|
|
89
|
+
"@semantic-release/release-notes-generator",
|
|
90
|
+
{
|
|
91
|
+
"preset": "conventionalcommits",
|
|
92
|
+
"presetConfig": {
|
|
93
|
+
"types": [
|
|
94
|
+
{
|
|
95
|
+
"type": "feat",
|
|
96
|
+
"section": "Features"
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"type": "fix",
|
|
100
|
+
"section": "Bug Fixes"
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"type": "chore",
|
|
104
|
+
"section": "Trivial Changes"
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"type": "docs",
|
|
108
|
+
"section": "Trivial Changes"
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"type": "test",
|
|
112
|
+
"section": "Tests"
|
|
113
|
+
}
|
|
114
|
+
]
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
],
|
|
118
|
+
"@semantic-release/changelog",
|
|
119
|
+
"@semantic-release/npm",
|
|
120
|
+
"@semantic-release/github",
|
|
121
|
+
"@semantic-release/git"
|
|
122
|
+
]
|
|
123
|
+
},
|
|
124
|
+
"scripts": {
|
|
125
|
+
"lint": "aegir lint",
|
|
126
|
+
"dep-check": "aegir dep-check dist/src/**/*.js dist/test/**/*.js",
|
|
127
|
+
"build": "tsc",
|
|
128
|
+
"pretest": "npm run build",
|
|
129
|
+
"test": "aegir test -t node -f dist/test/*.js dist/test/**/*.js",
|
|
130
|
+
"test:node": "aegir test -t node -f dist/test/*.js dist/test/**/*.js",
|
|
131
|
+
"release": "semantic-release"
|
|
132
|
+
},
|
|
133
|
+
"dependencies": {
|
|
134
|
+
"@libp2p/daemon-server": "^0.0.2",
|
|
135
|
+
"@libp2p/interfaces": "^1.3.17",
|
|
136
|
+
"@multiformats/multiaddr": "^10.1.8",
|
|
137
|
+
"es-main": "^1.0.2",
|
|
138
|
+
"yargs": "^17.3.1",
|
|
139
|
+
"yargs-promise": "^1.1.0"
|
|
140
|
+
},
|
|
141
|
+
"devDependencies": {
|
|
142
|
+
"aegir": "^36.0.0",
|
|
143
|
+
"sinon": "^13.0.1"
|
|
144
|
+
}
|
|
145
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
#! /usr/bin/env node
|
|
2
|
+
/* eslint no-console: ["error", { allow: ["log", "warn", "error"] }] */
|
|
3
|
+
|
|
4
|
+
import { Multiaddr } from '@multiformats/multiaddr'
|
|
5
|
+
import yargs from 'yargs'
|
|
6
|
+
// @ts-expect-error no types
|
|
7
|
+
import YargsPromise from 'yargs-promise'
|
|
8
|
+
import type { Libp2pServer } from '@libp2p/daemon-server'
|
|
9
|
+
// @ts-expect-error no types
|
|
10
|
+
import esMain from 'es-main'
|
|
11
|
+
|
|
12
|
+
const args = process.argv.slice(2)
|
|
13
|
+
const parser = new YargsPromise(yargs)
|
|
14
|
+
|
|
15
|
+
const log = console.log
|
|
16
|
+
|
|
17
|
+
export default async function main (processArgs: string[]) {
|
|
18
|
+
parser.yargs
|
|
19
|
+
.option('listen', {
|
|
20
|
+
desc: 'daemon control listen multiaddr',
|
|
21
|
+
type: 'string',
|
|
22
|
+
default: '/unix/tmp/p2pd.sock'
|
|
23
|
+
})
|
|
24
|
+
.option('quiet', {
|
|
25
|
+
alias: 'q',
|
|
26
|
+
desc: 'be quiet',
|
|
27
|
+
type: 'boolean',
|
|
28
|
+
default: false
|
|
29
|
+
})
|
|
30
|
+
.option('id', {
|
|
31
|
+
desc: 'peer identity; private key file',
|
|
32
|
+
type: 'string',
|
|
33
|
+
default: ''
|
|
34
|
+
})
|
|
35
|
+
.option('hostAddrs', {
|
|
36
|
+
desc: 'Comma separated list of multiaddrs the host should listen on',
|
|
37
|
+
type: 'string',
|
|
38
|
+
default: ''
|
|
39
|
+
})
|
|
40
|
+
.option('announceAddrs', {
|
|
41
|
+
desc: 'Comma separated list of multiaddrs the host should announce to the network',
|
|
42
|
+
type: 'string',
|
|
43
|
+
default: ''
|
|
44
|
+
})
|
|
45
|
+
.option('bootstrap', {
|
|
46
|
+
alias: 'b',
|
|
47
|
+
desc: 'Connects to bootstrap peers and bootstraps the dht if enabled',
|
|
48
|
+
type: 'boolean',
|
|
49
|
+
default: false
|
|
50
|
+
})
|
|
51
|
+
.option('bootstrapPeers', {
|
|
52
|
+
desc: 'Comma separated list of bootstrap peers; defaults to the IPFS DHT peers',
|
|
53
|
+
type: 'string',
|
|
54
|
+
default: ''
|
|
55
|
+
})
|
|
56
|
+
.option('dht', {
|
|
57
|
+
desc: 'Enables the DHT in full node mode',
|
|
58
|
+
type: 'boolean',
|
|
59
|
+
default: false
|
|
60
|
+
})
|
|
61
|
+
.option('dhtClient', {
|
|
62
|
+
desc: '(Not yet supported) Enables the DHT in client mode',
|
|
63
|
+
type: 'boolean',
|
|
64
|
+
default: false
|
|
65
|
+
})
|
|
66
|
+
.option('nat', {
|
|
67
|
+
desc: 'Enables UPnP NAT hole punching',
|
|
68
|
+
type: 'boolean',
|
|
69
|
+
default: false
|
|
70
|
+
})
|
|
71
|
+
.option('connMgr', {
|
|
72
|
+
desc: '(Not yet supported) Enables the Connection Manager',
|
|
73
|
+
type: 'boolean',
|
|
74
|
+
default: false
|
|
75
|
+
})
|
|
76
|
+
.option('connMgrLo', {
|
|
77
|
+
desc: 'Number identifying the number of peers below which this node will not activate preemptive disconnections',
|
|
78
|
+
type: 'number'
|
|
79
|
+
})
|
|
80
|
+
.option('connMgrHi', {
|
|
81
|
+
desc: 'Number identifying the maximum number of peers the current peer is willing to be connected to before is starts disconnecting',
|
|
82
|
+
type: 'number'
|
|
83
|
+
})
|
|
84
|
+
.option('pubsub', {
|
|
85
|
+
desc: 'Enables pubsub',
|
|
86
|
+
type: 'boolean',
|
|
87
|
+
default: false
|
|
88
|
+
})
|
|
89
|
+
.option('pubsubRouter', {
|
|
90
|
+
desc: 'Specifies the pubsub router implementation',
|
|
91
|
+
type: 'string',
|
|
92
|
+
default: 'gossipsub'
|
|
93
|
+
})
|
|
94
|
+
.fail((msg: string, err: Error | undefined, yargs?: any) => {
|
|
95
|
+
if (err != null) {
|
|
96
|
+
throw err // preserve stack
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (args.length > 0) {
|
|
100
|
+
// eslint-disable-next-line
|
|
101
|
+
log(msg)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
yargs.showHelp()
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
const { data, argv } = await parser.parse(processArgs)
|
|
108
|
+
|
|
109
|
+
if (data != null) {
|
|
110
|
+
// Log help and exit
|
|
111
|
+
// eslint-disable-next-line
|
|
112
|
+
log(data)
|
|
113
|
+
process.exit(0)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const daemon = await createLibp2pServer(new Multiaddr(argv.listen), argv)
|
|
117
|
+
await daemon.start()
|
|
118
|
+
|
|
119
|
+
if (argv.quiet !== true) {
|
|
120
|
+
// eslint-disable-next-line
|
|
121
|
+
log('daemon has started')
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export async function createLibp2pServer (listenAddr: Multiaddr, argv: any): Promise<Libp2pServer> {
|
|
126
|
+
// const libp2p = await createLibp2p(argv)
|
|
127
|
+
// const daemon = await createServer(new Multiaddr(argv.listen), libp2p)
|
|
128
|
+
|
|
129
|
+
throw new Error('Not implemented yet')
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (esMain(import.meta) === true) {
|
|
133
|
+
main(process.argv)
|
|
134
|
+
.catch((err) => {
|
|
135
|
+
console.error(err)
|
|
136
|
+
process.exit(1)
|
|
137
|
+
})
|
|
138
|
+
}
|