javascript (node) RPC request issue

Suggestions and discussion of future versions
doctor_d
New User
New User
Posts: 3
Joined: Tue Mar 06, 2018 7:50 am
OS or Distro: Debian

javascript (node) RPC request issue

Postby doctor_d » Tue Mar 06, 2018 8:17 am

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
OS or Distro: Window 7

Re: javascript (node) RPC request issue

Postby mishagale » Wed Sep 12, 2018 12:49 pm

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
OS or Distro: Debian

Re: javascript (node) RPC request issue

Postby doctor_d » Wed Sep 12, 2018 1:14 pm

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: 14
Joined: Thu Jan 22, 2009 10:07 am
OS or Distro: gentoo
Location: Menlo Park, CA
Contact:

Re: javascript (node) RPC request issue

Postby cinderblock63 » Sat Nov 17, 2018 9:59 am

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
OS or Distro: Debian

Re: javascript (node) RPC request issue

Postby doctor_d » Sat Nov 17, 2018 10:19 am

Nice job, man! Maybe I'll give it a try.

cinderblock63
Member
Member
Posts: 14
Joined: Thu Jan 22, 2009 10:07 am
OS or Distro: gentoo
Location: Menlo Park, CA
Contact:

Re: javascript (node) RPC request issue

Postby cinderblock63 » Sat Nov 17, 2018 10:56 am

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


Return to “Development”

Who is online

Users browsing this forum: No registered users and 1 guest