ambrop7 14 лет назад
Родитель
Сommit
7833a71bae
4 измененных файлов с 21 добавлено и 24 удалено
  1. 2 4
      client/DPReceive.c
  2. 6 6
      client/DPRelay.c
  3. 10 9
      client/DataProto.c
  4. 3 5
      client/DataProto.h

+ 2 - 4
client/DPReceive.c

@@ -34,13 +34,11 @@
 
 
 static DPReceivePeer * find_peer (DPReceiveDevice *o, peerid_t id)
 static DPReceivePeer * find_peer (DPReceiveDevice *o, peerid_t id)
 {
 {
-    LinkedList2Node *node = LinkedList2_GetFirst(&o->peers_list);
-    while (node) {
+    for (LinkedList2Node *node = LinkedList2_GetFirst(&o->peers_list); node; node = LinkedList2Node_Next(node)) {
         DPReceivePeer *p = UPPER_OBJECT(node, DPReceivePeer, list_node);
         DPReceivePeer *p = UPPER_OBJECT(node, DPReceivePeer, list_node);
         if (p->peer_id == id) {
         if (p->peer_id == id) {
             return p;
             return p;
         }
         }
-        node = LinkedList2Node_Next(node);
     }
     }
     
     
     return NULL;
     return NULL;
@@ -49,7 +47,6 @@ static DPReceivePeer * find_peer (DPReceiveDevice *o, peerid_t id)
 static void receiver_recv_handler_send (DPReceiveReceiver *o, uint8_t *packet, int packet_len)
 static void receiver_recv_handler_send (DPReceiveReceiver *o, uint8_t *packet, int packet_len)
 {
 {
     DebugObject_Access(&o->d_obj);
     DebugObject_Access(&o->d_obj);
-    ASSERT(o->peer)
     DPReceivePeer *peer = o->peer;
     DPReceivePeer *peer = o->peer;
     DPReceiveDevice *device = peer->device;
     DPReceiveDevice *device = peer->device;
     ASSERT(packet_len >= 0)
     ASSERT(packet_len >= 0)
@@ -164,6 +161,7 @@ int DPReceiveDevice_Init (DPReceiveDevice *o, int device_mtu, DPReceiveDevice_ou
 {
 {
     ASSERT(device_mtu >= 0)
     ASSERT(device_mtu >= 0)
     ASSERT(device_mtu <= INT_MAX - DATAPROTO_MAX_OVERHEAD)
     ASSERT(device_mtu <= INT_MAX - DATAPROTO_MAX_OVERHEAD)
+    ASSERT(output_func)
     ASSERT(relay_flow_buffer_size > 0)
     ASSERT(relay_flow_buffer_size > 0)
     
     
     // init arguments
     // init arguments

+ 6 - 6
client/DPRelay.c

@@ -48,7 +48,7 @@ static struct DPRelay_flow * create_flow (DPRelaySource *src, DPRelaySink *sink,
     flow->sink = sink;
     flow->sink = sink;
     
     
     // init DataProtoFlow
     // init DataProtoFlow
-    if (!DataProtoFlow_Init(&flow->dp_flow, &src->router->dp_source, src->source_id, sink->dest_id, num_packets, inactivity_time, (DataProtoFlow_handler_inactivity)flow_inactivity_handler, flow)) {
+    if (!DataProtoFlow_Init(&flow->dp_flow, &src->router->dp_source, src->source_id, sink->dest_id, num_packets, inactivity_time, flow, (DataProtoFlow_handler_inactivity)flow_inactivity_handler)) {
         BLog(BLOG_ERROR, "relay flow %d->%d: DataProtoFlow_Init failed", (int)src->source_id, (int)sink->dest_id);
         BLog(BLOG_ERROR, "relay flow %d->%d: DataProtoFlow_Init failed", (int)src->source_id, (int)sink->dest_id);
         goto fail1;
         goto fail1;
     }
     }
@@ -178,14 +178,14 @@ void DPRelayRouter_Free (DPRelayRouter *o)
 
 
 void DPRelayRouter_SubmitFrame (DPRelayRouter *o, DPRelaySource *src, DPRelaySink *sink, uint8_t *data, int data_len, int num_packets, int inactivity_time)
 void DPRelayRouter_SubmitFrame (DPRelayRouter *o, DPRelaySource *src, DPRelaySink *sink, uint8_t *data, int data_len, int num_packets, int inactivity_time)
 {
 {
-    ASSERT(data_len >= 0)
-    ASSERT(data_len <= o->frame_mtu)
-    ASSERT(num_packets > 0)
-    ASSERT(!o->current_flow)
-    ASSERT(src->router == o)
     DebugObject_Access(&o->d_obj);
     DebugObject_Access(&o->d_obj);
     DebugObject_Access(&src->d_obj);
     DebugObject_Access(&src->d_obj);
     DebugObject_Access(&sink->d_obj);
     DebugObject_Access(&sink->d_obj);
+    ASSERT(!o->current_flow)
+    ASSERT(src->router == o)
+    ASSERT(data_len >= 0)
+    ASSERT(data_len <= o->frame_mtu)
+    ASSERT(num_packets > 0)
     
     
     // get memory location
     // get memory location
     uint8_t *out;
     uint8_t *out;

+ 10 - 9
client/DataProto.c

@@ -352,6 +352,7 @@ void DataProtoSink_Received (DataProtoSink *o, int peer_receiving)
 int DataProtoSource_Init (DataProtoSource *o, PacketRecvInterface *input, DataProtoSource_handler handler, void *user, BReactor *reactor)
 int DataProtoSource_Init (DataProtoSource *o, PacketRecvInterface *input, DataProtoSource_handler handler, void *user, BReactor *reactor)
 {
 {
     ASSERT(PacketRecvInterface_GetMTU(input) <= INT_MAX - DATAPROTO_MAX_OVERHEAD)
     ASSERT(PacketRecvInterface_GetMTU(input) <= INT_MAX - DATAPROTO_MAX_OVERHEAD)
+    ASSERT(handler)
     
     
     // init arguments
     // init arguments
     o->handler = handler;
     o->handler = handler;
@@ -363,6 +364,7 @@ int DataProtoSource_Init (DataProtoSource *o, PacketRecvInterface *input, DataPr
     
     
     // init router
     // init router
     if (!PacketRouter_Init(&o->router, DATAPROTO_MAX_OVERHEAD + o->frame_mtu, DATAPROTO_MAX_OVERHEAD, input, (PacketRouter_handler)source_router_handler, o, BReactor_PendingGroup(reactor))) {
     if (!PacketRouter_Init(&o->router, DATAPROTO_MAX_OVERHEAD + o->frame_mtu, DATAPROTO_MAX_OVERHEAD, input, (PacketRouter_handler)source_router_handler, o, BReactor_PendingGroup(reactor))) {
+        BLog(BLOG_ERROR, "PacketRouter_Init failed");
         goto fail0;
         goto fail0;
     }
     }
     
     
@@ -383,12 +385,12 @@ void DataProtoSource_Free (DataProtoSource *o)
     PacketRouter_Free(&o->router);
     PacketRouter_Free(&o->router);
 }
 }
 
 
-int DataProtoFlow_Init (
-    DataProtoFlow *o, DataProtoSource *source, peerid_t source_id, peerid_t dest_id, int num_packets,
-    int inactivity_time, DataProtoFlow_handler_inactivity handler_inactivity, void *user
-)
+int DataProtoFlow_Init (DataProtoFlow *o, DataProtoSource *source, peerid_t source_id, peerid_t dest_id, int num_packets, int inactivity_time, void *user,
+                        DataProtoFlow_handler_inactivity handler_inactivity)
 {
 {
+    DebugObject_Access(&source->d_obj);
     ASSERT(num_packets > 0)
     ASSERT(num_packets > 0)
+    ASSERT(!(inactivity_time >= 0) || handler_inactivity)
     
     
     // init arguments
     // init arguments
     o->source = source;
     o->source = source;
@@ -428,7 +430,7 @@ int DataProtoFlow_Init (
         goto fail1;
         goto fail1;
     }
     }
     
     
-    // set no DataProto
+    // set no sink
     b->sink = NULL;
     b->sink = NULL;
     
     
     DebugCounter_Increment(&source->d_ctr);
     DebugCounter_Increment(&source->d_ctr);
@@ -449,8 +451,8 @@ void DataProtoFlow_Free (DataProtoFlow *o)
 {
 {
     DebugObject_Free(&o->d_obj);
     DebugObject_Free(&o->d_obj);
     DebugCounter_Decrement(&o->source->d_ctr);
     DebugCounter_Decrement(&o->source->d_ctr);
-    struct DataProtoFlow_buffer *b = o->b;
     ASSERT(!o->sink_desired)
     ASSERT(!o->sink_desired)
+    struct DataProtoFlow_buffer *b = o->b;
     
     
     if (b->sink) {
     if (b->sink) {
         if (PacketPassFairQueueFlow_IsBusy(&b->sink_qflow)) {
         if (PacketPassFairQueueFlow_IsBusy(&b->sink_qflow)) {
@@ -491,9 +493,8 @@ void DataProtoFlow_Route (DataProtoFlow *o, int more)
     
     
     // route
     // route
     uint8_t *next_buf;
     uint8_t *next_buf;
-    if (!PacketRouter_Route(
-        &o->source->router, DATAPROTO_MAX_OVERHEAD + o->source->current_recv_len, &b->rbuf,
-        &next_buf, DATAPROTO_MAX_OVERHEAD, (more ? o->source->current_recv_len : 0)
+    if (!PacketRouter_Route(&o->source->router, DATAPROTO_MAX_OVERHEAD + o->source->current_recv_len, &b->rbuf,
+                            &next_buf, DATAPROTO_MAX_OVERHEAD, (more ? o->source->current_recv_len : 0)
     )) {
     )) {
         BLog(BLOG_NOTICE, "buffer full: %d->%d", (int)o->source_id, (int)o->dest_id);
         BLog(BLOG_NOTICE, "buffer full: %d->%d", (int)o->source_id, (int)o->dest_id);
         return;
         return;

+ 3 - 5
client/DataProto.h

@@ -182,14 +182,12 @@ void DataProtoSource_Free (DataProtoSource *o);
  *                        inactivity handler; <0 to disable. Note that the flow is considered
  *                        inactivity handler; <0 to disable. Note that the flow is considered
  *                        active as long as its buffer is non-empty, even if is not attached to
  *                        active as long as its buffer is non-empty, even if is not attached to
  *                        a {@link DataProtoSink}.
  *                        a {@link DataProtoSink}.
- * @param handler_inactivity inactivity handler, if inactivity_time >=0
  * @param user value to pass to handler
  * @param user value to pass to handler
+ * @param handler_inactivity inactivity handler, if inactivity_time >=0
  * @return 1 on success, 0 on failure
  * @return 1 on success, 0 on failure
  */
  */
-int DataProtoFlow_Init (
-    DataProtoFlow *o, DataProtoSource *source, peerid_t source_id, peerid_t dest_id, int num_packets,
-    int inactivity_time, DataProtoFlow_handler_inactivity handler_inactivity, void *user
-) WARN_UNUSED;
+int DataProtoFlow_Init (DataProtoFlow *o, DataProtoSource *source, peerid_t source_id, peerid_t dest_id, int num_packets, int inactivity_time, void *user,
+                        DataProtoFlow_handler_inactivity handler_inactivity) WARN_UNUSED;
 
 
 /**
 /**
  * Frees the flow.
  * Frees the flow.