javascript (node) RPC request issue

Suggestions and discussion of future versions
Post Reply
doctor_d
New User
New User
Posts: 3
Joined: Tue Mar 06, 2018 7:50 am

javascript (node) RPC request issue

Post 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
mishagale
New User
New User
Posts: 4
Joined: Sat May 23, 2015 11:14 am

Re: javascript (node) RPC request issue

Post by mishagale »

Looks like you are using bencode, but I believe deluge RPC uses rencode?
doctor_d
New User
New User
Posts: 3
Joined: Tue Mar 06, 2018 7:50 am

Re: javascript (node) RPC request issue

Post 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.
cinderblock63
Member
Member
Posts: 23
Joined: Thu Jan 22, 2009 10:07 am
Location: Menlo Park, CA
Contact:

Re: javascript (node) RPC request issue

Post 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
doctor_d
New User
New User
Posts: 3
Joined: Tue Mar 06, 2018 7:50 am

Re: javascript (node) RPC request issue

Post by doctor_d »

Nice job, man! Maybe I'll give it a try.
cinderblock63
Member
Member
Posts: 23
Joined: Thu Jan 22, 2009 10:07 am
Location: Menlo Park, CA
Contact:

Re: javascript (node) RPC request issue

Post 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
Post Reply