Example #1
0
/** @brief Remove the stream from the session streams hash table, and notify the user **/
inline static void delete_stream ( pntoh_tcp_session_t session , pntoh_tcp_stream_t *stream , int reason , int extra )
{
	pntoh_tcp_stream_t item = 0;

	if ( !stream || !(*stream) )
		return;

	item = *stream;

	if ( session->streams != 0 )
	{
	  if ( htable_find ( session->streams, item->key, 0 ) != 0 )
		{
		  htable_remove ( session->streams , item->key, 0);
			sem_post ( &session->max_streams );
		}
	}

	if ( session->timewait != 0 )
	{
	  if ( htable_find ( session->timewait, item->key, 0 ) != 0 )
		{
		  htable_remove ( session->timewait , item->key, 0 );
			sem_post ( &session->max_timewait );
		}
	}

	switch ( extra )
	{
		case NTOH_MAX_SYN_RETRIES_REACHED:
			extra = NTOH_REASON_MAX_SYN_RETRIES_REACHED;
			break;

		case NTOH_MAX_SYNACK_RETRIES_REACHED:
			extra = NTOH_REASON_MAX_SYNACK_RETRIES_REACHED;
			break;

		case NTOH_HANDSHAKE_FAILED:
			extra = NTOH_REASON_HSFAILED;
			break;
	}

	if ( item->client.receive )
		((pntoh_tcp_callback_t)item->function)(item,&item->client, &item->server,0, reason , extra );

    free_lockaccess ( &item->lock );

	free ( item );
	*stream = 0;

	return;
}
Example #2
0
/** @brief Frees a TCP session **/
inline static void __tcp_free_session ( pntoh_tcp_session_t session )
{
	pntoh_tcp_session_t ptr = 0;
	pntoh_tcp_stream_t 	item = 0;
	ntoh_tcp_key_t		first = 0;

	if ( params.sessions_list == session )
		params.sessions_list = session->next;
	else{
		for ( ptr = params.sessions_list ; ptr != 0 && ptr->next != session ; ptr = ptr->next );

		if ( ptr != 0 )
			ptr->next = session->next;
	}

	lock_access( &session->lock );


	while ( ( first = htable_first ( session->timewait ) ) != 0 )
	{
	  item = (pntoh_tcp_stream_t)htable_remove(session->timewait,first,0);
		lock_access ( &item->lock );
		__tcp_free_stream ( session , &item , NTOH_REASON_SYNC , NTOH_REASON_EXIT );
	}

	while ( ( first = htable_first ( session->streams ) ) != 0 )
	{
	  item = (pntoh_tcp_stream_t)htable_remove(session->streams,first, 0);
		lock_access ( &item->lock );
		__tcp_free_stream ( session , &item , NTOH_REASON_SYNC , NTOH_REASON_EXIT );
	}

	unlock_access( &session->lock );

	pthread_cancel ( session->tID );
	pthread_join ( session->tID , 0 );
	sem_destroy ( &session->max_streams );
	sem_destroy ( &session->max_timewait );

	free_lockaccess ( &session->lock );

	htable_destroy ( &session->streams );
	htable_destroy ( &session->timewait );
    
    free ( session );

    return;
}
Example #3
0
/**
 * Locate record for query hits for specified MUID.
 *
 * @returns located record, or NULL if not found.
 */
static dqhit_t *
dh_locate(const struct guid *muid)
{
	bool found = FALSE;
	const void *key;
	void *value;

	if (NULL == by_muid_old)
		return NULL;		/* DH layer shutdown occurred already */

	/*
	 * Look in the old table first.  If we find something there, move it
	 * to the new table to keep te record "alive" since we still get hits
	 * for this query.
	 */

	found = htable_lookup_extended(by_muid_old, muid, &key, &value);

	if (found) {
		htable_remove(by_muid_old, key);
		g_assert(!htable_contains(by_muid, key));
		htable_insert(by_muid, key, value);
		return value;
	}

	return htable_lookup(by_muid, muid);
}
Example #4
0
static gboolean
prepare_remove_record(GtkTreeModel *model, GtkTreePath *unused_path,
	GtkTreeIter *iter, gpointer udata)
{
	struct result_data *rd;
	record_t *rc;
	search_t *search;

	(void) unused_path;

	search = udata;
	rd = get_result_data(model, iter);
	rc = rd->record;

	if (rc->sha1) {
		struct result_data *parent;
		
		parent = find_parent(search, rd);
		if (rd == parent) {
			htable_remove(search->parents, rd);
		} else if (parent) {
			parent->children--;
			search_gui_set_data(model, parent);
		}
	}
	result_data_free(search, rd);
	return FALSE;
}
Example #5
0
/**
 * @fn void virtual_cache_remove(virtual_cache_t vc, cache_item_name_t name)
 * @brief Remove an item from the virtual cache.
 * @param vc The virtual cache pointer.
 * @param name The item name.
 */
void virtual_cache_remove(virtual_cache_t vc, cache_item_name_t name) {
  struct virtual_cache_s *v = (struct virtual_cache_s*)vc;
  if(!v) return;
  virtual_cache_item_t item = htable_lookup(v->table, name);
  if(item) {
    virtual_cache_item_delete(item);
    htable_remove(v->table, name);
  }
}
Example #6
0
/**
 * Callout queue callback fired when waiting event times out.
 */
static void
wq_timed_out(cqueue_t *cq, void *arg)
{
	wq_event_t *we = arg;
	hash_list_t *hl;
	wq_status_t status;

	wq_event_check(we);
	g_assert(we->tm != NULL);

	cq_zero(cq, &we->tm->timeout_ev);
	hl = htable_lookup(waitqueue, we->key);

	g_assert(hl != NULL);

	/*
	 * Invoke the callback with the sentinel data signalling a timeout.
	 */

	status = (*we->cb)(we->arg, WQ_TIMED_OUT);

	/*
	 * When the callback returns WQ_SLEEP, we re-instantiate the initial
	 * timeout.
	 *
	 * Otherwise the event is discarded (removed from the wait queue) and
	 * the callback will never be invoked again for this event.
	 */

	switch (status) {
	case WQ_SLEEP:
		we->tm->timeout_ev = cq_main_insert(we->tm->delay, wq_timed_out, we);
		return;
	case WQ_EXCLUSIVE:
		s_critical("weird status WQ_EXCLUSIVE on timeout invocation of %s()",
			stacktrace_function_name(we->cb));
		/* FALL THROUGH */
	case WQ_REMOVE:
		hash_list_remove(hl, we);

		/*
		 * Cleanup the table if it ends-up being empty.
		 */

		if (0 == hash_list_length(hl)) {
			hash_list_free(&hl);
			htable_remove(waitqueue, we->key);
		}

		wq_event_free(we);
		return;
	}

	g_assert_not_reached();
}
Example #7
0
void
sip_calls_rotate()
{
    sip_call_t *call = vector_first(calls.list);

    // Remove from callids hash
    htable_remove(calls.callids, call->callid);
    // Remove first call from active and call lists
    vector_remove(calls.active, call);
    vector_remove(calls.list, call);

}
Example #8
0
void
fi_gui_source_hide(struct download *d)
{
	GtkTreeIter *iter;

	iter = htable_lookup(fi_sources, d);
	if (iter) {
		if (store_sources) {
			gtk_list_store_remove(store_sources, iter);
		}
		htable_remove(fi_sources, d);
		WFREE(iter);
	}
}
Example #9
0
/**
 * Free the callback waiting indication.
 */
static void
urpc_cb_free(struct urpc_cb *ucb, bool in_shutdown)
{
	urpc_cb_check(ucb);

	if (in_shutdown) {
		(*ucb->cb)(URPC_TIMEOUT, ucb->addr, ucb->port, NULL, 0, ucb->arg);
	} else {
		htable_remove(pending, ucb->s);
	}

	cq_cancel(&ucb->timeout_ev);
	socket_free_null(&ucb->s);
	ucb->magic = 0;
	WFREE(ucb);
}
Example #10
0
File: sip.c Project: irontec/sngrep
void
sip_calls_rotate()
{
    sip_call_t *call;
    vector_iter_t it = vector_iterator(calls.list);
    while ((call = vector_iterator_next(&it))) {
        if (!call->locked) {
            // Remove from callids hash
            htable_remove(calls.callids, call->callid);
            // Remove first call from active and call lists
            vector_remove(calls.active, call);
            vector_remove(calls.list, call);
            return;
        }
    }
}
Example #11
0
/**
 * Callback: called when an upload is removed from the backend.
 *
 * Either immediately clears the upload from the frontend or just
 * set the upload_row_info->valid to FALSE, so we don't accidentally
 * try to use the handle to communicate with the backend.
 */
static void
upload_removed(gnet_upload_t uh, const gchar *reason)
{
    upload_row_data_t *rd;

    /* Invalidate row and remove it from the GUI if autoclear is on */
	rd = find_upload(uh);
	g_assert(NULL != rd);
	rd->valid = FALSE;
	gtk_widget_set_sensitive(button_uploads_clear_completed, TRUE);
	if (reason != NULL)
		gtk_list_store_set(store_uploads, &rd->iter, c_ul_status, reason, (-1));
	sl_removed_uploads = g_slist_prepend(sl_removed_uploads, rd);
	htable_remove(upload_handles, uint_to_pointer(uh));
	/* NB: rd MUST NOT be freed yet because it contains the GtkTreeIter! */
}
Example #12
0
int opt_decision(int old_container_id, int chunk_size){
	int rewrite=0;
	double thr;
	int value;
	
	if((scan_htable->num_items*1.0)<= MIN(1.0/cur_factor,1.0/max_factor)){
		rewrite=0;; // no rewrite
		int i=0;
		double size=0;
		while(i<=scan_htable->num_items && ( size/G_total_size<=0.05))
			size+=factor_buckets[i];
		
		cur_factor=size/G_total_size;
	}
		
	else{
		if(max_b<scan_htable->num_items)
			max_b=scan_htable->num_items;
		
		factor_buckets[scan_htable->num_items]+=chunk_size;
		
		//printf("%d \t",scan_htable->num_items);
		ReferItem * rf=htable_lookup(scan_htable,&old_container_id);
		if(rf){ // find the min container_id with the minimal counts
			
			int min_cid=0;
			int min_count=2147483647;
			int size=0;
			ReferItem * var;
			foreach_htable(var,scan_htable){
				if(min_count> var->count){
					min_count=var->chunk_count;
					min_cid=var->container_id;
					size=var->size;
				}
			}
			if(min_cid){
				htable_remove(cap_htable,&min_cid);
				rewrite_size+=size;
				int i=0;
				
				
			}
		}
	}
}
Example #13
0
/**
 * Notify wake-up condition to sleepers on the key.
 *
 * @param key		the rendez-vous point
 * @param data		additional data to supply to woken-up parties
 */
void
wq_wakeup(const void *key, void *data)
{
	hash_list_t *hl;

	hl = htable_lookup(waitqueue, key);

	if (hl != NULL) {
		wq_notify(hl, data);

		/*
		 * Cleanup the table if it ends-up being empty.
		 */

		if (0 == hash_list_length(hl)) {
			hash_list_free(&hl);
			htable_remove(waitqueue, key);
		}
	}
}
Example #14
0
/**
 * Remove an event from the queue.
 */
static void
wq_remove(wq_event_t *we)
{
	hash_list_t *hl;

	wq_event_check(we);

	hl = htable_lookup(waitqueue, we->key);
	if (NULL == hl) {
		s_critical("attempt to remove event %s() on unknown key %p",
			stacktrace_function_name(we->cb), we->key);
	} if (NULL == hash_list_remove(hl, we)) {
		s_critical("attempt to remove unknown event %s() on %p",
			stacktrace_function_name(we->cb), we->key);
	} else if (0 == hash_list_length(hl)) {
		hash_list_free(&hl);
		htable_remove(waitqueue, we->key);
	}

	wq_event_free(we);
}
Example #15
0
/**
 * Construct a list of prefixes to declare at this node.
 */
static GSList *
xfmt_ns_declarations(struct xfmt_pass2 *xp2, const xnode_t *xn)
{
    GSList *ns = NULL;
    GSList *sl, *uris;

    uris = htable_lookup(xp2->node2uri, xn);

    GM_SLIST_FOREACH(uris, sl) {
        const char *uri = sl->data;
        const char *prefix = xfmt_new_prefix(xp2, uri);

        ns = gm_slist_prepend_const(ns, prefix);
    }

    if (uris != NULL) {
        htable_remove(xp2->node2uri, xn);
        g_slist_free(uris);
    }

    return g_slist_reverse(ns);
}
Example #16
0
/**
 * Remove a key from the map.
 *
 * @return TRUE if the key was found and removed from the map.
 */
bool
map_remove(const map_t *m, const void *key)
{
	map_check(m);

	switch (m->type) {
	case MAP_HASH:
		return htable_remove(m->u.ht, key);
		break;
	case MAP_ORDERED_HASH:
		return ohash_table_remove(m->u.ot, key);
		break;
	case MAP_PATRICIA:
		return patricia_remove(m->u.pt, key);
		break;
	case MAP_MAXTYPE:
		break;
	}

	g_assert_not_reached();
	return FALSE;
}
Example #17
0
/**
 * Removes all references to the given node handle in the gui.
 */
void
nodes_gui_remove_node(const struct nid *node_id)
{
	struct node_data *data;

    /*
     * Make sure node is removed from the "changed" hash tables so
     * we don't try an update later.
     */

	remove_item(ht_node_info_changed, node_id);
	remove_item(ht_node_flags_changed, node_id);
	remove_item(ht_pending_lookups, node_id);

	data = find_node(node_id);
	if (data) {
		g_assert(nid_equal(node_id, data->node_id));

		gtk_list_store_remove(nodes_model, &data->iter);
		htable_remove(nodes_handles, data->node_id);
		node_data_free(data);
	}
}
Example #18
0
void  capping_reset(){
	
	CapItem * rf;
	foreach_htable(rf,cap_htable){
		htable_remove(cap_htable,&rf->container_id);
	}
void unset_variable(char *var)
{
	char *p = htable_fetch(var_table, var);
	htable_remove(var_table, var);
	free(p);
}
Example #20
0
static void map_unset_dimension(zval *obj, zval *offset)
{
    Map *map = Z_MAP_P(obj);
    htable_remove(map->table, offset, NULL);
}
Example #21
0
/** @brief Handles the closing of the connection **/
inline static void handle_closing_connection ( pntoh_tcp_session_t session , pntoh_tcp_stream_t stream , pntoh_tcp_peer_t origin , pntoh_tcp_peer_t destination , pntoh_tcp_segment_t segment, int who )
{
	static unsigned short count = 0;
	pntoh_tcp_peer_t	peer = origin;
	pntoh_tcp_peer_t	side = destination;
	pntoh_tcp_stream_t	twait = 0;
	ntoh_tcp_key_t		key = 0;

	if ( segment != 0 )
		queue_segment ( session , origin , segment );

	send_peer_segments ( session , stream , destination , origin , origin->next_seq , 0 , 0, who );

	if ( ! origin->segments )
		return;

	if ( count++ < 1 )
	{
		handle_closing_connection ( session , stream , destination , origin , 0, who );
		count = 0;
	}

	if ( stream->status == NTOH_STATUS_CLOSING )
	{
		if ( stream->closedby == NTOH_CLOSEDBY_CLIENT )
		{
			peer = &stream->client;
			side = &stream->server;
		}else{
			peer = &stream->server;
			side = &stream->client;
		}
	}

	/* check segment seq and ack */
    
    if (origin->segments == NULL) 
        return;

	if ( origin->segments->seq == origin->next_seq && origin->segments->ack == destination->next_seq )
	{
		/* unlink the first segment */
		segment = origin->segments;
		origin->segments = segment->next;
	}else
		return;

	switch ( peer->status )
	{
		case NTOH_STATUS_ESTABLISHED:
			if ( ! (segment->flags & TH_FIN) )
				break;

			origin->status = NTOH_STATUS_FINWAIT1;
			destination->status = NTOH_STATUS_CLOSEWAIT;
			stream->status = NTOH_STATUS_CLOSING;

			if ( origin == &stream->client )
				stream->closedby = NTOH_CLOSEDBY_CLIENT;
			else if ( origin == &stream->server )
				stream->closedby = NTOH_CLOSEDBY_SERVER;

			break;

		case NTOH_STATUS_FINWAIT1:
			if ( segment->flags & TH_FIN )
			{
				peer->status = NTOH_STATUS_CLOSING;
				side->status = NTOH_STATUS_LASTACK;
			}else if ( segment->flags & TH_ACK )
				peer->status = NTOH_STATUS_FINWAIT2;
			break;

		case NTOH_STATUS_CLOSING:
			if ( segment->flags & TH_ACK )
			{
				peer->status = NTOH_STATUS_TIMEWAIT;
				side->status = NTOH_STATUS_CLOSED;
				stream->status = NTOH_STATUS_CLOSED;
			}
			break;

		case NTOH_STATUS_FINWAIT2:
			if ( segment->flags & (TH_ACK | TH_FIN) )
			{
				peer->status = NTOH_STATUS_TIMEWAIT;

				if ( segment->flags & TH_FIN )
					side->status = NTOH_STATUS_LASTACK;
				else if ( segment->flags & TH_ACK )
					stream->status = side->status = NTOH_STATUS_CLOSED;
			}
			break;

		case NTOH_STATUS_TIMEWAIT:
			if ( segment->flags & TH_ACK )
				stream->status = side->status = NTOH_STATUS_CLOSED;
			break;
	}

	if ( segment->flags & (TH_FIN | TH_RST) )
		origin->next_seq++;

	free ( segment );

	if ( stream->status != NTOH_STATUS_CLOSED && origin->receive )
		((pntoh_tcp_callback_t)stream->function) ( stream , origin , destination , 0 , NTOH_REASON_SYNC , 0 );

	/* should we add this stream to TIMEWAIT queue? */
	if ( stream->status == NTOH_STATUS_CLOSING && IS_TIMEWAIT(stream->client , stream->server) )
	{
  if ( ! htable_find ( session->timewait , stream->key, 0 ) )
		{
            htable_remove ( session->streams , stream->key, 0 );
			sem_post ( &session->max_streams );

			while ( sem_trywait ( &session->max_timewait ) != 0 )
			{
				key = htable_first ( session->timewait );
				twait = htable_remove ( session->timewait , key, 0 );
				__tcp_free_stream ( session , &twait , NTOH_REASON_SYNC , NTOH_REASON_CLOSED );
			}

			htable_insert ( session->timewait , stream->key , stream );
		}
	}

	return;
}