Commit e3443b77 authored by Jonathon Duerig's avatar Jonathon Duerig
Browse files

Backwards compatibility w/ existing monitor + fix that Pramod noticed.

parent 80d60cf6
......@@ -72,12 +72,12 @@ public:
}
prefix.size = message.size();
prefix.key = key;
char headerBuffer[Header::headerSize];
char headerBuffer[Header::maxHeaderSize];
saveHeader(headerBuffer, prefix);
int result = startMessage(Header::headerSize + message.size());
int result = startMessage(Header::headerSize() + message.size());
if (result == SENDING_MESSAGE)
{
writeMessage(headerBuffer, Header::headerSize);
writeMessage(headerBuffer, Header::headerSize());
writeMessage(message.c_str(), message.size());
endMessage();
}
......
......@@ -64,21 +64,10 @@ void DirectInput::nextCommand(fd_set * readable)
Header::PREFIX_SIZE - index, 0);
if (error == Header::PREFIX_SIZE - index)
{
char version = headerBuffer[Header::PREFIX_SIZE - 1];
switch (version)
{
case 0:
versionSize = Header::PREFIX_SIZE + Header::VERSION_0_SIZE;
break;
case 1:
versionSize = Header::PREFIX_SIZE + Header::VERSION_1_SIZE;
break;
default:
logWrite(ERROR, "Unknown version: %d"
", assuming that it really means version 1", version);
versionSize = Header::PREFIX_SIZE + Header::VERSION_1_SIZE;
break;
}
unsigned char version = headerBuffer[Header::PREFIX_SIZE - 1];
global::CONTROL_VERSION = version;
versionSize = Header::headerSize();
index += error;
state = HEADER;
}
else if (error > 0)
......@@ -103,8 +92,8 @@ void DirectInput::nextCommand(fd_set * readable)
&& FD_ISSET(monitorSocket, readable))
{
int error = recv(monitorSocket, headerBuffer + index,
Header::headerSize - index, 0);
if (error == Header::headerSize - index)
Header::headerSize() - index, 0);
if (error == Header::headerSize() - index)
{
// logWrite(COMMAND_INPUT, "Finished reading a command header");
loadHeader(headerBuffer, &commandHeader);
......@@ -203,7 +192,7 @@ int DirectInput::checksum(void)
int flip = 1;
int total = 0;
int i = 0;
for (i = 0; i < Header::headerSize; ++i)
for (i = 0; i < Header::headerSize(); ++i)
{
total += (headerBuffer[i] & 0xff) * flip;
// flip *= -1;
......
......@@ -34,7 +34,7 @@ private:
int monitorAccept;
int monitorSocket;
int index;
char headerBuffer[Header::headerSize];
char headerBuffer[Header::maxHeaderSize];
int versionSize;
Header commandHeader;
enum { bodyBufferSize = 0xffff };
......
......@@ -44,7 +44,7 @@ namespace global
// compatible by taking advantage of the fact that the old headers
// has a char 'transport' that was always set to 0 for
// TCP_CONNECTION.
const unsigned char CONTROL_VERSION = 1;
unsigned char CONTROL_VERSION = 1;
// Udp-CHANGES-Begin
const short int USHORT_INT_SIZE = sizeof(unsigned short int);
......@@ -260,7 +260,7 @@ bool replayWrite(char * source, int size)
void replayWriteCommand(char * head, char * body, unsigned short bodySize)
{
bool success = true;
success = replayWrite(head, Header::headerSize);
success = replayWrite(head, Header::headerSize());
if (success)
{
replayWrite(body, bodySize);
......@@ -273,10 +273,10 @@ void replayWritePacket(PacketInfo * packet)
head.type = packet->packetType;
head.size = packet->census();
head.key = packet->elab;
char headBuffer[Header::headerSize];
char headBuffer[Header::maxHeaderSize];
saveHeader(headBuffer, head);
bool success = replayWrite(headBuffer, Header::headerSize);
bool success = replayWrite(headBuffer, Header::headerSize());
if (success)
{
char *packetBuffer;
......
......@@ -85,14 +85,14 @@ extern char * optarg;
#elif BYTEORDER == LITTLE_ENDIAN
#define htonll(A) ( (((uint64_t)(A) & 0xff00000000000000ULL) >> 56) | \
(((uint64_t)(A) & 0x00ff000000000000ULL) >> 40) | \
(((uint64_t)(A) & 0x0000ff0000000000ULL) >> 24) | \
(((uint64_t)(A) & 0x000000ff00000000ULL) >> 8) | \
(((uint64_t)(A) & 0x00000000ff000000ULL) << 8) | \
(((uint64_t)(A) & 0x0000000000ff0000ULL) << 24) | \
(((uint64_t)(A) & 0x000000000000ff00ULL) << 40) | \
(((uint64_t)(A) & 0x00000000000000ffULL) << 56) )
#define htonll(A) ( (((uint64_t)(A) & 0xff00000000000000ULL) >> 56) | \
(((uint64_t)(A) & 0x00ff000000000000ULL) >> 40) | \
(((uint64_t)(A) & 0x0000ff0000000000ULL) >> 24) | \
(((uint64_t)(A) & 0x000000ff00000000ULL) >> 8) | \
(((uint64_t)(A) & 0x00000000ff000000ULL) << 8) | \
(((uint64_t)(A) & 0x0000000000ff0000ULL) << 24) | \
(((uint64_t)(A) & 0x000000000000ff00ULL) << 40) | \
(((uint64_t)(A) & 0x00000000000000ffULL) << 56) )
#endif
// Udp-CHANGES-End
......@@ -370,7 +370,7 @@ namespace global
extern int logFlags;
extern const unsigned char CONTROL_VERSION;
extern unsigned char CONTROL_VERSION;
// Udp-CHANGES-Begin
extern const short int USHORT_INT_SIZE;
......@@ -389,13 +389,13 @@ namespace global
// Udp-CHANGES-Begin
struct UdpPacketInfo
{
unsigned short int seqNum;
unsigned short int packetSize;
unsigned long long timeStamp;
bool isFake;
unsigned short int seqNum;
unsigned short int packetSize;
unsigned long long timeStamp;
bool isFake;
};
class equalSeqNum:public std::binary_function<UdpPacketInfo , unsigned short int, bool>
class equalSeqNum:public std::binary_function<UdpPacketInfo , unsigned short int, bool>
{
public:
bool operator()(const UdpPacketInfo& packet, unsigned short int seqNum) const
......@@ -404,7 +404,7 @@ class equalSeqNum:public std::binary_function<UdpPacketInfo , unsigned short int
}
};
class lessSeqNum:public std::binary_function<UdpPacketInfo , unsigned short int, bool>
class lessSeqNum:public std::binary_function<UdpPacketInfo , unsigned short int, bool>
{
public:
bool operator()(const UdpPacketInfo& packet,unsigned short int seqNum) const
......
......@@ -467,7 +467,7 @@ bool replayReadHeader(char * dest)
void replayLoop(void)
{
bool done = false;
char headerBuffer[Header::headerSize];
char headerBuffer[Header::maxHeaderSize];
Header head;
vector<char> packetBuffer;
struct tcp_info kernel;
......
......@@ -144,7 +144,14 @@ char * saveHeader(char * buffer, Header const & value)
pos = saveShort(pos, value.size);
pos = saveChar(pos, value.version);
logReplay("key", 0);
pos = saveBuffer(pos, value.key.id, ElabOrder::idSize);
if (global::CONTROL_VERSION < 1)
{
pos = saveBuffer(pos, value.key.id, Header::VERSION_0_SIZE);
}
else
{
pos = saveBuffer(pos, value.key.id, ElabOrder::idSize);
}
// pos = saveInt(pos, value.key.ip);
// pos = saveShort(pos, value.key.localPort);
// pos = saveShort(pos, value.key.remotePort);
......@@ -485,10 +492,17 @@ std::auto_ptr<Command> loadCommand(Header * head, char * body)
case NEW_CONNECTION_COMMAND:
{
NewConnectionCommand * newConnect = new NewConnectionCommand();
unsigned char temp;
char * buffer = body;
loadChar(buffer, &temp);
newConnect->transport = temp;
if (head->version < 1)
{
newConnect->transport = TCP_CONNECTION;
}
else
{
unsigned char temp = 0;
char * buffer = body;
loadChar(buffer, &temp);
newConnect->transport = temp;
}
result.reset(newConnect);
break;
}
......@@ -498,7 +512,7 @@ std::auto_ptr<Command> loadCommand(Header * head, char * body)
case CONNECTION_MODEL_COMMAND:
{
ConnectionModelCommand * model = new ConnectionModelCommand();
unsigned int temp;
unsigned int temp = 0;
char * buffer = body;
buffer = loadInt(buffer, &temp);
model->type = temp;
......@@ -511,7 +525,7 @@ std::auto_ptr<Command> loadCommand(Header * head, char * body)
{
SensorCommand * model = new SensorCommand();
char * buffer = body;
unsigned int temp;
unsigned int temp = 0;
buffer = loadInt(buffer, &temp);
model->type = temp;
result.reset(model);
......@@ -520,8 +534,16 @@ std::auto_ptr<Command> loadCommand(Header * head, char * body)
case CONNECT_COMMAND:
{
ConnectCommand * connect = new ConnectCommand();
char * buffer = body;
unsigned int tempIp;
unsigned int tempIp = 0;
char * buffer = NULL;
if (head->version < 1)
{
buffer = head->key.id;
}
else
{
buffer = body;
}
buffer = loadInt(buffer, &tempIp);
connect->ip = tempIp;
result.reset(connect);
......
......@@ -31,8 +31,22 @@ public:
enum { VERSION_1_SIZE = ElabOrder::idSize };
// headerSize is the buffer for the size of the largest version.
enum { headerSize = PREFIX_SIZE + VERSION_1_SIZE };
// headerSize() yields the header size for the current version.
static int headerSize(void)
{
switch (global::CONTROL_VERSION)
{
case 0:
return PREFIX_SIZE + VERSION_0_SIZE;
case 1:
return PREFIX_SIZE + VERSION_1_SIZE;
default:
return PREFIX_SIZE + VERSION_1_SIZE;
}
}
// maxHeaderSize is the buffer for the size of the largest version.
enum { maxHeaderSize = PREFIX_SIZE + VERSION_1_SIZE };
};
int getLastSaveloadSize(void);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment