Skip to content

Commit

Permalink
remove trailing whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
a1346054 committed Aug 14, 2021
1 parent 851195d commit 4355a29
Show file tree
Hide file tree
Showing 27 changed files with 78 additions and 81 deletions.
2 changes: 1 addition & 1 deletion src/crypto/base64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void base64_encode( const uint8_t *raw, const size_t raw_len,
raw += 3;
b64 += 4;
}

/* last byte of input, last 4 of output */
uint8_t lastchar = *raw;
b64[0] = table[(lastchar >> 2) & 0x3f];
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Base64Key::Base64Key(PRNG &prng)
string Base64Key::printable_key( void ) const
{
char base64[ 24 ];

base64_encode( key, 16, base64, 24 );

if ( (base64[ 23 ] != '=')
Expand Down
14 changes: 7 additions & 7 deletions src/crypto/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,17 @@ namespace Crypto {
public:
Nonce( uint64_t val );
Nonce( const char *s_bytes, size_t len );

string cc_str( void ) const { return string( bytes + 4, 8 ); }
const char *data( void ) const { return bytes; }
uint64_t val( void ) const;
};

class Message {
public:
const Nonce nonce;
const string text;

Message( const char *nonce_bytes, size_t nonce_len,
const char *text_bytes, size_t text_len )
: nonce( nonce_bytes, nonce_len ),
Expand All @@ -130,7 +130,7 @@ namespace Crypto {
: nonce( s_nonce ),
text( s_text ) {}
};

class Session {
private:
Base64Key key;
Expand All @@ -141,21 +141,21 @@ namespace Crypto {
AlignedBuffer plaintext_buffer;
AlignedBuffer ciphertext_buffer;
AlignedBuffer nonce_buffer;

public:
static const int RECEIVE_MTU = 2048;
/* Overhead (not counting the nonce, which is handled by network transport) */
static const int ADDED_BYTES = 16 /* final OCB block */;

Session( Base64Key s_key );
~Session();

const string encrypt( const Message & plaintext );
const Message decrypt( const char *str, size_t len );
const Message decrypt( const string & ciphertext ) {
return decrypt( ciphertext.data(), ciphertext.size() );
}

Session( const Session & );
Session & operator=( const Session & );
};
Expand Down
8 changes: 4 additions & 4 deletions src/examples/ntester.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ int main( int argc, char *argv[] )
if ( argc > 1 ) {
server = false;
/* client */

key = argv[ 1 ];
ip = argv[ 2 ];
port = argv[ 3 ];

raw_n = new Transport<UserStream, UserStream>( me, remote, key, ip, port );
} else {
raw_n = new Transport<UserStream, UserStream>( me, remote, NULL, NULL );
Expand All @@ -86,7 +86,7 @@ int main( int argc, char *argv[] )
perror( "select" );
exit( 1 );
}

n->tick();

if ( sel.read( network_fd ) ) {
Expand Down Expand Up @@ -167,6 +167,6 @@ int main( int argc, char *argv[] )
if ( tcsetattr( STDIN_FILENO, TCSANOW, &saved_termios ) < 0 ) {
perror( "tcsetattr" );
exit( 1 );
}
}
}
}
8 changes: 4 additions & 4 deletions src/examples/termemu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,13 @@ static void emulate_terminal( int fd )
perror( "read" );
return;
}

std::string terminal_to_host;

for ( int i = 0; i < bytes_read; i++ ) {
terminal_to_host += complete.act( Parser::UserByte( buf[ i ] ) );
}

if ( swrite( fd, terminal_to_host.c_str(), terminal_to_host.length() ) < 0 ) {
break;
}
Expand All @@ -288,7 +288,7 @@ static void emulate_terminal( int fd )
perror( "read" );
return;
}

std::string terminal_to_host = complete.act( std::string( buf, bytes_read ) );
if ( swrite( fd, terminal_to_host.c_str(), terminal_to_host.length() ) < 0 ) {
break;
Expand Down
16 changes: 8 additions & 8 deletions src/frontend/mosh-server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -728,12 +728,12 @@ static void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &
if ( sel.read( network_fd ) ) {
/* packet received from the network */
network.recv();

/* is new user input available for the terminal? */
if ( network.get_remote_state_num() != last_remote_num ) {
last_remote_num = network.get_remote_state_num();


Network::UserStream us;
us.apply_string( network.get_remote_diff() );
/* apply userstream to terminal */
Expand Down Expand Up @@ -828,12 +828,12 @@ static void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &
}
}
}

if ( (!network.shutdown_in_progress()) && sel.read( host_fd ) ) {
/* input from the host needs to be fed to the terminal */
const int buf_size = 16384;
char buf[ buf_size ];

/* fill buffer if possible */
ssize_t bytes_read = read( host_fd, buf, buf_size );

Expand All @@ -843,7 +843,7 @@ static void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &
network.start_shutdown();
} else {
terminal_to_host += terminal.act( string( buf, bytes_read ) );

/* update client with new state of terminal */
network.set_current_state( terminal );
}
Expand All @@ -858,7 +858,7 @@ static void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &
if ( network_timeout_ms &&
network_timeout_ms <= time_since_remote_state ) {
idle_shutdown = true;
fprintf( stderr, "Network idle for %llu seconds.\n",
fprintf( stderr, "Network idle for %llu seconds.\n",
static_cast<unsigned long long>( time_since_remote_state / 1000 ) );
}
if ( sel.signal( SIGUSR1 )
Expand All @@ -876,7 +876,7 @@ static void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &
break;
}
}

/* quit if our shutdown has been acknowledged */
if ( network.shutdown_in_progress() && network.shutdown_acknowledged() ) {
break;
Expand All @@ -894,7 +894,7 @@ static void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &

#ifdef HAVE_UTEMPTER
/* update utmp if has been more than 30 seconds since heard from client */
if ( connected_utmp
if ( connected_utmp
&& time_since_remote_state > 30000 ) {
utempter_remove_record( host_fd );

Expand Down
19 changes: 9 additions & 10 deletions src/frontend/stmclient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ void STMClient::shutdown( void )

/* Restore terminal and terminal-driver state */
swrite( STDOUT_FILENO, display.close().c_str() );

if ( tcsetattr( STDIN_FILENO, TCSANOW, &saved_termios ) < 0 ) {
perror( "tcsetattr" );
exit( 1 );
Expand Down Expand Up @@ -239,7 +239,7 @@ void STMClient::main_init( void )
if ( ioctl( STDIN_FILENO, TIOCGWINSZ, &window_size ) < 0 ) {
perror( "ioctl TIOCGWINSZ" );
return;
}
}

/* local state */
local_framebuffer = Terminal::Framebuffer( window_size.ws_col, window_size.ws_row );
Expand Down Expand Up @@ -290,7 +290,7 @@ void STMClient::output_new_frame( void )
void STMClient::process_network_input( void )
{
network->recv();

/* Now give hints to the overlays */
overlays.get_notification_engine().server_heard( network->get_latest_remote_state().timestamp );
overlays.get_notification_engine().server_acked( network->get_sent_state_acked_timestamp() );
Expand Down Expand Up @@ -366,7 +366,7 @@ bool STMClient::process_user_input( int fd )
} else {
/* Escape key followed by anything other than . and ^ gets sent literally */
net.get_current_state().push_back( Parser::UserByte( escape_key ) );
net.get_current_state().push_back( Parser::UserByte( the_byte ) );
net.get_current_state().push_back( Parser::UserByte( the_byte ) );
}

quit_sequence_started = false;
Expand All @@ -391,7 +391,7 @@ bool STMClient::process_user_input( int fd )
repaint_requested = true;
}

net.get_current_state().push_back( Parser::UserByte( the_byte ) );
net.get_current_state().push_back( Parser::UserByte( the_byte ) );
}

return true;
Expand All @@ -404,16 +404,16 @@ bool STMClient::process_resize( void )
perror( "ioctl TIOCGWINSZ" );
return false;
}

/* tell remote emulator */
Parser::Resize res( window_size.ws_col, window_size.ws_row );

if ( !network->shutdown_in_progress() ) {
network->get_current_state().push_back( res );
}

/* note remote emulator will probably reply with its own Resize to adjust our state */

/* tell prediction engine */
overlays.get_prediction_engine().reset();

Expand Down Expand Up @@ -480,7 +480,7 @@ bool STMClient::main( void )
if ( network_ready_to_read ) {
process_network_input();
}

if ( sel.read( STDIN_FILENO ) && !process_user_input( STDIN_FILENO ) ) { /* input from the user needs to be fed to the network */
if ( !network->has_remote_addr() ) {
break;
Expand Down Expand Up @@ -577,4 +577,3 @@ bool STMClient::main( void )
}
return clean_shutdown;
}

2 changes: 1 addition & 1 deletion src/frontend/stmclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class STMClient {
}
if ( predict_overwrite && !strcmp( predict_overwrite, "yes" ) ) {
overlays.get_prediction_engine().set_predict_overwrite( true );
}
}
}

void init( void );
Expand Down
18 changes: 9 additions & 9 deletions src/frontend/terminaloverlay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ void NotificationEngine::apply( Framebuffer &fb ) const
this_cell->get_renditions().set_attribute(Renditions::bold, true);
this_cell->get_renditions().set_foreground_color( 7 );
this_cell->get_renditions().set_background_color( 4 );

this_cell->append( ch );
this_cell->set_wide( chwidth == 2 );
combining_cell = this_cell;
Expand Down Expand Up @@ -306,7 +306,7 @@ void NotificationEngine::adjust_message( void )
{
if ( timestamp() >= message_expiration ) {
message.clear();
}
}
}

int NotificationEngine::wait_time( void ) const
Expand Down Expand Up @@ -420,7 +420,7 @@ void PredictionEngine::init_cursor( const Framebuffer &fb )
{
if ( cursors.empty() ) {
/* initialize new cursor prediction */

cursors.push_back( ConditionalCursorMove( local_frame_sent + 1,
fb.ds.get_cursor_row(),
fb.ds.get_cursor_col(),
Expand Down Expand Up @@ -552,7 +552,7 @@ void PredictionEngine::cull( const Framebuffer &fb )
}

/* When predictions come in quickly, slowly take away the glitch trigger. */
if ( now - j->prediction_time < GLITCH_THRESHOLD
if ( now - j->prediction_time < GLITCH_THRESHOLD
&& ( glitch_trigger > 0 && now - GLITCH_REPAIR_MININTERVAL >= last_quick_confirmation ) ) {
glitch_trigger--;
last_quick_confirmation = now;
Expand Down Expand Up @@ -593,7 +593,7 @@ void PredictionEngine::cull( const Framebuffer &fb )
}

/* go through cursor predictions */
if ( !cursors.empty()
if ( !cursors.empty()
&& cursor().get_validity( fb,
local_frame_acked, local_frame_late_acked ) == IncorrectOrExpired ) {
/*
Expand Down Expand Up @@ -721,7 +721,7 @@ void PredictionEngine::new_user_byte( char the_byte, const Framebuffer &fb )
cell.tentative_until_epoch = prediction_epoch;
cell.expire( local_frame_sent + 1, now );
cell.original_contents.push_back( *fb.get_cell( cursor().row, i ) );

if ( i + 2 < fb.ds.get_width() ) {
ConditionalOverlayCell &next_cell = the_row.overlay_cells[ i + 1 ];
const Cell *next_cell_actual = fb.get_cell( cursor().row, i + 1 );
Expand Down Expand Up @@ -788,7 +788,7 @@ void PredictionEngine::new_user_byte( char the_byte, const Framebuffer &fb )
cell.replacement = *prev_cell_actual;
}
}

ConditionalOverlayCell &cell = the_row.overlay_cells[ cursor().col ];
cell.reset_with_orig();
cell.active = true;
Expand Down Expand Up @@ -834,7 +834,7 @@ void PredictionEngine::new_user_byte( char the_byte, const Framebuffer &fb )
newline_carriage_return( fb );
} else {
// fprintf( stderr, "Execute 0x%x\n", act.ch );
become_tentative();
become_tentative();
}
} else if ( type_act == typeid( Parser::Esc_Dispatch ) ) {
// fprintf( stderr, "Escape sequence\n" );
Expand All @@ -848,7 +848,7 @@ void PredictionEngine::new_user_byte( char the_byte, const Framebuffer &fb )
}
} else if ( act.char_present && (act.ch == L'D') ) { /* left arrow */
init_cursor( fb );

if ( cursor().col > 0 ) {
cursor().col--;
cursor().expire( local_frame_sent + 1, now );
Expand Down
1 change: 0 additions & 1 deletion src/include/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ version.h: ../../VERSION
mv -f $@.new $@; \
fi
@rm -f $@.new

5 changes: 2 additions & 3 deletions src/network/network.cc
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ string Connection::recv_one( int sock_to_recv )
} else {
const double alpha = 1.0 / 8.0;
const double beta = 1.0 / 4.0;

RTTVAR = (1 - beta) * RTTVAR + ( beta * fabs( SRTT - R ) );
SRTT = (1 - alpha) * SRTT + ( alpha * R );
}
Expand Down Expand Up @@ -613,7 +613,7 @@ uint16_t Network::timestamp_diff( uint16_t tsnew, uint16_t tsold )
if ( diff < 0 ) {
diff += 65536;
}

assert( diff >= 0 );
assert( diff <= 65535 );

Expand Down Expand Up @@ -701,6 +701,5 @@ bool Connection::parse_portrange( const char * desired_port, int & desired_port_
return false;
}


return true;
}
Loading

0 comments on commit 4355a29

Please sign in to comment.