예제 #1
0
static inline void dlg_replicate_profiles(void)
{
	unsigned i;
	str send_buffer;

	bin_get_buffer(&send_buffer);

	for (i = 0; i < repl_prof_dests_nr; i++)
		msg_send(0,PROTO_BIN,&repl_prof_dests[i].to,0,send_buffer.s,send_buffer.len,0);
}
예제 #2
0
파일: clusterer.c 프로젝트: Danfx/opensips
static int send_to(int cluster_id, int proto)
{
	table_entry_value_t *value;
	str send_buffer;
	unsigned long ctime = time(0);
	int ok = -1;

	if (proto == PROTO_BIN)
		bin_get_buffer(&send_buffer);

	lock_start_read(ref_lock);

	value = clusterer_find_nodes(cluster_id, proto);
	for (; value; value = value->next) {
		ok = 0;
		if (value->state == 1) {
			if (value->prev_no_tries != -1 &&
				value->no_tries > 0 &&
				value->prev_no_tries == value->no_tries) {
				value->no_tries = 0;
			}
			value->prev_no_tries = value->no_tries;
		}

		if (value->state == 2) {
			if ((ctime - value->last_attempt) >= value->duration) {
				value->last_attempt = ctime;
				value->state = 1;
				value->no_tries = 0;
			}
		}

		if (value->state == 1) {
			if (proto == PROTO_BIN) {
				if (msg_send(NULL, PROTO_BIN, &value->addr, 0,
				             send_buffer.s, send_buffer.len, 0) != 0) {
					LM_ERR("cannot send message\n");
					temp_disable_machine(value);
				}
			}
		}
	}

	lock_stop_read(ref_lock);

	return ok;
}
예제 #3
0
/**
 * replicates a local dialog delete event to all the destinations
 * specified with the 'replicate_dialogs' modparam
 */
void replicate_dialog_deleted(struct dlg_cell *dlg)
{
	struct replication_dest *d;
	static str module_name = str_init("dialog");
	str send_buffer;

	if (bin_init(&module_name, REPLICATION_DLG_DELETED, BIN_VERSION) != 0)
		goto error;

	bin_push_str(&dlg->callid);
	bin_push_str(&dlg->legs[DLG_CALLER_LEG].tag);
	bin_push_str(&dlg->legs[callee_idx(dlg)].tag);

	bin_get_buffer(&send_buffer);

	for (d = replication_dests; d; d = d->next)
		msg_send(0,PROTO_BIN,&d->to,0,send_buffer.s,send_buffer.len,0);

	if_update_stat(dlg_enable_stats,delete_sent,1);
	return;
error:
	LM_ERR("Failed to replicate deleted dialog\n");
}
예제 #4
0
static inline void rl_replicate(void)
{
	str send_buffer;
	clusterer_node_t *nodes;
	clusterer_node_t *d;
	
	nodes = clusterer_api.get_nodes(rl_repl_cluster, PROTO_BIN);
	if(nodes == NULL)
		return;

	bin_get_buffer(&send_buffer);
	
	for (d = nodes; d; d = d->next){
		if(msg_send(NULL, PROTO_BIN, &d->addr, 0, send_buffer.s,send_buffer.len,0) != 0){
			LM_ERR("cannot send message\n");
			clusterer_api.set_state(rl_repl_cluster, d->machine_id, 2, PROTO_BIN);
		}
		
	}
	
	clusterer_api.free_nodes(nodes);
	
}
예제 #5
0
/**
 * replicates a local dialog update to all the destinations
 * specified with the 'replicate_dialogs' modparam
 */
void replicate_dialog_updated(struct dlg_cell *dlg)
{
	struct replication_dest *d;
	static str module_name = str_init("dialog");
	int callee_leg;
	str *vars, *profiles;
	str send_buffer;

	if (bin_init(&module_name, REPLICATION_DLG_UPDATED, BIN_VERSION) != 0)
		goto error;

	callee_leg = callee_idx(dlg);

	bin_push_str(&dlg->callid);
	bin_push_str(&dlg->legs[DLG_CALLER_LEG].tag);
	bin_push_str(&dlg->legs[callee_leg].tag);

	bin_push_str(&dlg->from_uri);
	bin_push_str(&dlg->to_uri);

	bin_push_int(dlg->h_id);
	bin_push_int(dlg->start_ts);
	bin_push_int(dlg->state);

	bin_push_str(&dlg->legs[DLG_CALLER_LEG].bind_addr->sock_str);
	if (dlg->legs[callee_leg].bind_addr)
		bin_push_str(&dlg->legs[callee_leg].bind_addr->sock_str);
	else
		bin_push_str(NULL);

	bin_push_str(&dlg->legs[DLG_CALLER_LEG].r_cseq);
	bin_push_str(&dlg->legs[callee_leg].r_cseq);
	bin_push_str(&dlg->legs[DLG_CALLER_LEG].route_set);
	bin_push_str(&dlg->legs[callee_leg].route_set);
	bin_push_str(&dlg->legs[DLG_CALLER_LEG].contact);
	bin_push_str(&dlg->legs[callee_leg].contact);
	bin_push_str(&dlg->legs[callee_leg].from_uri);
	bin_push_str(&dlg->legs[callee_leg].to_uri);

	/* XXX: on shutdown only? */
	vars = write_dialog_vars(dlg->vals);
	dlg_lock_dlg(dlg);
	profiles = write_dialog_profiles(dlg->profile_links);
	dlg_unlock_dlg(dlg);

	bin_push_str(vars);
	bin_push_str(profiles);
	bin_push_int(dlg->user_flags);
	bin_push_int(dlg->flags &
			     ~(DLG_FLAG_NEW|DLG_FLAG_CHANGED|DLG_FLAG_VP_CHANGED));
	bin_push_int((unsigned int)time(0) + dlg->tl.timeout - get_ticks());
	bin_push_int(dlg->legs[DLG_CALLER_LEG].last_gen_cseq);
	bin_push_int(dlg->legs[callee_leg].last_gen_cseq);

	bin_get_buffer(&send_buffer);

	for (d = replication_dests; d; d = d->next)
		msg_send(0,PROTO_BIN,&d->to,0,send_buffer.s,send_buffer.len,0);

	if_update_stat(dlg_enable_stats,update_sent,1);
	return;

error:
	LM_ERR("Failed to replicate updated dialog\n");
}