@babblevoice/projectrtp 2.3.5 → 2.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,26 @@
1
+ name: C/C++ CI
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+
8
+ runs-on: ubuntu-latest
9
+
10
+ steps:
11
+ - uses: actions/checkout@v1
12
+ - name: update
13
+ run: sudo apt update
14
+ - name: submodules
15
+ run: git submodule update --init --recursive
16
+ - name: Install apt dependencies
17
+ run: sudo apt install libboost-dev libboost-system-dev libspandsp-dev gnutls-dev libsrtp2-dev cmake ccache
18
+ - name: Build ilbc
19
+ run: |
20
+ cd libilbc
21
+ cmake . -DCMAKE_INSTALL_LIBDIR=/lib -DCMAKE_INSTALL_INCLUDEDIR=/usr/include; cmake --build .; sudo cmake --install .
22
+ cd ..
23
+ - name: Build project
24
+ run: |
25
+ cd src
26
+ make
@@ -0,0 +1,19 @@
1
+ name: Run Linters
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+
8
+ runs-on: ubuntu-latest
9
+
10
+ steps:
11
+ - uses: actions/checkout@v1
12
+ - name: update
13
+ run: sudo apt update
14
+ - name: submodules
15
+ run: sudo apt install cppcheck
16
+ - name: Run cppcheck
17
+ run: |
18
+ cppcheck ./src
19
+
package/README.md CHANGED
@@ -116,9 +116,9 @@ Build ilbc from the sub module plus install other dependancies.
116
116
 
117
117
  ```bash
118
118
 
119
- apt install libboost-dev libspandsp-dev gnutls-dev libsrtp2-dev cmake
119
+ apt install libboost-dev libboost-system-dev libspandsp-dev gnutls-dev libsrtp2-dev cmake ccache
120
120
 
121
- cd ilbc
121
+ cd libilbc
122
122
  cmake . -DCMAKE_INSTALL_LIBDIR=/lib -DCMAKE_INSTALL_INCLUDEDIR=/usr/include; cmake --build .; cmake --install .
123
123
  cd ..
124
124
  ```
package/index.js CHANGED
@@ -468,6 +468,10 @@ class projectrtp {
468
468
  else chan.id = uuidv4()
469
469
 
470
470
  chan.uuid = uuidv4()
471
+
472
+ /* ensure we are identicle to the node version of this object */
473
+ chan.openchannel = this.openchannel.bind( this )
474
+
471
475
  return chan
472
476
  }
473
477
  }
package/lib/node.js CHANGED
@@ -37,6 +37,7 @@ class rtpnode {
37
37
  this.address = address
38
38
  this.port = port
39
39
  this.instance = uuidv4()
40
+ this.connections = new Map()
40
41
  this.messagestate = message.newstate()
41
42
 
42
43
  /* pre callbacks are called when we receive an instruction from
@@ -70,11 +71,17 @@ class rtpnode {
70
71
 
71
72
  return new Promise( resolve => {
72
73
  this._onsocketreadypromiseresolve = resolve
73
- this.connection = net.createConnection( this.port, this.host )
74
+ const connection = net.createConnection( this.port, this.host )
75
+ this.connection = connection
74
76
  this.connection.setKeepAlive( true )
75
-
76
77
  this.connection.on( "connect", this._onsocketconnect.bind( this ) )
77
- this.connection.on( "data", this._onsocketdata.bind( this ) )
78
+ const con = {
79
+ connectionid: uuidv4(),
80
+ connection,
81
+ "connectionlength": 0
82
+ }
83
+ this.connections[ con.connectionid ] = con
84
+ this.connection.on( "data", this._onsocketdata.bind( this, con ) )
78
85
  this.connection.on( "error", this._onsocketerror.bind( this ) )
79
86
  this.connection.on( "close", this._onsocketclose.bind( this ) )
80
87
  } )
@@ -87,9 +94,14 @@ class rtpnode {
87
94
  let listenresolve
88
95
  const listenpromise = new Promise( ( r ) => listenresolve = r )
89
96
  this.server = net.createServer( ( connection ) => {
90
- this.connection = connection
91
- this.connection.setKeepAlive( true )
92
- this.connection.on( "data", this._onsocketdata.bind( this ) )
97
+ const con = {
98
+ connectionid: uuidv4(),
99
+ connection,
100
+ "connectionlength": 0
101
+ }
102
+ this.connections[ con.connectionid ] = con
103
+ connection.setKeepAlive( true )
104
+ connection.on( "data", this._onsocketdata.bind( this, con ) )
93
105
  } )
94
106
 
95
107
  this.server.listen( this.port, this.address )
@@ -104,7 +116,7 @@ class rtpnode {
104
116
  */
105
117
  _onsocketconnect( /* sock */ ) {
106
118
  console.log( "Connected to " + this.host + ":" + this.port )
107
- this.send( {} )
119
+ this.send( {}, this.connection )
108
120
  this._onsocketreadypromiseresolve( this )
109
121
  this._reconnecttime = 500 /* mS */
110
122
  }
@@ -148,14 +160,15 @@ class rtpnode {
148
160
  /**
149
161
  * Send a message back to the main server, include stats to help with load balancing.
150
162
  * @param { object } msg
163
+ * @param { object } connection
151
164
  * @returns { void }
152
165
  */
153
- send( msg ) {
166
+ send( msg, connection ) {
154
167
  this._post( msg, ( modifiedmsg ) => {
155
168
  if( this._destroying ) return
156
169
  msg.status = this.prtp.stats()
157
170
  msg.status.instance = instance
158
- this.connection.write( message.createmessage( modifiedmsg ) )
171
+ connection.write( message.createmessage( modifiedmsg ) )
159
172
  } )
160
173
  }
161
174
 
@@ -168,17 +181,21 @@ class rtpnode {
168
181
  nodeinterface.clean()
169
182
 
170
183
  if( this._reconnecttimerid ) clearTimeout( this._reconnecttimerid )
171
- this.connection.destroy()
184
+ if( this.connection ) this.connection.destroy()
185
+ this.connections.forEach( ( connection ) => {
186
+ connection.destroy()
187
+ } )
172
188
  if ( this.server ) this.server.close()
173
189
  }
174
190
 
175
191
  /**
176
192
  *
177
193
  * @param { object } msg
194
+ * @param { object } con
178
195
  * @returns { Promise< Boolean > }
179
196
  */
180
- async _processmessage( msg ) {
181
- return ( await this._openchannel( msg ) || this._updatechannel( msg ) )
197
+ async _processmessage( msg, con ) {
198
+ return ( await this._openchannel( msg, con ) || this._updatechannel( msg, con ) )
182
199
  }
183
200
 
184
201
  /**
@@ -244,15 +261,16 @@ class rtpnode {
244
261
  }
245
262
 
246
263
  /**
247
- * @private
248
- * @param { Buffer } data
264
+ * @privateopenchannel
265
+ * @param { Buffer } data
266
+ * @param { object } con
249
267
  * @returns { void }
250
268
  */
251
- _onsocketdata( data ) {
269
+ _onsocketdata( con, data ) {
252
270
  message.parsemessage( this.messagestate, data, ( msg ) => {
253
271
  try {
254
272
  this._pre( msg, ( modifiedmsg ) => {
255
- this._processmessage( modifiedmsg )
273
+ this._processmessage( modifiedmsg, con )
256
274
  } )
257
275
  } catch( e ) {
258
276
  console.error( "Unhandled exception in babble-rtp", e )
@@ -262,30 +280,40 @@ class rtpnode {
262
280
 
263
281
  /**
264
282
  * @private
265
- * @param { object } msg
283
+ * @param { object } msg
284
+ * @param { object } con
266
285
  * @returns { Promise< Boolean > }
267
286
  */
268
- async _openchannel( msg ) {
287
+ async _openchannel( msg, con ) {
269
288
  if( "open" !== msg.channel ) return false
289
+ con.connectionlength += 1
270
290
  msg.forcelocal = true
271
291
 
272
292
  const chan = await this.prtp.openchannel( msg, ( x ) => {
273
- if( "close" === x.action ) channels.delete( chan.uuid )
274
- this.send( { ...{ "id": chan.id, "uuid": chan.uuid }, ...x } )
293
+ this.send( { ...{ "id": chan.id, "uuid": chan.uuid }, ...x }, con.connection )
294
+ if( "close" === x.action ) {
295
+ con.connectionlength -= 1
296
+ channels.delete( chan.uuid )
297
+
298
+ if( 0 == con.connectionlength ) {
299
+ this.connections.delete( con.instance )
300
+ con.connection.destroy()
301
+ }
302
+ }
275
303
  } )
276
-
277
304
  channels.set( chan.uuid, chan )
278
- this.send( { ...chan, ...{ "action": "open" } } )
305
+ this.send( { ...chan, ...{ "action": "open" } }, con.connection )
279
306
 
280
307
  return true
281
308
  }
282
309
 
283
310
  /**
284
311
  * @private
285
- * @param { object } msg
312
+ * @param { object } msg
313
+ * @param { object } con
286
314
  * @returns boolean
287
315
  */
288
- _updatechannel( msg ) {
316
+ _updatechannel( msg, con ) {
289
317
 
290
318
  if( undefined === msg.channel ) return false
291
319
  if( undefined === msg.uuid ) return false
@@ -300,7 +328,7 @@ class rtpnode {
300
328
  "id": msg.id,
301
329
  "uuid": msg.uuid
302
330
  }
303
- this.send( { ...{ "error": "Unknown method" }, ...channelidentifiers } )
331
+ this.send( { ...{ "error": "Unknown method" }, ...channelidentifiers }, con.connection )
304
332
  }
305
333
 
306
334
  return true
package/lib/server.js CHANGED
@@ -243,12 +243,7 @@ class channel {
243
243
  if ( receivedmsg.id === chnl.id ) chnl._on( receivedmsg )
244
244
  }
245
245
 
246
- /* find channel and indicate connect */
247
- if( openresolve && "open" == receivedmsg.action ) {
248
- newchannel.uuid = receivedmsg.uuid
249
- newchannel.local = receivedmsg.local
250
- openresolve( newchannel )
251
- }
246
+ if ( openresolve ) openresolve( newchannel )
252
247
  } )
253
248
  } )
254
249
 
@@ -304,7 +299,7 @@ class channel {
304
299
 
305
300
  /* any outstanding to remove where unmix was not called first? */
306
301
  this._removebridge()
307
-
302
+
308
303
  /* close us */
309
304
  this._write( {
310
305
  "channel": "close",
@@ -582,13 +577,12 @@ class channel {
582
577
  */
583
578
  _runopen( msg ) {
584
579
  if( "open" !== msg.action ) return false
585
- if( !this.openresolve ) return true
586
580
 
587
581
  this.local = msg.local
588
582
  this.action = msg.action
589
-
590
583
  this.uuid = msg.uuid
591
584
 
585
+ if( !this.openresolve ) return true
592
586
  this.openresolve( this )
593
587
  delete this.openresolve
594
588
  delete this.openreject
@@ -604,6 +598,12 @@ class channel {
604
598
  */
605
599
  _runclose( msg ) {
606
600
  if( "close" !== msg.action ) return
601
+
602
+ if( undefined !== this.openresolve ) {
603
+ this.openresolve()
604
+ delete this.openresolve
605
+ delete this.openreject
606
+ }
607
607
 
608
608
  if( this.channels ) {
609
609
  // adjust with filter
@@ -612,11 +612,6 @@ class channel {
612
612
  if( 0 === this.channels.length && this.connection.sock ) this.connection.sock.destroy()
613
613
  }
614
614
 
615
- if( undefined !== this.openresolve ) {
616
- this.openresolve()
617
- delete this.openresolve
618
- delete this.openreject
619
- }
620
615
  if( this.connection && this.connection.sock && !this.channels ) {
621
616
  this.connection.sock.destroy()
622
617
  delete this.connection.sock
@@ -633,7 +628,6 @@ class channel {
633
628
  _on( msg ) {
634
629
  msg.timestamp = ( new Date ).getTime()
635
630
  this.history.push( msg )
636
-
637
631
  if( this._runopen( msg ) ) return
638
632
 
639
633
  this.em.emit( "all", msg )
@@ -654,7 +648,7 @@ class channel {
654
648
  if( "" !== uuid ) {
655
649
  msg.uuid = uuid
656
650
  }
657
-
651
+
658
652
  this.connection.sock.write( message.createmessage( msg ) )
659
653
 
660
654
  msg.timestamp = ( new Date ).getTime()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babblevoice/projectrtp",
3
- "version": "2.3.5",
3
+ "version": "2.3.7",
4
4
  "description": "A scalable Node addon RTP server",
5
5
  "main": "index.js",
6
6
  "directories": {
package/src/binding.gyp CHANGED
@@ -3,6 +3,7 @@
3
3
  {
4
4
  "target_name": "projectrtp",
5
5
  "defines": [ "NODE_MODULE", "BOOST_NO_EXCEPTIONS", "BOOST_EXCEPTION_DISABLE" ],
6
+ "cflags_cc!": [ "-fno-rtti" ],
6
7
  "cflags_cc": [
7
8
  "-O3",
8
9
  "-g",
package/src/makefile CHANGED
@@ -1,8 +1,8 @@
1
1
  # -O3 includes -fopt-info-vec -fopt-info-vec-missed
2
2
  DEBUG:= -DDEBUG -g
3
3
  RELEASE:=-O3
4
- CCOPTS:=-Wall -fstack-protector-all -std=c++17 -fconcepts -fsanitize=address -fsanitize=leak -DTESTSUITE
5
- LL:=-lboost_system -lpthread -lrt -L./build/Debug/test/ -lspandsp -lilbc -lgnutls -lsrtp2 -lm -fsanitize=address -fsanitize=leak
4
+ CCOPTS:=-Wall -fstack-protector-all -std=c++20 -fconcepts -fsanitize=address,leak -DTESTSUITE
5
+ LL:=-lboost_system -lpthread -lrt -L./build/Debug/test/ -lspandsp -lilbc -lgnutls -lsrtp2 -lm -fsanitize=address,leak
6
6
 
7
7
  COMPILER:=g++
8
8
  LINKER:=g++
@@ -56,4 +56,8 @@ module.exports = async ( mstimeout ) => {
56
56
  expect( clienta.play( { "loop": true, "files": [ { "wav": "/tmp/ukringing.wav" } ] } ) ).to.be.true
57
57
  expect( channela.echo() ).to.be.true
58
58
 
59
- }
59
+ setTimeout( () => {
60
+ clienta.close()
61
+ }, mstimeout )
62
+
63
+ }
@@ -589,7 +589,7 @@ describe( "rtpproxy server", function() {
589
589
  expect( openreceived ).to.be.true
590
590
  } )
591
591
 
592
- it( "Node as listener server to test", async () => {
592
+ it( "1 channel, node as listener server to test", async () => {
593
593
 
594
594
  const ourport = getnextport()
595
595
  prtp.server.clearnodes()
@@ -604,6 +604,41 @@ describe( "rtpproxy server", function() {
604
604
  n.destroy()
605
605
  } )
606
606
 
607
+ it( "2 channels, node as listener server to test", async () => {
608
+
609
+ const ourport = getnextport()
610
+ prtp.server.clearnodes()
611
+ prtp.server.addnode( { host: "127.0.0.1", port: ourport } )
612
+
613
+ const ournode = node.create( prtp )
614
+
615
+ const n = await ournode.listen( "127.0.0.1", ourport )
616
+ const chnl = await prtp.openchannel()
617
+ const chnl2 = await prtp.openchannel()
618
+ await chnl.close()
619
+ await chnl2.close()
620
+ await new Promise( ( resolve ) => { setTimeout( () => resolve(), 100 ) } )
621
+ n.destroy()
622
+ } )
623
+
624
+ it( "2 channels, node as listener server to test - open a channel through another one", async () => {
625
+
626
+ const ourport = getnextport()
627
+ prtp.server.clearnodes()
628
+ prtp.server.addnode( { host: "127.0.0.1", port: ourport } )
629
+
630
+ const ournode = node.create( prtp )
631
+
632
+ const n = await ournode.listen( "127.0.0.1", ourport )
633
+ const chnl = await prtp.openchannel()
634
+ const chnl2 = await chnl.openchannel()
635
+ await new Promise( ( resolve ) => { setTimeout( () => resolve(), 100 ) } )
636
+ await chnl.close()
637
+ await chnl2.close()
638
+ await new Promise( ( resolve ) => { setTimeout( () => resolve(), 100 ) } )
639
+ n.destroy()
640
+ } )
641
+
607
642
  it( "Ensure we receive middle messages", async() => {
608
643
  /*
609
644
  i.e. messages we receive inbetween an open and close