This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: dht ready * test: enable dht core test * feat: add dht cli * chore: enable dht by default * fix: code review * chore: increase silent timeout even more * fix: code review * fix: ci tests * fix: code review * fix: make ci happy again
- Loading branch information
Showing
54 changed files
with
1,196 additions
and
243 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,14 @@ | ||
'use strict' | ||
|
||
module.exports = { | ||
command: 'dht <command>', | ||
|
||
description: 'Issue commands directly through the DHT.', | ||
|
||
builder (yargs) { | ||
return yargs.commandDir('dht') | ||
}, | ||
|
||
handler (argv) { | ||
} | ||
} |
This file contains 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,23 @@ | ||
'use strict' | ||
|
||
const print = require('../../utils').print | ||
|
||
module.exports = { | ||
command: 'findpeer <peerID>', | ||
|
||
describe: 'Find the multiaddresses associated with a Peer ID.', | ||
|
||
builder: {}, | ||
|
||
handler ({ getIpfs, peerID, resolve }) { | ||
resolve((async () => { | ||
const ipfs = await getIpfs() | ||
const peers = await ipfs.dht.findPeer(peerID) | ||
const addresses = peers.multiaddrs.toArray().map((ma) => ma.toString()) | ||
|
||
addresses.forEach((addr) => { | ||
print(addr) | ||
}) | ||
})()) | ||
} | ||
} |
This file contains 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,33 @@ | ||
'use strict' | ||
|
||
const print = require('../../utils').print | ||
|
||
module.exports = { | ||
command: 'findprovs <key>', | ||
|
||
describe: 'Find peers that can provide a specific value, given a key.', | ||
|
||
builder: { | ||
'num-providers': { | ||
alias: 'n', | ||
describe: 'The number of providers to find. Default: 20.', | ||
default: 20 | ||
} | ||
}, | ||
|
||
handler (argv) { | ||
const { getIpfs, key, resolve } = argv | ||
const opts = { | ||
maxNumProviders: argv['num-providers'] | ||
} | ||
|
||
resolve((async () => { | ||
const ipfs = await getIpfs() | ||
const provs = await ipfs.dht.findProvs(key, opts) | ||
|
||
provs.forEach((element) => { | ||
print(element.id.toB58String()) | ||
}) | ||
})()) | ||
} | ||
} |
This file contains 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,20 @@ | ||
'use strict' | ||
|
||
const print = require('../../utils').print | ||
|
||
module.exports = { | ||
command: 'get <key>', | ||
|
||
describe: 'Given a key, query the routing system for its best value.', | ||
|
||
builder: {}, | ||
|
||
handler ({ getIpfs, key, resolve }) { | ||
resolve((async () => { | ||
const ipfs = await getIpfs() | ||
const value = await ipfs.dht.get(key) | ||
|
||
print(value) | ||
})()) | ||
} | ||
} |
This file contains 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,26 @@ | ||
'use strict' | ||
|
||
module.exports = { | ||
command: 'provide <key>', | ||
|
||
describe: 'Announce to the network that you are providing given values.', | ||
|
||
builder: { | ||
recursive: { | ||
alias: 'r', | ||
recursive: 'Recursively provide entire graph.', | ||
default: false | ||
} | ||
}, | ||
|
||
handler ({ getIpfs, key, recursive, resolve }) { | ||
const opts = { | ||
recursive | ||
} | ||
|
||
resolve((async () => { | ||
const ipfs = await getIpfs() | ||
await ipfs.dht.provide(key, opts) | ||
})()) | ||
} | ||
} |
This file contains 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,16 @@ | ||
'use strict' | ||
|
||
module.exports = { | ||
command: 'put <key> <value>', | ||
|
||
describe: 'Write a key/value pair to the routing system.', | ||
|
||
builder: {}, | ||
|
||
handler ({ getIpfs, key, value, resolve }) { | ||
resolve((async () => { | ||
const ipfs = await getIpfs() | ||
await ipfs.dht.put(key, value) | ||
})()) | ||
} | ||
} |
This file contains 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,22 @@ | ||
'use strict' | ||
|
||
const print = require('../../utils').print | ||
|
||
module.exports = { | ||
command: 'query <peerID>', | ||
|
||
describe: 'Find the closest Peer IDs to a given Peer ID by querying the DHT.', | ||
|
||
builder: {}, | ||
|
||
handler ({ getIpfs, peerID, resolve }) { | ||
resolve((async () => { | ||
const ipfs = await getIpfs() | ||
const result = await ipfs.dht.query(peerID) | ||
|
||
result.forEach((peerID) => { | ||
print(peerID.id.toB58String()) | ||
}) | ||
})()) | ||
} | ||
} |
Oops, something went wrong.