-
-
Notifications
You must be signed in to change notification settings - Fork 203
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
Can't seem to get mutable Put with salt to work #146
Comments
I tried to replicate you issue with some code from the tests, here's what I came up with : var DHT = require('bittorrent-dht')
var ed = require('ed25519-supercop')
var keypair = ed.createKeyPair(ed.createSeed())
var dht1 = new DHT({ verify: ed.verify })
var dht2 = new DHT({ verify: ed.verify })
var sign = function (keypair) {
return function (buf) {
return ed.sign(buf, keypair.publicKey, keypair.secretKey)
}
}
var pending = 2
dht1.listen(function () {
dht2.addNode({ host: '127.0.0.1', port: dht1.address().port })
dht2.once('node', ready)
})
dht2.listen(function () {
dht1.addNode({ host: '127.0.0.1', port: dht2.address().port })
dht1.once('node', ready)
ready()
})
function ready () {
if (--pending !== 0) return
console.log('start')
var fopts = {
k: keypair.publicKey,
v: Buffer('aaaaaaaaaa'),
seq: 0,
salt: Buffer('seasalt'),
sign: sign(keypair),
}
dht1.put(fopts, function (err, hash) {
if(err) console.warn(err)
else console.log('dht1 set', fopts.v.toString('utf8'), 'at', hash.toString('hex'))
dht2.get(hash, function (err, res) {
if(err) console.warn(err)
else console.log('dht2 received', res ? res.v.toString('utf8') : null )
})
})
} Here's what I figured so far :
And as you noticed, it's all working fine if the salt parameter is removed |
Yeah, it's strange. We're getting replies from remote DHTs that they've stored the value. Perhaps those peers are quickly discarding mutable values with salts? I've added a bunch of debug messages to monitor what's happening, but the core of it seems to be that |
Afaik utorrent did not support salted puts for a while, but iirc it returned an error response to the put RPC in that case which should lead the writing node to try storing it on other nodes. Libtorrent and my own implementation do support it.
Since BEP44 support is not as widespread as basic BEP5 it might have to cast a wider net, at least looking for a sufficient amount of responses with tokens, since that would indicate that the nodes actually understood the query instead of just returning nodes lists. |
It's not strange. 1 and 2 work because there is at least one node is bittorrent-dht, which calculate the hash based on salt + key, but the BEP44 said the hash should be calculated based on key + salt, that's why 3 doesn't work. #157 suppose to fix this issue. |
This is fixed in 7.5.2, thanks to @thomasyuan 👏 |
Maybe I'm being dense, but this still isn't working with bootstrap == true. I can get it to work when I manually add known nodes, but how can I discover them? @thomasyuan |
It's weird. I tested yesterday at home, with the code @pldubouilh posted here. It failed. BTW, you might need another patch I posted at #158. (I think the PR is not enough, see my comments). Here is the log when it worked.
|
FWIW, this is still not working for me. I'm not able to retrieve anything stored with a salted mutable Put. |
I'm having some issues getting mutable Put to work with a salt—it works fine without. Here's some example code to add a mutable item to the DHT… (usage:
node put.js Hello world!
)…And the script to retrieve the key… (usage
node get.js 81b692589463a1745493dbfa2dd403d1c9d095b6
)If I remove the
{salt: "test"}
options argument input.js
, everything works fine. But for my use case, I really need the salt. I may be misunderstanding some part of the API—if so, let me know where I've gone wrong!The text was updated successfully, but these errors were encountered: