GithubHelp home page GithubHelp logo

davehorton / drachtio Goto Github PK

View Code? Open in Web Editor NEW

This project forked from senchalabs/connect

68.0 68.0 18.0 4.96 MB

DEPRECATED!! please use https://github.com/davehorton/drachtio-srf

Home Page: https://github.com/davehorton/drachtio-srf

License: MIT License

Makefile 0.38% JavaScript 99.62%

drachtio's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

drachtio's Issues

Outbound mode: endSession not closing underlying socket connection

Having a slight issue with connections not being closed when running in "outbound" mode. Based off of the example code but using Srf.

srf.register((req, res) => {
  logger.info('srf.register socket:', res.socket);

  try {
    logger.info({ registration: req.registration }, 'Received an authenticated registration request');

    if( 'unregister' === req.registration.type ) {
      res.send(200);
    } else {
      // min_expiry
      if (req.registration.expires < 900) {
        req.registration.expires = 900;
      }

      const contactUri = req.registration.contact[0].uri;
      
      res.send(200, {
        headers: {
          'Contact': '<' + contactUri + '>;expires=' + Math.floor(response.registration.expires / 1000)
        }
      });
    }
  } catch (err) {
    res.send(503, err.message);
    // TODO: handle error accordingly!
  } finally {    
    srf.endSession(res);        
  }
});

The amount of client connections continues to rise on drachtio-server, and the output from the logging call in the code above for 'res.socket' is as follows:

[2018-04-25T09:06:31.718Z] INFO (1 on tv2-call-router-node-535718781-91n9d): srf.register socket: 
{
  "connecting": false,
  "_hadError": false,
  "_handle": {
    "bytesRead": 1610,
    "_externalStream": {
      
    },
    "fd": 194,
    "reading": true,
    "owner": "[Circular]",
    "onconnection": null,
    "writeQueueSize": 0
  },
  "_parent": null,
  "_host": null,
  "_readableState": {
    "objectMode": false,
    "highWaterMark": 16384,
    "buffer": {
      "head": null,
      "tail": null,
      "length": 0
    },
    "length": 0,
    "pipes": null,
    "pipesCount": 0,
    "flowing": true,
    "ended": false,
    "endEmitted": false,
    "reading": true,
    "sync": false,
    "needReadable": true,
    "emittedReadable": false,
    "readableListening": false,
    "resumeScheduled": false,
    "destroyed": false,
    "defaultEncoding": "utf8",
    "awaitDrain": 0,
    "readingMore": false,
    "decoder": {
      "encoding": "utf8",
      "lastNeed": 0,
      "lastTotal": 0,
      "lastChar": {
        "type": "Buffer",
        "data": [
          200,
          72,
          139,
          77
        ]
      }
    },
    "encoding": "utf8"
  },
  "readable": true,
  "domain": null,
  "_events": {
    
  },
  "_eventsCount": 7,
  "_writableState": {
    "objectMode": false,
    "highWaterMark": 16384,
    "finalCalled": false,
    "needDrain": false,
    "ending": false,
    "ended": false,
    "finished": false,
    "destroyed": false,
    "decodeStrings": false,
    "defaultEncoding": "utf8",
    "length": 0,
    "writing": false,
    "corked": 0,
    "sync": false,
    "bufferProcessing": false,
    "writecb": null,
    "writelen": 0,
    "bufferedRequest": null,
    "lastBufferedRequest": null,
    "pendingcb": 0,
    "prefinished": false,
    "errorEmitted": false,
    "bufferedRequestCount": 0,
    "corkedRequestsFree": {
      "next": null,
      "entry": null
    }
  },
  "writable": true,
  "allowHalfOpen": false,
  "_bytesDispatched": 66,
  "_sockname": {
    "address": "::ffff:10.244.200.177",
    "family": "IPv6",
    "port": 4000
  },
  "_pendingData": null,
  "_pendingEncoding": "",
  "server": {
    "domain": null,
    "_events": {
      
    },
    "_eventsCount": 2,
    "_connections": 184,
    "_handle": {
      "bytesRead": 0,
      "_externalStream": {
        
      },
      "fd": 10,
      "reading": false,
      "owner": "[Circular]",
      "onread": null,
      "writeQueueSize": 0
    },
    "_usingSlaves": false,
    "_slaves": [
      
    ],
    "_unref": false,
    "allowHalfOpen": false,
    "pauseOnConnect": false,
    "_connectionKey": "6::::4000"
  },
  "_server": {
    "domain": null,
    "_events": {
      
    },
    "_eventsCount": 2,
    "_connections": 184,
    "_handle": {
      "bytesRead": 0,
      "_externalStream": {
        
      },
      "fd": 10,
      "reading": false,
      "owner": "[Circular]",
      "onread": null,
      "writeQueueSize": 0
    },
    "_usingSlaves": false,
    "_slaves": [
      
    ],
    "_unref": false,
    "allowHalfOpen": false,
    "pauseOnConnect": false,
    "_connectionKey": "6::::4000"
  },
  "_peername": {
    "address": "::ffff:10.155.250.70",
    "family": "IPv6",
    "port": 57810
  },
  "_consuming": true
}

The "_connections": 184, never reduces but just keeps climbing even after calling srf.endSession(res). It gets to the point where the file descriptors are exhausted and we need to restart the application to get rid of the connections.

Using npm packages:
"drachtio": "^4.1.9",
"drachtio-mw-registration-parser": "0.0.2",
"drachtio-srf": "^4.2.11",
"passport": "^0.4.0",
"passport-http": "^0.3.0"

Authentication is using passport middleware with DigestAuthentication.

Please let me know if you require any additional information. Thanks

getParsedHeader returns quoted "components" with the quotes included

Hi Dave,

req.getParsedHeader('Authorization') returns like so:

[2017-10-04T10:18:16.290Z] DEBUG (3468 on steve-xps-eos): Authorization header
authorization: [
{
"scheme": "Digest",
"username": ""9123c799-e4dc-4dd5-ae11-3b7e35df57d0"",
"realm": ""fibrephone.co.za"",
"nonce": ""VbkBPUJl4rAGa5fwSzuS6ffhOH98LpFh"",
"uri": ""sip:[email protected]:6060;transport=TCP"",
"response": ""84d4b16e1e8898b70fe5f45bac381acb"",
"cnonce": ""5e385c0f4224a7332acb25753ce41452"",
"nc": "00000001",
"qop": "auth",
"algorithm": "MD5"
}
]

It doesn't seem very useful for me that the returned components contain embedded quotes?

Perhaps it creates a backward compatibility problem to change it, but it would be handier if they were just used as delimiters and not returned in the result?

Thanks,
Steve

should disconnect socket after invalid message in outbound mode

When an invalid or corrupt message is received on the tcp socket in outbound mode, it is almost always a spammer or misdirected http request. Curerntly the socket is not being closed by drachtio -- it should be immediately closed and discarded. The logs below show an example where the socket is not closed.

Mon, 29 Jan 2018 06:30:44 GMT drachtio:socket _initServer: added socket: 62160:3002, count now: 1
{"level":50,"time":1517207444879,"msg":"uncaughtException: Error: invalid message from server, did not start with length#: \u0003\u0000\u0000+&�\u0000\u0000\u0000\u0000\u0000Cookie: mstshash=hello\r\n\u0001\u0000\b\u0000\u0003\u0000\u0000\u0000","pid":621,"hostname":"drachtio-group-staging-ds65","v":1}
Error: invalid message from server, did not start with length#: ^C^@^@+&�^@^@^@^@^@Cookie: mstshash=hello^M
^A^@^H^@^C^@^@^@
    at WireProtocol._onData (/usr/local/src/node-srs/node_modules/drachtio/lib/wire-protocol.js:238:19)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at TCP.onread (net.js:547:20)
Mon, 29 Jan 2018 07:04:39 GMT drachtio:socket _initServer: added socket: 51187:3002, count now: 2
{"level":50,"time":1517209479050,"msg":"uncaughtException: Error: invalid message from server, did not start with length#: \u0003\u0000\u0000+&�\u0000\u0000\u0000\u0000\u0000Cookie: mstshash=hello\r\n\u0001\u0000\b\u0000\u0003\u0000\u0000\u0000","pid":621,"hostname":"drachtio-group-staging-ds65","v":1}
Error: invalid message from server, did not start with length#: ^C^@^@+&�^@^@^@^@^@Cookie: mstshash=hello^M
^A^@^H^@^C^@^@^@
    at WireProtocol._onData (/usr/local/src/node-srs/node_modules/drachtio/lib/wire-protocol.js:238:19)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at TCP.onread (net.js:547:20)
Mon, 29 Jan 2018 07:33:33 GMT drachtio:socket _initServer: added socket: 61943:3002, count now: 3
{"level":50,"time":1517211213321,"msg":"uncaughtException: Error: invalid message from server, did not start with length#: \u0003\u0000\u0000+&�\u0000\u0000\u0000\u0000\u0000Cookie: mstshash=hello\r\n\u0001\u0000\b\u0000\u0003\u0000\u0000\u0000","pid":621,"hostname":"drachtio-group-staging-ds65","v":1}
Error: invalid message from server, did not start with length#: ^C^@^@+&�^@^@^@^@^@Cookie: mstshash=hello^M
^A^@^H^@^C^@^@^@
    at WireProtocol._onData (/usr/local/src/node-srs/node_modules/drachtio/lib/wire-protocol.js:238:19)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at TCP.onread (net.js:547:20)
Mon, 29 Jan 2018 07:39:21 GMT drachtio:socket _initServer: added socket: 60040:3002, count now: 4

lib/wire-protocol.js regex issue

Hi,

I'm facing quite a lot of error invalid message from server, did not start with length#:.
I'm using drachtio 4.1.6 package and spotted an issue with a regex in the _onData handler of wire-protocol

  _onData(socket, msg) {
    this._logger('<===' + CRLF + msg + CRLF) ;

    if (!this.mapIncomingMsg.has(socket)) {
      this.mapIncomingMsg.set(socket, {
        incomingMsg: '',
        length: -1
      });
    }
    const obj = this.mapIncomingMsg.get(socket) ;
    try {
      while ([...msg].length > 0) {
        let pos ;
        if (0 === obj.incomingMsg.length) {
          //waiting for a new message
          pos = msg.indexOf('#') ;
          if (-1 === pos) {
            if (msg.match(/^\\d+$/)) {
              //it can happen that a message is broken between the length digits and '#'
              obj.incomingMsg = msg ;
              obj.incomingMsgLength = -1 ;  //unknown
              return ;
            }
            else {
              throw new Error('invalid message from server, did not start with length#: ' + msg) ;
            }
          }
          msg = this.parseMessageHeader(msg, pos, obj);
        }

The msg.match(/^\\d+$/) is probably wrong and should be msg.match(/^\d+$/)

Cheers

Drachtio stops communicating with app

Hi Dave,

I've just had a scenario where the drachtio server simply stops communicating with the Javascript application (drachtio-srf). I have the standard errors in my Javascript, but no output in the logs.

Looking through drachtio.log, I can't see much to point me in the right direction. Is there any indication anywhere of what information is sent to the registered application, what happens if it unregisters, etc?

Thanks!

SIP trinket provider

Wow autocorrect - SIP Trunk provider

Hi there,

Just wondering if I am able to register with another sip server/provider and handle the flow?

Many thanks,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.