Process resize entirely on server

This commit is contained in:
Keith Winstein
2012-01-07 03:46:18 -05:00
parent c0845631de
commit ec2469257b
10 changed files with 79 additions and 25 deletions
+3 -3
View File
@@ -1,6 +1,6 @@
proto = userinput.proto transportinstruction.proto
source = parse.cpp parserstate.cpp parser.cpp terminal.cpp termemu.cpp parseraction.cpp terminalfunctions.cpp swrite.cpp terminalframebuffer.cpp terminaldispatcher.cpp terminaluserinput.cpp terminaldisplay.cpp network.cpp ntester.cpp ocb.cpp base64.cpp encrypt.cpp decrypt.cpp crypto.cpp networktransport.cpp transportfragment.cpp user.cpp userinput.pb.cc completeterminal.cpp stm-server.cpp stm.cpp transportinstruction.pb.cc transportsender.cpp stmclient.cpp terminaloverlay.cpp
objects = parserstate.o parser.o terminal.o parseraction.o terminalfunctions.o swrite.o terminalframebuffer.o terminaldispatcher.o terminaluserinput.o terminaldisplay.o network.o ocb.o base64.o crypto.o networktransport.o transportfragment.o user.o userinput.pb.o completeterminal.o transportinstruction.pb.o transportsender.o stmclient.o terminaloverlay.o
proto = userinput.proto hostinput.proto transportinstruction.proto
source = parse.cpp parserstate.cpp parser.cpp terminal.cpp termemu.cpp parseraction.cpp terminalfunctions.cpp swrite.cpp terminalframebuffer.cpp terminaldispatcher.cpp terminaluserinput.cpp terminaldisplay.cpp network.cpp ntester.cpp ocb.cpp base64.cpp encrypt.cpp decrypt.cpp crypto.cpp networktransport.cpp transportfragment.cpp user.cpp userinput.pb.cc completeterminal.cpp stm-server.cpp stm.cpp transportinstruction.pb.cc transportsender.cpp stmclient.cpp terminaloverlay.cpp hostinput.pb.cc
objects = parserstate.o parser.o terminal.o parseraction.o terminalfunctions.o swrite.o terminalframebuffer.o terminaldispatcher.o terminaluserinput.o terminaldisplay.o network.o ocb.o base64.o crypto.o networktransport.o transportfragment.o user.o userinput.pb.o completeterminal.o transportinstruction.pb.o transportsender.o stmclient.o terminaloverlay.o hostinput.pb.o
executables = parse termemu ntester encrypt decrypt stm-server stm
CXX = g++
+28 -6
View File
@@ -1,8 +1,11 @@
#include "completeterminal.hpp"
#include "hostinput.pb.h"
using namespace std;
using namespace Parser;
using namespace Terminal;
using namespace HostBuffers;
string Complete::act( const string &str )
{
@@ -33,17 +36,36 @@ string Complete::act( const Action *act )
/* interface for Network::Transport */
string Complete::diff_from( const Complete &existing )
{
if ( existing.get_fb() == get_fb() ) {
return "";
} else {
return Terminal::Display::new_frame( true, existing.get_fb(), terminal.get_fb() );
HostBuffers::HostMessage output;
if ( !(existing.get_fb() == get_fb()) ) {
if ( (existing.get_fb().ds.get_width() != terminal.get_fb().ds.get_width())
|| (existing.get_fb().ds.get_height() != terminal.get_fb().ds.get_height()) ) {
Instruction *new_res = output.add_instruction();
new_res->MutableExtension( resize )->set_width( terminal.get_fb().ds.get_width() );
new_res->MutableExtension( resize )->set_height( terminal.get_fb().ds.get_height() );
}
Instruction *new_inst = output.add_instruction();
new_inst->MutableExtension( hostbytes )->set_hoststring( Terminal::Display::new_frame( true, existing.get_fb(), terminal.get_fb() ) );
}
return output.SerializeAsString();
}
void Complete::apply_string( string diff )
{
string terminal_to_host = act( diff );
assert( terminal_to_host.empty() );
HostBuffers::HostMessage input;
assert( input.ParseFromString( diff ) );
for ( int i = 0; i < input.instruction_size(); i++ ) {
if ( input.instruction( i ).HasExtension( hostbytes ) ) {
string terminal_to_host = act( input.instruction( i ).GetExtension( hostbytes ).hoststring() );
assert( terminal_to_host.empty() ); /* server never interrogates client terminal */
} else if ( input.instruction( i ).HasExtension( resize ) ) {
act( new Resize( input.instruction( i ).GetExtension( resize ).width(),
input.instruction( i ).GetExtension( resize ).height() ) );
}
}
}
bool Complete::operator==( Complete const &x ) const
+25
View File
@@ -0,0 +1,25 @@
option optimize_for = LITE_RUNTIME;
package HostBuffers;
message HostMessage {
repeated Instruction instruction = 1;
}
message Instruction {
extensions 2 to max;
}
message HostBytes {
optional bytes hoststring = 4;
}
message ResizeMessage {
optional int32 width = 5;
optional int32 height = 6;
}
extend Instruction {
optional HostBytes hostbytes = 2;
optional ResizeMessage resize = 3;
}
+2
View File
@@ -14,6 +14,8 @@ using namespace std;
using namespace Crypto;
namespace Network {
static const unsigned int MOSH_PROTOCOL_VERSION = 1;
uint64_t timestamp( void );
uint16_t timestamp16( void );
uint16_t timestamp_diff( uint16_t tsnew, uint16_t tsold );
+4
View File
@@ -42,6 +42,10 @@ void Transport<MyState, RemoteState>::recv( void )
if ( fragments.add_fragment( frag ) ) { /* complete packet */
Instruction inst = fragments.get_assembly();
if ( inst.protocol_version() != MOSH_PROTOCOL_VERSION ) {
throw NetworkException( "Mosh protocol version mismatch", 0 );
}
sender.process_acknowledgment_through( inst.ack_num() );
/* first, make sure we don't already have the new state */
-3
View File
@@ -67,9 +67,6 @@ namespace Network {
MyState &get_current_state( void ) { return sender.get_current_state(); }
void set_current_state( const MyState &x ) { sender.set_current_state( x ); }
typename list< TimestampedState<RemoteState > >::iterator begin( void ) { return received_states.begin(); }
typename list< TimestampedState<RemoteState > >::iterator end( void ) { return received_states.end(); }
uint64_t get_remote_state_num( void ) { return received_states.back().num; }
const TimestampedState<RemoteState> & get_latest_remote_state( void ) const { return received_states.back(); }
+7 -1
View File
@@ -73,6 +73,12 @@ int main( void )
exit( 1 );
}
/* clear STY environment variable so GNU screen regards us as top level */
if ( unsetenv( "STY" ) < 0 ) {
perror( "unsetenv" );
exit( 1 );
}
/* get shell name */
struct passwd *pw = getpwuid( geteuid() );
if ( pw == NULL ) {
@@ -84,7 +90,7 @@ int main( void )
my_argv[ 0 ] = strdup( pw->pw_shell );
assert( my_argv[ 0 ] );
my_argv[ 1 ] = NULL;
if ( execve( pw->pw_shell, my_argv, environ ) < 0 ) {
perror( "execve" );
exit( 1 );
+2 -7
View File
@@ -236,14 +236,9 @@ bool STMClient::process_resize( void )
if ( !network->shutdown_in_progress() ) {
network->get_current_state().push_back( res );
}
/* tell local emulator -- there is probably a safer way to do this */
for ( auto i = network->begin();
i != network->end();
i++ ) {
i->state.act( &res );
}
/* note remote emulator will probably reply with its own Resize to adjust our state */
/* tell prediction engine */
overlays.get_prediction_engine().reset();
+7 -5
View File
@@ -3,10 +3,12 @@ option optimize_for = LITE_RUNTIME;
package TransportBuffers;
message Instruction {
optional uint64 old_num = 1;
optional uint64 new_num = 2;
optional uint64 ack_num = 3;
optional uint64 throwaway_num = 4;
optional uint32 protocol_version = 1;
optional bytes diff = 5;
optional uint64 old_num = 2;
optional uint64 new_num = 3;
optional uint64 ack_num = 4;
optional uint64 throwaway_num = 5;
optional bytes diff = 6;
}
+1
View File
@@ -218,6 +218,7 @@ template <class MyState>
void TransportSender<MyState>::send_in_fragments( string diff, uint64_t new_num )
{
Instruction inst;
inst.set_protocol_version( MOSH_PROTOCOL_VERSION );
inst.set_old_num( assumed_receiver_state->num );
inst.set_new_num( new_num );
inst.set_ack_num( ack_num );