コード例 #1
0
ファイル: test_engine.c プロジェクト: DastanIqbal/FreeSWITCH
zrtp_status_t zrtp_test_endpoint_destroy(zrtp_test_id_t id) {
	unsigned i;
	zrtp_status_t s = zrtp_status_ok;
	zrtp_endpoint_t *endpoint = zrtp_test_endpoint_by_id(id);

	endpoint->is_running = 0;

	if (endpoint->input_queue) {
		/* Push faked element to the queue to unlock incoming threads */
		for (i=0; i<K_ZRTP_TEST_PROCESSORS_COUNT; i++) {
			zrtp_queue_elem_t *elem = malloc(sizeof(zrtp_queue_elem_t));
			elem->size = 0;
			zrtp_test_queue_push(endpoint->input_queue, elem);
		}
		zrtp_sleep(0.5*1000);

		zrtp_test_queue_destroy(endpoint->input_queue);
	}

	for (i=0; i<20; i++) zrtp_sleep(100);

	if (endpoint) {
		/* Shut down libzrtp */
		if (endpoint->zrtp)
			s = zrtp_down(endpoint->zrtp);

		/* Clean-up ZRTP cache after ourselves */
		remove(endpoint->cfg.zrtp.def_cache_path.buffer);
	} else {
		s = zrtp_status_fail;
	}

	return s;
}
コード例 #2
0
int main()
{
	int status;
	
	status = zrtp_test_zrtp_init();
	if (0 != status) {
		return status;
	}
#if (ZRTP_TEST_ENABLE_CRYPTO_SELFTESTS == 1)
	zrtp_test_crypto(zrtp_global);
#endif
	
	{
		zrtp_test_channel_id_t id;
		zrtp_test_channel_config_t sconfig;
		
		sconfig.is_autosecure = 0;
		sconfig.is_preshared  = 0;
		sconfig.streams_count = 1;
		
		status = zrtp_test_channel_create(&sconfig, &id);
		
		if (0 == status) {
			zrtp_test_channel_start(id);
		}
	}
	
	while (1) {
		zrtp_sleep(1000);
	}
	
	
	do_quit();
	
	return 0;
}
コード例 #3
0
ファイル: test_engine.c プロジェクト: DastanIqbal/FreeSWITCH
void *process_outgoing(void *param)
#endif
{
	unsigned packets_counter = 0;
	zrtp_endpoint_t *the_endpoint = (zrtp_endpoint_t *)param;

	while (the_endpoint->is_running) {
		zrtp_test_stream_t* stream = NULL;
		unsigned i;

		zrtp_status_t s = zrtp_status_fail;
		zrtp_test_packet_t* packet;
		zrtp_queue_elem_t* elem;
		char* word = NULL;

		zrtp_sleep(K_ZRTP_TEST_RTP_RATE);

		/* Get random channel to operate with and select random peer */
		stream = get_stream_to_process_(the_endpoint);
		if (!stream) {
			continue;
		}

		elem = zrtp_sys_alloc(sizeof(zrtp_queue_elem_t));
		if (!elem) {
			break;
		}
		packet = (zrtp_test_packet_t*) elem->data;
		packet->is_rtp = (packets_counter++ % 20); /* Every 20-th packet is RTCP */

		/*
		 * Construct RTP/RTCP Packet
		 */
		if (packet->is_rtp)
		{
			ZRTP_UNALIGNED(zrtp_rtp_hdr_t) *rtp_hdr = (zrtp_rtp_hdr_t*)packet->body;

			/* Fill RTP Header according to the specification */
			zrtp_memset(rtp_hdr, 0, sizeof(zrtp_rtp_hdr_t));
			rtp_hdr->version = 2;			/* Current RTP version 2 */
			rtp_hdr->pt = 0;				/* PCMU padding type */
			rtp_hdr->ssrc = zrtp_hton32(stream->id);		/* Use stream Identifier as it's SSRC */
			if (stream->seq >= 0xFFFF) {
				stream->seq = 0;
			}
			rtp_hdr->seq = zrtp_hton16(stream->seq++);
			rtp_hdr->ts = zrtp_hton32((uint32_t)(zrtp_time_now()/1000));

			/* Get RTP body from PGP words lists */
			word = (char*)(i ? hash_word_list_odd[packets_counter % 256] : hash_word_list_even[packets_counter % 256]);

			zrtp_memcpy(packet->body + sizeof(zrtp_rtp_hdr_t), word, (uint32_t)strlen(word));
			packet->length = sizeof(zrtp_rtp_hdr_t) + (uint32_t)strlen(word);

			/* Process RTP media with libzrtp */
			s = zrtp_process_rtp(stream->zrtp, packet->body, &packet->length);
		}
		else {
			ZRTP_UNALIGNED(zrtp_rtcp_hdr_t) *rtcp_hdr = (zrtp_rtcp_hdr_t*)packet->body;

			/* Fill RTCP Header according to the specification */
			rtcp_hdr->rc = 0;
			rtcp_hdr->version = 2;
			rtcp_hdr->ssrc = stream->id;

			/* Get RTP body from PGP words lists. Put RTCP marker at the beginning */
			zrtp_memcpy(packet->body + sizeof(zrtp_rtcp_hdr_t), "RTCP", 4);
			word = (char*)( i ? hash_word_list_odd[packets_counter % 256] : hash_word_list_even[packets_counter % 256]);

			zrtp_memcpy(packet->body + sizeof(zrtp_rtcp_hdr_t) + 4, word, (uint32_t)strlen(word));
			packet->length = sizeof(zrtp_rtcp_hdr_t) + (uint32_t)strlen(word) + 4;
			/* RTCP packets sould be 32 byes aligned */
			packet->length += (packet->length % 4) ? (4 - packet->length % 4) : 0;

			/* Process RTCP control with libzrtp */
			s = zrtp_process_rtcp(stream->zrtp, packet->body, &packet->length);
		}

		elem->size = packet->length;

		/* Handle zrtp_process_xxx() instructions */
		switch (s) {
		/* Put the packet to the queue ==> send packet to the other side pear */
		case zrtp_status_ok: {
			ZRTP_LOG(3, (_ZTU_,"Outgoing: (%s) [%p:ssrc=%u] OK. <%s%s> encrypted %d bytes.\n",
					zrtp_log_state2str(stream->zrtp->state), stream->zrtp, stream->id, packet->is_rtp ? "" : "RTCP", word, packet->length));
			zrtp_test_queue_push(stream->output, elem);
		} break;

		case zrtp_status_drop: {
			ZRTP_LOG(1, (_ZTU_,"Outgoing: (%s) [%p:ssrc=%u] DROPPED.\n",
					zrtp_log_state2str(stream->zrtp->state), stream->zrtp, stream->id));
		} break;

		case zrtp_status_fail: {
			ZRTP_LOG(1, (_ZTU_,"Outgoing: (%s) [%p:ssrc=%u] ENCRYPT FAILED.\n",
					zrtp_log_state2str(stream->zrtp->state), stream->zrtp, stream->id));
		}	break;

		default:
			break;
		}

		if (zrtp_status_ok != s) {
			zrtp_sys_free(packet);
		}
	}
#if   (ZRTP_PLATFORM == ZP_WIN32) || (ZRTP_PLATFORM == ZP_WINCE)
	return 0;
#else
	return NULL;
#endif
}