Skip to content
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

AssertionError [ERR_ASSERTION]: Difference is Invalid #2

Open
dragouf opened this issue Nov 5, 2017 · 14 comments
Open

AssertionError [ERR_ASSERTION]: Difference is Invalid #2

dragouf opened this issue Nov 5, 2017 · 14 comments

Comments

@dragouf
Copy link

dragouf commented Nov 5, 2017

thanks for this library, anyway I got this :

AssertionError [ERR_ASSERTION]: Difference is Invalid
    at BufferReader.move (.\hapclieny\node_modules\buffer-reader\index.js:29:5)
    at EventedHttpClient._parseMessage (.\hapclient\node_modules\hap-client\dist\EventedHttpClient.js:230:24)
    at EventedHttpClient._bufferSplitter (.\hapclient\node_modules\hap-client\dist\EventedHttpClient.js:187:27)
    at Socket.socket.on (.\hapclient\node_modules\message-socket\dist\index.js:157:29)
    at emitNone (events.js:106:13)
    at Socket.emit (events.js:208:7)
    at emitReadable_ (_stream_readable.js:513:10)
    at emitReadable (_stream_readable.js:507:7)
    at addChunk (_stream_readable.js:274:7)
    at readableAddChunk (_stream_readable.js:250:11)

when I try to execute this :

import { Observable, Subject } from 'rxjs';
import HapClient from 'hap-client';

const client = new HapClient('NodeClient', "192.168.1.93", 80);
client
  .pair(
      Observable.of('137-61-085')
  )
  .subscribe({
      complete() {
          console.log("Pairing complete");
      }
  });

any idea ?

I execute this on windows 10

@dragouf
Copy link
Author

dragouf commented Nov 5, 2017

I tried on linux ubuntu 17 with nodejs 8 and got the same error (this come from hap-client-tool but it same for the script above which use hap-client) :


assert.js:42
  throw new errors.AssertionError({
  ^

AssertionError [ERR_ASSERTION]: Difference is Invalid
    at BufferReader.move (/usr/lib/node_modules/hap-client-tool/node_modules/buffer-reader/index.js:29:5)
    at EventedHttpClient._parseMessage (/usr/lib/node_modules/hap-client-tool/node_modules/hap-client/dist/EventedHttpClient.js:230:24)
    at EventedHttpClient._bufferSplitter (/usr/lib/node_modules/hap-client-tool/node_modules/hap-client/dist/EventedHttpClient.js:187:27)
    at Socket.socket.on (/usr/lib/node_modules/hap-client-tool/node_modules/message-socket/dist/index.js:157:29)
    at emitNone (events.js:106:13)
    at Socket.emit (events.js:208:7)
    at emitReadable_ (_stream_readable.js:513:10)
    at emitReadable (_stream_readable.js:507:7)
    at addChunk (_stream_readable.js:274:7)
    at readableAddChunk (_stream_readable.js:250:11)

@dragouf
Copy link
Author

dragouf commented Nov 6, 2017

@forty2

@forty2
Copy link
Owner

forty2 commented Nov 6, 2017

@dragouf Apologies, I was away from my computer all weekend. I will take a look at this sometime this evening.

@forty2
Copy link
Owner

forty2 commented Nov 7, 2017

@dragouf Usually buffer issues like this turn out to be either an old version of Node, or something weird about the data being returned by the device itself. Since you've tried with Node 8, we can be pretty sure Node isn't the problem :-) What kind of device are you trying to connect to?

@dragouf
Copy link
Author

dragouf commented Nov 7, 2017

Thanks for your reply.
I’m using koogeek smart plug :
https://www.koogeek.com/p-p1eu.html

@forty2
Copy link
Owner

forty2 commented Nov 8, 2017

Yeah, I haven't tested with that device before. It's probably returning some unexpected data; let's see if we can figure out what. Could you please try again (either with hap-client-tool or with your original hap-client code), but this time set the environment variable DEBUG=* first? This will produce a ton of debugging output which will hopefully contain enough information to figure out what's going wrong.

@dragouf
Copy link
Author

dragouf commented Nov 8, 2017

ok no problem. Here is the result of the hap-client-tool command in debug :

message-socket no connection; let's make one. +0ms
  hap-client:hap Reusing long-term keys +0ms
  hap-client:tlv turning 0 into buffer +0ms
  hap-client:tlv adding 1 bytes of type 0 to the buffer starting at 0 +1ms
  hap-client:tlv turning 1 into buffer +0ms
  hap-client:tlv adding 1 bytes of type 6 to the buffer starting at 0 +0ms
  hap-client:hap encoded request: <Buffer 00 01 00 06 01 01> +2ms
  hap-client:http POSTing to /pair-setup: <Buffer 00 01 00 06 01 01> +0ms
  hap-client:http requesting: POST /pair-setup +2ms
  hap-client:http raw request: 504f5354202f706169722d736574757020485454502f312e310d0a486f73743a203139322e3136382e312e39353a38300d0a436f6e74656e742d547970653a206170706c69636174696f6e2f70616972696e672b746c76380d0a436f6e74656e742d4c656e6774683a20360d0a0d0a000100060101 +1ms
  hap-client:http raw request (post middleware): 504f5354202f706169722d736574757020485454502f312e310d0a486f73743a203139322e3136382e312e39353a38300d0a436f6e74656e742d547970653a206170706c69636174696f6e2f70616972696e672b746c76380d0a436f6e74656e742d4c656e6774683a20360d0a0d0a000100060101 +0ms
  hap-client:http Request sent +0ms
  message-socket connection pending +50ms
  message-socket socket connected; let's do some work +363ms
  message-socket Getting down to business +1ms
  message-socket sent: 504f5354202f706169722d736574757020485454502f312e310d0a486f73743a203139322e3136382e312e39353a38300d0a436f6e74656e742d547970653a206170706c69636174696f6e2f70616972696e672b746c76380d0a436f6e74656e742d4c656e6774683a20360d0a0d0a000100060101 +0ms
  message-socket nothing to do! +0ms
  message-socket got raw message: 485454502f312e3120323030204f4b0d0a +9ms
  message-socket existing buffer:  +0ms
  hap-client:http status: HTTP, 1.1, 200, OK +377ms

@dragouf
Copy link
Author

dragouf commented Nov 8, 2017

also tried with the dump command :

message-socket no connection; let's make one. +0ms
  hap-client:hap Reusing long-term keys +0ms
  hap-client:tlv turning 0 into buffer +0ms
  hap-client:tlv adding 1 bytes of type 0 to the buffer starting at 0 +1ms
  hap-client:tlv turning 1 into buffer +0ms
  hap-client:tlv adding 1 bytes of type 6 to the buffer starting at 0 +0ms
  hap-client:tlv adding 32 bytes of type 3 to the buffer starting at 0 +0ms
  hap-client:hap encoded request: <Buffer 00 01 00 06 01 01 03 20 82 e0 99 c8 36 0b 23 59 f5 92 2f 64 0e c4 1b 9f 90 0a f4 ac 96 54 58 61 55 e9 28 c4 25 e5 62 42> +3ms
  hap-client:http POSTing to /pair-verify: <Buffer 00 01 00 06 01 01 03 20 82 e0 99 c8 36 0b 23 59 f5 92 2f 64 0e c4 1b 9f 90 0a f4 ac 96 54 58 61 55 e9 28 c4 25 e5 62 42> +0ms
  hap-client:http requesting: POST /pair-verify +1ms
  hap-client:http raw request: 504f5354202f706169722d76657269667920485454502f312e310d0a486f73743a203139322e3136382e312e39353a38300d0a436f6e74656e742d547970653a206170706c69636174696f6e2f70616972696e672b746c76380d0a436f6e74656e742d4c656e6774683a2034300d0a0d0a000100060101032082e099c8360b2359f5922f640ec41b9f900af4ac9654586155e928c425e56242 +0ms
  hap-client:http raw request (post middleware): 504f5354202f706169722d76657269667920485454502f312e310d0a486f73743a203139322e3136382e312e39353a38300d0a436f6e74656e742d547970653a206170706c69636174696f6e2f70616972696e672b746c76380d0a436f6e74656e742d4c656e6774683a2034300d0a0d0a000100060101032082e099c8360b2359f5922f640ec41b9f900af4ac9654586155e928c425e56242 +0ms
  hap-client:http Request sent +0ms
  message-socket connection pending +48ms
  message-socket socket connected; let's do some work +1ms
  message-socket Getting down to business +1ms
  message-socket sent: 504f5354202f706169722d76657269667920485454502f312e310d0a486f73743a203139322e3136382e312e39353a38300d0a436f6e74656e742d547970653a206170706c69636174696f6e2f70616972696e672b746c76380d0a436f6e74656e742d4c656e6774683a2034300d0a0d0a000100060101032082e099c8360b2359f5922f640ec41b9f900af4ac9654586155e928c425e56242 +0ms
  message-socket nothing to do! +1ms
  message-socket got raw message: 485454502f312e3120323030204f4b0d0a +36ms
  message-socket existing buffer:  +1ms
  hap-client:http status: HTTP, 1.1, 200, OK +43ms
assert.js:42
  throw new errors.AssertionError({
  ^

AssertionError [ERR_ASSERTION]: Difference is Invalid
    at BufferReader.move (/usr/lib/node_modules/hap-client-tool/node_modules/buffer-reader/index.js:29:5)
    at EventedHttpClient._parseMessage (/usr/lib/node_modules/hap-client-tool/node_modules/hap-client/dist/EventedHttpClient.js:230:24)
    at EventedHttpClient._bufferSplitter (/usr/lib/node_modules/hap-client-tool/node_modules/hap-client/dist/EventedHttpClient.js:187:27)
    at Socket.socket.on (/usr/lib/node_modules/hap-client-tool/node_modules/message-socket/dist/index.js:157:29)
    at emitNone (events.js:106:13)
    at Socket.emit (events.js:208:7)
    at emitReadable_ (_stream_readable.js:513:10)
    at emitReadable (_stream_readable.js:507:7)
    at addChunk (_stream_readable.js:274:7)
    at readableAddChunk (_stream_readable.js:250:11)

in the previous result it also has the AssertionError [ERR_ASSERTION]: Difference is Invalid but didn't paste it.

@dragouf
Copy link
Author

dragouf commented Nov 8, 2017

in case here is what I get with avahi-browse :

+ wlp1s0 IPv6 Koogeek-P1-C93CAC                             _hap._tcp            local
+ wlp1s0 IPv4 Koogeek-P1-C93CAC                             _hap._tcp            local
= wlp1s0 IPv6 Koogeek-P1-C93CAC                             _hap._tcp            local
   hostname = [hap-C93CAC.local]
   address = [192.168.1.95]
   port = [80]
   txt = ["s#=1" "ci=7" "sf=0" "pv=1.0" "md=P1EU" "id=F8:89:61:8B:12:B0" "ff=1" "c#=1"]
= wlp1s0 IPv4 Koogeek-P1-C93CAC                             _hap._tcp            local
   hostname = [hap-C93CAC.local]
   address = [192.168.1.95]
   port = [80]
   txt = ["s#=1" "ci=7" "sf=0" "pv=1.0" "md=P1EU" "id=F8:89:61:8B:12:B0" "ff=1" "c#=1"]

@forty2
Copy link
Owner

forty2 commented Nov 10, 2017

@dragouf I think what's going on here is that the HTTP response from the device is being split over multiple network messages, which the parsing code isn't set up to handle.

If you wouldn't mind helping debug, could you please go into your node_modules/hap-client/dist folder and open EventedHttpClient.js, and replace line 187 with this code:

let parsed;
try {
   parsed = this._parseMessage(new _bufferReader2.default(processed));
} catch (e) {
   // parsing failed; wait for more data
  return [[], buf];
}

This should catch the exception and wait for more data to come in before trying again.

If you have trouble making this change, I can put together a new version for you to test with this weekend.

Thanks!

@dragouf
Copy link
Author

dragouf commented Nov 10, 2017

@forty2 thanks for the fix, I tried with hap-client-tool -c node -p 80 -d 192.168.1.93 pair and now got this with the fix :

  message-socket no connection; let's make one. +0ms
  hap-client:hap Reusing long-term keys +0ms
  hap-client:tlv turning 0 into buffer +0ms
  hap-client:tlv adding 1 bytes of type 0 to the buffer starting at 0 +0ms
  hap-client:tlv turning 1 into buffer +0ms
  hap-client:tlv adding 1 bytes of type 6 to the buffer starting at 0 +0ms
  hap-client:hap encoded request: <Buffer 00 01 00 06 01 01> +0ms
  hap-client:http POSTing to /pair-setup: <Buffer 00 01 00 06 01 01> +0ms
  hap-client:http requesting: POST /pair-setup +15ms
  hap-client:http raw request: 504f5354202f706169722d736574757020485454502f312e310d0a486f73743a203139322e3136382e312e39333a38300d0a436f6e74656e742d547970653a206170706c69636174696f6e2f70616972696e672b746c76380d0a436f6e74656e742d4c656e6774683a20360d0a0d0a000100060101 +0ms
  hap-client:http raw request (post middleware): 504f5354202f706169722d736574757020485454502f312e310d0a486f73743a203139322e3136382e312e39333a38300d0a436f6e74656e742d547970653a206170706c69636174696f6e2f70616972696e672b746c76380d0a436f6e74656e742d4c656e6774683a20360d0a0d0a000100060101 +0ms
  hap-client:http Request sent +0ms
  message-socket connection pending +46ms
  message-socket socket connected; let's do some work +0ms
  message-socket Getting down to business +0ms
  message-socket sent: 504f5354202f706169722d736574757020485454502f312e310d0a486f73743a203139322e3136382e312e39333a38300d0a436f6e74656e742d547970653a206170706c69636174696f6e2f70616972696e672b746c76380d0a436f6e74656e742d4c656e6774683a20360d0a0d0a000100060101 +0ms
  message-socket nothing to do! +16ms
  message-socket got raw message: 485454502f312e3120323030204f4b0d0a +0ms
  message-socket existing buffer:  +0ms
  hap-client:http status: HTTP, 1.1, 200, OK +16ms
  message-socket leftover: 485454502f312e3120323030204f4b0d0a +0ms
  message-socket got raw message: 436f6e6e656374696f6e3a206b6565702d616c6976650d0a436f6e74656e742d547970653a206170706c69636174696f6e2f70616972696e672b746c76380d0a436f6e74656e742d4c656e6774683a20360d0a0d0a060102070106 +78ms
  message-socket existing buffer: 485454502f312e3120323030204f4b0d0a +0ms
  hap-client:http status: HTTP, 1.1, 200, OK +78ms
  hap-client:http Reading 6 bytes for body... +0ms
  hap-client:http There are 6 bytes left in the buffer +0ms
  hap-client:http finished reading +0ms
  hap-client:http parsing body +0ms
  hap-client:http returning from 108 to 108 +0ms
  message-socket leftover:  +16ms
  message-socket there are 1 observers +0ms
  message-socket delivering to 1 +0ms
Error: Pairing failure: MaxAuthenticationAttempts
    at .\hap-client-tool\node_modules\hap-client\dist\HapClient.js:124:47
    at tryCatcher (.\hap-client-tool\node_modules\rxjs\util\tryCatch.js:6:31)
    at ExpandSubscriber._next (.\hap-client-tool\node_modules\rxjs\operators\expand.js:108:59)
    at ExpandSubscriber.Subscriber.next (.\hap-client-tool\node_modules\rxjs\Subscriber.js:89:18)
    at DeferSubscriber.OuterSubscriber.notifyNext (.\hap-client-tool\node_modules\rxjs\OuterSubscriber.js:19:26)
    at InnerSubscriber._next (.\hap-client-tool\node_modules\rxjs\InnerSubscriber.js:23:21)
    at InnerSubscriber.Subscriber.next (.\hap-client-tool\node_modules\rxjs\Subscriber.js:89:18)
    at TakeSubscriber._next (.\hap-client-tool\node_modules\rxjs\operators\take.js:82:30)
    at TakeSubscriber.Subscriber.next (.\hap-client-tool\node_modules\rxjs\Subscriber.js:89:18)
    at FilterSubscriber._next (.\hap-client-tool\node_modules\rxjs\operators\filter.js:89:30)
  message-socket got raw message: null +15ms
  message-socket existing buffer:  +0ms
  message-socket leftover:  +0ms

@dragouf
Copy link
Author

dragouf commented Nov 19, 2017

Hi @forty2,

no idea about this error ?
I wanted to try to debug to but my home computer is not working for the moment...

@bandrews
Copy link

I'm having similar issues, except with an iHome Smart Plug iSP6X. Making the fix to line 187 for multi part responses got me past the Difference Is Invalid error, but now I'm stuck at the MaxAuthenticationAttempts pairing failure as well. Here's my log in case it helps:

C:\Users\username\AppData\Roaming\npm\node_modules>hap-client-tool pair -d 192.168.1.117 -p 80 > output
message-socket no connection; let's make one. +0ms
hap-client:hap Reusing long-term keys +0ms
hap-client:tlv turning 0 into buffer +0ms
hap-client:tlv adding 1 bytes of type 0 to the buffer starting at 0 +1ms
hap-client:tlv turning 1 into buffer +0ms
hap-client:tlv adding 1 bytes of type 6 to the buffer starting at 0 +0ms
hap-client:hap encoded request: <Buffer 00 01 00 06 01 01> +2ms
hap-client:http POSTing to /pair-setup: <Buffer 00 01 00 06 01 01> +0ms
hap-client:http requesting: POST /pair-setup +1ms
hap-client:http raw request: 504f5354202f706169722d736574757020485454502f312e310d0a486f73743a203139322e3136382e312e3131373a38300d0a436f6e74656e742d547970653a206170706c69636174696f6e2f70616972696e672b746c76380d0a436f6e74656e742d4c656e6774683a20360d0a0d0a000100060101 +0ms
hap-client:http raw request (post middleware): 504f5354202f706169722d736574757020485454502f312e310d0a486f73743a203139322e3136382e312e3131373a38300d0a436f6e74656e742d547970653a206170706c69636174696f6e2f70616972696e672b746c76380d0a436f6e74656e742d4c656e6774683a20360d0a0d0a000100060101 +0ms
hap-client:http Request sent +0ms
message-socket connection pending +31ms
message-socket socket connected; let's do some work +90ms
message-socket Getting down to business +5ms
message-socket sent: 504f5354202f706169722d736574757020485454502f312e310d0a486f73743a203139322e3136382e312e3131373a38300d0a436f6e74656e742d547970653a206170706c69636174696f6e2f70616972696e672b746c76380d0a436f6e74656e742d4c656e6774683a20360d0a0d0a000100060101 +1ms
message-socket nothing to do! +1ms
message-socket got raw message: 485454502f312e3120323030204f4b0d0a +8ms
message-socket existing buffer: +0ms
hap-client:http status: HTTP, 1.1, 200, OK +111ms
message-socket leftover: 485454502f312e3120323030204f4b0d0a +5ms
message-socket got raw message: 436f6e6e656374696f6e3a206b6565702d616c6976650d0a436f6e74656e742d547970653a206170706c69636174696f6e2f70616972696e672b746c76380d0a436f6e74656e742d4c656e6774683a20360d0a0d0a060102070106 +37ms
message-socket existing buffer: 485454502f312e3120323030204f4b0d0a +9ms
hap-client:http status: HTTP, 1.1, 200, OK +48ms
hap-client:http Reading 6 bytes for body... +4ms
hap-client:http There are 6 bytes left in the buffer +16ms
hap-client:http finished reading +2ms
hap-client:http parsing body +3ms
hap-client:http returning from 108 to 108 +2ms
message-socket leftover: +28ms
message-socket there are 1 observers +2ms
message-socket delivering to 1 +2ms
Error: Pairing failure: MaxAuthenticationAttempts
at C:\Users\username\AppData\Roaming\npm\node_modules\hap-client-tool\node_modules\hap-client\dist\HapClient.js:124:47
at tryCatcher (C:\Users\username\AppData\Roaming\npm\node_modules\hap-client-tool\node_modules\rxjs\util\tryCatch.js:6:31)
at ExpandSubscriber._next (C:\Users\username\AppData\Roaming\npm\node_modules\hap-client-tool\node_modules\rxjs\operators\expand.js:108:59)
at ExpandSubscriber.Subscriber.next (C:\Users\username\AppData\Roaming\npm\node_modules\hap-client-tool\node_modules\rxjs\Subscriber.js:89:18)
at DeferSubscriber.OuterSubscriber.notifyNext (C:\Users\username\AppData\Roaming\npm\node_modules\hap-client-tool\node_modules\rxjs\OuterSubscriber.js:19:26)
at InnerSubscriber._next (C:\Users\username\AppData\Roaming\npm\node_modules\hap-client-tool\node_modules\rxjs\InnerSubscriber.js:23:21)
at InnerSubscriber.Subscriber.next (C:\Users\username\AppData\Roaming\npm\node_modules\hap-client-tool\node_modules\rxjs\Subscriber.js:89:18)
at TakeSubscriber._next (C:\Users\username\AppData\Roaming\npm\node_modules\hap-client-tool\node_modules\rxjs\operators\take.js:82:30)
at TakeSubscriber.Subscriber.next (C:\Users\username\AppData\Roaming\npm\node_modules\hap-client-tool\node_modules\rxjs\Subscriber.js:89:18)
at FilterSubscriber._next (C:\Users\username\AppData\Roaming\npm\node_modules\hap-client-tool\node_modules\rxjs\operators\filter.js:89:30)
message-socket got raw message: null +25ms
message-socket existing buffer: +2ms
message-socket leftover: +2ms

@raufis27
Copy link

Same problem here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants