ambrop7 15 жил өмнө
parent
commit
8bf44ec382

+ 2 - 1
flow/BufferWriter.h

@@ -30,6 +30,7 @@
 
 #include <stdint.h>
 
+#include <misc/debug.h>
 #include <system/DebugObject.h>
 #include <flow/PacketRecvInterface.h>
 
@@ -83,7 +84,7 @@ PacketRecvInterface * BufferWriter_GetOutput (BufferWriter *o);
  *            It will have space for MTU bytes.
  * @return 1 on success, 0 on failure
  */
-int BufferWriter_StartPacket (BufferWriter *o, uint8_t **buf);
+int BufferWriter_StartPacket (BufferWriter *o, uint8_t **buf) WARN_UNUSED;
 
 /**
  * Submits a packet written to the buffer.

+ 2 - 1
flow/SPProtoDecoder.c

@@ -102,7 +102,8 @@ static int decode_packet (SPProtoDecoder *o, uint8_t *in, int in_len, uint8_t **
     // check OTP
     if (SPPROTO_HAVE_OTP(o->sp_params)) {
         struct spproto_otpdata *header_otpd = (struct spproto_otpdata *)(header + SPPROTO_HEADER_OTPDATA_OFF(o->sp_params));
-        if (!OTPChecker_CheckOTP(&o->otpchecker, ltoh16(header_otpd->seed_id), header_otpd->otp)) {
+        uint16_t seed_id = ltoh16(header_otpd->seed_id);
+        if (!OTPChecker_CheckOTP(&o->otpchecker, seed_id, header_otpd->otp)) {
             DEBUG("packet has wrong OTP");
             return 0;
         }

+ 5 - 4
flow/SPProtoEncoder.c

@@ -26,6 +26,7 @@
 #include <misc/debug.h>
 #include <misc/balign.h>
 #include <misc/offset.h>
+#include <misc/byteorder.h>
 #include <security/BRandom.h>
 #include <security/BHash.h>
 
@@ -45,10 +46,11 @@ static int can_encode (SPProtoEncoder *o)
 static int encode_packet (SPProtoEncoder *o)
 {
     ASSERT(o->in_len >= 0)
-    ASSERT(o->in_len <= o->input_mtu)
     ASSERT(o->out_have)
     ASSERT(can_encode(o))
     
+    ASSERT(o->in_len <= o->input_mtu)
+    
     // plaintext is either output packet or our buffer
     uint8_t *plaintext = (!SPPROTO_HAVE_ENCRYPTION(o->sp_params) ? o->out : o->buf);
     
@@ -61,7 +63,7 @@ static int encode_packet (SPProtoEncoder *o)
     // write OTP
     if (SPPROTO_HAVE_OTP(o->sp_params)) {
         struct spproto_otpdata *header_otpd = (struct spproto_otpdata *)(header + SPPROTO_HEADER_OTPDATA_OFF(o->group->sp_params));
-        header_otpd->seed_id = o->otpgen_seed_id;
+        header_otpd->seed_id = htol16(o->otpgen_seed_id);
         header_otpd->otp = OTPGenerator_GetOTP(&o->otpgen);
     }
     
@@ -105,7 +107,6 @@ static int encode_packet (SPProtoEncoder *o)
 static void do_encode (SPProtoEncoder *o)
 {
     ASSERT(o->in_len >= 0)
-    ASSERT(o->in_len <= o->input_mtu)
     ASSERT(o->out_have)
     ASSERT(can_encode(o))
     
@@ -113,9 +114,9 @@ static void do_encode (SPProtoEncoder *o)
     int out_len = encode_packet(o);
     
     // finish packet
-    PacketRecvInterface_Done(&o->output, out_len);
     o->in_len = -1;
     o->out_have = 0;
+    PacketRecvInterface_Done(&o->output, out_len);
 }
 
 static void maybe_encode (SPProtoEncoder *o)

+ 0 - 2
flow/SPProtoEncoder.h

@@ -60,8 +60,6 @@ typedef struct {
     int out_have;
     uint8_t *out;
     uint8_t *buf;
-    LinkedList2Node group_list_node;
-    BPending continue_job;
     DebugObject d_obj;
 } SPProtoEncoder;