LCOV - code coverage report
Current view: top level - src/network - networktransport.h (source / functions) Hit Total Coverage
Test: mosh-1.3.2 Code Coverage Lines: 22 22 100.0 %
Date: 2022-02-06 20:19:53 Functions: 0 0 -
Legend: Lines: hit not hit

          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 NETWORK_TRANSPORT_HPP
      34             : #define NETWORK_TRANSPORT_HPP
      35             : 
      36             : #include <string>
      37             : #include <signal.h>
      38             : #include <time.h>
      39             : #include <list>
      40             : #include <vector>
      41             : 
      42             : #include "network.h"
      43             : #include "transportsender.h"
      44             : #include "transportfragment.h"
      45             : 
      46             : 
      47             : namespace Network {
      48             :   template <class MyState, class RemoteState>
      49             :   class Transport
      50             :   {
      51             :   private:
      52             :     /* the underlying, encrypted network connection */
      53             :     Connection connection;
      54             : 
      55             :     /* sender side */
      56             :     TransportSender<MyState> sender;
      57             : 
      58             :     /* helper methods for recv() */
      59             :     void process_throwaway_until( uint64_t throwaway_num );
      60             : 
      61             :     /* simple receiver */
      62             :     list< TimestampedState<RemoteState> > received_states;
      63             :     uint64_t receiver_quench_timer;
      64             :     RemoteState last_receiver_state; /* the state we were in when user last queried state */
      65             :     FragmentAssembly fragments;
      66             :     unsigned int verbose;
      67             : 
      68             :   public:
      69             :     Transport( MyState &initial_state, RemoteState &initial_remote,
      70             :                const char *desired_ip, const char *desired_port );
      71             :     Transport( MyState &initial_state, RemoteState &initial_remote,
      72             :                const char *key_str, const char *ip, const char *port );
      73             : 
      74             :     /* Send data or an ack if necessary. */
      75       32232 :     void tick( void ) { sender.tick(); }
      76             : 
      77             :     /* Returns the number of ms to wait until next possible event. */
      78       33132 :     int wait_time( void ) { return sender.wait_time(); }
      79             : 
      80             :     /* Blocks waiting for a packet. */
      81             :     void recv( void );
      82             : 
      83             :     /* Find diff between last receiver state and current remote state, then rationalize states. */
      84             :     string get_remote_diff( void );
      85             : 
      86             :     /* Shut down other side of connection. */
      87             :     /* Illegal to change current_state after this. */
      88         452 :     void start_shutdown( void ) { sender.start_shutdown(); }
      89      118710 :     bool shutdown_in_progress( void ) const { return sender.get_shutdown_in_progress(); }
      90        1473 :     bool shutdown_acknowledged( void ) const { return sender.get_shutdown_acknowledged(); }
      91        1025 :     bool shutdown_ack_timed_out( void ) const { return sender.shutdown_ack_timed_out(); }
      92           6 :     bool has_remote_addr( void ) const { return connection.get_has_remote_addr(); }
      93             : 
      94             :     /* Other side has requested shutdown and we have sent one ACK */
      95       32680 :     bool counterparty_shutdown_ack_sent( void ) const { return sender.get_counterparty_shutdown_acknowledged(); }
      96             : 
      97         452 :     std::string port( void ) const { return connection.port(); }
      98         904 :     string get_key( void ) const { return connection.get_key(); }
      99             : 
     100        1675 :     MyState &get_current_state( void ) { return sender.get_current_state(); }
     101       23153 :     void set_current_state( const MyState &x ) { sender.set_current_state( x ); }
     102             : 
     103       68702 :     uint64_t get_remote_state_num( void ) const { return received_states.back().num; }
     104             : 
     105       37417 :     const TimestampedState<RemoteState> & get_latest_remote_state( void ) const { return received_states.back(); }
     106             : 
     107       33132 :     const std::vector< int > fds( void ) const { return connection.fds(); }
     108             : 
     109         900 :     void set_verbose( unsigned int s_verbose ) { sender.set_verbose( s_verbose ); verbose = s_verbose; }
     110             : 
     111         448 :     void set_send_delay( int new_delay ) { sender.set_send_delay( new_delay ); }
     112             : 
     113        3333 :     uint64_t get_sent_state_acked_timestamp( void ) const { return sender.get_sent_state_acked_timestamp(); }
     114        3333 :     uint64_t get_sent_state_acked( void ) const { return sender.get_sent_state_acked(); }
     115         659 :     uint64_t get_sent_state_last( void ) const { return sender.get_sent_state_last(); }
     116             : 
     117        3333 :     unsigned int send_interval( void ) const { return sender.send_interval(); }
     118             : 
     119             :     const Addr &get_remote_addr( void ) const { return connection.get_remote_addr(); }
     120             :     socklen_t get_remote_addr_len( void ) const { return connection.get_remote_addr_len(); }
     121             : 
     122        5640 :     std::string &get_send_error( void ) { return connection.get_send_error(); }
     123             :   };
     124             : }
     125             : 
     126             : #endif

Generated by: LCOV version 1.14