1 #ifndef _IPXE_PEERMUX_H
2 #define _IPXE_PEERMUX_H
3 
4 /** @file
5  *
6  * Peer Content Caching and Retrieval (PeerDist) protocol multiplexer
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 
12 #include <stdint.h>
13 #include <ipxe/list.h>
14 #include <ipxe/refcnt.h>
15 #include <ipxe/interface.h>
16 #include <ipxe/process.h>
17 #include <ipxe/uri.h>
18 #include <ipxe/xferbuf.h>
19 #include <ipxe/pccrc.h>
20 
21 /** Maximum number of concurrent block downloads */
22 #define PEERMUX_MAX_BLOCKS 32
23 
24 /** PeerDist download content information cache */
25 struct peerdist_info_cache {
26 	/** Content information */
27 	struct peerdist_info info;
28 	/** Content information segment */
29 	struct peerdist_info_segment segment;
30 	/** Content information block */
31 	struct peerdist_info_block block;
32 };
33 
34 /** A PeerDist multiplexed block download */
35 struct peerdist_multiplexed_block {
36 	/** PeerDist download multiplexer */
37 	struct peerdist_multiplexer *peermux;
38 	/** List of multiplexed blocks */
39 	struct list_head list;
40 	/** Data transfer interface */
41 	struct interface xfer;
42 };
43 
44 /** PeerDist statistics */
45 struct peerdist_statistics {
46 	/** Maximum observed number of peers */
47 	unsigned int peers;
48 	/** Number of blocks downloaded in total */
49 	unsigned int total;
50 	/** Number of blocks downloaded from peers */
51 	unsigned int local;
52 };
53 
54 /** A PeerDist download multiplexer */
55 struct peerdist_multiplexer {
56 	/** Reference count */
57 	struct refcnt refcnt;
58 	/** Data transfer interface */
59 	struct interface xfer;
60 	/** Content information interface */
61 	struct interface info;
62 	/** Original URI */
63 	struct uri *uri;
64 
65 	/** Content information data transfer buffer */
66 	struct xfer_buffer buffer;
67 	/** Content information cache */
68 	struct peerdist_info_cache cache;
69 
70 	/** Block download initiation process */
71 	struct process process;
72 	/** List of busy block downloads */
73 	struct list_head busy;
74 	/** List of idle block downloads */
75 	struct list_head idle;
76 	/** Block downloads */
77 	struct peerdist_multiplexed_block block[PEERMUX_MAX_BLOCKS];
78 
79 	/** Statistics */
80 	struct peerdist_statistics stats;
81 };
82 
83 extern int peermux_filter ( struct interface *xfer, struct interface *info,
84 			    struct uri *uri );
85 
86 #endif /* _IPXE_PEERMUX_H */
87