Line data Source code
1 : /* 2 : Mosh: the mobile shell 3 : Copyright 2012 Keith Winstein 4 : 5 : This program is free software: you can redistribute it and/or modify 6 : it under the terms of the GNU General Public License as published by 7 : the Free Software Foundation, either version 3 of the License, or 8 : (at your option) any later version. 9 : 10 : This program is distributed in the hope that it will be useful, 11 : but WITHOUT ANY WARRANTY; without even the implied warranty of 12 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 : GNU General Public License for more details. 14 : 15 : You should have received a copy of the GNU General Public License 16 : along with this program. If not, see <http://www.gnu.org/licenses/>. 17 : 18 : In addition, as a special exception, the copyright holders give 19 : permission to link the code of portions of this program with the 20 : OpenSSL library under certain conditions as described in each 21 : individual source file, and distribute linked combinations including 22 : the two. 23 : 24 : You must obey the GNU General Public License in all respects for all 25 : of the code used other than OpenSSL. If you modify file(s) with this 26 : exception, you may extend this exception to your version of the 27 : file(s), but you are not obligated to do so. If you do not wish to do 28 : so, delete this exception statement from your version. If you delete 29 : this exception statement from all source files in the program, then 30 : also delete it here. 31 : */ 32 : 33 : #ifndef TRANSPORT_FRAGMENT_HPP 34 : #define TRANSPORT_FRAGMENT_HPP 35 : 36 : #include <stdint.h> 37 : #include <vector> 38 : #include <string> 39 : 40 : #include "transportinstruction.pb.h" 41 : 42 : namespace Network { 43 : using std::vector; 44 : using std::string; 45 : using namespace TransportBuffers; 46 : 47 37151 : class Fragment 48 : { 49 : public: 50 : static const size_t frag_header_len = sizeof( uint64_t ) + sizeof( uint16_t ); 51 : 52 : uint64_t id; 53 : uint16_t fragment_num; 54 : bool final; 55 : 56 : bool initialized; 57 : 58 : string contents; 59 : 60 5285 : Fragment() 61 5285 : : id( -1 ), fragment_num( -1 ), final( false ), initialized( false ), contents() 62 : {} 63 : 64 5333 : Fragment( uint64_t s_id, uint16_t s_fragment_num, bool s_final, const string & s_contents ) 65 5333 : : id( s_id ), fragment_num( s_fragment_num ), final( s_final ), initialized( true ), 66 5333 : contents( s_contents ) 67 5333 : {} 68 : 69 : Fragment( const string &x ); 70 : 71 : string tostring( void ); 72 : 73 : bool operator==( const Fragment &x ) const; 74 : }; 75 : 76 : class FragmentAssembly 77 : { 78 : private: 79 : vector<Fragment> fragments; 80 : uint64_t current_id; 81 : int fragments_arrived, fragments_total; 82 : 83 : public: 84 900 : FragmentAssembly() : fragments(), current_id( -1 ), fragments_arrived( 0 ), fragments_total( -1 ) {} 85 : bool add_fragment( Fragment &inst ); 86 : Instruction get_assembly( void ); 87 : }; 88 : 89 0 : class Fragmenter 90 : { 91 : private: 92 : uint64_t next_instruction_id; 93 : Instruction last_instruction; 94 : size_t last_MTU; 95 : 96 : public: 97 900 : Fragmenter() : next_instruction_id( 0 ), last_instruction(), last_MTU( -1 ) 98 : { 99 900 : last_instruction.set_old_num( -1 ); 100 900 : last_instruction.set_new_num( -1 ); 101 900 : } 102 : vector<Fragment> make_fragments( const Instruction &inst, size_t MTU ); 103 32680 : uint64_t last_ack_sent( void ) const { return last_instruction.ack_num(); } 104 : }; 105 : 106 : } 107 : 108 : #endif