Revision 11fce711 ml.c

View differences:

ml.c
55 55
#include "transmissionHandler.h"
56 56

  
57 57
#define LOG_MODULE "[ml] "
58
#include "grapes_log.h"
58
#include "ml_log.h"
59 59

  
60 60
/**************************** START OF INTERNALS ***********************/
61 61

  
......
161 161
void register_recv_localsocketID_cb(receive_localsocketID_cb local_socketID_cb)
162 162
{
163 163
	if (local_socketID_cb == NULL)
164
		printf("Register receive_localsocketID_cb: NULL ptr \n");
164
		error("ML : Register receive_localsocketID_cb: NULL ptr \n");
165 165
	else
166 166
	receive_SocketID_cb = local_socketID_cb;
167 167
}
168 168

  
169 169

  
170
void keep_connection_alive(const int connectionID)
171
{
172

  
173
    // to be done with the NAT traversal
174
    // send a message over the wire
175
    printf("\n");
176

  
177
}
170
//void keep_connection_alive(const int connectionID)
171
//{
172
//
173
//    // to be done with the NAT traversal
174
//    // send a message over the wire
175
//    printf("\n");
176
//
177
//}
178 178

  
179 179
void unsetStunServer()
180 180
{
......
304 304
		connectbuf[con_id]->ctrl_msg_buf = malloc(MAX);
305 305

  
306 306
	if(connectbuf[con_id]->ctrl_msg_buf == NULL) {
307
		error("ML: can not allocate memory for connection message");
307
		error("ML: can not allocate memory for connection message\n");
308 308
		return;
309 309
	}
310 310

  
......
361 361
		* send an ok
362 362
		*/
363 363
		case INVITE:
364
			debug("ML: received INVITE");
364
			debug("ML: received INVITE\n");
365 365
			/*
366 366
			* check if another connection for the external connectionID exist
367 367
			* that was established within the last 2 seconds
......
381 381
			if (con_id == CONNECTBUFSIZE) {
382 382
				// create an entry in the connecttrybuf
383 383
				if(free_con_id == -1) {
384
					error("ML: no new connect_buf available");
384
					error("ML: no new connect_buf available\n");
385 385
					return;
386 386
				}
387 387
				connectbuf[free_con_id] = (connect_data *) malloc(sizeof(connect_data));
......
403 403
			}
404 404
			break;
405 405
		case CONNECT:
406
			debug("ML: received CONNECT");
406
			debug("ML: received CONNECT\n");
407 407

  
408 408
			if(msg_h->remote_con_id != -1 && connectbuf[msg_h->remote_con_id] == NULL) {
409
				error("ML: received CONNECT for unexistent connection");
409
				error("ML: received CONNECT for inexistent connection\n");
410 410
				return;
411 411
			}
412 412

  
......
441 441
				// send the READY
442 442
				send_conn_msg(msg_h->remote_con_id, con_msg->pmtu_size, READY);
443 443

  
444
			debug("ML: active connection established");
444
			debug("ML: active connection established\n");
445 445
			break;
446 446

  
447 447
			/*
......
449 449
			* connection active change the pmtu size
450 450
			*/
451 451
		case READY:
452
			debug("ML: received READY");
452
			debug("ML: received READY\n");
453 453
			if(connectbuf[msg_h->remote_con_id] == NULL) {
454
				error("ML: received READY for unexistent connection");
454
				error("ML: received READY for inexistent connection\n");
455 455
				return;
456 456
			}
457 457
			/*
......
475 475
				}
476 476
				connectbuf[msg_h->remote_con_id]->connection_head =
477 477
					connectbuf[msg_h->remote_con_id]->connection_last = NULL;
478
				debug("ML: passiv connection established");
478
				debug("ML: passive connection established\n");
479 479
			}
480 480
			break;
481 481
	}
......
516 516
void recv_timeout_cb(int fd, short event, void *arg)
517 517
{
518 518
	int recv_id = (long) arg;
519
	debug("ML: recv_timeout_cb called");
519
	debug("ML: recv_timeout_cb called\n");
520 520

  
521 521
	if (recvdatabuf[recv_id] == NULL) {
522 522
		return;
......
584 584
// process a single recv data message
585 585
void recv_data_msg(struct msg_header *msg_h, char *msgbuf, int bufsize)
586 586
{
587
	debug("transmissionHandler: received data message called");
587
	debug("ML: received data message called\n");
588 588

  
589 589
	int recv_id, free_recv_id = -1;
590 590

  
591 591
	if(connectbuf[msg_h->remote_con_id] == NULL) {
592
		debug("ML: Received a message not related to any opened connection!");
592
		debug("ML: Received a message not related to any opened connection!\n");
593 593
		return;
594 594
	}
595 595

  
......
708 708
//done
709 709
void pmtu_timeout_cb(int fd, short event, void *arg)
710 710
{
711
	debug("ML: pmtu timeout called");
711
	debug("ML: pmtu timeout called\n");
712 712

  
713 713
	int con_id = (long) arg;
714 714
	pmtu new_pmtusize;
715 715
	struct timeval timeout;
716 716

  
717 717
	if(connectbuf[con_id] == NULL) {
718
		error("ML: pmtu timeout called on non existing con_id");
718
		error("ML: pmtu timeout called on non existing con_id\n");
719 719
		return;
720 720
	}
721 721

  
......
751 751
			connectbuf[con_id]->pmtusize = MAX;
752 752
		} else {
753 753
			//nothing to do we have to give up
754
			error("ML: Could not create connection with connectionID %i!",con_id);
754
			error("ML: Could not create connection with connectionID %i!\n",con_id);
755 755
			// envoke the callback for failed connection establishment
756 756
			if(failed_Connection_cb != NULL)
757 757
				(failed_Connection_cb) (con_id, NULL);
......
794 794

  
795 795
void pmtu_error_cb_th(char *msg, int msglen)
796 796
{
797
	debug("ML: pmtu_error callback called msg_size: %d",msglen);
797
	debug("ML: pmtu_error callback called msg_size: %d\n",msglen);
798 798
	//TODO debug
799 799
	return;
800 800

  
......
846 846
//    connectbuf[connectionID]->pmtutrysize = new_pmtusize;
847 847

  
848 848
    if (new_pmtusize == ERROR) {
849
		fprintf(stderr,
850
			"transmissionHandler:  Could not create connection with connectionID %i !\n",
849
		error("ML:  Could not create connection with connectionID %i !\n",
851 850
			connectionID);
852 851

  
853 852
		if(failed_Connection_cb != NULL)
......
940 939
//done --
941 940
void recv_pkg(int fd, short event, void *arg)
942 941
{
943
	debug("ML: recv_pkg called");
942
	debug("ML: recv_pkg called\n");
944 943

  
945 944
	struct msg_header *msg_h;
946 945
	char msgbuf[MAX];
......
961 960
	unsigned short stun_bind_response = 0x0101;
962 961
	unsigned short * msgspot = (unsigned short *) msgbuf;
963 962
	if (*msgspot == stun_bind_response) {
964
		debug("ML: recv_pkg: parse stun message called");
963
		debug("ML: recv_pkg: parse stun message called\n");
965 964
		recv_stun_msg(msgbuf, recvSize);
966 965
		return;
967 966
	}
......
981 980
			msginfNow.remote_socketID = &(c_msg->sock_id);
982 981
		}
983 982
		else if(connectbuf[msg_h->remote_con_id] == NULL) {
984
			error("ML: received pkg called with non existent connection");
983
			error("ML: received pkg called with non existent connection\n");
985 984
			return;
986 985
		} else
987 986
			msginfNow.remote_socketID = &(connectbuf[msg_h->remote_con_id]->external_socketID);
......
999 998

  
1000 999
	switch(msg_h->msg_type) {
1001 1000
		case ML_CON_MSG:
1002
			debug("ML: received conn pkg");
1001
			debug("ML: received conn pkg\n");
1003 1002
			recv_conn_msg(msg_h, bufptr, msg_size);
1004 1003
			break;
1005 1004
		default:
1006 1005
			if(msg_h->msg_type < 127) {
1007
				debug("ML: received data pkg");
1006
				debug("ML: received data pkg\n");
1008 1007
				recv_data_msg(msg_h, bufptr, msg_size);
1009 1008
				break;
1010 1009
			}
1011
			debug("ML: unrecognised msg_type");
1010
			debug("ML: unrecognised msg_type\n");
1012 1011
			break;
1013 1012
	}
1014 1013
}
......
1030 1029
void nat_traversal_timeout(int fd, short event, void *arg)
1031 1030
{
1032 1031
	if (NAT_traversal == false) {
1033
		debug("ML: NAT traversal request resend");
1032
		debug("ML: NAT traversal request re-send\n");
1034 1033
		send_stun_request(socketfd, &stun_server);
1035 1034

  
1036 1035
		/*
......
1049 1048
{
1050 1049
	struct hostent *h = gethostbyname(ipaddr);
1051 1050
	if (!h) {
1052
		error("Unable to resolve hostname %s\n", ipaddr);
1051
		error("Unable to resolve host name %s\n", ipaddr);
1053 1052
	exit(-1);
1054 1053
    }
1055 1054
    unsigned long *addr = (unsigned long *) (h->h_addr);
......
1139 1138
void mlRegisterGetRecvPktInf(get_recv_pkt_inf_cb recv_pkt_inf_cb){
1140 1139

  
1141 1140
	if (recv_pkt_inf_cb == NULL)
1142
		printf("Register get_recv_pkt_inf_cb failed: NULL ptr  \n");
1141
		error("Register get_recv_pkt_inf_cb failed: NULL ptr  \n");
1143 1142
	else
1144 1143
		get_Recv_pkt_inf_cb = recv_pkt_inf_cb;
1145 1144

  
......
1148 1147
void mlRegisterGetSendPktInf(get_send_pkt_inf_cb  send_pkt_inf_cb){
1149 1148

  
1150 1149
	if (send_pkt_inf_cb == NULL)
1151
		printf("Register get_send_pkt_inf_cb: NULL ptr  \n");
1150
		error("Register get_send_pkt_inf_cb: NULL ptr  \n");
1152 1151
	else
1153 1152
		get_Send_pkt_inf_cb = send_pkt_inf_cb;
1154 1153

  
......
1158 1157
void mlRegisterSetMonitoringHeaderPktCb(set_monitoring_header_pkt_cb monitoring_header_pkt_cb ){
1159 1158

  
1160 1159
	if (monitoring_header_pkt_cb == NULL)
1161
		printf("Register set_monitoring_header_pkt_cb: NULL ptr  \n");
1160
		error("Register set_monitoring_header_pkt_cb: NULL ptr  \n");
1162 1161
	else
1163 1162
		set_Monitoring_header_pkt_cb = monitoring_header_pkt_cb;
1164 1163

  
......
1167 1166
void mlRegisterGetRecvDataInf(get_recv_data_inf_cb recv_data_inf_cb){
1168 1167

  
1169 1168
	if (recv_data_inf_cb == NULL)
1170
		printf("Register get_recv_data_inf_cb: NULL ptr  \n");
1169
		error("Register get_recv_data_inf_cb: NULL ptr  \n");
1171 1170
	else
1172 1171
		get_Recv_data_inf_cb = recv_data_inf_cb;
1173 1172

  
......
1176 1175
void mlRegisterGetSendDataInf(get_send_data_inf_cb  send_data_inf_cb){
1177 1176

  
1178 1177
	if (send_data_inf_cb == NULL)
1179
		printf("Register get_send_data_inf_cb: NULL ptr  \n");
1178
		error("Register get_send_data_inf_cb: NULL ptr  \n");
1180 1179
	else
1181 1180
		get_Send_data_inf_cb = send_data_inf_cb;
1182 1181

  
......
1185 1184
void mlRegisterSetMonitoringHeaderDataCb(set_monitoring_header_data_cb monitoring_header_data_cb){
1186 1185

  
1187 1186
	if (monitoring_header_data_cb == NULL)
1188
		printf("Register set_monitoring_header_data_cb : NULL ptr  \n");
1187
		error("Register set_monitoring_header_data_cb : NULL ptr  \n");
1189 1188
	else
1190 1189
	set_Monitoring_header_data_cb = monitoring_header_data_cb;
1191 1190

  
......
1194 1193
void mlRegisterRecvConnectionCb(receive_connection_cb recv_conn_cb){
1195 1194

  
1196 1195
	if (recv_conn_cb == NULL)
1197
		printf("Register receive_connection_cb: NULL ptr  \n");
1196
		error("Register receive_connection_cb: NULL ptr  \n");
1198 1197
	else
1199 1198
		receive_Connection_cb = recv_conn_cb;
1200 1199

  
......
1203 1202
void mlRegisterErrorConnectionCb(connection_failed_cb conn_failed){
1204 1203

  
1205 1204
	if (conn_failed == NULL)
1206
		printf("Register connection_failed_cb: NULL ptr  \n");
1205
		error("Register connection_failed_cb: NULL ptr  \n");
1207 1206
	else
1208 1207
	failed_Connection_cb = conn_failed;
1209 1208

  
......
1213 1212

  
1214 1213
    if (msgtype > 126) {
1215 1214

  
1216
	printf
1217
	    ("transmissionHandler: Could not register recv_data callback. Msgtype is greater then 126 \n");
1215
    	error
1216
	    ("ML: Could not register recv_data callback. Msgtype is greater then 126 \n");
1218 1217

  
1219 1218
    }
1220 1219

  
1221 1220
    if (data_cb == NULL) {
1222 1221

  
1223
	printf("Register receive data callback: NUll ptr \n ");
1222
    	error("ML: Register receive data callback: NUll ptr \n ");
1224 1223

  
1225 1224
    } else {
1226 1225

  
......
1277 1276

  
1278 1277
	int con_id;
1279 1278
	if (external_socketID == NULL) {
1280
		error("ML: cannot open connection: one of the socketIDs is NULL");
1279
		error("ML: cannot open connection: one of the socketIDs is NULL\n");
1281 1280
		return -1;
1282 1281
	}
1283 1282
	if (NAT_traversal == false) {
1284
		error("ML: cannot open connection: NAT traversal for socketID still in progress");
1283
		error("ML: cannot open connection: NAT traversal for socketID still in progress\n");
1285 1284
		return -1;
1286 1285
	}
1287 1286
	if (connection_cb == NULL) {
1288
		error("ML: cannot open connection: connection_cb is NULL");
1287
		error("ML: cannot open connection: connection_cb is NULL\n");
1289 1288
		return -1;
1290 1289
	}
1291 1290

  
......
1350 1349
	} //end of for
1351 1350

  
1352 1351
	if (con_id == CONNECTBUFSIZE) {
1353
		error("ML: Could not open connection: connbuffer full");
1352
		error("ML: Could not open connection: connection buffer full\n");
1354 1353
		return -1;
1355 1354
	}
1356 1355

  
......
1380 1379
void mlSendData(const int connectionID,char *sendbuf,int bufsize,unsigned char msgtype,send_params *sParams){
1381 1380

  
1382 1381
	if (connectionID < 0) {
1383
		error("ML: send data failed: connectionID does not exist");
1382
		error("ML: send data failed: connectionID does not exist\n");
1384 1383
		return;
1385 1384
	}
1386 1385

  
1387 1386
	if (connectbuf[connectionID] == NULL) {
1388
		error("ML: send data failed: connectionID does not exist");
1387
		error("ML: send data failed: connectionID does not exist\n");
1389 1388
		return;
1390 1389
	}
1391 1390
	if (connectbuf[connectionID]->status != READY) {
1392
	    error("ML: send data failed: connection is not active");
1391
	    error("ML: send data failed: connection is not active\n");
1393 1392
	    return;
1394 1393
	}
1395 1394

  
......
1406 1405

  
1407 1406
    if (nr_entries < 1 || nr_entries > 5) {
1408 1407

  
1409
	printf
1410
	    ("send_all_data ERROR: nr_enties is not between 1 and 5 \n ");
1408
	error
1409
	    ("ML : sendALlData : nr_enties is not between 1 and 5 \n ");
1411 1410
	return 0;
1412 1411

  
1413 1412
    } else {
......
1494 1493
	return 0;
1495 1494
#if 0
1496 1495
	if (rParams == NULL) {
1497
		error("ML: recv_data failed: recv_params is a NULL ptr");
1496
		error("ML: recv_data failed: recv_params is a NULL ptr\n");
1498 1497
		return 0;
1499 1498
    } else {
1500 1499

  
1501
	printf("transmissionhandler: recv data called \n");
1500
	info("ML: recv data called \n");
1502 1501

  
1503 1502
	int i = 0;
1504 1503
	int returnValue = 0;
......
1511 1510

  
1512 1511
		if (recvdatabuf[i]->connectionID == connectionID) {
1513 1512

  
1514
		    printf("transmissionhandler: recv data has entry  \n");
1513
		    info("ML: recv data has entry  \n");
1515 1514

  
1516 1515
		    double timepass = difftime(endtime, recvdatabuf[i]->starttime);
1517 1516

  
......
1596 1595

  
1597 1596
			if (timepass > timeout) {
1598 1597

  
1599
			    printf("transmissionHandler: recv_data timeout called  \n");
1598
			    info("ML: recv_data timeout called  \n");
1600 1599

  
1601 1600
			    // some data about the missing chunks should
1602 1601
			    // be added here
......
1809 1808

  
1810 1809
//Added by Robert Birke as comodity functions
1811 1810

  
1812
int mlPrintSocketID(socketID_handle socketID) {
1813
	char str[SOCKETID_STRING_SIZE];
1814
	mlSocketIDToString(socketID, str, sizeof(str));
1815
	printf("int->%s<-ext\n",str);
1816
}
1811
//int mlPrintSocketID(socketID_handle socketID) {
1812
//	char str[SOCKETID_STRING_SIZE];
1813
//	mlSocketIDToString(socketID, str, sizeof(str));
1814
//	printf(stderr,"int->%s<-ext\n",str);
1815
//}
1817 1816

  
1818 1817
/*
1819 1818
 * hash code of a socketID

Also available in: Unified diff