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