Permalink
Browse files

registrant updates

Prepare for multiple registrant per host
  • Loading branch information...
1 parent b6ed72a commit f6be2fe1b9b5e883fbede4af6a8bbc677bbc37af @shimaore committed Feb 17, 2014
@@ -1,8 +1,3 @@
-###
-(c) 2010 Stephane Alnet
-Released under the Affero GPL3 license or above
-###
-
p_fun = (f) -> '('+f+')'
ddoc =
@@ -118,8 +113,10 @@ ddoc.views.registrant_by_host =
hosts = [hosts]
for host in hosts
- value.binding_URI = "sip:00#{doc.number}@#{host}:5070"
- emit [host,1], value
+ [hostname,port] = host.split /:/
+ port ?= 5070
+ value.binding_URI = "sip:00#{doc.number}@#{hostname}:#{port}"
+ emit [hostname,1], value
if doc.type? and doc.type is 'host' and doc.applications.indexOf('applications/registrant') >= 0
# Make sure these records show up at the top
@@ -0,0 +1,15 @@
+ccnq3 = require 'ccnq3'
+process_commands = require './api'
+ccnq3.config (config) ->
+ ccnq3.amqp (c) ->
+ c.exchange 'commands', {type:'topic',durable:true,autoDelete:false}, (e) ->
+ c.queue "commands-#{config.host}", (q) ->
+
+ # Handle requests specific to this host.
+ q.bind e, "request-#{config.host}"
+ # Handle requests addressed to all hosts.
+ q.bind e, "request"
+
+ q.subscribe (request) ->
+ process_commands request, (response) ->
+ e.publish "response-#{request.reference}", response
@@ -3,22 +3,23 @@ ccnq3 = require 'ccnq3'
opensips_command = require './opensips-command'
params = require './params'
-service = null
-kill_service = ->
- service.kill 'SIGKILL'
- service = null
+service = {}
process_command = (port,command,cfg) ->
+ kill_service = ->
+ service[port].kill 'SIGKILL'
+ service[port] = null
+
stop_service = ->
opensips_command port, ":kill:\n"
- if service?
+ if service[port]?
setTimeout kill_service, 4000
start_service = ->
- if service?
+ if service[port]?
ccnq3.log "WARNING in start_service: service already running?"
shared_megs = 1024
pkg_megs = 512
- service = spawn '/usr/sbin/opensips', [ '-m', shared_megs, '-M', pkg_megs, '-f', cfg ]
+ service[port] = spawn '/usr/sbin/opensips', [ '-m', shared_megs, '-M', pkg_megs, '-f', cfg ]
switch command
when 'stop'
@@ -29,33 +30,39 @@ process_command = (port,command,cfg) ->
do stop_service
setTimeout start_service, 5000
-@api =
- start:
- description: 'Start the registrant OpenSIPS process'
- category: 'registrant'
- do: (cb) ->
- ccnq3.config (p) ->
- if not p.registrant? then return
- p = params p
- process_command p.mi_port, 'start', p.runtime_opensips_cfg
- cb?()
-
- restart:
- description: 'Restart the registrant OpenSIPS process'
- category: 'registrant'
- do: (cb) ->
- ccnq3.config (p) ->
- if not p.registrant? then return
- p = params p
- process_command p.mi_port, 'restart', p.runtime_opensips_cfg
- cb?()
-
- stop:
- description: 'Stop the registrant OpenSIPS process'
- category: 'registrant'
- do: (cb) ->
- ccnq3.config (p) ->
- if not p.registrant? then return
- p = params p
- process_command p.mi_port, 'stop', p.runtime_opensips_cfg
- cb?()
+module.exports = (command,cb) ->
+ unless command.command?
+ cb error:"`command` is a required parameter", arguments: command
+
+ ccnq3.config (config) ->
+ if command.port?
+ switch command.command
+ when 'restart registrant'
+ c = 'restart'
+ when 'start registrant'
+ c = 'start'
+ when 'stop registrant'
+ c = 'stop'
+ else
+ cb error:"Invalid command", received:command
+
+ p = params {proxy_port:command.port}, config
+ process_command command.port+30000, c, p.runtime_opensips_cfg
+ cb?()
+
+ else
+ switch command.command
+ when 'restart all registrant'
+ c = 'restart'
+ when 'start all registrant'
+ c = 'start'
+ when 'stop all registrant'
+ c = 'stop'
+ else
+ cb error:"Invalid command", received:command
+
+ for r in config.registrants
+ p = params r, config
+ process_command command.port+30000, c, p.runtime_opensips_cfg
+
+ cb?()
@@ -13,6 +13,9 @@ module.exports = (p,config) ->
params.opensips_base_lib = base_path
params.notify_via_rabbitmq ?= "#{config.amqp}/logging".replace(/^amqp/,'rabbitmq') if config.amqp?
- params[k] = p.registrant[k] for own k of p.registrant
+ params[k] = p[k] for own k of p
+
+ params.mi_port = params.proxy_port + 30000 # i.e. 35070 etc.
+ params.runtime_opensips_cfg = "#{params.runtime_opensips_cfg}.#{params.proxy_port}"
return params
@@ -2,32 +2,23 @@
pico = require 'pico'
ccnq3 = require 'ccnq3'
-{api} = require './api'
-
+params = require './params'
# Agent main process
ccnq3.config (config) ->
provisioning = pico config.provisioning.local_couchdb_uri
- handler = (p) ->
-
- if not p.registrant? then return
+ handler = (config) ->
- base_path = "./opensips"
- model = 'registrant'
+ if not config.registrants? then return
- params = require('./params') p
+ for r in config.registrants
+ do (r) ->
+ p = params r, config
- # Build the configuration file.
- require("#{base_path}/compiler.coffee") params, config
-
- # Process any MI commands
- if p.sip_commands?.registrant?
- r = api[p.sip_commands.registrant]
- if r?
- ccnq3.log r.description
- r.do()
+ # Build the configuration file.
+ require("#{base_path}/compiler.coffee") params, config
# At startup, use the current document.
handler config
@@ -40,3 +31,5 @@ ccnq3.config (config) ->
hostname: config.host
provisioning.monitor options, handler
+
+require './amqp-listener'
@@ -47,7 +47,7 @@
"uac_timer_interval": 10,
"proxy_port": 5070,
"fifo_path": "/tmp/registrant_fifo",
- "mi_port": 30010,
+ "mi_port": 35070,
"sip_domain_name": "bypassed",
"skip_domain_check": 1,
View
@@ -365,9 +365,6 @@ Configuration options:
A special "sofia_profile" key "opensips" is used to send events to a running OpenSIPS process (rather than a
FreeSwitch sofia profile). See below for more information.
- A special "sofia_profile" key "registrant" is used to send events to a running registrant process (rather than a
- FreeSwitch sofia profile). See below for more information.
-
* `sip_variables`: {} of global (FreeSwitch) variables; defaults to {}
The idea is that these can be used on a per-host basis by additional dialplans, profiles, etc.
@@ -533,7 +530,7 @@ Caveat: Since the trace files on the various hosts are rotated to not exceed a g
Related: applications/registrant
-* `registrant`:
+* `registrants`: An array of object containing the following items:
* `local_ipv4`: string, IP where to send incoming calls (generally the local server)
@@ -939,7 +936,7 @@ number (provisioning records)
* `registrant_remote_ipv4`: remote server for applications/registrant
-* `registrant_host`: host(s) where this registration should be effective
+* `registrant_host`: host(s) where this registration should be effective; if the port is different from the default [5070] port, use the `hostname:port` format.
This parameter can actually be either a string (single host) or an array of strings (multiple hosts).

0 comments on commit f6be2fe

Please sign in to comment.