Page 1 of 1

javascript (node) RPC request issue

Posted: Tue Mar 06, 2018 8:17 am
by doctor_d
Hello deluge forum,
I'm struggling to make my own rpc client using nodejs based on this one: https://github.com/JohnDoee/deluge-client
The connection seems to work (if I turn off the daemon and run the code I clearly get a connection error) but when I send the request I get no answer (.on('data' function () {}) never fires).
On the other hand if I use deluge-client from JohnDoee everything works perfectly. His code is pretty clear but since I am a newbie in python maybe I missed something.

Here's my code

Code: Select all


var tls = require('tls')
var zlib = require('zlib')
var bencode = require('bencode')

var client = tls.connect({
		port: 58846,
		host: '127.0.0.1',
		rejectUnauthorized: false,
		checkServerIdentity: () => {
			return undefined
		},
		secureContext: tls.createSecureContext({secureProtocol: 'SSLv23_method'}),
	}, () => {
	var login = send(1, 'daemon.login', ['USERNAME', 'PASSWORD'], {})
	.then((buff) => {
		client.write(buff)
		var command = send(2, 'core.get_torrents_status', {}, ['name', 'progress', 'is_seed', 'paused', 'total_seeds', 'is_finished', 'state', 'files', 'file_progress'])
		.then((buff2) => {
			client.write(buff2)
		})
	})
})

.setEncoding('utf8')

// Add a 'data' event handler for the client socket
// data is what the server sent to this socket
.on('data', (data) => {
    console.log('DATA: ' + data)
})

.on('end', () => {
    console.log('Connection ended')
})

// Add a 'close' event handler for the client socket
.on('close', () => {
    console.log('Connection closed')
})

.on('error', (error) => {
    console.log('err ' + error)
})

var send = (request_id, method, args, kwargs) => {
	return new Promise ((resolve, reject) => {
		zlib.deflate(bencode.encode([request_id, method, args, kwargs]), (err, buffer) => {
			return resolve(buffer)
		})
	})
}

What am I doing wrong? Is there any way to enable some logging (daemon side)?

Thanks in advance

Re: javascript (node) RPC request issue

Posted: Wed Sep 12, 2018 12:49 pm
by mishagale
Looks like you are using bencode, but I believe deluge RPC uses rencode?

Re: javascript (node) RPC request issue

Posted: Wed Sep 12, 2018 1:14 pm
by doctor_d
I guess you're right. I ended up using JohnDoee Py library since I didn't have the time to port rencode to js.

Re: javascript (node) RPC request issue

Posted: Sat Nov 17, 2018 9:59 am
by cinderblock63
Doctor D, You're in luck!

I recently wanted the same thing you did.

I decided to bite the bullet and reimplement rencode in JavaScript. Check it out:

https://github.com/cinderblock/python-rencode

I am working on an RPC library for deluge as well:

https://github.com/cinderblock/node-deluge-rpc

Re: javascript (node) RPC request issue

Posted: Sat Nov 17, 2018 10:19 am
by doctor_d
Nice job, man! Maybe I'll give it a try.

Re: javascript (node) RPC request issue

Posted: Sat Nov 17, 2018 10:56 am
by cinderblock63
Thanks! It's still pretty untested. Well, I've written a bunch of tests to test python-rencode.

Stuff I have tested in deluge RPC:

- login
- addTorrentUrl