Add chaff to outgoing instructions (closes #26 github issue)
This commit is contained in:
@@ -144,6 +144,7 @@ vector<Fragment> Fragmenter::make_fragments( const Instruction &inst, int MTU )
|
|||||||
|| (inst.new_num() != last_instruction.new_num())
|
|| (inst.new_num() != last_instruction.new_num())
|
||||||
|| (inst.ack_num() != last_instruction.ack_num())
|
|| (inst.ack_num() != last_instruction.ack_num())
|
||||||
|| (inst.throwaway_num() != last_instruction.throwaway_num())
|
|| (inst.throwaway_num() != last_instruction.throwaway_num())
|
||||||
|
|| (inst.chaff() != last_instruction.chaff())
|
||||||
|| (inst.protocol_version() != last_instruction.protocol_version())
|
|| (inst.protocol_version() != last_instruction.protocol_version())
|
||||||
|| (last_MTU != MTU) ) {
|
|| (last_MTU != MTU) ) {
|
||||||
next_instruction_id++;
|
next_instruction_id++;
|
||||||
|
|||||||
@@ -21,6 +21,8 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#include "transportsender.h"
|
#include "transportsender.h"
|
||||||
#include "transportfragment.h"
|
#include "transportfragment.h"
|
||||||
@@ -46,6 +48,7 @@ TransportSender<MyState>::TransportSender( Connection *s_connection, MyState &in
|
|||||||
SEND_MINDELAY( 15 ),
|
SEND_MINDELAY( 15 ),
|
||||||
last_heard( 0 )
|
last_heard( 0 )
|
||||||
{
|
{
|
||||||
|
srand( time( NULL ) ); /* for chaff */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Try to send roughly two frames per RTT, bounded by limits on frame rate */
|
/* Try to send roughly two frames per RTT, bounded by limits on frame rate */
|
||||||
@@ -257,6 +260,18 @@ void TransportSender<MyState>::rationalize_states( void )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const string make_chaff( void )
|
||||||
|
{
|
||||||
|
const int CHAFF_MAX = 16;
|
||||||
|
|
||||||
|
char chaff[ CHAFF_MAX ];
|
||||||
|
for ( int i = 0; i < CHAFF_MAX; i++ ) {
|
||||||
|
chaff[ i ] = rand() % 256;
|
||||||
|
}
|
||||||
|
int chaff_len = rand() % (CHAFF_MAX + 1);
|
||||||
|
return string( chaff, chaff_len );
|
||||||
|
}
|
||||||
|
|
||||||
template <class MyState>
|
template <class MyState>
|
||||||
void TransportSender<MyState>::send_in_fragments( string diff, uint64_t new_num )
|
void TransportSender<MyState>::send_in_fragments( string diff, uint64_t new_num )
|
||||||
{
|
{
|
||||||
@@ -268,6 +283,7 @@ void TransportSender<MyState>::send_in_fragments( string diff, uint64_t new_num
|
|||||||
inst.set_ack_num( ack_num );
|
inst.set_ack_num( ack_num );
|
||||||
inst.set_throwaway_num( sent_states.front().num );
|
inst.set_throwaway_num( sent_states.front().num );
|
||||||
inst.set_diff( diff );
|
inst.set_diff( diff );
|
||||||
|
inst.set_chaff( make_chaff() );
|
||||||
|
|
||||||
if ( new_num == uint64_t(-1) ) {
|
if ( new_num == uint64_t(-1) ) {
|
||||||
shutdown_tries++;
|
shutdown_tries++;
|
||||||
|
|||||||
@@ -11,4 +11,6 @@ message Instruction {
|
|||||||
optional uint64 throwaway_num = 5;
|
optional uint64 throwaway_num = 5;
|
||||||
|
|
||||||
optional bytes diff = 6;
|
optional bytes diff = 6;
|
||||||
|
|
||||||
|
optional bytes chaff = 7;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user