|
@@ -24,9 +24,11 @@
|
24
|
24
|
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
25
|
25
|
|
26
|
26
|
#include <stdlib.h>
|
|
27
|
+#include <stdio.h>
|
27
|
28
|
#include <errno.h>
|
28
|
29
|
#include <ipxe/uri.h>
|
29
|
30
|
#include <ipxe/xferbuf.h>
|
|
31
|
+#include <ipxe/job.h>
|
30
|
32
|
#include <ipxe/peerblk.h>
|
31
|
33
|
#include <ipxe/peermux.h>
|
32
|
34
|
|
|
@@ -74,6 +76,28 @@ static void peermux_close ( struct peerdist_multiplexer *peermux, int rc ) {
|
74
|
76
|
intf_shutdown ( &peermux->info, rc );
|
75
|
77
|
}
|
76
|
78
|
|
|
79
|
+/**
|
|
80
|
+ * Report progress of PeerDist download
|
|
81
|
+ *
|
|
82
|
+ * @v peermux PeerDist download multiplexer
|
|
83
|
+ * @v progress Progress report to fill in
|
|
84
|
+ * @ret ongoing_rc Ongoing job status code (if known)
|
|
85
|
+ */
|
|
86
|
+static int peermux_progress ( struct peerdist_multiplexer *peermux,
|
|
87
|
+ struct job_progress *progress ) {
|
|
88
|
+ struct peerdist_statistics *stats = &peermux->stats;
|
|
89
|
+ unsigned int percentage;
|
|
90
|
+
|
|
91
|
+ /* Construct PeerDist status message */
|
|
92
|
+ if ( stats->total ) {
|
|
93
|
+ percentage = ( ( 100 * stats->local ) / stats->total );
|
|
94
|
+ snprintf ( progress->message, sizeof ( progress->message ),
|
|
95
|
+ "%3d%% from %d peers", percentage, stats->peers );
|
|
96
|
+ }
|
|
97
|
+
|
|
98
|
+ return 0;
|
|
99
|
+}
|
|
100
|
+
|
77
|
101
|
/**
|
78
|
102
|
* Receive content information
|
79
|
103
|
*
|
|
@@ -274,6 +298,35 @@ peermux_block_buffer ( struct peerdist_multiplexed_block *peermblk ) {
|
274
|
298
|
return xfer_buffer ( &peermux->xfer );
|
275
|
299
|
}
|
276
|
300
|
|
|
301
|
+/**
|
|
302
|
+ * Record peer discovery statistics
|
|
303
|
+ *
|
|
304
|
+ * @v peermblk PeerDist multiplexed block download
|
|
305
|
+ * @v peer Selected peer (or NULL)
|
|
306
|
+ * @v peers List of available peers
|
|
307
|
+ */
|
|
308
|
+static void peermux_block_stat ( struct peerdist_multiplexed_block *peermblk,
|
|
309
|
+ struct peerdisc_peer *peer,
|
|
310
|
+ struct list_head *peers ) {
|
|
311
|
+ struct peerdist_multiplexer *peermux = peermblk->peermux;
|
|
312
|
+ struct peerdist_statistics *stats = &peermux->stats;
|
|
313
|
+ struct peerdisc_peer *tmp;
|
|
314
|
+ unsigned int count = 0;
|
|
315
|
+
|
|
316
|
+ /* Record maximum number of available peers */
|
|
317
|
+ list_for_each_entry ( tmp, peers, list )
|
|
318
|
+ count++;
|
|
319
|
+ if ( count > stats->peers )
|
|
320
|
+ stats->peers = count;
|
|
321
|
+
|
|
322
|
+ /* Update block counts */
|
|
323
|
+ if ( peer )
|
|
324
|
+ stats->local++;
|
|
325
|
+ stats->total++;
|
|
326
|
+ DBGC2 ( peermux, "PEERMUX %p downloaded %d/%d from %d peers\n",
|
|
327
|
+ peermux, stats->local, stats->total, stats->peers );
|
|
328
|
+}
|
|
329
|
+
|
277
|
330
|
/**
|
278
|
331
|
* Close multiplexed block download
|
279
|
332
|
*
|
|
@@ -303,6 +356,8 @@ static void peermux_block_close ( struct peerdist_multiplexed_block *peermblk,
|
303
|
356
|
|
304
|
357
|
/** Data transfer interface operations */
|
305
|
358
|
static struct interface_operation peermux_xfer_operations[] = {
|
|
359
|
+ INTF_OP ( job_progress, struct peerdist_multiplexer *,
|
|
360
|
+ peermux_progress ),
|
306
|
361
|
INTF_OP ( intf_close, struct peerdist_multiplexer *, peermux_close ),
|
307
|
362
|
};
|
308
|
363
|
|
|
@@ -330,6 +385,8 @@ static struct interface_operation peermux_block_operations[] = {
|
330
|
385
|
peermux_block_deliver ),
|
331
|
386
|
INTF_OP ( xfer_buffer, struct peerdist_multiplexed_block *,
|
332
|
387
|
peermux_block_buffer ),
|
|
388
|
+ INTF_OP ( peerdisc_stat, struct peerdist_multiplexed_block *,
|
|
389
|
+ peermux_block_stat ),
|
333
|
390
|
INTF_OP ( intf_close, struct peerdist_multiplexed_block *,
|
334
|
391
|
peermux_block_close ),
|
335
|
392
|
};
|