Hi,

So this is patch 13 :-)

This fixes the segfault when upload_slots = 0. It does not refuse the
download, instead it is scheduled with an ETA for a long long long time.

This patch should also be more fair with the upload slots in general
when there are multiple queues.

I haven't gotten the time to test it myself for a long time. So please
apply the patch only if you have the time to test the patch yourself, or
if you have sharing disabled.

- Jeroen


Index: src/parq.c
===================================================================
RCS file: /cvsroot/gtk-gnutella/gtk-gnutella-current/src/parq.c,v
retrieving revision 1.11
diff -u -r1.11 parq.c
--- src/parq.c	26 Mar 2003 21:01:58 -0000	1.11
+++ src/parq.c	27 Mar 2003 19:56:48 -0000
@@ -534,6 +534,8 @@
 	g_assert(parq_ul->queue->size > 0);
 	g_assert(parq_ul->queue->by_Position != NULL);
 	
+	parq_upload_decrease_all_after(parq_ul);	
+
 	/* Remove the current queued item from all lists */
 	parq_ul->queue->by_Position = 
 		g_list_remove(parq_ul->queue->by_Position, parq_ul);
@@ -603,7 +605,10 @@
 			 * is unknown.
 			 * Pessimistic: 1 bytes / sec
 			 */
-			ETA += parq_ul_prev->file_size / max_uploads;
+			if (max_uploads > 0)
+				ETA += parq_ul_prev->file_size / max_uploads;
+			else
+				ETA = (guint) -1;
 		}
 	}
 	
@@ -684,6 +689,9 @@
 	}
 	
 	queue = (struct parq_ul_queue *) g_list_nth_data(ul_parqs, slot - 1);
+
+	/* We might need to reactivate the queue */
+	queue->active = TRUE;
 	
 	g_assert(queue != NULL);
 	g_assert(queue->active == TRUE);
@@ -767,14 +775,17 @@
 
 		parq_ul->ETA = ETA;
 		
-		/* Recalculate ETA */
-		if (bw_http_out != 0 && bws_out_enabled) {
-			ETA += parq_ul->file_size / (bw_http_out / max_uploads);
-		} else {
-			// FIXME, should use average bandwith here
-			/* Pessimistic: 1 bytes / sec */
-			ETA += parq_ul->file_size;
-		}
+		if (max_uploads > 0) {
+			/* Recalculate ETA */
+			if (bw_http_out != 0 && bws_out_enabled) {
+				ETA += parq_ul->file_size / (bw_http_out / max_uploads);
+			} else {
+				// FIXME, should use average bandwith here
+				/* Pessimistic: 1 bytes / sec */
+				ETA += parq_ul->file_size;
+			}
+		} else
+			ETA = (guint) -1;
 	}
 }
 
@@ -872,9 +883,6 @@
 	for (sl = remove; sl != NULL; sl = sl->next) {
 		struct parq_ul_queued *parq_ul = (struct parq_ul_queued *) sl->data;
 
-		/* Move uploads after the current upload up one slot */
-		parq_upload_decrease_all_after(parq_ul);
-	
 		parq_upload_free(parq_ul);
 	}
 	
@@ -966,8 +974,8 @@
 static gboolean parq_upload_continue(struct parq_ul_queued *uq, gint free_slots)
 {
 	GList *l = NULL;
-	guint needed = 0;
-
+	int pos;
+	
 	g_assert(uq != NULL);
 		
 	/*
@@ -996,30 +1004,20 @@
 	}
 	 */
 	
-	/*
-	 * If the current position = 1 and the current queue hasn't already an item
-	 * uploading than the upload is allowed by default.
-	 */
-	if (uq->position == 1 && uq->queue->active_uploads == 0)
-		return TRUE;
+	for (pos = 1; pos <= max_uploads; pos++) {
+		for (l = g_list_last(ul_parqs); l; l = l->prev) {
+			struct parq_ul_queue *queue = (struct parq_ul_queue *) l->data;
+
+			if (uq->position == pos)
+				return TRUE;
 	
-	/* If position is zero the download is already downloading */
-	g_assert(uq->position != 0);
-		
-	/* See wether the other queues are allowed to get an upload position */
-	for (l = ul_parqs; l ; l = l->next) {
-		struct parq_ul_queue *queue = (struct parq_ul_queue *) l->data;
-		
-		printf("PARQ UL: Q %d/%d Active: %d\n\r", 
-				g_list_position(ul_parqs, g_list_find(ul_parqs, queue)) + 1,
-				g_list_length(ul_parqs),
-				queue->active_uploads);
+			if (queue->active_uploads < pos && queue->size >= pos)
+				return FALSE;
+		}
 		
-		if (queue->size > 1 && queue->active_uploads == 0)
-			needed++;
-	}
 		
-	return needed < free_slots;
+ 	}
+ 	return FALSE;
 }
 
 /*
@@ -1190,12 +1188,10 @@
 
 	u->parq_status = 0;			// XXX -- get rid of `parq_status'?
 	
-	if (parq_ul->position == 0)
+	if (parq_ul->position <= parq_ul->queue->active_uploads)
 		return;
 	
 	parq_ul->queue->active_uploads++;
-	parq_ul->position = 0;	// Mark as uploading
-	parq_upload_decrease_all_after(parq_ul);	
 }
 
 void parq_upload_add(gnutella_upload_t *u)
@@ -1234,7 +1230,8 @@
 	if (parq_ul == NULL)
 		return;
 
-	if (parq_ul->position == 0 && u->keep_alive && u->status == GTA_UL_WAITING) {
+	if (parq_ul->position <= parq_ul->queue->active_uploads
+		  && u->keep_alive && u->status == GTA_UL_WAITING) {
 		printf("**** PARQ UL Q %d/%d: Not removed, waiting for new request\r\n",
 			g_list_position(ul_parqs, 
 				g_list_find(ul_parqs, parq_ul->queue)) + 1,
@@ -1249,10 +1246,8 @@
 			g_list_length(ul_parqs));
 				
 	
-	if (parq_ul->position == 0)
+	if (parq_ul->position <= parq_ul->queue->active_uploads)
 		parq_ul->queue->active_uploads--;
-	else
-		parq_upload_decrease_all_after(parq_ul);
 	
 	g_assert(parq_ul->queue->active_uploads >= 0);
 	
@@ -1438,14 +1433,9 @@
 
 		g_assert(parq_ul != NULL);
 		
-		/* 
-		 * Don't decrease queued position which already have an upload position
-		 */
-		if (parq_ul->position > 0) {
-			parq_ul->position--;
+		parq_ul->position--;
 		
-			g_assert(parq_ul->position > 0);
-		}
+		g_assert(parq_ul->position > 0);
 	}
 }
 

Reply via email to