Initial network support
This commit is contained in:
@@ -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
|
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
|
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
|
repos = templates.rpo
|
||||||
executables = parse termemu
|
executables = parse termemu ntester
|
||||||
|
|
||||||
CXX = g++
|
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
|
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
|
termemu: termemu.o $(objects) parse # serialize link steps because of -frepo
|
||||||
$(CXX) $(CXXFLAGS) -o $@ termemu.o $(objects) $(LIBS)
|
$(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
|
templates.o: templates.cpp
|
||||||
$(CXX) $(CXXFLAGS) -frepo -c -o $@ $<
|
$(CXX) $(CXXFLAGS) -frepo -c -o $@ $<
|
||||||
|
|
||||||
|
|||||||
+32
@@ -0,0 +1,32 @@
|
|||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include "network.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace Network;
|
||||||
|
|
||||||
|
template <class Payload>
|
||||||
|
Connection<Payload>::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 <class Payload>
|
||||||
|
Connection<Payload>::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 <class Payload>
|
||||||
|
Connection<Payload>::Connection( const char *ip, const char *port, bool server )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
+44
@@ -0,0 +1,44 @@
|
|||||||
|
#ifndef NETWORK_HPP
|
||||||
|
#define NETWORK_HPP
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <deque>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace Network {
|
||||||
|
template <class Payload>
|
||||||
|
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<Packet> send_queue;
|
||||||
|
std::deque<Packet> recv_queue;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Connection( const char *ip, const char *port, bool server );
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
#include "network.hpp"
|
||||||
|
|
||||||
|
class KeyStroke
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
char letter;
|
||||||
|
};
|
||||||
|
|
||||||
|
int main( void )
|
||||||
|
{
|
||||||
|
Network::Connection<KeyStroke> n();
|
||||||
|
}
|
||||||
@@ -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.
|
||||||
|
|
||||||
Reference in New Issue
Block a user