-
Notifications
You must be signed in to change notification settings - Fork 11
fix: get the daemon working outside of tests #127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
saul-jb
wants to merge
42
commits into
libp2p:main
Choose a base branch
from
saul-jb:daemon-fixes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 34 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
ea9fdc1
Fix handshake types.
bd12e5f
Fix stream client test.
74bbfb4
Fix yargs issues.
6f2bbf1
Get libp2p to run.
dae4325
Add ipfs boostrap peers as default.
f73d832
Add websockets to transports.
11ecd7e
Add pubsub support.
2a21cae
Remove yargs-promise.
a99dd27
Add default option for hostAddrs.
0828d1e
Enable cli tests.
544deb4
Get the daemon-server to start.
774f320
Fix listen address and argument issues.
3f0fcc5
Handle announceAddrs argument.
a79b220
Only bootstrap peers if enabled.
d7cf214
Handle the id argument.
f71bf2c
Add DHT support.
8de058e
Documentation.
452cb8e
Fix linter errors.
cf89521
Specify the internal port.
52c9577
Add global flag to the install command.
260ff6d
Fix argument condition statements.
8a51bdd
Add option for PSK.
b5f7ae7
Fix boolean argument conditions.
5dcf6ad
Merge branch 'master' into daemon-fixes
c552285
Add option for pubsub peer discovery.
d087784
Add option for specifying the peer discovery interval.
00cde14
Add options for relay configuration.
881206e
Fix type errors.
ffd2e64
Refactor createLibp2pServer into separate file.
ab64429
Fix cli tests.
68424f9
Merge branch 'master' into daemon-fixes
086e4dd
Bump @libp2p/tcp.
e3e12be
Add missing deps.
111784d
Set the default listen address to a unix domain socket.
c2da702
Merge branch 'master' into daemon-fixes
47cb010
Fix type issue.
41a1d61
Bump packages.
3c2da35
Fix multiaddr in tests.
a16d9d7
Migrate server to libp2p 0.40.
2b75a0e
Prevent importsNotUsedAsValues error in libp2p-gossipsub.
c8f7438
Fix linting in libp2p-daemon-client.
8e58de1
Change hostAddrs default to localhost.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ | |
| ## Install | ||
|
|
||
| ```console | ||
| $ npm i @libp2p/daemon | ||
| $ npm i --location=global @libp2p/daemon | ||
| ``` | ||
|
|
||
| ## Specs | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| import { promises as fs } from 'fs' | ||
| import type { Multiaddr } from '@multiformats/multiaddr' | ||
| import { createServer, Libp2pServer } from '@libp2p/daemon-server' | ||
| import { Libp2p, createLibp2p, Libp2pOptions } from 'libp2p' | ||
| import { PreSharedKeyConnectionProtector } from 'libp2p/pnet' | ||
| import { Noise } from '@chainsafe/libp2p-noise' | ||
| import { Mplex } from '@libp2p/mplex' | ||
| import { TCP } from '@libp2p/tcp' | ||
| import { WebSockets } from '@libp2p/websockets' | ||
| import { Bootstrap } from '@libp2p/bootstrap' | ||
| import { GossipSub } from '@chainsafe/libp2p-gossipsub' | ||
| import { FloodSub } from '@libp2p/floodsub' | ||
| import { PubSubPeerDiscovery } from '@libp2p/pubsub-peer-discovery' | ||
| import { unmarshalPrivateKey } from '@libp2p/crypto/keys' | ||
| import { createFromPrivKey } from '@libp2p/peer-id-factory' | ||
| import { KadDHT } from '@libp2p/kad-dht' | ||
|
|
||
| export default { | ||
| createLibp2pServer: async function (listenAddr: Multiaddr, argv: any): Promise<Libp2pServer> { | ||
| // Minimum libp2p setup. | ||
| const options: Libp2pOptions = { | ||
| addresses: { | ||
| listen: argv.hostAddrs.split(','), | ||
| announce: argv.announceAddrs.split(',') | ||
| }, | ||
|
|
||
| transports: [new TCP(), new WebSockets()], | ||
| connectionEncryption: [new Noise()], | ||
| streamMuxers: [new Mplex()], | ||
| peerDiscovery: [] | ||
| } | ||
|
|
||
| // Load key file as peer ID. | ||
| if (argv.id != null) { | ||
| const marshaledKey: Buffer = await fs.readFile(argv.id) | ||
| const unmarshaledKey = await unmarshalPrivateKey(marshaledKey) | ||
| const peerId = await createFromPrivKey(unmarshaledKey) | ||
|
|
||
| options.peerId = peerId | ||
| } | ||
|
|
||
| // Enable bootstrap peers. | ||
| if (argv.bootstrap === true && options.peerDiscovery != null) { | ||
| options.peerDiscovery.push( | ||
| new Bootstrap({ | ||
| interval: argv.discoveryInterval, | ||
| list: argv.bootstrapPeers.split(',') | ||
| }) | ||
| ) | ||
| } | ||
|
|
||
| // Configure PubSub | ||
| if (argv.pubsub === true) { | ||
| // Router implementation. | ||
| switch (argv.pubsubRouter) { | ||
| case 'gossipsub': | ||
| options.pubsub = new GossipSub({ allowPublishToZeroPeers: true }) | ||
| break | ||
| case 'floodsub': | ||
| options.pubsub = new FloodSub() | ||
| break | ||
| default: | ||
| throw new Error('invalid pubsubRouter type') | ||
| } | ||
|
|
||
| // Peer discovery | ||
| if (argv.pubsubDiscovery === true && options.peerDiscovery != null) { | ||
| options.peerDiscovery.push( | ||
| new PubSubPeerDiscovery({ interval: argv.discoveryInterval }) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| // Enable DHT | ||
| if (argv.dht === true) { | ||
| options.dht = new KadDHT() | ||
| } | ||
|
|
||
| // Configure PSK | ||
| if (argv.psk != null) { | ||
| const swarmKey: Buffer = await fs.readFile(argv.psk) | ||
|
|
||
| options.connectionProtector = new PreSharedKeyConnectionProtector({ | ||
| psk: swarmKey | ||
| }) | ||
| } | ||
|
|
||
| // Configure relay | ||
| if (argv.relay === true) { | ||
| options.relay = { | ||
| enabled: true | ||
| } | ||
|
|
||
| if (argv.relayAuto === true) { | ||
| options.relay.autoRelay = { | ||
| enabled: true, | ||
| maxListeners: argv.relayAutoListeners | ||
| } | ||
| } | ||
|
|
||
| if (argv.relayHop === true) { | ||
| options.relay.hop = { | ||
| enabled: true | ||
| } | ||
| } | ||
|
|
||
| if (argv.relayAdvertise === true) { | ||
| options.relay.advertise = { | ||
| enabled: true | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const libp2p: Libp2p = await createLibp2p(options) | ||
| const daemon: Libp2pServer = createServer(listenAddr, libp2p) | ||
|
|
||
| return daemon | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.