Remove using-declarations for std:: types

This commit is contained in:
Alex Chernyakhovsky
2023-07-30 17:46:02 -04:00
committed by Alex Chernyakhovsky
parent 8469db91db
commit 19ad493dcb
21 changed files with 173 additions and 189 deletions
+8 -8
View File
@@ -107,13 +107,13 @@ AlignedBuffer::AlignedBuffer( size_t len, const char *data )
}
}
Base64Key::Base64Key( string printable_key )
Base64Key::Base64Key( std::string printable_key )
{
if ( printable_key.length() != 22 ) {
throw CryptoException( "Key must be 22 letters long." );
}
string base64 = printable_key + "==";
std::string base64 = printable_key + "==";
size_t len = 16;
if ( !base64_decode( base64.data(), 24, key, &len ) ) {
@@ -140,7 +140,7 @@ Base64Key::Base64Key(PRNG &prng)
prng.fill( key, sizeof( key ) );
}
string Base64Key::printable_key( void ) const
std::string Base64Key::printable_key( void ) const
{
char base64[ 24 ];
@@ -148,11 +148,11 @@ string Base64Key::printable_key( void ) const
if ( (base64[ 23 ] != '=')
|| (base64[ 22 ] != '=') ) {
throw CryptoException( string( "Unexpected output from base64_encode: " ) + string( base64, 24 ) );
throw CryptoException( std::string( "Unexpected output from base64_encode: " ) + std::string( base64, 24 ) );
}
base64[ 22 ] = 0;
return string( base64 );
return std::string( base64 );
}
Session::Session( Base64Key s_key )
@@ -197,7 +197,7 @@ Nonce::Nonce( const char *s_bytes, size_t len )
memcpy( bytes + 4, s_bytes, 8 );
}
const string Session::encrypt( const Message & plaintext )
const std::string Session::encrypt( const Message & plaintext )
{
const size_t pt_len = plaintext.text.size();
const int ciphertext_len = pt_len + 16;
@@ -242,7 +242,7 @@ const string Session::encrypt( const Message & plaintext )
throw CryptoException( "Encrypted 2^47 blocks.", true );
}
string text( ciphertext_buffer.data(), ciphertext_len );
std::string text( ciphertext_buffer.data(), ciphertext_len );
return plaintext.nonce.cc_str() + text;
}
@@ -280,7 +280,7 @@ const Message Session::decrypt( const char *str, size_t len )
throw CryptoException( "Packet failed integrity check." );
}
const Message ret( nonce, string( plaintext_buffer.data(), pt_len ) );
const Message ret( nonce, std::string( plaintext_buffer.data(), pt_len ) );
return ret;
}
+9 -11
View File
@@ -46,13 +46,11 @@ long int myatoi( const char *str );
class PRNG;
namespace Crypto {
using std::string;
class CryptoException : public std::exception {
public:
string text;
std::string text;
bool fatal;
CryptoException( string s_text, bool s_fatal = false )
CryptoException( std::string s_text, bool s_fatal = false )
: text( s_text ), fatal( s_fatal ) {};
const char *what() const throw () { return text.c_str(); }
~CryptoException() throw () {}
@@ -95,8 +93,8 @@ namespace Crypto {
public:
Base64Key(); /* random key */
Base64Key(PRNG &prng);
Base64Key( string printable_key );
string printable_key( void ) const;
Base64Key( std::string printable_key );
std::string printable_key( void ) const;
unsigned char *data( void ) { return key; }
};
@@ -111,7 +109,7 @@ namespace Crypto {
Nonce( uint64_t val );
Nonce( const char *s_bytes, size_t len );
string cc_str( void ) const { return string( bytes + 4, 8 ); }
std::string cc_str( void ) const { return std::string( bytes + 4, 8 ); }
const char *data( void ) const { return bytes; }
uint64_t val( void ) const;
};
@@ -119,14 +117,14 @@ namespace Crypto {
class Message {
public:
const Nonce nonce;
const string text;
const std::string text;
Message( const char *nonce_bytes, size_t nonce_len,
const char *text_bytes, size_t text_len )
: nonce( nonce_bytes, nonce_len ),
text( text_bytes, text_len ) {}
Message( const Nonce & s_nonce, const string & s_text )
Message( const Nonce & s_nonce, const std::string & s_text )
: nonce( s_nonce ),
text( s_text ) {}
};
@@ -150,9 +148,9 @@ namespace Crypto {
Session( Base64Key s_key );
~Session();
const string encrypt( const Message & plaintext );
const std::string encrypt( const Message & plaintext );
const Message decrypt( const char *str, size_t len );
const Message decrypt( const string & ciphertext ) {
const Message decrypt( const std::string & ciphertext ) {
return decrypt( ciphertext.data(), ciphertext.size() );
}
+3 -3
View File
@@ -106,9 +106,9 @@ int main( int argc, char **argv )
overlays.apply( *new_state );
/* calculate minimal difference from where we are */
const string diff( display.new_frame( false,
*local_framebuffer,
*new_state ) );
const std::string diff( display.new_frame( false,
*local_framebuffer,
*new_state ) );
/* make sure to use diff */
if ( diff.size() > INT_MAX ) {
+1 -1
View File
@@ -56,7 +56,7 @@ int main( int argc, char *argv[] )
/* Encrypt message */
string ciphertext = session.encrypt( Message( nonce, input.str() ) );
std::string ciphertext = session.encrypt( Message( nonce, input.str() ) );
std::cerr << "Key: " << key.printable_key() << std::endl;
+1 -1
View File
@@ -179,7 +179,7 @@ int main( int argc, char *argv[] )
char *predict_overwrite = getenv( "MOSH_PREDICTION_OVERWRITE" );
/* can be NULL */
string key( env_key );
std::string key( env_key );
if ( unsetenv( "MOSH_KEY" ) < 0 ) {
perror( "unsetenv" );
+27 -27
View File
@@ -104,7 +104,7 @@ static void serve( int host_fd,
long network_signaled_timeout );
static int run_server( const char *desired_ip, const char *desired_port,
const string &command_path, char *command_argv[],
const std::string &command_path, char *command_argv[],
const int colors, unsigned int verbose, bool with_motd );
@@ -125,7 +125,7 @@ static void print_usage( FILE *stream, const char *argv0 )
static bool print_motd( const char *filename );
static void chdir_homedir( void );
static bool motd_hushed( void );
static void warn_unattached( const string & ignore_entry );
static void warn_unattached( const std::string & ignore_entry );
/* Simple spinloop */
static void spin( void )
@@ -142,19 +142,19 @@ static void spin( void )
}
}
static string get_SSH_IP( void )
static std::string get_SSH_IP( void )
{
const char *SSH_CONNECTION = getenv( "SSH_CONNECTION" );
if ( !SSH_CONNECTION ) { /* Older sshds don't set this */
fputs( "Warning: SSH_CONNECTION not found; binding to any interface.\n", stderr );
return string( "" );
return std::string( "" );
}
std::istringstream ss( SSH_CONNECTION );
string dummy, local_interface_IP;
std::string dummy, local_interface_IP;
ss >> dummy >> dummy >> local_interface_IP;
if ( !ss ) {
fputs( "Warning: Could not parse SSH_CONNECTION; binding to any interface.\n", stderr );
return string( "" );
return std::string( "" );
}
/* Strip IPv6 prefix. */
@@ -177,14 +177,14 @@ int main( int argc, char *argv[] )
fatal_assert( argc > 0 );
const char *desired_ip = NULL;
string desired_ip_str;
std::string desired_ip_str;
const char *desired_port = NULL;
string command_path;
std::string command_path;
char **command_argv = NULL;
int colors = 0;
unsigned int verbose = 0; /* don't close stdin/stdout/stderr */
/* Will cause mosh-server not to correctly detach on old versions of sshd. */
list<string> locale_vars;
std::list<std::string> locale_vars;
/* strip off command */
for ( int i = 1; i < argc; i++ ) {
@@ -249,7 +249,7 @@ int main( int argc, char *argv[] )
verbose++;
break;
case 'l':
locale_vars.push_back( string( optarg ) );
locale_vars.push_back( std::string( optarg ) );
break;
default:
/* don't die on unknown options */
@@ -286,7 +286,7 @@ int main( int argc, char *argv[] )
/* Get shell */
char *my_argv[ 2 ];
string shell_name;
std::string shell_name;
if ( !command_argv ) {
/* get shell name */
const char *shell = getenv( "SHELL" );
@@ -299,7 +299,7 @@ int main( int argc, char *argv[] )
shell = pw->pw_shell;
}
string shell_path( shell );
std::string shell_path( shell );
if ( shell_path.empty() ) { /* empty shell means Bourne shell */
shell_path = _PATH_BSHELL;
}
@@ -307,7 +307,7 @@ int main( int argc, char *argv[] )
command_path = shell_path;
size_t shell_slash( shell_path.rfind('/') );
if ( shell_slash == string::npos ) {
if ( shell_slash == std::string::npos ) {
shell_name = shell_path;
} else {
shell_name = shell_path.substr(shell_slash + 1);
@@ -332,11 +332,11 @@ int main( int argc, char *argv[] )
if ( !is_utf8_locale() ) {
/* save details for diagnostic */
LocaleVar native_ctype = get_ctype();
string native_charset( locale_charset() );
std::string native_charset( locale_charset() );
/* apply locale-related environment variables from client */
clear_locale_variables();
for ( list<string>::const_iterator i = locale_vars.begin();
for ( std::list<std::string>::const_iterator i = locale_vars.begin();
i != locale_vars.end();
i++ ) {
char *env_string = strdup( i->c_str() );
@@ -350,7 +350,7 @@ int main( int argc, char *argv[] )
set_native_locale();
if ( !is_utf8_locale() ) {
LocaleVar client_ctype = get_ctype();
string client_charset( locale_charset() );
std::string client_charset( locale_charset() );
fprintf( stderr, "mosh-server needs a UTF-8 native locale to run.\n\n"
"Unfortunately, the local environment (%s) specifies\n"
@@ -377,7 +377,7 @@ int main( int argc, char *argv[] )
}
static int run_server( const char *desired_ip, const char *desired_port,
const string &command_path, char *command_argv[],
const std::string &command_path, char *command_argv[],
const int colors, unsigned int verbose, bool with_motd ) {
/* get network idle timeout */
long network_timeout = 0;
@@ -723,7 +723,7 @@ static void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &
now = Network::timestamp();
uint64_t time_since_remote_state = now - network.get_latest_remote_state().timestamp;
string terminal_to_host;
std::string terminal_to_host;
if ( sel.read( network_fd ) ) {
/* packet received from the network */
@@ -842,7 +842,7 @@ static void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &
if ( bytes_read <= 0 ) {
network.start_shutdown();
} else {
terminal_to_host += terminal.act( string( buf, bytes_read ) );
terminal_to_host += terminal.act( std::string( buf, bytes_read ) );
/* update client with new state of terminal */
network.set_current_state( terminal );
@@ -992,13 +992,13 @@ static bool motd_hushed( void )
#ifdef HAVE_UTMPX_H
static bool device_exists( const char *ut_line )
{
string device_name = string( "/dev/" ) + string( ut_line );
std::string device_name = std::string( "/dev/" ) + std::string( ut_line );
struct stat buf;
return 0 == lstat( device_name.c_str(), &buf );
}
#endif
static void warn_unattached( const string & ignore_entry )
static void warn_unattached( const std::string & ignore_entry )
{
#ifdef HAVE_UTMPX_H
/* get username */
@@ -1009,16 +1009,16 @@ static void warn_unattached( const string & ignore_entry )
return;
}
const string username( pw->pw_name );
const std::string username( pw->pw_name );
/* look for unattached sessions */
vector< string > unattached_mosh_servers;
std::vector< std::string > unattached_mosh_servers;
while ( struct utmpx *entry = getutxent() ) {
if ( (entry->ut_type == USER_PROCESS)
&& (username == string( entry->ut_user )) ) {
&& (username == std::string( entry->ut_user )) ) {
/* does line show unattached mosh session */
string text( entry->ut_host );
std::string text( entry->ut_host );
if ( (text.size() >= 5)
&& (text.substr( 0, 5 ) == "mosh ")
&& (text[ text.size() - 1 ] == ']')
@@ -1036,9 +1036,9 @@ static void warn_unattached( const string & ignore_entry )
printf( "\033[37;44mMosh: You have a detached Mosh session on this server (%s).\033[m\n\n",
unattached_mosh_servers.front().c_str() );
} else {
string pid_string;
std::string pid_string;
for ( vector< string >::const_iterator it = unattached_mosh_servers.begin();
for ( std::vector< std::string >::const_iterator it = unattached_mosh_servers.begin();
it != unattached_mosh_servers.end();
it++ ) {
pid_string += " - " + *it + "\n";
+18 -20
View File
@@ -63,8 +63,6 @@
#include "src/network/networktransport-impl.h"
using std::wstring;
void STMClient::resume( void )
{
/* Restore termios state */
@@ -84,7 +82,7 @@ void STMClient::init( void )
{
if ( !is_utf8_locale() ) {
LocaleVar native_ctype = get_ctype();
string native_charset( locale_charset() );
std::string native_charset( locale_charset() );
fprintf( stderr, "mosh-client needs a UTF-8 native locale to run.\n\n"
"Unfortunately, the client's environment (%s) specifies\n"
@@ -123,7 +121,7 @@ void STMClient::init( void )
/* Add our name to window title */
if ( !getenv( "MOSH_TITLE_NOPREFIX" ) ) {
overlays.set_title_prefix( wstring( L"[mosh] " ) );
overlays.set_title_prefix( std::wstring( L"[mosh] " ) );
}
/* Set terminal escape key. */
@@ -185,25 +183,25 @@ void STMClient::init( void )
snprintf(escape_key_name_buf, sizeof escape_key_name_buf, "\"%c\"", escape_key);
escape_requires_lf = true;
}
string tmp;
tmp = string( escape_pass_name_buf );
wstring escape_pass_name = std::wstring(tmp.begin(), tmp.end());
tmp = string( escape_key_name_buf );
wstring escape_key_name = std::wstring(tmp.begin(), tmp.end());
std::string tmp;
tmp = std::string( escape_pass_name_buf );
std::wstring escape_pass_name = std::wstring(tmp.begin(), tmp.end());
tmp = std::string( escape_key_name_buf );
std::wstring escape_key_name = std::wstring(tmp.begin(), tmp.end());
escape_key_help = L"Commands: Ctrl-Z suspends, \".\" quits, " + escape_pass_name + L" gives literal " + escape_key_name;
overlays.get_notification_engine().set_escape_key_string( tmp );
}
wchar_t tmp[ 128 ];
swprintf( tmp, 128, L"Nothing received from server on UDP port %s.", port.c_str() );
connecting_notification = wstring( tmp );
connecting_notification = std::wstring( tmp );
}
void STMClient::shutdown( void )
{
/* Restore screen state */
overlays.get_notification_engine().set_notification_string( wstring( L"" ) );
overlays.get_notification_engine().set_notification_string( std::wstring( L"" ) );
overlays.get_notification_engine().server_heard( timestamp() );
overlays.set_title_prefix( wstring( L"" ) );
overlays.set_title_prefix( std::wstring( L"" ) );
output_new_frame();
/* Restore terminal and terminal-driver state */
@@ -246,7 +244,7 @@ void STMClient::main_init( void )
new_state = Terminal::Framebuffer( 1, 1 );
/* initialize screen */
string init = display.new_frame( false, local_framebuffer, local_framebuffer );
std::string init = display.new_frame( false, local_framebuffer, local_framebuffer );
swrite( STDOUT_FILENO, init.data(), init.size() );
/* open network */
@@ -277,7 +275,7 @@ void STMClient::output_new_frame( void )
overlays.apply( new_state );
/* calculate minimal difference from where we are */
const string diff( display.new_frame( !repaint_requested,
const std::string diff( display.new_frame( !repaint_requested,
local_framebuffer,
new_state ) );
swrite( STDOUT_FILENO, diff.data(), diff.size() );
@@ -337,7 +335,7 @@ bool STMClient::process_user_input( int fd )
if ( quit_sequence_started ) {
if ( the_byte == '.' ) { /* Quit sequence is Ctrl-^ . */
if ( net.has_remote_addr() && (!net.shutdown_in_progress()) ) {
overlays.get_notification_engine().set_notification_string( wstring( L"Exiting on user request..." ), true );
overlays.get_notification_engine().set_notification_string( std::wstring( L"Exiting on user request..." ), true );
net.start_shutdown();
return true;
}
@@ -485,7 +483,7 @@ bool STMClient::main( void )
if ( !network->has_remote_addr() ) {
break;
} else if ( !network->shutdown_in_progress() ) {
overlays.get_notification_engine().set_notification_string( wstring( L"Exiting..." ), true );
overlays.get_notification_engine().set_notification_string( std::wstring( L"Exiting..." ), true );
network->start_shutdown();
}
}
@@ -506,7 +504,7 @@ bool STMClient::main( void )
if ( !network->has_remote_addr() ) {
break;
} else if ( !network->shutdown_in_progress() ) {
overlays.get_notification_engine().set_notification_string( wstring( L"Signal received, shutting down..." ), true );
overlays.get_notification_engine().set_notification_string( std::wstring( L"Signal received, shutting down..." ), true );
network->start_shutdown();
}
}
@@ -534,7 +532,7 @@ bool STMClient::main( void )
&& (timestamp() - network->get_latest_remote_state().timestamp > 250) ) {
if ( timestamp() - network->get_latest_remote_state().timestamp > 15000 ) {
if ( !network->shutdown_in_progress() ) {
overlays.get_notification_engine().set_notification_string( wstring( L"Timed out waiting for server..." ), true );
overlays.get_notification_engine().set_notification_string( std::wstring( L"Timed out waiting for server..." ), true );
network->start_shutdown();
}
} else {
@@ -548,7 +546,7 @@ bool STMClient::main( void )
network->tick();
string & send_error = network->get_send_error();
std::string & send_error = network->get_send_error();
if ( !send_error.empty() ) {
overlays.get_notification_engine().set_network_error( send_error );
send_error.clear();
@@ -571,7 +569,7 @@ bool STMClient::main( void )
} else {
wchar_t tmp[ 128 ];
swprintf( tmp, 128, L"Crypto exception: %s", e.what() );
overlays.get_notification_engine().set_notification_string( wstring( tmp ) );
overlays.get_notification_engine().set_notification_string( std::wstring( tmp ) );
}
}
}
+5 -5
View File
@@ -100,7 +100,7 @@ Validity ConditionalOverlayCell::get_validity( const Framebuffer &fb, int row,
}
if ( current.contents_match( replacement ) ) {
vector<Cell>::const_iterator it = original_contents.begin();
std::vector<Cell>::const_iterator it = original_contents.begin();
for ( ; it != original_contents.end(); it++ ) {
if ( it->contents_match( replacement ) )
break;
@@ -248,14 +248,14 @@ void NotificationEngine::apply( Framebuffer &fb ) const
explanation, keystroke_str );
}
wstring string_to_draw( tmp );
std::wstring string_to_draw( tmp );
int overlay_col = 0;
Cell *combining_cell = fb.get_mutable_cell( 0, 0 );
/* We unfortunately duplicate the terminal's logic for how to render a Unicode sequence into graphemes */
for ( wstring::const_iterator i = string_to_draw.begin(); i != string_to_draw.end(); i++ ) {
for ( std::wstring::const_iterator i = string_to_draw.begin(); i != string_to_draw.end(); i++ ) {
if ( overlay_col >= fb.ds.get_width() ) {
break;
}
@@ -339,7 +339,7 @@ void OverlayManager::apply( Framebuffer &fb )
title.apply( fb );
}
void TitleEngine::set_prefix( const wstring &s )
void TitleEngine::set_prefix( const std::wstring &s )
{
prefix = Terminal::Framebuffer::title_type( s.begin(), s.end() );
}
@@ -615,7 +615,7 @@ void PredictionEngine::cull( const Framebuffer &fb )
/* NB: switching from list to another STL container could break this code.
So we don't use the cursors_type typedef. */
for ( list<ConditionalCursorMove>::iterator it = cursors.begin();
for ( std::list<ConditionalCursorMove>::iterator it = cursors.begin();
it != cursors.end(); ) {
if ( it->get_validity( fb, local_frame_acked, local_frame_late_acked ) != Pending ) {
it = cursors.erase( it );
+7 -9
View File
@@ -44,8 +44,6 @@
namespace Overlay {
using namespace Terminal;
using namespace Network;
using std::deque;
using std::wstring;
enum Validity {
Pending,
@@ -139,8 +137,8 @@ namespace Overlay {
private:
uint64_t last_word_from_server;
uint64_t last_acked_state;
string escape_key_string;
wstring message;
std::string escape_key_string;
std::wstring message;
bool message_is_network_error;
uint64_t message_expiration;
bool show_quit_keystroke;
@@ -152,12 +150,12 @@ namespace Overlay {
public:
void adjust_message( void );
void apply( Framebuffer &fb ) const;
const wstring &get_notification_string( void ) const { return message; }
const std::wstring &get_notification_string( void ) const { return message; }
void server_heard( uint64_t s_last_word ) { last_word_from_server = s_last_word; }
void server_acked( uint64_t s_last_acked ) { last_acked_state = s_last_acked; }
int wait_time( void ) const;
void set_notification_string( const wstring &s_message, bool permanent = false, bool s_show_quit_keystroke = true )
void set_notification_string( const std::wstring &s_message, bool permanent = false, bool s_show_quit_keystroke = true )
{
message = s_message;
if ( permanent ) {
@@ -169,7 +167,7 @@ namespace Overlay {
show_quit_keystroke = s_show_quit_keystroke;
}
void set_escape_key_string( const string &s_name )
void set_escape_key_string( const std::string &s_name )
{
char tmp[ 128 ];
snprintf( tmp, sizeof tmp, " [To quit: %s .]", s_name.c_str() );
@@ -312,7 +310,7 @@ namespace Overlay {
public:
void apply( Framebuffer &fb ) const { fb.prefix_window_title( prefix ); }
TitleEngine() : prefix() {}
void set_prefix( const wstring &s );
void set_prefix( const std::wstring &s );
};
/* the overlay manager */
@@ -328,7 +326,7 @@ namespace Overlay {
NotificationEngine & get_notification_engine( void ) { return notifications; }
PredictionEngine & get_prediction_engine( void ) { return predictions; }
void set_title_prefix( const wstring &s ) { title.set_prefix( s ); }
void set_title_prefix( const std::wstring &s ) { title.set_prefix( s ); }
OverlayManager() : notifications(), predictions(), title() {}
+4 -5
View File
@@ -36,24 +36,23 @@
#include "src/util/dos_assert.h"
using namespace Network;
using std::string;
string Compressor::compress_str( const string &input )
std::string Compressor::compress_str( const std::string &input )
{
long unsigned int len = BUFFER_SIZE;
dos_assert( Z_OK == compress( buffer, &len,
reinterpret_cast<const unsigned char *>( input.data() ),
input.size() ) );
return string( reinterpret_cast<char *>( buffer ), len );
return std::string( reinterpret_cast<char *>( buffer ), len );
}
string Compressor::uncompress_str( const string &input )
std::string Compressor::uncompress_str( const std::string &input )
{
long unsigned int len = BUFFER_SIZE;
dos_assert( Z_OK == uncompress( buffer, &len,
reinterpret_cast<const unsigned char *>( input.data() ),
input.size() ) );
return string( reinterpret_cast<char *>( buffer ), len );
return std::string( reinterpret_cast<char *>( buffer ), len );
}
/* construct on first use */
+8 -8
View File
@@ -80,7 +80,7 @@ Packet::Packet( const Message & message )
timestamp = be16toh( data[ 0 ] );
timestamp_reply = be16toh( data[ 1 ] );
payload = string( message.text.begin() + 2 * sizeof( uint16_t ), message.text.end() );
payload = std::string( message.text.begin() + 2 * sizeof( uint16_t ), message.text.end() );
}
/* Output from packet */
@@ -91,12 +91,12 @@ Message Packet::toMessage( void )
uint16_t ts_net[ 2 ] = { static_cast<uint16_t>( htobe16( timestamp ) ),
static_cast<uint16_t>( htobe16( timestamp_reply ) ) };
string timestamps = string( (char *)ts_net, 2 * sizeof( uint16_t ) );
std::string timestamps = std::string( (char *)ts_net, 2 * sizeof( uint16_t ) );
return Message( Nonce( direction_seq ), timestamps + payload );
}
Packet Connection::new_packet( const string &s_payload )
Packet Connection::new_packet( const std::string &s_payload )
{
uint16_t outgoing_timestamp_reply = -1;
@@ -391,7 +391,7 @@ Connection::Connection( const char *key_str, const char *ip, const char *port )
set_MTU( remote_addr.sa.sa_family );
}
void Connection::send( const string & s )
void Connection::send( const std::string & s )
{
if ( !has_remote_addr ) {
return;
@@ -399,7 +399,7 @@ void Connection::send( const string & s )
Packet px = new_packet( s );
string p = session.encrypt( px.toMessage() );
std::string p = session.encrypt( px.toMessage() );
ssize_t bytes_sent = sendto( sock(), p.data(), p.size(), MSG_DONTWAIT,
&remote_addr.sa, remote_addr_len );
@@ -428,13 +428,13 @@ void Connection::send( const string & s )
}
}
string Connection::recv( void )
std::string Connection::recv( void )
{
assert( !socks.empty() );
for ( std::deque< Socket >::const_iterator it = socks.begin();
it != socks.end();
it++ ) {
string payload;
std::string payload;
try {
payload = recv_one( it->fd());
} catch ( NetworkException & e ) {
@@ -453,7 +453,7 @@ string Connection::recv( void )
throw NetworkException( "No packet received" );
}
string Connection::recv_one( int sock_to_recv )
std::string Connection::recv_one( int sock_to_recv )
{
/* receive source address, ECN, and payload in msghdr structure */
Addr packet_remote_addr;
+12 -12
View File
@@ -57,12 +57,12 @@ namespace Network {
class NetworkException : public std::exception {
public:
string function;
std::string function;
int the_errno;
private:
string my_what;
std::string my_what;
public:
NetworkException( string s_function="<none>", int s_errno=0)
NetworkException( std::string s_function="<none>", int s_errno=0)
: function( s_function ), the_errno( s_errno ),
my_what(function + ": " + strerror(the_errno)) {}
const char *what() const throw () { return my_what.c_str(); }
@@ -79,10 +79,10 @@ namespace Network {
const uint64_t seq;
Direction direction;
uint16_t timestamp, timestamp_reply;
string payload;
std::string payload;
Packet( Direction s_direction,
uint16_t s_timestamp, uint16_t s_timestamp_reply, const string & s_payload )
uint16_t s_timestamp, uint16_t s_timestamp_reply, const std::string & s_payload )
: seq( Crypto::unique() ), direction( s_direction ),
timestamp( s_timestamp ), timestamp_reply( s_timestamp_reply ), payload( s_payload )
{}
@@ -188,9 +188,9 @@ namespace Network {
double RTTVAR;
/* Error from send()/sendto(). */
string send_error;
std::string send_error;
Packet new_packet( const string &s_payload );
Packet new_packet( const std::string &s_payload );
void hop_port( void );
@@ -198,7 +198,7 @@ namespace Network {
void prune_sockets( void );
string recv_one( int sock_to_recv );
std::string recv_one( int sock_to_recv );
void set_MTU( int family );
@@ -209,13 +209,13 @@ namespace Network {
Connection( const char *desired_ip, const char *desired_port ); /* server */
Connection( const char *key_str, const char *ip, const char *port ); /* client */
void send( const string & s );
string recv( void );
void send( const std::string & s );
std::string recv( void );
const std::vector< int > fds( void ) const;
int get_MTU( void ) const { return MTU; }
std::string port( void ) const;
string get_key( void ) const { return key.printable_key(); }
std::string get_key( void ) const { return key.printable_key(); }
bool get_has_remote_addr( void ) const { return has_remote_addr; }
uint64_t timeout( void ) const;
@@ -224,7 +224,7 @@ namespace Network {
const Addr &get_remote_addr( void ) const { return remote_addr; }
socklen_t get_remote_addr_len( void ) const { return remote_addr_len; }
string &get_send_error( void )
std::string &get_send_error( void )
{
return send_error;
}
+9 -9
View File
@@ -70,7 +70,7 @@ Transport<MyState, RemoteState>::Transport( MyState &initial_state, RemoteState
template <class MyState, class RemoteState>
void Transport<MyState, RemoteState>::recv( void )
{
string s( connection.recv() );
std::string s( connection.recv() );
Fragment frag( s );
if ( fragments.add_fragment( frag ) ) { /* complete packet */
@@ -86,7 +86,7 @@ void Transport<MyState, RemoteState>::recv( void )
connection.set_last_roundtrip_success( sender.get_sent_state_acked_timestamp() );
/* first, make sure we don't already have the new state */
for ( typename list< TimestampedState<RemoteState> >::iterator i = received_states.begin();
for ( typename std::list< TimestampedState<RemoteState> >::iterator i = received_states.begin();
i != received_states.end();
i++ ) {
if ( inst.new_num() == i->num ) {
@@ -96,7 +96,7 @@ void Transport<MyState, RemoteState>::recv( void )
/* now, make sure we do have the old state */
bool found = 0;
typename list< TimestampedState<RemoteState> >::iterator reference_state = received_states.begin();
typename std::list< TimestampedState<RemoteState> >::iterator reference_state = received_states.begin();
while ( reference_state != received_states.end() ) {
if ( inst.old_num() == reference_state->num ) {
found = true;
@@ -140,7 +140,7 @@ void Transport<MyState, RemoteState>::recv( void )
}
/* Insert new state in sorted place */
for ( typename list< TimestampedState<RemoteState> >::iterator i = received_states.begin();
for ( typename std::list< TimestampedState<RemoteState> >::iterator i = received_states.begin();
i != received_states.end();
i++ ) {
if ( i->num > new_state.num ) {
@@ -170,9 +170,9 @@ void Transport<MyState, RemoteState>::recv( void )
template <class MyState, class RemoteState>
void Transport<MyState, RemoteState>::process_throwaway_until( uint64_t throwaway_num )
{
typename list< TimestampedState<RemoteState> >::iterator i = received_states.begin();
typename std::list< TimestampedState<RemoteState> >::iterator i = received_states.begin();
while ( i != received_states.end() ) {
typename list< TimestampedState<RemoteState> >::iterator inext = i;
typename std::list< TimestampedState<RemoteState> >::iterator inext = i;
inext++;
if ( i->num < throwaway_num ) {
received_states.erase( i );
@@ -184,15 +184,15 @@ void Transport<MyState, RemoteState>::process_throwaway_until( uint64_t throwawa
}
template <class MyState, class RemoteState>
string Transport<MyState, RemoteState>::get_remote_diff( void )
std::string Transport<MyState, RemoteState>::get_remote_diff( void )
{
/* find diff between last receiver state and current remote state, then rationalize states */
string ret( received_states.back().state.diff_from( last_receiver_state ) );
std::string ret( received_states.back().state.diff_from( last_receiver_state ) );
const RemoteState *oldest_receiver_state = &received_states.front().state;
for ( typename list< TimestampedState<RemoteState> >::reverse_iterator i = received_states.rbegin();
for ( typename std::list< TimestampedState<RemoteState> >::reverse_iterator i = received_states.rbegin();
i != received_states.rend();
i++ ) {
i->state.subtract( oldest_receiver_state );
+3 -3
View File
@@ -59,7 +59,7 @@ namespace Network {
void process_throwaway_until( uint64_t throwaway_num );
/* simple receiver */
list< TimestampedState<RemoteState> > received_states;
std::list< TimestampedState<RemoteState> > received_states;
uint64_t receiver_quench_timer;
RemoteState last_receiver_state; /* the state we were in when user last queried state */
FragmentAssembly fragments;
@@ -81,7 +81,7 @@ namespace Network {
void recv( void );
/* Find diff between last receiver state and current remote state, then rationalize states. */
string get_remote_diff( void );
std::string get_remote_diff( void );
/* Shut down other side of connection. */
/* Illegal to change current_state after this. */
@@ -95,7 +95,7 @@ namespace Network {
bool counterparty_shutdown_ack_sent( void ) const { return sender.get_counterparty_shutdown_acknowledged(); }
std::string port( void ) const { return connection.port(); }
string get_key( void ) const { return connection.get_key(); }
std::string get_key( void ) const { return connection.get_key(); }
MyState &get_current_state( void ) { return sender.get_current_state(); }
void set_current_state( const MyState &x ) { sender.set_current_state( x ); }
+15 -15
View File
@@ -41,23 +41,23 @@
using namespace Network;
using namespace TransportBuffers;
static string network_order_string( uint16_t host_order )
static std::string network_order_string( uint16_t host_order )
{
uint16_t net_int = htobe16( host_order );
return string( (char *)&net_int, sizeof( net_int ) );
return std::string( (char *)&net_int, sizeof( net_int ) );
}
static string network_order_string( uint64_t host_order )
static std::string network_order_string( uint64_t host_order )
{
uint64_t net_int = htobe64( host_order );
return string( (char *)&net_int, sizeof( net_int ) );
return std::string( (char *)&net_int, sizeof( net_int ) );
}
string Fragment::tostring( void )
std::string Fragment::tostring( void )
{
assert( initialized );
string ret;
std::string ret;
ret += network_order_string( id );
@@ -72,12 +72,12 @@ string Fragment::tostring( void )
return ret;
}
Fragment::Fragment( const string &x )
Fragment::Fragment( const std::string &x )
: id( -1 ), fragment_num( -1 ), final( false ), initialized( true ),
contents()
{
fatal_assert( x.size() >= frag_header_len );
contents = string( x.begin() + frag_header_len, x.end() );
contents = std::string( x.begin() + frag_header_len, x.end() );
uint64_t data64;
uint16_t *data16 = (uint16_t *)x.data();
@@ -131,7 +131,7 @@ Instruction FragmentAssembly::get_assembly( void )
{
assert( fragments_arrived == fragments_total );
string encoded;
std::string encoded;
for ( int i = 0; i < fragments_total; i++ ) {
assert( fragments.at( i ).initialized );
@@ -154,7 +154,7 @@ bool Fragment::operator==( const Fragment &x ) const
&& ( initialized == x.initialized ) && ( contents == x.contents );
}
vector<Fragment> Fragmenter::make_fragments( const Instruction &inst, size_t MTU )
std::vector<Fragment> Fragmenter::make_fragments( const Instruction &inst, size_t MTU )
{
MTU -= Fragment::frag_header_len;
if ( (inst.old_num() != last_instruction.old_num())
@@ -175,17 +175,17 @@ vector<Fragment> Fragmenter::make_fragments( const Instruction &inst, size_t MTU
last_instruction = inst;
last_MTU = MTU;
string payload = get_compressor().compress_str( inst.SerializeAsString() );
std::string payload = get_compressor().compress_str( inst.SerializeAsString() );
uint16_t fragment_num = 0;
vector<Fragment> ret;
std::vector<Fragment> ret;
while ( !payload.empty() ) {
string this_fragment;
std::string this_fragment;
bool final = false;
if ( payload.size() > MTU ) {
this_fragment = string( payload.begin(), payload.begin() + MTU );
payload = string( payload.begin() + MTU, payload.end() );
this_fragment = std::string( payload.begin(), payload.begin() + MTU );
payload = std::string( payload.begin() + MTU, payload.end() );
} else {
this_fragment = payload;
payload.clear();
+6 -8
View File
@@ -40,8 +40,6 @@
#include "src/protobufs/transportinstruction.pb.h"
namespace Network {
using std::vector;
using std::string;
using namespace TransportBuffers;
class Fragment
@@ -55,20 +53,20 @@ namespace Network {
bool initialized;
string contents;
std::string contents;
Fragment()
: id( -1 ), fragment_num( -1 ), final( false ), initialized( false ), contents()
{}
Fragment( uint64_t s_id, uint16_t s_fragment_num, bool s_final, const string & s_contents )
Fragment( uint64_t s_id, uint16_t s_fragment_num, bool s_final, const std::string & s_contents )
: id( s_id ), fragment_num( s_fragment_num ), final( s_final ), initialized( true ),
contents( s_contents )
{}
Fragment( const string &x );
Fragment( const std::string &x );
string tostring( void );
std::string tostring( void );
bool operator==( const Fragment &x ) const;
};
@@ -76,7 +74,7 @@ namespace Network {
class FragmentAssembly
{
private:
vector<Fragment> fragments;
std::vector<Fragment> fragments;
uint64_t current_id;
int fragments_arrived, fragments_total;
@@ -99,7 +97,7 @@ namespace Network {
last_instruction.set_old_num( -1 );
last_instruction.set_new_num( -1 );
}
vector<Fragment> make_fragments( const Instruction &inst, size_t MTU );
std::vector<Fragment> make_fragments( const Instruction &inst, size_t MTU );
uint64_t last_ack_sent( void ) const { return last_instruction.ack_num(); }
};
+13 -13
View File
@@ -167,7 +167,7 @@ void TransportSender<MyState>::tick( void )
/* Determine if a new diff or empty ack needs to be sent */
string diff = current_state.diff_from( assumed_receiver_state->state );
std::string diff = current_state.diff_from( assumed_receiver_state->state );
attempt_prospective_resend_optimization( diff );
@@ -236,7 +236,7 @@ void TransportSender<MyState>::add_sent_state( uint64_t the_timestamp, uint64_t
}
template <class MyState>
void TransportSender<MyState>::send_to_receiver( const string & diff )
void TransportSender<MyState>::send_to_receiver( const std::string & diff )
{
uint64_t new_num;
if ( current_state == sent_states.back().state ) { /* previously sent */
@@ -275,7 +275,7 @@ void TransportSender<MyState>::update_assumed_receiver_state( void )
transmitted recently enough ago */
assumed_receiver_state = sent_states.begin();
typename list< TimestampedState<MyState> >::iterator i = sent_states.begin();
typename std::list< TimestampedState<MyState> >::iterator i = sent_states.begin();
i++;
while ( i != sent_states.end() ) {
@@ -298,7 +298,7 @@ void TransportSender<MyState>::rationalize_states( void )
current_state.subtract( known_receiver_state );
for ( typename list< TimestampedState<MyState> >::reverse_iterator i = sent_states.rbegin();
for ( typename std::list< TimestampedState<MyState> >::reverse_iterator i = sent_states.rbegin();
i != sent_states.rend();
i++ ) {
i->state.subtract( known_receiver_state );
@@ -306,18 +306,18 @@ void TransportSender<MyState>::rationalize_states( void )
}
template <class MyState>
const string TransportSender<MyState>::make_chaff( void )
const std::string TransportSender<MyState>::make_chaff( void )
{
const size_t CHAFF_MAX = 16;
const size_t chaff_len = prng.uint8() % (CHAFF_MAX + 1);
char chaff[ CHAFF_MAX ];
prng.fill( chaff, chaff_len );
return string( chaff, chaff_len );
return std::string( chaff, chaff_len );
}
template <class MyState>
void TransportSender<MyState>::send_in_fragments( const string & diff, uint64_t new_num )
void TransportSender<MyState>::send_in_fragments( const std::string & diff, uint64_t new_num )
{
Instruction inst;
@@ -333,10 +333,10 @@ void TransportSender<MyState>::send_in_fragments( const string & diff, uint64_t
shutdown_tries++;
}
vector<Fragment> fragments = fragmenter.make_fragments( inst, connection->get_MTU()
- Network::Connection::ADDED_BYTES
- Crypto::Session::ADDED_BYTES );
for ( vector<Fragment>::iterator i = fragments.begin();
std::vector<Fragment> fragments = fragmenter.make_fragments( inst, connection->get_MTU()
- Network::Connection::ADDED_BYTES
- Crypto::Session::ADDED_BYTES );
for ( std::vector<Fragment>::iterator i = fragments.begin();
i != fragments.end();
i++ ) {
connection->send( i->tostring() );
@@ -404,13 +404,13 @@ void TransportSender<MyState>::set_ack_num( uint64_t s_ack_num )
/* Investigate diff against known receiver state instead */
/* Mutates proposed_diff */
template <class MyState>
void TransportSender<MyState>::attempt_prospective_resend_optimization( string &proposed_diff )
void TransportSender<MyState>::attempt_prospective_resend_optimization( std::string &proposed_diff )
{
if ( assumed_receiver_state == sent_states.begin() ) {
return;
}
string resend_diff = current_state.diff_from( sent_states.front().state );
std::string resend_diff = current_state.diff_from( sent_states.front().state );
/* We do a prophylactic resend if it would make the diff shorter,
or if it would lengthen it by no more than 100 bytes and still be
+4 -6
View File
@@ -44,8 +44,6 @@
#include "src/crypto/prng.h"
namespace Network {
using std::list;
using std::pair;
using namespace TransportBuffers;
/* timing parameters */
@@ -62,11 +60,11 @@ namespace Network {
private:
/* helper methods for tick() */
void update_assumed_receiver_state( void );
void attempt_prospective_resend_optimization( string &proposed_diff );
void attempt_prospective_resend_optimization( std::string &proposed_diff );
void rationalize_states( void );
void send_to_receiver( const string & diff );
void send_to_receiver( const std::string & diff );
void send_empty_ack( void );
void send_in_fragments( const string & diff, uint64_t new_num );
void send_in_fragments( const std::string & diff, uint64_t new_num );
void add_sent_state( uint64_t the_timestamp, uint64_t num, MyState &state );
/* state of sender */
@@ -106,7 +104,7 @@ namespace Network {
/* chaff to disguise instruction length */
PRNG prng;
const string make_chaff( void );
const std::string make_chaff( void );
uint64_t mindelay_clock; /* time of first pending change to current state */
+8 -8
View File
@@ -43,12 +43,12 @@ using namespace ClientBuffers;
void UserStream::subtract( const UserStream *prefix )
{
// if we are subtracting ourself from ourself, just clear the deque
// if we are subtracting ourself from ourself, just clear the std::deque
if ( this == prefix ) {
actions.clear();
return;
}
for ( deque<UserEvent>::const_iterator i = prefix->actions.begin();
for ( std::deque<UserEvent>::const_iterator i = prefix->actions.begin();
i != prefix->actions.end();
i++ ) {
assert( this != prefix );
@@ -58,11 +58,11 @@ void UserStream::subtract( const UserStream *prefix )
}
}
string UserStream::diff_from( const UserStream &existing ) const
std::string UserStream::diff_from( const UserStream &existing ) const
{
deque<UserEvent>::const_iterator my_it = actions.begin();
std::deque<UserEvent>::const_iterator my_it = actions.begin();
for ( deque<UserEvent>::const_iterator i = existing.actions.begin();
for ( std::deque<UserEvent>::const_iterator i = existing.actions.begin();
i != existing.actions.end();
i++ ) {
assert( my_it != actions.end() );
@@ -80,7 +80,7 @@ string UserStream::diff_from( const UserStream &existing ) const
/* can we combine this with a previous Keystroke? */
if ( (output.instruction_size() > 0)
&& (output.instruction( output.instruction_size() - 1 ).HasExtension( keystroke )) ) {
output.mutable_instruction( output.instruction_size() - 1 )->MutableExtension( keystroke )->mutable_keys()->append( string( &the_byte, 1 ) );
output.mutable_instruction( output.instruction_size() - 1 )->MutableExtension( keystroke )->mutable_keys()->append( std::string( &the_byte, 1 ) );
} else {
Instruction *new_inst = output.add_instruction();
new_inst->MutableExtension( keystroke )->set_keys( &the_byte, 1 );
@@ -105,14 +105,14 @@ string UserStream::diff_from( const UserStream &existing ) const
return output.SerializeAsString();
}
void UserStream::apply_string( const string &diff )
void UserStream::apply_string( const std::string &diff )
{
ClientBuffers::UserMessage input;
fatal_assert( input.ParseFromString( diff ) );
for ( int i = 0; i < input.instruction_size(); i++ ) {
if ( input.instruction( i ).HasExtension( keystroke ) ) {
string the_bytes = input.instruction( i ).GetExtension( keystroke ).keys();
std::string the_bytes = input.instruction( i ).GetExtension( keystroke ).keys();
for ( unsigned int loc = 0; loc < the_bytes.size(); loc++ ) {
actions.push_back( UserEvent( UserByte( the_bytes.at( loc ) ) ) );
}
+4 -8
View File
@@ -41,10 +41,6 @@
#include "src/terminal/parseraction.h"
namespace Network {
using std::deque;
using std::list;
using std::string;
enum UserEventType {
UserByteType = 0,
ResizeType = 1
@@ -70,7 +66,7 @@ namespace Network {
class UserStream
{
private:
deque<UserEvent> actions;
std::deque<UserEvent> actions;
public:
UserStream() : actions() {}
@@ -84,9 +80,9 @@ namespace Network {
/* interface for Network::Transport */
void subtract( const UserStream *prefix );
string diff_from( const UserStream &existing ) const;
string init_diff( void ) const { return diff_from( UserStream() ); };
void apply_string( const string &diff );
std::string diff_from( const UserStream &existing ) const;
std::string init_diff( void ) const { return diff_from( UserStream() ); };
void apply_string( const std::string &diff );
bool operator==( const UserStream &x ) const { return actions == x.actions; }
bool compare( const UserStream & ) { return false; }
+8 -9
View File
@@ -34,10 +34,9 @@
#include "terminaluserinput.h"
using namespace Terminal;
using std::string;
string UserInput::input( const Parser::UserByte *act,
bool application_mode_cursor_keys )
std::string UserInput::input( const Parser::UserByte *act,
bool application_mode_cursor_keys )
{
/* The user will always be in application mode. If stm is not in
application mode, convert user's cursor control function to an
@@ -54,15 +53,15 @@ string UserInput::input( const Parser::UserByte *act,
if ( act->c == 0x1b ) { /* ESC */
state = ESC;
}
return string( &act->c, 1 );
return std::string( &act->c, 1 );
case ESC:
if ( act->c == 'O' ) { /* ESC O = 7-bit SS3 */
state = SS3;
return string();
return std::string();
}
state = Ground;
return string( &act->c, 1 );
return std::string( &act->c, 1 );
case SS3:
state = Ground;
@@ -70,15 +69,15 @@ string UserInput::input( const Parser::UserByte *act,
&& (act->c >= 'A')
&& (act->c <= 'D') ) {
char translated_cursor[ 2 ] = { '[', act->c };
return string( translated_cursor, 2 );
return std::string( translated_cursor, 2 );
} else {
char original_cursor[ 2 ] = { 'O', act->c };
return string( original_cursor, 2 );
return std::string( original_cursor, 2 );
}
default:
assert( !"unexpected state" );
state = Ground;
return string();
return std::string();
}
}