소스 검색

DataProto: cosmetic changes

ambrop7 14 년 전
부모
커밋
9fd3c68ea6
2개의 변경된 파일28개의 추가작업 그리고 27개의 파일을 삭제
  1. 16 16
      client/DataProto.c
  2. 12 11
      client/DataProto.h

+ 16 - 16
client/DataProto.c

@@ -105,7 +105,7 @@ void up_job_handler (DataProtoSink *o)
     return;
 }
 
-void device_router_handler (DataProtoSource *o, uint8_t *buf, int recv_len)
+void source_router_handler (DataProtoSource *o, uint8_t *buf, int recv_len)
 {
     ASSERT(buf)
     ASSERT(recv_len >= 0)
@@ -364,7 +364,7 @@ int DataProtoSource_Init (DataProtoSource *o, PacketRecvInterface *input, DataPr
     o->frame_mtu = PacketRecvInterface_GetMTU(input);
     
     // init router
-    if (!PacketRouter_Init(&o->router, DATAPROTO_MAX_OVERHEAD + o->frame_mtu, DATAPROTO_MAX_OVERHEAD, input, (PacketRouter_handler)device_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))) {
         goto fail1;
     }
     
@@ -387,14 +387,14 @@ void DataProtoSource_Free (DataProtoSource *o)
 }
 
 int DataProtoFlow_Init (
-    DataProtoFlow *o, DataProtoSource *device, peerid_t source_id, peerid_t dest_id, int num_packets,
+    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
 )
 {
     ASSERT(num_packets > 0)
     
     // init arguments
-    o->device = device;
+    o->source = source;
     o->source_id = source_id;
     o->dest_id = dest_id;
     
@@ -416,17 +416,17 @@ int DataProtoFlow_Init (
     b->inactivity_time = inactivity_time;
     
     // init connector
-    PacketPassConnector_Init(&b->connector, DATAPROTO_MAX_OVERHEAD + device->frame_mtu, BReactor_PendingGroup(device->reactor));
+    PacketPassConnector_Init(&b->connector, DATAPROTO_MAX_OVERHEAD + source->frame_mtu, BReactor_PendingGroup(source->reactor));
     
     // init inactivity monitor
     PacketPassInterface *buf_out = PacketPassConnector_GetInput(&b->connector);
     if (b->inactivity_time >= 0) {
-        PacketPassInactivityMonitor_Init(&b->monitor, buf_out, device->reactor, b->inactivity_time, handler_inactivity, user);
+        PacketPassInactivityMonitor_Init(&b->monitor, buf_out, source->reactor, b->inactivity_time, handler_inactivity, user);
         buf_out = PacketPassInactivityMonitor_GetInput(&b->monitor);
     }
     
     // init route buffer
-    if (!RouteBuffer_Init(&b->rbuf, DATAPROTO_MAX_OVERHEAD + device->frame_mtu, buf_out, num_packets)) {
+    if (!RouteBuffer_Init(&b->rbuf, DATAPROTO_MAX_OVERHEAD + source->frame_mtu, buf_out, num_packets)) {
         BLog(BLOG_ERROR, "RouteBuffer_Init failed");
         goto fail1;
     }
@@ -435,7 +435,7 @@ int DataProtoFlow_Init (
     b->dp = NULL;
     
     DebugObject_Init(&o->d_obj);
-    DebugCounter_Increment(&device->d_ctr);
+    DebugCounter_Increment(&source->d_ctr);
     
     return 1;
     
@@ -453,7 +453,7 @@ void DataProtoFlow_Free (DataProtoFlow *o)
 {
     struct DataProtoFlow_buffer *b = o->b;
     ASSERT(!o->dp_desired)
-    DebugCounter_Decrement(&o->device->d_ctr);
+    DebugCounter_Decrement(&o->source->d_ctr);
     DebugObject_Free(&o->d_obj);
     
     if (b->dp) {
@@ -481,12 +481,12 @@ void DataProtoFlow_Route (DataProtoFlow *o, int more)
 {
     struct DataProtoFlow_buffer *b = o->b;
     ASSERT(more == 0 || more == 1)
-    PacketRouter_AssertRoute(&o->device->router);
-    ASSERT(o->device->current_buf)
+    PacketRouter_AssertRoute(&o->source->router);
+    ASSERT(o->source->current_buf)
     DebugObject_Access(&o->d_obj);
     
     // write header
-    struct dataproto_header *header = (struct dataproto_header *)o->device->current_buf;
+    struct dataproto_header *header = (struct dataproto_header *)o->source->current_buf;
     // don't set flags, it will be set in notifier_handler
     header->from_id = htol16(o->source_id);
     header->num_peer_ids = htol16(1);
@@ -496,14 +496,14 @@ void DataProtoFlow_Route (DataProtoFlow *o, int more)
     // route
     uint8_t *next_buf;
     if (!PacketRouter_Route(
-        &o->device->router, DATAPROTO_MAX_OVERHEAD + o->device->current_recv_len, &b->rbuf,
-        &next_buf, DATAPROTO_MAX_OVERHEAD, (more ? o->device->current_recv_len : 0)
+        &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);
         return;
     }
     
-    o->device->current_buf = (more ? next_buf : NULL);
+    o->source->current_buf = (more ? next_buf : NULL);
 }
 
 void DataProtoFlow_Attach (DataProtoFlow *o, DataProtoSink *dp)
@@ -511,7 +511,7 @@ void DataProtoFlow_Attach (DataProtoFlow *o, DataProtoSink *dp)
     struct DataProtoFlow_buffer *b = o->b;
     ASSERT(dp)
     ASSERT(!o->dp_desired)
-    ASSERT(o->device->frame_mtu <= dp->frame_mtu)
+    ASSERT(o->source->frame_mtu <= dp->frame_mtu)
     DebugObject_Access(&o->d_obj);
     DebugObject_Access(&dp->d_obj);
     

+ 12 - 11
client/DataProto.h

@@ -74,8 +74,8 @@ typedef struct {
 } DataProtoSink;
 
 /**
- * Object that receives frames from a device and routes
- * them to buffers in {@link DataProtoFlow} objects.
+ * Receives frames from a {@link PacketRecvInterface} input and
+ * allows the user to route them to buffers in {@link DataProtoFlow} objects.
  */
 typedef struct {
     DataProtoSource_handler handler;
@@ -90,11 +90,12 @@ typedef struct {
 } DataProtoSource;
 
 /**
- * Local frame source.
- * Buffers frames received from the TAP device, addressed to a particular peer.
+ * Contains a buffer for frames from a specific peer to a specific peer.
+ * Receives frames from a {@link DataProtoSource} as routed by the user.
+ * Can be attached to a {@link DataProtoSink} to send out frames.
  */
 typedef struct {
-    DataProtoSource *device;
+    DataProtoSource *source;
     peerid_t source_id;
     peerid_t dest_id;
     DataProtoSink *dp_desired;
@@ -150,8 +151,8 @@ void DataProtoSink_Received (DataProtoSink *o, int peer_receiving);
  * Initiazes the object.
  * 
  * @param o the object
- * @param input device input. Its input MTU must be <= INT_MAX - DATAPROTO_MAX_OVERHEAD.
- * @param handler handler called when a packet arrives to allow the user to route it to
+ * @param input frame input. Its input MTU must be <= INT_MAX - DATAPROTO_MAX_OVERHEAD.
+ * @param handler handler called when a frame arrives to allow the user to route it to
  *                appropriate {@link DataProtoFlow} objects.
  * @param user value passed to handler
  * @param reactor reactor we live in
@@ -161,7 +162,7 @@ int DataProtoSource_Init (DataProtoSource *o, PacketRecvInterface *input, DataPr
 
 /**
  * Frees the object.
- * There must be no {@link DataProtoFlow} objects referring to this device.
+ * There must be no {@link DataProtoFlow} objects using this source.
  * 
  * @param o the object
  */
@@ -172,7 +173,7 @@ void DataProtoSource_Free (DataProtoSource *o);
  * The object is initialized in not attached state.
  * 
  * @param o the object
- * @param device device to receive frames from
+ * @param source source to receive frames from
  * @param source_id source peer ID to encode in the headers (i.e. our ID)
  * @param dest_id destination peer ID to encode in the headers (i.e. ID if the peer this
  *                object belongs to)
@@ -186,7 +187,7 @@ void DataProtoSource_Free (DataProtoSource *o);
  * @return 1 on success, 0 on failure
  */
 int DataProtoFlow_Init (
-    DataProtoFlow *o, DataProtoSource *device, peerid_t source_id, peerid_t dest_id, int num_packets,
+    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;
 
@@ -199,7 +200,7 @@ int DataProtoFlow_Init (
 void DataProtoFlow_Free (DataProtoFlow *o);
 
 /**
- * Routes a frame from the device to this object.
+ * Routes a frame from the flow's source to this flow.
  * Must be called from within the job context of the {@link DataProtoSource_handler} handler.
  * Must not be called after this has been called with more=0 for the current frame.
  *