Skip to content

Commit

Permalink
usrloc: Refactor clustering file structure
Browse files Browse the repository at this point in the history
  • Loading branch information
liviuchircu committed Jan 16, 2019
1 parent fecf154 commit e149ee4
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 50 deletions.
2 changes: 1 addition & 1 deletion modules/usrloc/dlist.c
Expand Up @@ -50,7 +50,7 @@
#include "utime.h"
#include "ul_mod.h"
#include "ul_callback.h"
#include "ureplication.h"
#include "ul_cluster.h"
#include "usrloc.h"


Expand Down
2 changes: 1 addition & 1 deletion modules/usrloc/ucontact.c
Expand Up @@ -46,7 +46,7 @@
#include "ul_callback.h"
#include "urecord.h"
#include "ucontact.h"
#include "ureplication.h"
#include "ul_cluster.h"
#include "udomain.h"
#include "dlist.h"
#include "utime.h"
Expand Down
2 changes: 1 addition & 1 deletion modules/usrloc/udomain.c
Expand Up @@ -47,7 +47,7 @@

#include "ul_mod.h" /* usrloc module parameters */
#include "utime.h"
#include "ureplication.h"
#include "ul_cluster.h"
#include "ul_callback.h"
#include "usrloc.h"

Expand Down
42 changes: 34 additions & 8 deletions modules/usrloc/ureplication.c → modules/usrloc/ul_cluster.c
@@ -1,7 +1,7 @@
/*
* Usrloc record and contact replication
* user location clustering
*
* Copyright (C) 2013 OpenSIPS Solutions
* Copyright (C) 2013-2019 OpenSIPS Solutions
*
* This file is part of opensips, a free SIP server.
*
Expand All @@ -17,16 +17,12 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* History:
* --------
* 2013-10-09 initial version (Liviu)
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "../../forward.h"

#include "ureplication.h"
#include "ul_cluster.h"
#include "ul_mod.h"
#include "dlist.h"
#include "kv_store.h"
Expand All @@ -35,6 +31,36 @@ str contact_repl_cap = str_init("usrloc-contact-repl");

struct clusterer_binds clusterer_api;

int ul_init_cluster(void)
{
if (location_cluster <= 0) {
LM_ERR("Invalid 'location_cluster'! It must be a positive integer!\n");
return -1;
}

if (load_clusterer_api(&clusterer_api) != 0) {
LM_ERR("failed to load clusterer API\n");
return -1;
}

/* register handler for processing usrloc packets to the clusterer module */
if (clusterer_api.register_capability(&contact_repl_cap,
receive_binary_packets, receive_cluster_event, location_cluster,
rr_persist == RRP_SYNC_FROM_CLUSTER? 1 : 0,
(cluster_mode == CM_FEDERATION
|| cluster_mode == CM_FEDERATION_CACHEDB) ?
NODE_CMP_EQ_SIP_ADDR : NODE_CMP_ANY) < 0) {
LM_ERR("cannot register callbacks to clusterer module!\n");
return -1;
}

if (rr_persist == RRP_SYNC_FROM_CLUSTER &&
clusterer_api.request_sync(&contact_repl_cap, location_cluster, 0) < 0)
LM_ERR("Sync request failed\n");

return 0;
}

/* packet sending */

void replicate_urecord_insert(urecord_t *r)
Expand Down
21 changes: 10 additions & 11 deletions modules/usrloc/ureplication.h → modules/usrloc/ul_cluster.h
@@ -1,7 +1,7 @@
/*
* Usrloc record and contact replication
* user location clustering
*
* Copyright (C) 2013 OpenSIPS Solutions
* Copyright (C) 2013-2019 OpenSIPS Solutions
*
* This file is part of opensips, a free SIP server.
*
Expand All @@ -17,22 +17,19 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* History:
* --------
* 2013-10-09 initial version (Liviu)
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef _USRLOC_REPLICATION_H_
#define _USRLOC_REPLICATION_H_
#ifndef _USRLOC_CLUSTER_H_
#define _USRLOC_CLUSTER_H_

#include "../../ut.h"
#include "../../bin_interface.h"
#include "../../socket_info.h"
#include "../../resolve.h"
#include "../../timer.h"
#include "../clusterer/api.h"

#include "urecord.h"

#define REPL_URECORD_INSERT 1
Expand All @@ -48,6 +45,9 @@ extern struct clusterer_binds clusterer_api;

extern str contact_repl_cap;

int ul_init_cluster(void);
int is_my_contact(ucontact_t *c);

/* duplicate local events to other OpenSIPS instances */
void replicate_urecord_insert(urecord_t *r);
void replicate_urecord_delete(urecord_t *r);
Expand All @@ -58,5 +58,4 @@ void replicate_ucontact_delete(urecord_t *r, ucontact_t *c);
void receive_binary_packets(bin_packet_t *packet);
void receive_cluster_event(enum clusterer_event ev, int node_id);

#endif /* _USRLOC_REPLICATION_H_ */

#endif /* _USRLOC_CLUSTER_H_ */
2 changes: 1 addition & 1 deletion modules/usrloc/ul_mi.c
Expand Up @@ -44,7 +44,7 @@
#include "utime.h"
#include "ul_mod.h"
#include "usrloc.h"
#include "ureplication.h"
#include "ul_cluster.h"
#include "kv_store.h"


Expand Down
29 changes: 3 additions & 26 deletions modules/usrloc/ul_mod.c
Expand Up @@ -55,7 +55,7 @@
#include "udomain.h" /* {insert,delete,get,release}_urecord */
#include "urecord.h" /* {insert,delete,get}_ucontact */
#include "ucontact.h" /* update_ucontact */
#include "ureplication.h"
#include "ul_cluster.h"
#include "ul_mi.h"
#include "ul_callback.h"
#include "usrloc.h"
Expand Down Expand Up @@ -480,34 +480,11 @@ static int mod_init(void)
return -1;
}

if (location_cluster < 0) {
LM_ERR("Invalid cluster id to replicate contacts to, must be 0 or "
"a positive number\n");
if (ul_init_cluster() < 0) {
LM_ERR("failed to init clustering support!\n");
return -1;
}

if (location_cluster) {
if (load_clusterer_api(&clusterer_api) != 0) {
LM_DBG("failed to find clusterer API - is clusterer module loaded?\n");
return -1;
}

/* register handler for processing usrloc packets to the clusterer module */
if (clusterer_api.register_capability(&contact_repl_cap,
receive_binary_packets, receive_cluster_event, location_cluster,
rr_persist == RRP_SYNC_FROM_CLUSTER? 1 : 0,
(cluster_mode == CM_FEDERATION
|| cluster_mode == CM_FEDERATION_CACHEDB) ?
NODE_CMP_EQ_SIP_ADDR : NODE_CMP_ANY) < 0) {
LM_ERR("cannot register callbacks to clusterer module!\n");
return -1;
}

if (rr_persist == RRP_SYNC_FROM_CLUSTER &&
clusterer_api.request_sync(&contact_repl_cap, location_cluster, 0) < 0)
LM_ERR("Sync request failed\n");
}

init_flag = 1;

return 0;
Expand Down
2 changes: 1 addition & 1 deletion modules/usrloc/urecord.c
Expand Up @@ -42,7 +42,7 @@
#include "ul_mod.h"
#include "utime.h"
#include "ul_callback.h"
#include "ureplication.h"
#include "ul_cluster.h"
#include "udomain.h"
#include "dlist.h"
#include "usrloc.h"
Expand Down

0 comments on commit e149ee4

Please sign in to comment.