From 267f5a31a7ea0815f607069a339f4590308f1954 Mon Sep 17 00:00:00 2001 From: Keith Winstein Date: Sun, 1 Jan 2012 21:42:05 -0500 Subject: [PATCH] Get rid of path MTU discovery --- crypto.cpp | 2 +- crypto.hpp | 2 +- network.cpp | 49 +++------------------------------------------ network.hpp | 25 ++++++++--------------- transportsender.cpp | 31 ++++++---------------------- 5 files changed, 19 insertions(+), 90 deletions(-) diff --git a/crypto.cpp b/crypto.cpp index 724d199..1681f21 100644 --- a/crypto.cpp +++ b/crypto.cpp @@ -74,7 +74,7 @@ Base64Key::Base64Key() } } -string Base64Key::printable_key( void ) +string Base64Key::printable_key( void ) const { char base64[ 25 ]; diff --git a/crypto.hpp b/crypto.hpp index 5f2be4a..18067df 100644 --- a/crypto.hpp +++ b/crypto.hpp @@ -23,7 +23,7 @@ namespace Crypto { public: Base64Key(); /* random key */ Base64Key( string printable_key ); - string printable_key( void ); + string printable_key( void ) const; unsigned char *data( void ) { return key; } }; diff --git a/network.cpp b/network.cpp index 109b09f..8ffb896 100644 --- a/network.cpp +++ b/network.cpp @@ -75,13 +75,6 @@ void Connection::setup( void ) if ( sock < 0 ) { throw NetworkException( "socket", errno ); } - - /* Enable path MTU discovery */ - char flag = IP_PMTUDISC_DO; - socklen_t optlen = sizeof( flag ); - if ( setsockopt( sock, IPPROTO_IP, IP_MTU_DISCOVER, &flag, optlen ) < 0 ) { - throw NetworkException( "setsockopt", errno ); - } } Connection::Connection() /* server */ @@ -89,7 +82,6 @@ Connection::Connection() /* server */ remote_addr(), server( true ), attached( false ), - MTU( RECEIVE_MTU ), key(), session( key ), direction( TO_CLIENT ), @@ -119,7 +111,6 @@ Connection::Connection( const char *key_str, const char *ip, int port ) /* clien remote_addr(), server( false ), attached( false ), - MTU( RECEIVE_MTU ), key( key_str ), session( key ), direction( TO_SERVER ), @@ -152,37 +143,6 @@ Connection::Connection( const char *key_str, const char *ip, int port ) /* clien attached = true; } -void Connection::update_MTU( void ) -{ - if ( !attached ) { - return; - } - - /* We don't want to use our main socket because we don't want to have to connect it */ - int path_MTU_socket = socket( AF_INET, SOCK_DGRAM, 0 ); - if ( path_MTU_socket < 0 ) { - throw NetworkException( "socket", errno ); - } - - /* Connect socket so we can retrieve path MTU */ - if ( connect( path_MTU_socket, (sockaddr *)&remote_addr, sizeof( remote_addr ) ) < 0 ) { - throw NetworkException( "connect", errno ); - } - - socklen_t optlen = sizeof( MTU ); - if ( getsockopt( path_MTU_socket, IPPROTO_IP, IP_MTU, &MTU, &optlen ) < 0 ) { - throw NetworkException( "getsockopt", errno ); - } - - if ( optlen != sizeof( MTU ) ) { - throw NetworkException( "Error getting path MTU", errno ); - } - - if ( close( path_MTU_socket ) < 0 ) { - throw NetworkException( "close", errno ); - } -} - void Connection::send( string s ) { assert( attached ); @@ -194,10 +154,7 @@ void Connection::send( string s ) ssize_t bytes_sent = sendto( sock, p.data(), p.size(), 0, (sockaddr *)&remote_addr, sizeof( remote_addr ) ); - if ( (bytes_sent < 0) && (errno == EMSGSIZE) ) { - update_MTU(); - throw MTUException( MTU ); - } else if ( bytes_sent == static_cast( p.size() ) ) { + if ( bytes_sent == static_cast( p.size() ) ) { return; } else { throw NetworkException( "sendto", errno ); @@ -274,7 +231,7 @@ string Connection::recv( void ) return p.payload; /* we do return out-of-order or duplicated packets to caller */ } -int Connection::port( void ) +int Connection::port( void ) const { struct sockaddr_in local_addr; socklen_t addrlen = sizeof( local_addr ); @@ -322,7 +279,7 @@ uint16_t Network::timestamp_diff( uint16_t tsnew, uint16_t tsold ) return diff; } -uint64_t Connection::timeout( void ) +uint64_t Connection::timeout( void ) const { uint64_t RTO = lrint( ceil( SRTT + 4 * RTTVAR ) ); if ( RTO < MIN_RTO ) { diff --git a/network.hpp b/network.hpp index 2ac567d..f6ec1b2 100644 --- a/network.hpp +++ b/network.hpp @@ -18,12 +18,6 @@ namespace Network { uint16_t timestamp16( void ); uint16_t timestamp_diff( uint16_t tsnew, uint16_t tsold ); - class MTUException { - public: - int MTU; - MTUException( int s_MTU ) : MTU( s_MTU ) {}; - }; - class NetworkException { public: string function; @@ -57,6 +51,7 @@ namespace Network { class Connection { private: static const int RECEIVE_MTU = 2048; + static const int SEND_MTU = 1400; static const uint64_t MIN_RTO = 50; /* ms */ static const uint64_t MAX_RTO = 1000; /* ms */ @@ -66,8 +61,6 @@ namespace Network { bool server; bool attached; - int MTU; - Base64Key key; Session session; @@ -91,17 +84,15 @@ namespace Network { void send( string s ); string recv( void ); - int fd( void ) { return sock; } - void update_MTU( void ); - int get_MTU( void ) { return MTU; } + int fd( void ) const { return sock; } + int get_MTU( void ) const { return SEND_MTU; } - int port( void ); - string get_key( void ) { return key.printable_key(); } - bool get_attached( void ) { return attached; } + int port( void ) const; + string get_key( void ) const { return key.printable_key(); } + bool get_attached( void ) const { return attached; } - uint64_t timeout( void ); - double get_SRTT( void ) { return SRTT; } - // bool pending_timestamp( void ) { return ( saved_timestamp != uint16_t(-1) ); } + uint64_t timeout( void ) const; + double get_SRTT( void ) const { return SRTT; } }; } diff --git a/transportsender.cpp b/transportsender.cpp index 8eb53c7..8dd0882 100644 --- a/transportsender.cpp +++ b/transportsender.cpp @@ -159,32 +159,14 @@ void TransportSender::send_to_receiver( string diff ) new_num = uint64_t( -1 ); } - int MTU_tries = 0; - while ( 1 ) { - MTU_tries++; - - if ( MTU_tries > 20 ) { - fprintf( stderr, "Error, could not send fragments after 20 tries (MTU = %d).\n", - connection->get_MTU() ); - return; - } - - if ( new_num == sent_states.back().num ) { - sent_states.back().timestamp = timestamp(); - } else { - // sent_states.push_back( TimestampedState( timestamp(), new_num, current_state ) ); - add_sent_state( timestamp(), new_num, current_state ); - } - - try { - send_in_fragments( diff, new_num ); // Can throw NetworkException - break; - } catch ( MTUException m ) { - fprintf( stderr, "Caught Path MTU exception, MTU now = %d\n", connection->get_MTU() ); - new_num++; - } + if ( new_num == sent_states.back().num ) { + sent_states.back().timestamp = timestamp(); + } else { + add_sent_state( timestamp(), new_num, current_state ); } + send_in_fragments( diff, new_num ); // Can throw NetworkException + /* successfully sent, probably */ /* ("probably" because the FIRST size-exceeded datagram doesn't get an error) */ assumed_receiver_state = sent_states.end(); @@ -246,7 +228,6 @@ void TransportSender::send_in_fragments( string diff, uint64_t new_num shutdown_tries++; } - connection->update_MTU(); vector fragments = fragmenter.make_fragments( inst, connection->get_MTU() ); for ( auto i = fragments.begin(); i != fragments.end(); i++ ) {