Revision 2c702104 transmissionHandler.c

View differences:

transmissionHandler.c
1635 1635
		(get_Recv_pkt_inf_cb) ((void *) &msginfNow);
1636 1636
	}
1637 1637

  
1638
    // check if a recv_data exist and enter data
1639
    for (i = 0; i < RECVDATABUFSIZE; i++) {
1640

  
1641
	 if (recvdatabuf[i] != NULL) {
1638
	// check if a recv_data exist and enter data
1639
	for (i = 0; i < RECVDATABUFSIZE; i++) {
1640
		if (recvdatabuf[i] != NULL) {
1641
			if (local_connectionID == recvdatabuf[i]->connectionID && seqnr == recvdatabuf[i]->seqnr) {
1642 1642

  
1643
	   if (local_connectionID == recvdatabuf[i]->connectionID && seqnr == recvdatabuf[i]->seqnr) {
1643
				printf("connID %d\n", recvdatabuf[i]->connectionID);
1644
				printf("seqnr %d\n", recvdatabuf[i]->seqnr);
1644 1645

  
1645
			printf("connID %d\n", recvdatabuf[i]->connectionID);
1646
			printf("seqnr %d\n", recvdatabuf[i]->seqnr);
1646
				if (firstPacketArrived = 1) {
1647
					recvdatabuf[i]->firstPacketArrived = 1;
1648
				}
1649
				// increment fragmentnr
1650
				recvdatabuf[i]->recvFragments = recvdatabuf[i]->recvFragments + 1;
1651
				int fragmentsize = connectbuf[local_connectionID]->pmtusize - MSGL_HEADER_SIZE;
1652
				char *bufptr = NULL;
1653
				bufptr = recvdatabuf[i]->recvbuf;
1654
				bufptr += offset;
1655
				// enter the data into the buffer
1656
				int cpysize = fragmentsize;
1647 1657

  
1648
			if (firstPacketArrived = 1) {
1649
				recvdatabuf[i]->firstPacketArrived = 1;
1650
		}
1651
			// increment fragmentnr
1652
			recvdatabuf[i]->recvFragments = recvdatabuf[i]->recvFragments + 1;
1653
			int fragmentsize = connectbuf[local_connectionID]->pmtusize - MSGL_HEADER_SIZE;
1654
			char *bufptr = NULL;
1655
			bufptr = recvdatabuf[i]->recvbuf;
1656
			bufptr += offset;
1657
			// enter the data into the buffer
1658
			int cpysize = fragmentsize;
1659

  
1660
			// check for last fragment
1661
			if (recvdatabuf[i]->nrFragments == recvdatabuf[i]->recvFragments) {
1662
			cpysize = recvdatabuf[i]->bufsize - offset;
1663
		}
1664
			// adapt copy size for the last fragment without
1665
			// monitoring header
1666
			if (monitoringHeaderType == 0 || monitoringHeaderType == 1) {
1667
			// adapt copy size for the last fragment with the
1668
			// monitoring header
1669
			msgbufptr = &msgbuf[18];
1670
			memcpy(bufptr, msgbufptr, cpysize);
1671
			} else if (monitoringHeaderType == 2 || monitoringHeaderType == 3) {
1672
			int bufpos = MSGL_HEADER_SIZE + MON_PACKET_HEADER_SIZE;
1673
			printf("bufpos %d \n", bufpos);
1674
			msgbufptr = &msgbuf[bufpos];
1675
			// cpysize = cpysize + MON_PACKET_HEADER_SIZE;
1676
			printf("cpyssize %d \n", cpysize);
1677
			memcpy(bufptr, msgbufptr, cpysize);
1678
		}
1658
				// check for last fragment
1659
				if (recvdatabuf[i]->nrFragments == recvdatabuf[i]->recvFragments) {
1660
					cpysize = recvdatabuf[i]->bufsize - offset;
1661
				}
1662
				// adapt copy size for the last fragment without
1663
				// monitoring header
1664
				if (monitoringHeaderType == 0 || monitoringHeaderType == 1) {
1665
					// adapt copy size for the last fragment with the
1666
					// monitoring header
1667
					msgbufptr = &msgbuf[18];
1668
					memcpy(bufptr, msgbufptr, cpysize);
1669
				} else if (monitoringHeaderType == 2 || monitoringHeaderType == 3) {
1670
					int bufpos = MSGL_HEADER_SIZE + MON_PACKET_HEADER_SIZE;
1671
					printf("bufpos %d \n", bufpos);
1672
					msgbufptr = &msgbuf[bufpos];
1673
					// cpysize = cpysize + MON_PACKET_HEADER_SIZE;
1674
					printf("cpyssize %d \n", cpysize);
1675
					memcpy(bufptr, msgbufptr, cpysize);
1676
				}
1679 1677

  
1680
			_bool = TRUE;
1678
				_bool = TRUE;
1681 1679

  
1682
			/*
1683
		 	* all fragments arrived and it are multiple fragments 
1684
		 	*/
1680
				/*
1681
		 		* all fragments arrived and it are multiple fragments 
1682
		 		*/
1685 1683

  
1686
			if (recvdatabuf[i]->nrFragments == recvdatabuf[i]->recvFragments) {
1687
				if (firstPacketArrived = 1) {
1688
				recvdatabuf[i]->firstPacketArrived = 1;
1689
			}
1684
				if (recvdatabuf[i]->nrFragments == recvdatabuf[i]->recvFragments) {
1685
					if (firstPacketArrived = 1) {
1686
					recvdatabuf[i]->firstPacketArrived = 1;
1687
				}
1690 1688

  
1691 1689
				printf("set the status of recvbuf 1  \n");
1692 1690
				recvdatabuf[i]->status = 1;
1693 1691

  
1694 1692
				// extract the monitoring module data header
1695 1693
				if (monitoringHeaderType == 1 || monitoringHeaderType == 3) {
1696
				memcpy(monitoringDataHeader, recvdatabuf[i]->recvbuf, MON_DATA_HEADER_SIZE);
1694
					memcpy(monitoringDataHeader, recvdatabuf[i]->recvbuf, MON_DATA_HEADER_SIZE);
1697 1695

  
1698
			// shorten the recv buffer and change the
1699
			// buffersize
1700
				recvdatabuf[i]->recvbuf += MON_DATA_HEADER_SIZE;
1701
				recvdatabuf[i]->bufsize -= MON_DATA_HEADER_SIZE;
1702
				recvdatabuf[i]->monitoringDataHeader = monitoringDataHeader;
1703
			}
1696
					// shorten the recv buffer and change the
1697
					// buffersize
1698
					recvdatabuf[i]->recvbuf += MON_DATA_HEADER_SIZE;
1699
					recvdatabuf[i]->bufsize -= MON_DATA_HEADER_SIZE;
1700
					recvdatabuf[i]->monitoringDataHeader = monitoringDataHeader;
1701
				}
1704 1702

  
1705 1703
				if (recv_data_callback) {
1706 1704

  
......
1766 1764
				}
1767 1765
			}
1768 1766
		}
1769
	 }
1770
  	 }
1767
		}
1768
	}
1771 1769

  
1772 1770

  
1773 1771
   // if the dataID and connectionId dont exist: create a new recv object
1774 1772
	if (_bool == FALSE) {
1775

  
1776 1773
		for (i = 0; i < RECVDATABUFSIZE; i++) {
1777

  
1778 1774
			if (recvdatabuf[i] == NULL) {
1779 1775
				recvdatabuf[i] = (recvdata *) malloc(sizeof(recvdata));
1780 1776
				recvdatabuf[i]->connectionID = local_connectionID;
......
1907 1903
						event_add(ev, &recvdatabuf[i]->timeout_value);
1908 1904
					}
1909 1905
				}
1906
				break;
1910 1907
			}
1911
			break;
1908
			//break; missplaced ??
1912 1909
		}
1913 1910
	}
1914 1911
    // printf("still here 11\n");
......
2366 2363

  
2367 2364
}
2368 2365

  
2366

  
2367
/*
2368
 * hash code of a socketID
2369
 * TODO might think of a better way
2370
 */
2371
int hash_socketID(socketID_handle sock)
2372
{
2373
    return sock->internal_addr.udpaddr.sin_port +
2374
			  sock->external_addr.udpaddr.sin_port;
2375
}
2376

  
2369 2377
/*
2370 2378
 * compares 2 socketIDs: returns 0 if they are equl otherwise 1 
2371 2379
 */
2372 2380
int compare_socketIDs(socketID_handle sock1, socketID_handle sock2)
2373 2381
{
2382
	/*
2383
	* compare internal addr 
2384
	*/
2385
	if (sock1->internal_addr.udpaddr.sin_addr.s_addr != 
2386
	    sock2->internal_addr.udpaddr.sin_addr.s_addr)
2387
			return 1;
2374 2388

  
2375
    int resultValue = 0;
2376
    socketaddrgen udpgen1;
2377
    socketaddrgen udpgen2;
2378
    struct sockaddr_in udpaddr1;
2379
    struct sockaddr_in udpaddr2;
2380

  
2381
    /*
2382
     * compare internal addr 
2383
     */
2384
    udpgen1 = sock1->internal_addr;
2385
    udpgen2 = sock2->internal_addr;
2386

  
2387
    udpaddr1 = udpgen1.udpaddr;
2388
    udpaddr2 = udpgen2.udpaddr;
2389

  
2390
    if (udpaddr1.sin_addr.s_addr != udpaddr2.sin_addr.s_addr) {
2391

  
2392
	resultValue = 1;
2393

  
2394
    }
2395

  
2396
    if (udpaddr1.sin_port != udpaddr2.sin_port) {
2397

  
2398
	resultValue = 1;
2399

  
2400
    }
2401

  
2402
    /*
2403
     * compare external addr 
2404
     */
2405
    udpgen1 = sock1->external_addr;
2406
    udpgen2 = sock2->external_addr;
2407
    udpaddr1 = udpgen1.udpaddr;
2408
    udpaddr2 = udpgen2.udpaddr;
2409

  
2410
    if (udpaddr1.sin_addr.s_addr != udpaddr2.sin_addr.s_addr) {
2411

  
2412
	resultValue = 1;
2413

  
2414
    }
2415

  
2416
    if (udpaddr1.sin_port != udpaddr2.sin_port) {
2417

  
2418
	resultValue = 1;
2419

  
2420
    }
2389
	if (sock1->internal_addr.udpaddr.sin_port !=
2390
		 sock2->internal_addr.udpaddr.sin_port)
2391
			return 1;
2421 2392

  
2393
	/*
2394
	* compare external addr 
2395
	*/
2396
	if (sock1->external_addr.udpaddr.sin_addr.s_addr != 
2397
	    sock2->external_addr.udpaddr.sin_addr.s_addr)
2398
			return 1;
2422 2399

  
2423
    return resultValue;
2400
	if (sock1->external_addr.udpaddr.sin_port !=
2401
		 sock2->external_addr.udpaddr.sin_port)
2402
			return 1;
2424 2403

  
2404
	return 0;
2425 2405
}
2426 2406

  
2427 2407
/*
......
2505 2485

  
2506 2486
}
2507 2487

  
2508

  
2509
int socketID_to_String(socketID_handle socketID, char *socketID_string)
2488
int print_socketID(socketID_handle socketID)
2510 2489
{
2511 2490

  
2512 2491
    socketaddrgen udpgen;
......
2529 2508
    inet_ntop(AF_INET, &(udpaddr.sin_addr), internal_addr,
2530 2509
	      INET_ADDRSTRLEN);
2531 2510

  
2532
    if (external_addr == NULL || internal_addr == NULL) {
2533

  
2534
	return -1;
2511
    if (external_addr == NULL || internal_addr == NULL)
2512
		return -1;
2535 2513

  
2536
    } else {
2537

  
2538
	char *bufptr;
2539
	bufptr = &socketID_string[0];
2540

  
2541
	memcpy(bufptr, external_addr, INET_ADDRSTRLEN);
2542

  
2543
	bufptr = &socketID_string[16];
2544

  
2545
	memcpy(bufptr, &external_port, 4);
2546

  
2547
	bufptr = &socketID_string[20];
2548

  
2549
	memcpy(bufptr, internal_addr, INET_ADDRSTRLEN);
2550

  
2551
	bufptr = &socketID_string[36];
2552

  
2553
	memcpy(bufptr, &internal_port, 4);
2514
	printf("Ext %s:%d Int %s:%d\n",external_addr,external_port,internal_addr,internal_port);
2515
}
2554 2516

  
2517
int socketID_to_String(socketID_handle sock, char *sock_string)
2518
{
2519
	char internal_addr[INET_ADDRSTRLEN];
2520
	char external_addr[INET_ADDRSTRLEN];
2521
   inet_ntop(AF_INET, &(sock->internal_addr.udpaddr.sin_addr.s_addr), internal_addr, INET_ADDRSTRLEN);
2522
	inet_ntop(AF_INET, &(sock->external_addr.udpaddr.sin_addr.s_addr), external_addr, INET_ADDRSTRLEN);
2523
	
2524
	sprintf(sock_string,"%s:%d %s:%d", internal_addr, sock->internal_addr.udpaddr.sin_port,
2525
		external_addr,	sock->external_addr.udpaddr.sin_port);
2555 2526
	return 0;
2556

  
2557
    }
2558

  
2559 2527
}
2560 2528

  
2561
socketID_handle string_to_socketID(char *socketID_string)
2529
int string_to_socketID(char* socketID_string, socketID_handle sock)
2562 2530
{
2531
	//@TODO add checks against malformed string
2532
	char external_addr[INET_ADDRSTRLEN];
2533
	int external_port;
2534
	char internal_addr[INET_ADDRSTRLEN];
2535
	int internal_port;
2536

  
2537
	char *pch;
2538

  
2539
	//replace ':' with a blank
2540
	pch=strchr(socketID_string,':');
2541
	while (pch!=NULL){
2542
				*pch = ' ';
2543
		pch=strchr(pch+1,':');
2544
	}
2563 2545

  
2564
    char external_addr[INET_ADDRSTRLEN];
2565
    int external_port;
2566
    char internal_addr[INET_ADDRSTRLEN];
2567
    int internal_port;
2568

  
2569
    // get the data into variables
2570
    char *bufptr;
2571
    bufptr = &socketID_string[0];
2572
    memcpy(external_addr, bufptr, INET_ADDRSTRLEN);
2573

  
2574
    bufptr = &socketID_string[16];
2575
    memcpy(&external_port, bufptr, 4);
2576

  
2577
    bufptr = &socketID_string[20];
2578
    memcpy(internal_addr, bufptr, INET_ADDRSTRLEN);
2579

  
2580
    bufptr = &socketID_string[36];
2581
    memcpy(&internal_port, bufptr, 4);
2582

  
2583

  
2584
    struct sockaddr_in udpaddr_ex;
2585
    udpaddr_ex.sin_family = AF_INET;
2586
    udpaddr_ex.sin_addr.s_addr = inet_addr(external_addr);
2587
    udpaddr_ex.sin_port = external_port;
2588

  
2589
    struct sockaddr_in udpaddr_in;
2590
    udpaddr_in.sin_family = AF_INET;
2591
    udpaddr_in.sin_addr.s_addr = inet_addr(internal_addr);
2592
    udpaddr_in.sin_port = internal_port;
2593

  
2594
    socketaddrgen udpgen_ex;
2595
    udpgen_ex.udpaddr = udpaddr_ex;
2596
    local_socketID.external_addr = udpgen_ex;
2597

  
2598
    socketaddrgen udpgen_in;
2599
    udpgen_in.udpaddr = udpaddr_in;
2600
    local_socketID.external_addr = udpgen_in;
2546
	sscanf(socketID_string,"%s %d %s %d", internal_addr, &internal_port,
2547
		external_addr, &external_port);
2601 2548

  
2602
    socketID_handle new_SocketID = malloc(sizeof(socket_ID));
2603
    new_SocketID->external_addr = udpgen_ex;
2604
    new_SocketID->internal_addr = udpgen_in;
2549
	sock->internal_addr.udpaddr.sin_addr.s_addr = inet_addr(internal_addr);
2550
	sock->internal_addr.udpaddr.sin_port = internal_port;
2605 2551

  
2606
    // return the socketID_handle
2607
    return new_SocketID;
2552
	sock->external_addr.udpaddr.sin_addr.s_addr = inet_addr(external_addr);
2553
	sock->external_addr.udpaddr.sin_port = external_port;
2554
	return 0;
2608 2555
}
2609 2556

  
2610 2557

  

Also available in: Unified diff