Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7851 in orxonox.OLD for branches/network/src


Ignore:
Timestamp:
May 25, 2006, 1:27:00 PM (18 years ago)
Author:
rennerc
Message:

compression implemented

Location:
branches/network/src
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/lib/network/Makefile.am

    r7748 r7851  
    2222                      message_manager.cc \
    2323                      network_log.cc \
     24                      zip.cc \
    2425                      \
    2526                      synchronizeable_var/synchronizeable_var.cc \
     
    5455                 message_manager.h \
    5556                 network_log.h \
     57                 zip.h \
    5658                 \
    5759                 synchronizeable_var/synchronizeable_var.h \
  • branches/network/src/lib/network/connection_monitor.cc

    r7792 r7851  
    3333  this->incomingUnzippedBandWidth = 0;
    3434  this->outgoingUnzippedBandWidth = 0;
     35  this->incomingZippedBandWidth = 0;
     36  this->outgoingZippedBandWidth = 0;
    3537  this->nIncomingPackets = 0;
    3638  this->nOutgoingPackets = 0;
     39  this->nZIncomingPackets = 0;
     40  this->nZOutgoingPackets = 0;
    3741 
    3842  this->lastPacketTick = 0;
     
    5660  outgoingUnzippedBandWidth = calculateBandWidth( outgoingUnzippedPacketHistory, tick );
    5761 
    58   NETPRINTF(n)("UPSTREAM: user: %d bandwidth %f\n", userId, outgoingUnzippedBandWidth );
     62  NETPRINTF(n)("UNZIPPED UPSTREAM: user: %d bandwidth %f\n", userId, outgoingUnzippedBandWidth );
    5963 
    6064  // count zero bytes
     
    104108  incomingUnzippedBandWidth = calculateBandWidth( incomingUnzippedPacketHistory, tick );
    105109 
    106   NETPRINTF(n)("DOWNSTREAM: user: %d bandwidth %f\n", userId, incomingUnzippedBandWidth );
     110  NETPRINTF(n)("UNZIPPED DOWNSTREAM: user: %d bandwidth %f\n", userId, incomingUnzippedBandWidth );
    107111 
    108112}
     
    132136
    133137
     138
     139
     140void 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
     155void 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  
    2424    void processUnzippedOutgoingPacket( byte * data, int length, int stateId );
    2525    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 );
    2729   
    2830    void calculatePing();
     
    4042    std::map<int,int>   outgoingUnzippedPacketHistory;
    4143   
     44    std::map<int,int>   incomingZippedPacketHistory;
     45    std::map<int,int>   outgoingZippedPacketHistory;
     46   
    4247    std::list<int>      ackDelay;
    4348    int                 ping;
     
    4651    float               outgoingUnzippedBandWidth;
    4752   
     53    float               incomingZippedBandWidth;
     54    float               outgoingZippedBandWidth;
     55   
    4856    int                 nIncomingPackets;
    4957    int                 nOutgoingPackets;
     58   
     59    int                 nZIncomingPackets;
     60    int                 nZOutgoingPackets;
    5061   
    5162    int                 lastPacketTick;
  • branches/network/src/lib/network/network_stream.cc

    r7809 r7851  
    3030#include "shared_network_data.h"
    3131#include "message_manager.h"
     32#include "preferences.h"
     33#include "zip.h"
     34
     35#include "src/lib/util/loading/resource_manager.h"
    3236
    3337#include "network_log.h"
     
    8892  myHostId = 0;
    8993  currentState = 0;
     94 
     95  remainingBytesToWriteToDict = Preferences::getInstance()->getInt( "compression", "writedict", 0 );
     96 
     97  assert( Zip::getInstance()->loadDictionary( "testdict" ) );
    9098}
    9199
     
    365373void NetworkStream::handleUpstream( )
    366374{
    367   byte buf[UDP_PACKET_SIZE];
    368375  int offset;
    369376  int n;
     
    430437    assert( Converter::intToByteArray( offset, buf, INTSIZE ) == INTSIZE );
    431438   
    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 );
    433451   
    434452    peer->second.connectionMonitor->processUnzippedOutgoingPacket( buf, offset, currentState );
     453    peer->second.connectionMonitor->processZippedOutgoingPacket( compBuf, compLength, currentState );
    435454   
    436455    NETPRINTF(n)("send packet: %d userId = %d\n", offset, peer->second.userId);
     
    443462void NetworkStream::handleDownstream( )
    444463{
    445   byte buf[UDP_PACKET_SIZE];
    446464  int offset = 0;
    447465 
    448466  int length = 0;
    449467  int packetLength = 0;
     468  int compLength = 0;
    450469  int uniqueId = 0;
    451470  int state = 0;
     
    460479      continue;
    461480
    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     
    464485      if ( packetLength < 4*INTSIZE )
    465486      {
     
    468489        continue;
    469490      }
     491     
     492      if ( this->remainingBytesToWriteToDict > 0 )
     493        writeToNewDict( buf, packetLength );
    470494   
    471495      assert( Converter::byteArrayToInt( buf, &length ) == INTSIZE );
     
    586610      }
    587611     
     612      peer->second.connectionMonitor->processZippedIncomingPacket( compBuf, compLength, currentState, ackedState );
    588613      peer->second.connectionMonitor->processUnzippedIncomingPacket( buf, offset, currentState, ackedState );
    589614   
     
    629654}
    630655
    631 
    632 
    633 
    634 
    635 
     656/**
     657 * writes data to DATA/dicts/newdict
     658 * @param data pointer to data
     659 * @param length length
     660 */
     661void 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  
    1515#include "handshake.h"
    1616#include "connection_monitor.h"
     17#include "udp_server_socket.h"
    1718
    1819class Synchronizeable;
     
    8283    void handleNewClient( int userId );
    8384    void cleanUpOldSyncList();
     85   
     86    void writeToNewDict( byte * data, int length );
    8487
    8588
     
    9497    int                        myHostId;
    9598   
    96     int                        currentState;
     99    int                        currentState;                //!< current state id
    97100
    98101    NetworkGameManager*        networkGameManager;
    99102
    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
    101109};
    102110#endif /* _NETWORK_STREAM */
  • branches/network/src/orxonox.cc

    r7749 r7851  
    8686
    8787REGISTER_ARG_ARG(  t, telnetport,  "network","telnetport",        "Port to use for network debug output",               "port" );
     88REGISTER_ARG_ARG(  _, write_dict,  "compression", "writedict",    "write packets to DATA/dicts/newdict",               "numBytes" );
    8889
    8990/**
Note: See TracChangeset for help on using the changeset viewer.