reklatsmasters / dnscrypt

dnscrypt - authenticated and encrypted dns client for nodejs
MIT License
14 stars 1 forks source link

Both callback and async style not working #7

Closed unixfox closed 4 years ago

unixfox commented 4 years ago

Hello I tried the example code in the Usage section but it doesn't seem to work:

dnscrypt.resolve('example.com', (err, addresses) => { if (err) { console.error(err); } else { console.log(addresses); } });

It returns this error:

/tmp/node_modules/dnscrypt/src/dnscrypt.js:163 callback(null, addresses); ^

TypeError: callback is not a function at /tmp/node_modules/dnscrypt/src/dnscrypt.js:163:7 at AsyncQuery.callback (/tmp/node_modules/dnscrypt/src/dnscrypt.js:137:7) at Protocol.onresponse (/tmp/node_modules/dnscrypt/src/protocol.js:266:14) at Protocol.onmessage (/tmp/node_modules/dnscrypt/src/protocol.js:151:14) at Socket. (/tmp/node_modules/dnscrypt/src/protocol.js:68:51) at Socket.emit (events.js:210:5) at UDP.onMessage [as onmessage] (dgram.js:910:8)

- With async/await style:
```js
const dnscrypt = require('dnscrypt');

(async () => {
        await dnscrypt.resolve4('example.com');
})();

It returns this error:

/tmp/node_modules/next-state/src/index.js:54
      throw new TypeError('Invalid state set');
      ^

TypeError: Invalid state set
    at StateMachine.next (/tmp/node_modules/next-state/src/index.js:54:13)
    at Protocol.forgetCertificate (/tmp/node_modules/dnscrypt/src/protocol.js:78:20)
    at DNSCrypt.close (/tmp/node_modules/dnscrypt/src/dnscrypt.js:53:19)
    at /tmp/node_modules/dnscrypt/src/dns.js:30:9
    at /tmp/node_modules/dnscrypt/src/dnscrypt.js:163:7
    at AsyncQuery.callback (/tmp/node_modules/dnscrypt/src/dnscrypt.js:137:7)
    at Protocol.onresponse (/tmp/node_modules/dnscrypt/src/protocol.js:266:14)
    at Protocol.onmessage (/tmp/node_modules/dnscrypt/src/protocol.js:151:14)
    at Socket.<anonymous> (/tmp/node_modules/dnscrypt/src/protocol.js:68:51)
    at Socket.emit (events.js:210:5)

I'm using NodeJS v13.1.0 but it didn't work with NodeJS v12.13.0 and v8.16.2 too. Maybe I'm missing something in the code?

reklatsmasters commented 4 years ago

Looks strange. Of course, it’s worked for me. Ok, I will fix that.