From 6ea66b7aabc106b83a49d9d8380d130486db2c5d Mon Sep 17 00:00:00 2001 From: Keith Winstein Date: Tue, 2 Aug 2011 12:49:02 -0400 Subject: [PATCH] Initial network support --- Makefile | 9 ++++++--- network.cpp | 32 ++++++++++++++++++++++++++++++++ network.hpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ ntester.cpp | 12 ++++++++++++ rtmnotes | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 127 insertions(+), 3 deletions(-) create mode 100644 network.cpp create mode 100644 network.hpp create mode 100644 ntester.cpp create mode 100644 rtmnotes diff --git a/Makefile b/Makefile index ff0a06d..08e52e8 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ -source = parse.cpp parserstate.cpp parser.cpp templates.cpp terminal.cpp termemu.cpp parseraction.cpp terminalfunctions.cpp swrite.cpp terminalframebuffer.cpp terminaldispatcher.cpp terminaluserinput.cpp terminaldisplay.cpp -objects = parserstate.o parser.o templates.o terminal.o parseraction.o terminalfunctions.o swrite.o terminalframebuffer.o terminaldispatcher.o terminaluserinput.o terminaldisplay.o +source = parse.cpp parserstate.cpp parser.cpp templates.cpp terminal.cpp termemu.cpp parseraction.cpp terminalfunctions.cpp swrite.cpp terminalframebuffer.cpp terminaldispatcher.cpp terminaluserinput.cpp terminaldisplay.cpp network.cpp ntester.cpp +objects = parserstate.o parser.o templates.o terminal.o parseraction.o terminalfunctions.o swrite.o terminalframebuffer.o terminaldispatcher.o terminaluserinput.o terminaldisplay.o network.o repos = templates.rpo -executables = parse termemu +executables = parse termemu ntester CXX = g++ CXXFLAGS = -g -O2 --std=c++0x -pedantic -Werror -Wall -Wextra -Weffc++ -fno-implicit-templates -fno-default-inline -pipe -D_FILE_OFFSET_BITS=64 -D_XOPEN_SOURCE=500 -D_GNU_SOURCE @@ -15,6 +15,9 @@ parse: parse.o $(objects) termemu: termemu.o $(objects) parse # serialize link steps because of -frepo $(CXX) $(CXXFLAGS) -o $@ termemu.o $(objects) $(LIBS) +ntester: ntester.o $(objects) termemu # serialize link steps because of -frepo + $(CXX) $(CXXFLAGS) -o $@ ntester.o $(objects) $(LIBS) + templates.o: templates.cpp $(CXX) $(CXXFLAGS) -frepo -c -o $@ $< diff --git a/network.cpp b/network.cpp new file mode 100644 index 0000000..b6a8c18 --- /dev/null +++ b/network.cpp @@ -0,0 +1,32 @@ +#include + +#include "network.hpp" + +using namespace std; +using namespace Network; + +template +Connection::Packet::Packet( int64_t s_seq, int64_t s_ack, Packet *s_previous, Payload s_state ) + : seq( s_seq ), ack( s_ack ), previous( s_previous ), state( s_state ) +{ + +} + +template +Connection::Packet::Packet( string wire ) +{ + assert( wire.length() >= 32 ); + + seq = be64toh( (uint64_t) *wire_c ); + reference_seq = be64toh( (uint64_t) *( wire_c + 8 ) ); + + tag = string( wire.begin() + 16, wire.begin() + 32 ); + + ack = be64toh( (uint64_t) *( wire_c + 16 ) ); +} + +template +Connection::Connection( const char *ip, const char *port, bool server ) +{ + +} diff --git a/network.hpp b/network.hpp new file mode 100644 index 0000000..867295f --- /dev/null +++ b/network.hpp @@ -0,0 +1,44 @@ +#ifndef NETWORK_HPP +#define NETWORK_HPP + +#include +#include +#include +#include +#include + +namespace Network { + template + class Connection { + private: + class Packet { + public: + int64_t seq; + int64_t reference_seq; + + std::string tag; + + int64_t ack; + + Payload state; + + Packet( int64_t s_seq, int64_t s_ack, Packet *s_previous, Payload s_state ); + Packet( std::string wire ); + }; + + int64_t next_seq; + int64_t next_ack; + int sequence_increment; + + int sock; + struct sockaddr_in addr; + + std::deque send_queue; + std::deque recv_queue; + + public: + Connection( const char *ip, const char *port, bool server ); + }; +} + +#endif diff --git a/ntester.cpp b/ntester.cpp new file mode 100644 index 0000000..fbca0c7 --- /dev/null +++ b/ntester.cpp @@ -0,0 +1,12 @@ +#include "network.hpp" + +class KeyStroke +{ +public: + char letter; +}; + +int main( void ) +{ + Network::Connection n(); +} diff --git a/rtmnotes b/rtmnotes new file mode 100644 index 0000000..25b1f1d --- /dev/null +++ b/rtmnotes @@ -0,0 +1,33 @@ +1. server maintains: + every frame it has ever been in. + + every packet it has ever sent. + + packet has: frame no, frame it depends on (maybe nothing), +0 server's Last Known Client Frame + + client has told us the latest frame it can now contruct + + some packets have transmitted frames > this recently, but those + frames haven't yet been acked + + some packets may have transmitted frames > this long ago + and haven't been acked. we call those lost + +2. most recent frame is "current frame" + + most recent frame not lost is "presumed client frame" + + most recent frame acked is "last known client frame" + +3. goal: transmit current frame to client by most efficient means + + could send packet depending on "nothing", "presumed client frame", + or "last known client frame" + +4. when client gets a packet, it tells us the latest frame it + can now construct + +5. when sending packet, server tells client last known client frame. + client discards all frames older than this. +