- Timestamp:
- May 25, 2006, 1:27:00 PM (19 years ago)
- Location:
- branches/network/src
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/lib/network/Makefile.am
r7748 r7851 22 22 message_manager.cc \ 23 23 network_log.cc \ 24 zip.cc \ 24 25 \ 25 26 synchronizeable_var/synchronizeable_var.cc \ … … 54 55 message_manager.h \ 55 56 network_log.h \ 57 zip.h \ 56 58 \ 57 59 synchronizeable_var/synchronizeable_var.h \ -
branches/network/src/lib/network/connection_monitor.cc
r7792 r7851 33 33 this->incomingUnzippedBandWidth = 0; 34 34 this->outgoingUnzippedBandWidth = 0; 35 this->incomingZippedBandWidth = 0; 36 this->outgoingZippedBandWidth = 0; 35 37 this->nIncomingPackets = 0; 36 38 this->nOutgoingPackets = 0; 39 this->nZIncomingPackets = 0; 40 this->nZOutgoingPackets = 0; 37 41 38 42 this->lastPacketTick = 0; … … 56 60 outgoingUnzippedBandWidth = calculateBandWidth( outgoingUnzippedPacketHistory, tick ); 57 61 58 NETPRINTF(n)("U PSTREAM: user: %d bandwidth %f\n", userId, outgoingUnzippedBandWidth );62 NETPRINTF(n)("UNZIPPED UPSTREAM: user: %d bandwidth %f\n", userId, outgoingUnzippedBandWidth ); 59 63 60 64 // count zero bytes … … 104 108 incomingUnzippedBandWidth = calculateBandWidth( incomingUnzippedPacketHistory, tick ); 105 109 106 NETPRINTF(n)(" DOWNSTREAM: user: %d bandwidth %f\n", userId, incomingUnzippedBandWidth );110 NETPRINTF(n)("UNZIPPED DOWNSTREAM: user: %d bandwidth %f\n", userId, incomingUnzippedBandWidth ); 107 111 108 112 } … … 132 136 133 137 138 139 140 void ConnectionMonitor::processZippedOutgoingPacket( byte * data, int length, int stateId ) 141 { 142 int tick = SDL_GetTicks(); 143 144 nZOutgoingPackets++; 145 146 // calculate bandwidth 147 outgoingZippedPacketHistory[tick] = length; 148 outgoingZippedBandWidth = calculateBandWidth( outgoingZippedPacketHistory, tick ); 149 150 NETPRINTF(n)("UPSTREAM: user: %d bandwidth %f\n", userId, outgoingZippedBandWidth ); 151 152 } 153 154 155 void ConnectionMonitor::processZippedIncomingPacket( byte * data, int length, int stateId, int ackedState ) 156 { 157 int tick = SDL_GetTicks(); 158 159 nZIncomingPackets++; 160 161 // calculate bandwidth 162 incomingZippedPacketHistory[tick] = length; 163 incomingZippedBandWidth = calculateBandWidth( incomingZippedPacketHistory, tick ); 164 165 NETPRINTF(n)("DOWNSTREAM: user: %d bandwidth %f\n", userId, incomingZippedBandWidth ); 166 167 } 168 -
branches/network/src/lib/network/connection_monitor.h
r7778 r7851 24 24 void processUnzippedOutgoingPacket( byte * data, int length, int stateId ); 25 25 void processUnzippedIncomingPacket( byte * data, int length, int stateId, int ackedState ); 26 void processZippedPacket( ); 26 27 void processZippedOutgoingPacket( byte * data, int length, int stateId ); 28 void processZippedIncomingPacket( byte * data, int length, int stateId, int ackedState ); 27 29 28 30 void calculatePing(); … … 40 42 std::map<int,int> outgoingUnzippedPacketHistory; 41 43 44 std::map<int,int> incomingZippedPacketHistory; 45 std::map<int,int> outgoingZippedPacketHistory; 46 42 47 std::list<int> ackDelay; 43 48 int ping; … … 46 51 float outgoingUnzippedBandWidth; 47 52 53 float incomingZippedBandWidth; 54 float outgoingZippedBandWidth; 55 48 56 int nIncomingPackets; 49 57 int nOutgoingPackets; 58 59 int nZIncomingPackets; 60 int nZOutgoingPackets; 50 61 51 62 int lastPacketTick; -
branches/network/src/lib/network/network_stream.cc
r7809 r7851 30 30 #include "shared_network_data.h" 31 31 #include "message_manager.h" 32 #include "preferences.h" 33 #include "zip.h" 34 35 #include "src/lib/util/loading/resource_manager.h" 32 36 33 37 #include "network_log.h" … … 88 92 myHostId = 0; 89 93 currentState = 0; 94 95 remainingBytesToWriteToDict = Preferences::getInstance()->getInt( "compression", "writedict", 0 ); 96 97 assert( Zip::getInstance()->loadDictionary( "testdict" ) ); 90 98 } 91 99 … … 365 373 void NetworkStream::handleUpstream( ) 366 374 { 367 byte buf[UDP_PACKET_SIZE];368 375 int offset; 369 376 int n; … … 430 437 assert( Converter::intToByteArray( offset, buf, INTSIZE ) == INTSIZE ); 431 438 432 assert( peer->second.socket->writePacket( buf, offset ) ); 439 int compLength = Zip::getInstance()->zip( buf, offset, compBuf, UDP_PACKET_SIZE ); 440 441 if ( compLength < 0 ) 442 { 443 PRINTF(1)("compression failed!\n"); 444 continue; 445 } 446 447 assert( peer->second.socket->writePacket( compBuf, compLength ) ); 448 449 if ( this->remainingBytesToWriteToDict > 0 ) 450 writeToNewDict( buf, offset ); 433 451 434 452 peer->second.connectionMonitor->processUnzippedOutgoingPacket( buf, offset, currentState ); 453 peer->second.connectionMonitor->processZippedOutgoingPacket( compBuf, compLength, currentState ); 435 454 436 455 NETPRINTF(n)("send packet: %d userId = %d\n", offset, peer->second.userId); … … 443 462 void NetworkStream::handleDownstream( ) 444 463 { 445 byte buf[UDP_PACKET_SIZE];446 464 int offset = 0; 447 465 448 466 int length = 0; 449 467 int packetLength = 0; 468 int compLength = 0; 450 469 int uniqueId = 0; 451 470 int state = 0; … … 460 479 continue; 461 480 462 while ( 0 < (packetLength = peer->second.socket->readPacket( buf, UDP_PACKET_SIZE )) ) 463 { 481 while ( 0 < (compLength = peer->second.socket->readPacket( compBuf, UDP_PACKET_SIZE )) ) 482 { 483 packetLength = Zip::getInstance()->unZip( compBuf, compLength, buf, UDP_PACKET_SIZE ); 484 464 485 if ( packetLength < 4*INTSIZE ) 465 486 { … … 468 489 continue; 469 490 } 491 492 if ( this->remainingBytesToWriteToDict > 0 ) 493 writeToNewDict( buf, packetLength ); 470 494 471 495 assert( Converter::byteArrayToInt( buf, &length ) == INTSIZE ); … … 586 610 } 587 611 612 peer->second.connectionMonitor->processZippedIncomingPacket( compBuf, compLength, currentState, ackedState ); 588 613 peer->second.connectionMonitor->processUnzippedIncomingPacket( buf, offset, currentState, ackedState ); 589 614 … … 629 654 } 630 655 631 632 633 634 635 656 /** 657 * writes data to DATA/dicts/newdict 658 * @param data pointer to data 659 * @param length length 660 */ 661 void NetworkStream::writeToNewDict( byte * data, int length ) 662 { 663 if ( remainingBytesToWriteToDict <= 0 ) 664 return; 665 666 if ( length > remainingBytesToWriteToDict ) 667 length = remainingBytesToWriteToDict; 668 669 std::string fileName = ResourceManager::getInstance()->getDataDir(); 670 fileName += "/dicts/newdict"; 671 672 FILE * f = fopen( fileName.c_str(), "a" ); 673 674 if ( !f ) 675 { 676 PRINTF(2)("could not open %s\n", fileName.c_str()); 677 remainingBytesToWriteToDict = 0; 678 return; 679 } 680 681 if ( fwrite( data, 1, length, f ) != length ) 682 { 683 PRINTF(2)("could not write to file\n"); 684 fclose( f ); 685 return; 686 } 687 688 fclose( f ); 689 690 remainingBytesToWriteToDict -= length; 691 } 692 693 694 695 696 697 -
branches/network/src/lib/network/network_stream.h
r7767 r7851 15 15 #include "handshake.h" 16 16 #include "connection_monitor.h" 17 #include "udp_server_socket.h" 17 18 18 19 class Synchronizeable; … … 82 83 void handleNewClient( int userId ); 83 84 void cleanUpOldSyncList(); 85 86 void writeToNewDict( byte * data, int length ); 84 87 85 88 … … 94 97 int myHostId; 95 98 96 int currentState; 99 int currentState; //!< current state id 97 100 98 101 NetworkGameManager* networkGameManager; 99 102 100 std::map<int,int> oldSynchronizeables; 103 std::map<int,int> oldSynchronizeables; //!< used to save recently deleted sync ids to not recreate them 104 105 byte buf[UDP_PACKET_SIZE]; //!< used by handleUp/Downstream 106 byte compBuf[UDP_PACKET_SIZE]; //!< used by handleUp/Downstream 107 108 int remainingBytesToWriteToDict; //!< if > 0 NetworkStream will write packets to DATA/dicts/newdict 101 109 }; 102 110 #endif /* _NETWORK_STREAM */ -
branches/network/src/orxonox.cc
r7749 r7851 86 86 87 87 REGISTER_ARG_ARG( t, telnetport, "network","telnetport", "Port to use for network debug output", "port" ); 88 REGISTER_ARG_ARG( _, write_dict, "compression", "writedict", "write packets to DATA/dicts/newdict", "numBytes" ); 88 89 89 90 /**
Note: See TracChangeset
for help on using the changeset viewer.