Пример #1
0
void
unregister_hash(char *buf, struct sockaddr_in *from_addr)
{
	tracker_unregister_t	*req = (tracker_unregister_t *)buf;
	peer_t			peer;
	int			index;
	int			i, j;

#ifdef	DEBUG
	fprintf(stderr, "unregister_hash:enter\n");
	fprintf(stderr, "unregister_hash:hash_table:before\n\n");
	print_hash_table();
#endif

	bzero(&peer, sizeof(peer));

	for (i = 0 ; i < req->numhashes ; ++i) {
		tracker_info_t	*info = &req->info[i];

		if (getpeers(info->hash, &index) != NULL) {
			for (j = 0 ; j < info->numpeers ; ++j) {
				peer.ip = info->peers[j].ip;
				removepeer(index, &peer, 1);
			}
		}
	}

#ifdef	DEBUG
	fprintf(stderr, "unregister_hash:hash_table:after\n\n");
	print_hash_table();
#endif
}
Пример #2
0
int main(int argc, char** argv) {
    struct hash_tablosu *htable=NULL;
    
    initialize_hash_table(&htable,3,5);
    print_hash_table(htable); 
    insert_hash_table(htable,"kadayif");
    insert_hash_table(htable,"Trabzonspor");
    insert_hash_table(htable,"kadayif");
    insert_hash_table(htable,"gundogdu");
    insert_hash_table(htable,"besiktas");
    insert_hash_table(htable,"baklava");
    insert_hash_table(htable,"dembaba");
    insert_hash_table(htable,"cardoza");
    
   
    print_hash_table(htable);
    
    hash_table_buyut(&htable,17,19);
    print_hash_table(htable);
    
    insert_hash_table(htable,"ankara");
    insert_hash_table(htable,"Ankara");
    print_hash_table(htable);
    return (EXIT_SUCCESS);
}
Пример #3
0
int main(){

    char* names[] = {"Abhijeet", "Ramdev", "Kamdev", "Shatmatdev", "This is it",
    "You are shit", "This is what I want to become", "I am a token",
    "Hallelujah", "I am the king of the world", "How I met you mother?",
    "Kamdev", "Luftwaffe"};

    printf("\t%lu\n",sizeof(names));
    for(int i = 0; i < (sizeof(names))/sizeof(names[0]); ++i){
        insert_hash(names[i]);
    }
    print_hash_table();
    delete_hash_table();
    print_hash_table(); 
}
Пример #4
0
void main(int argc, char **argv)
{
  Radar *radar;
  Sweep *sweep;

  if (argc != 3) {fprintf(stderr, "Usage: %s infile callid_or_firstfile\n", argv[0]); exit(-1);}
  RSL_radar_verbose_on();
  radar = RSL_wsr88d_to_radar(argv[1], argv[2]);
  if (radar == NULL) exit(-1);
/***********************************************************************/
/*                                                                     */
/*            You now have a pointer to Radar.                         */
/*            Now use *radar all you like.                             */
/*                                                                     */
/***********************************************************************/

/* Use radar->v[DZ_INDEX] for REFELECTIVITY
 *     radar->v[VR_INDEX] for VELOCITY
 *     radar->v[SW_INDEX] for SPECTRUM_WIDTH
 */

  sweep = RSL_get_first_sweep_of_volume(radar->v[DZ_INDEX]);
  print_hash_table(sweep);

  poke_about_sweep(sweep);

  exit(0);

}
Пример #5
0
void
unregister_all(char *buf, struct sockaddr_in *from_addr)
{
	peer_t		peer;
	int		i;

#ifdef	DEBUG
	fprintf(stderr, "unregister_all:enter\n");
	fprintf(stderr, "unregister_all:hash_table:before\n\n");
	print_hash_table();
#endif

	peer.ip = from_addr->sin_addr.s_addr;

	if (hash_table->head >= hash_table->tail) {
		for (i = hash_table->head - 1;
				(i > hash_table->tail) && (i >= 0) ; --i) {
			removepeer(i, &peer, 0);
		}
	} else {
		for (i = hash_table->head - 1; i >= 0 ; --i) {
			removepeer(i, &peer, 0);
		}

		for (i = (hash_table->size - 1) ;
				(i > hash_table->tail) && (i >= 0) ; --i) {
			removepeer(i, &peer, 0);
		}
	}

	compact_hash_table();
	reclaim_free_entries();

	clear_dt_table_entry(peer.ip);

#ifdef	DEBUG
	fprintf(stderr, "unregister_all:hash_table:after\n\n");
	print_hash_table();
#endif

}
Пример #6
0
int main()
{
	int i;
	key_t sample[] = {47, 7, 11, 11, 29, 16, 92, 22, 8, 3, 33};
	chain_t *hash_table[11];

	for (i = 0; i < array_length(hash_table); i++) {
		hash_table[i] = NULL;
	}

	create_hash_table(hash_table, sample, array_length(sample));
	
	print_hash_table(hash_table, array_length(hash_table));

	return 0;
}
Пример #7
0
void
verify_hash_table()
{
	int	i;

	print_hash_table();

	if (hash_table->head >= hash_table->tail) {
		for (i = hash_table->head - 1;
				(i > hash_table->tail) && (i >= 0) ; --i) {

			if (hash_table->entry[i].hash == 0) {
				fprintf(stderr, "verify_hash_table:1: error at entry %d\n", i);
				exit(-1);
			}
		}
	} else {
		for (i = hash_table->head - 1; i >= 0 ; --i) {
			if (hash_table->entry[i].hash == 0) {
				fprintf(stderr, "verify_hash_table:2: error at entry %d\n", i);
				exit(-1);
			}
		}

		for (i = (hash_table->size - 1) ;
				(i > hash_table->tail) && (i >= 0) ; --i) {

			if (hash_table->entry[i].hash == 0) {
				fprintf(stderr, "verify_hash_table:3: error at entry %d\n", i);
				exit(-1);
			}

		}
	}

	return;
}
Пример #8
0
void print_comtab()  {  /* Print Comment Table */
	print_hash_table(comment_table, false);
}
Пример #9
0
void print_symtab()  {  /* Print Symbol Table */
	printf("\n\nFrequency of identifiers");
	print_hash_table(id_table, true);
}
Пример #10
0
void
register_hash(char *buf, struct sockaddr_in *from_addr)
{
	tracker_register_t	*req = (tracker_register_t *)buf;
	hash_info_t		*hashinfo;
	tracker_info_t		*reqinfo;
	uint16_t		numpeers;
	peer_t			dynamic_peers[1];
	peer_t			*peers;
	int			i, j, k;

	for (i = 0; i < req->numhashes; ++i) {
		reqinfo = &req->info[i];
#ifdef	LATER
		fprintf(stderr,
			"register_hash:enter:hash (0x%llx)\n", reqinfo->hash);
		fprintf(stderr, "register_hash:hash_table:before\n\n");
		print_hash_table();
#endif

		if (reqinfo->numpeers == 0) {
			/*
			 * no peer specified. dynamically determine
			 * the peer IP address from the host who
			 * sent us the message
			 */
			numpeers = 1;
			dynamic_peers[0].ip = from_addr->sin_addr.s_addr;
			peers = dynamic_peers;
		} else {
			numpeers = reqinfo->numpeers;
			peers = reqinfo->peers;
		}

#ifdef	DEBUG
		fprintf(stderr, "register_hash:numpeers:1 (0x%d)\n", numpeers);
#endif

		/*
		 * scan the list for this hash.
		 */
		if ((hashinfo = getpeers(reqinfo->hash, NULL)) != NULL) {
			/*
			 * this hash is already in the table, see if this peer
			 * is already in the list
			 */
			for (j = 0 ; j < numpeers ; ++j) {
				int	found = 0;
		
				for (k = 0 ; k < hashinfo->numpeers ; ++k) {
					if (peers[j].ip ==
							hashinfo->peers[k].ip) {
						found = 1;
						hashinfo->peers[k].state =
							READY;
						break;
					}
				}

				if (!found) {
					peers[j].state = READY;
#ifdef	DEBUG
					fprintf(stderr, "register_hash:calling addpeer:1\n");
#endif
					addpeer(hashinfo, &peers[j]);
				}
			}
		} else {
			/*
			 * if not, then add this hash to the end of the list
			 */
			if ((hashinfo = newentry()) == NULL) {
				fprintf(stderr,
					"register_hash:newentry:failed\n");
				abort();
			}

			hashinfo->hash = reqinfo->hash;
			hashinfo->numpeers = 0;

			for (j = 0 ; j < numpeers ; ++j) {
				peers[j].state = READY;
#ifdef	DEBUG
				fprintf(stderr,
					"register_hash:calling addpeer:2\n");
#endif
				addpeer(hashinfo, &peers[j]);
			}
		}
#ifdef	LATER
	fprintf(stderr, "register_hash:hash_table:after\n\n");
	print_hash_table();
#endif

#ifdef	DEBUG
	fprintf(stderr, "register_hash:exit:hash (0x%llx)\n", reqinfo->hash);
#endif
	}
}
Пример #11
0
/*
 * 'size' is the number of new entries to be added to the table
 */
int
grow_hash_table(int size)
{
	uint32_t	oldsize = hash_table->size;
	uint32_t	newsize = size + hash_table->size;
	int		len;
	int		tailentries;

	len = sizeof(hash_table_t) + (newsize * sizeof(hash_info_t));

#ifdef	DEBUG
	fprintf(stderr, "grow_hash_table:enter:size (%d)\n", hash_table->size);
	fprintf(stderr, "grow_hash_table:enter:head (%d)\n", hash_table->head);
	fprintf(stderr, "grow_hash_table:enter:tail (%d)\n", hash_table->tail);

	fprintf(stderr, "grow_hash_table:before\n\n");
	print_hash_table();
#endif

	if ((hash_table = realloc(hash_table, len)) == NULL) {
		perror("grow_hash_table:realloc failed:");
		return(-1);
	}

	tailentries = oldsize - 1 - hash_table->tail;
#ifdef	DEBUG
	fprintf(stderr, "grow_hash_table:tailentries (%d)\n", tailentries);
#endif
	if (tailentries > 0) {
		/*
		 * if the tail is "not" pointing at the last entry of the
		 * old table, then we need to copy the bottom of the old
		 * table to the bottom of the new table
		 */
		memcpy(&hash_table->entry[newsize - tailentries],
			&hash_table->entry[hash_table->tail + 1],
			tailentries * sizeof(hash_info_t));
	}

	/*
	 * initialize the new entries
	 */
	bzero(&hash_table->entry[hash_table->head],
		(size + 1) * sizeof(hash_info_t));

	hash_table->size = newsize;
	hash_table->tail = hash_table->tail + size;

#ifdef	DEBUG
	fprintf(stderr, "grow_hash_table:exit:size (%d)\n", hash_table->size);
	fprintf(stderr, "grow_hash_table:exit:head (%d)\n", hash_table->head);
	fprintf(stderr, "grow_hash_table:exit:tail (%d)\n", hash_table->tail);

	fprintf(stderr, "grow_hash_table:after\n\n");
	print_hash_table();
#endif

#ifdef	DEBUG
	fprintf(stderr, "grow_hash_table:validate new free entries\n");
{
	int	i;

	for (i = hash_table->head; i <= hash_table->tail; ++i) {
		fprintf(stderr, "\tentry[%d] : hash (0x%llx)\n", i,
			hash_table->entry[i].hash);
		if (hash_table->entry[i].hash != 0) {
			fprintf(stderr, "grow_hash_table:validate fail\n");
			exit(-1);
		}
	}
}
#endif

	return(0);
}
Пример #12
0
/*
 * remove all free entries in between the head and the tail
 */
void
compact_hash_table()
{
	int	free_index = hash_table->head - 1;
	int	allocated_index;
	char	found, done;

#ifdef	DEBUG
	fprintf(stderr, "compact_hash_table:before\n\n");
	print_hash_table();
#endif

	while (1) {
		/*
		 * find a free slot
		 */
		found = 0;
		done = 0;
		while (!done) {
			if (free_index == hash_table->tail) {
				done = 1;
				continue;
			}

			if (free_index < 0) {
				free_index = hash_table->size - 1;
				continue;
			}

			if (hash_table->entry[free_index].hash == 0) {
				done = 1;
				found = 1;
				continue;
			}

			--free_index;
		}

		if (found == 0) {
			/*
			 * there are no free slots between head and tail
			 */
			return;
		}

		/*
		 * find the next allocated slot
		 */
		allocated_index = free_index - 1;
		found = 0;
		done = 0;

		while (!done) {
			if (allocated_index == hash_table->tail) {
				done = 1;
				continue;
			}

			if (allocated_index < 0) {
				allocated_index = hash_table->size - 1;
				continue;
			}

			if (hash_table->entry[allocated_index].hash != 0) {
				done = 1;
				found = 1;
				continue;
			}

			--allocated_index;
		}

		if (found == 0) {
			/*
			 * there are no allocated slots between free_index and
			 * tail
			 */
			return;
		}

		/*
		 * move the allocated slot to the free slot, then free the
		 * previous allocated slot
		 */
		hash_table->entry[free_index].hash =
			hash_table->entry[allocated_index].hash;
		hash_table->entry[free_index].numpeers =
			hash_table->entry[allocated_index].numpeers;
		hash_table->entry[free_index].peers =
			hash_table->entry[allocated_index].peers;

		hash_table->entry[allocated_index].hash = 0;
		hash_table->entry[allocated_index].numpeers = 0;
		hash_table->entry[allocated_index].peers = NULL;

		--free_index;
	}

#ifdef	DEBUG
	fprintf(stderr, "compact_hash_table:after\n\n");
	print_hash_table();
#endif

}
Пример #13
0
int main()
{
	tls_hash_table *hash_table = init_tls_hash_table();
	
	/*
	char *arr_sip[6] = {
						"192.168.101.105",
						"192.168.101.104",
						"192.168.101.106",
						"192.168.101.103",
						"192.168.101.110",
						"192.168.100.111"
	};

	char *arr_dip[6] = {
						"192.168.100.10",
						"192.168.100.11",
						"192.168.100.12",
						"192.168.100.13",
						"192.168.100.14",
						"192.168.101.1"
	};

	int arr_source[6] = {100,200,300,80,443,556};
	int arr_dst[6] = {200,100,300,443,80,655};
	*/
	char *arr_sip[6] = {
						"192.168.101.105",
						"192.168.101.104",
						"192.168.101.105",
						"192.168.101.103",
						"192.168.101.110",
						"192.168.100.111"
	};

	char *arr_dip[6] = {
						"192.168.101.104",
						"192.168.101.105",
						"192.168.101.104",
						"192.168.100.104",
						"192.168.100.14",
						"192.168.101.1"
	};

	int arr_source[6] = {100,200,100,80,443,556};
	int arr_dst[6] = {200,100,200,443,80,655};
	int i = 0;

	//create hash table
	for(i = 0; i < 5; i++)
	{
		tls_node *node = NULL;
		
		node = create_tls_node(i,arr_sip[i],arr_dip[i],arr_source[i],arr_dst[i]); 
		insert_tls_hash_node(hash_table,node,arr_sip[i],arr_dip[i],arr_source[i],arr_dst[i]);
	}

	print_hash_table(hash_table);

	int index;
	while(1)
	{
		printf("input query index :\n");
		scanf("%d",&index);
		tls_node *node = NULL;
		node = query_tls_hash_node(hash_table,arr_sip[index],arr_dip[index],arr_source[index],arr_dst[index]);

		if(node != NULL)
		{
			printf("sip = %s dip = %s source = %d dst = %d syn_time = %d\n",node->sourceIP,node->destIP,node->sourceport,node->destport,node->syn_time);
		}
		else
		{
			printf("can not find the index tupple\n");
		}
		//print_hash_table(hash_table);
		
		printf("input delete index:\n");
		scanf("%d",&index);
		delete_tls_hash_node(hash_table,arr_sip[index],arr_dip[index],arr_source[index],arr_dst[index]);
		print_hash_table(hash_table);
	}


}