iPXE
Functions | Variables
peermux.c File Reference

Peer Content Caching and Retrieval (PeerDist) protocol multiplexer. More...

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <ipxe/uri.h>
#include <ipxe/xferbuf.h>
#include <ipxe/job.h>
#include <ipxe/peerblk.h>
#include <ipxe/peermux.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static void peermux_free (struct refcnt *refcnt)
 Free PeerDist download multiplexer. More...
 
static void peermux_close (struct peerdist_multiplexer *peermux, int rc)
 Close PeerDist download multiplexer. More...
 
static int peermux_progress (struct peerdist_multiplexer *peermux, struct job_progress *progress)
 Report progress of PeerDist download. More...
 
static int peermux_info_deliver (struct peerdist_multiplexer *peermux, struct io_buffer *iobuf, struct xfer_metadata *meta)
 Receive content information. More...
 
static void peermux_info_close (struct peerdist_multiplexer *peermux, int rc)
 Close content information interface. More...
 
static void peermux_step (struct peerdist_multiplexer *peermux)
 Initiate multiplexed block download. More...
 
static int peermux_block_deliver (struct peerdist_multiplexed_block *peermblk, struct io_buffer *iobuf, struct xfer_metadata *meta)
 Receive data from multiplexed block download. More...
 
static struct xfer_bufferpeermux_block_buffer (struct peerdist_multiplexed_block *peermblk)
 Get multiplexed block download underlying data transfer buffer. More...
 
static void peermux_block_stat (struct peerdist_multiplexed_block *peermblk, struct peerdisc_peer *peer, struct list_head *peers)
 Record peer discovery statistics. More...
 
static void peermux_block_close (struct peerdist_multiplexed_block *peermblk, int rc)
 Close multiplexed block download. More...
 
int peermux_filter (struct interface *xfer, struct interface *info, struct uri *uri)
 Add PeerDist content-encoding filter. More...
 

Variables

static struct interface_operation peermux_xfer_operations []
 Data transfer interface operations. More...
 
static struct interface_descriptor peermux_xfer_desc
 Data transfer interface descriptor. More...
 
static struct interface_operation peermux_info_operations []
 Content information interface operations. More...
 
static struct interface_descriptor peermux_info_desc
 Content information interface descriptor. More...
 
static struct interface_operation peermux_block_operations []
 Block download data transfer interface operations. More...
 
static struct interface_descriptor peermux_block_desc
 Block download data transfer interface descriptor. More...
 
static struct process_descriptor peermux_process_desc
 Block download initiation process descriptor. More...
 

Detailed Description

Peer Content Caching and Retrieval (PeerDist) protocol multiplexer.

Definition in file peermux.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ peermux_free()

static void peermux_free ( struct refcnt refcnt)
static

Free PeerDist download multiplexer.

Parameters
refcntReference count

Definition at line 47 of file peermux.c.

47  {
48  struct peerdist_multiplexer *peermux =
50 
51  uri_put ( peermux->uri );
52  xferbuf_free ( &peermux->buffer );
53  free ( peermux );
54 }
static void uri_put(struct uri *uri)
Decrement URI reference count.
Definition: uri.h:205
void xferbuf_free(struct xfer_buffer *xferbuf)
Free data transfer buffer.
Definition: xferbuf.c:73
A reference counter.
Definition: refcnt.h:26
A PeerDist download multiplexer.
Definition: peermux.h:55
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
struct xfer_buffer buffer
Content information data transfer buffer.
Definition: peermux.h:66
struct uri * uri
Original URI.
Definition: peermux.h:63

References peerdist_multiplexer::buffer, container_of, free, peerdist_multiplexer::uri, uri_put(), and xferbuf_free().

Referenced by peermux_filter().

◆ peermux_close()

static void peermux_close ( struct peerdist_multiplexer peermux,
int  rc 
)
static

Close PeerDist download multiplexer.

Parameters
peermuxPeerDist download multiplexer
rcReason for close

Definition at line 62 of file peermux.c.

62  {
63  unsigned int i;
64 
65  /* Stop block download initiation process */
66  process_del ( &peermux->process );
67 
68  /* Shut down all block downloads */
69  for ( i = 0 ; i < PEERMUX_MAX_BLOCKS ; i++ )
70  intf_shutdown ( &peermux->block[i].xfer, rc );
71 
72  /* Shut down all other interfaces (which may be connected to
73  * the same object).
74  */
75  intf_nullify ( &peermux->info ); /* avoid potential loops */
76  intf_shutdown ( &peermux->xfer, rc );
77  intf_shutdown ( &peermux->info, rc );
78 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void intf_shutdown(struct interface *intf, int rc)
Shut down an object interface.
Definition: interface.c:278
void process_del(struct process *process)
Remove process from process list.
Definition: process.c:79
struct process process
Block download initiation process.
Definition: peermux.h:71
struct peerdist_multiplexed_block block[PEERMUX_MAX_BLOCKS]
Block downloads.
Definition: peermux.h:77
struct interface xfer
Data transfer interface.
Definition: peermux.h:41
void intf_nullify(struct interface *intf)
Ignore all further operations on an object interface.
Definition: interface.c:129
struct interface xfer
Data transfer interface.
Definition: peermux.h:59
#define PEERMUX_MAX_BLOCKS
Maximum number of concurrent block downloads.
Definition: peermux.h:22
struct interface info
Content information interface.
Definition: peermux.h:61

References peerdist_multiplexer::block, peerdist_multiplexer::info, intf_nullify(), intf_shutdown(), PEERMUX_MAX_BLOCKS, peerdist_multiplexer::process, process_del(), rc, peerdist_multiplexed_block::xfer, and peerdist_multiplexer::xfer.

Referenced by peermux_block_close(), peermux_info_close(), peermux_info_deliver(), and peermux_step().

◆ peermux_progress()

static int peermux_progress ( struct peerdist_multiplexer peermux,
struct job_progress progress 
)
static

Report progress of PeerDist download.

Parameters
peermuxPeerDist download multiplexer
progressProgress report to fill in
Return values
ongoing_rcOngoing job status code (if known)

Definition at line 87 of file peermux.c.

88  {
89  struct peerdist_statistics *stats = &peermux->stats;
90  unsigned int percentage;
91 
92  /* Construct PeerDist status message */
93  if ( stats->total ) {
94  percentage = ( ( 100 * stats->local ) / stats->total );
95  snprintf ( progress->message, sizeof ( progress->message ),
96  "%3d%% from %d peers", percentage, stats->peers );
97  }
98 
99  return 0;
100 }
PeerDist statistics.
Definition: peermux.h:45
unsigned int peers
Maximum observed number of peers.
Definition: peermux.h:47
unsigned int total
Number of blocks downloaded in total.
Definition: peermux.h:49
char message[32]
Message (optional)
Definition: job.h:32
struct peerdist_statistics stats
Statistics.
Definition: peermux.h:80
unsigned int local
Number of blocks downloaded from peers.
Definition: peermux.h:51
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382

References peerdist_statistics::local, job_progress::message, peerdist_statistics::peers, snprintf(), peerdist_multiplexer::stats, and peerdist_statistics::total.

◆ peermux_info_deliver()

static int peermux_info_deliver ( struct peerdist_multiplexer peermux,
struct io_buffer iobuf,
struct xfer_metadata meta 
)
static

Receive content information.

Parameters
peermuxPeerDist download multiplexer
iobufI/O buffer
metaData transfer metadata
Return values
rcReturn status code

Definition at line 110 of file peermux.c.

112  {
113  int rc;
114 
115  /* Add data to buffer */
116  if ( ( rc = xferbuf_deliver ( &peermux->buffer, iobuf, meta ) ) != 0 )
117  goto err;
118 
119  return 0;
120 
121  err:
122  peermux_close ( peermux, rc );
123  return rc;
124 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int xferbuf_deliver(struct xfer_buffer *xferbuf, struct io_buffer *iobuf, struct xfer_metadata *meta)
Add received data to data transfer buffer.
Definition: xferbuf.c:174
static void peermux_close(struct peerdist_multiplexer *peermux, int rc)
Close PeerDist download multiplexer.
Definition: peermux.c:62
struct xfer_buffer buffer
Content information data transfer buffer.
Definition: peermux.h:66
uint8_t meta
Metadata flags.
Definition: ena.h:14

References peerdist_multiplexer::buffer, meta, peermux_close(), rc, and xferbuf_deliver().

◆ peermux_info_close()

static void peermux_info_close ( struct peerdist_multiplexer peermux,
int  rc 
)
static

Close content information interface.

Parameters
peermuxPeerDist download multiplexer
rcReason for close

Definition at line 132 of file peermux.c.

132  {
133  struct xfer_buffer *buffer = &peermux->buffer;
134  struct peerdist_info *info = &peermux->cache.info;
135  size_t len;
136 
137  /* Terminate download on error */
138  if ( rc != 0 )
139  goto err;
140 
141  /* Successfully closing the content information interface
142  * indicates that the content information has been fully
143  * received, and initiates the actual PeerDist download.
144  */
145 
146  /* Shut down content information interface */
147  intf_shutdown ( &peermux->info, rc );
148 
149  /* Parse content information */
150  if ( ( rc = peerdist_info ( buffer->data, buffer->len, info ) ) != 0 ) {
151  DBGC ( peermux, "PEERMUX %p could not parse content info: %s\n",
152  peermux, strerror ( rc ) );
153  goto err;
154  }
155 
156  /* Notify recipient of total download size */
157  len = ( info->trim.end - info->trim.start );
158  if ( ( rc = xfer_seek ( &peermux->xfer, len ) ) != 0 ) {
159  DBGC ( peermux, "PEERMUX %p could not presize buffer: %s\n",
160  peermux, strerror ( rc ) );
161  goto err;
162  }
163  xfer_seek ( &peermux->xfer, 0 );
164 
165  /* Start block download process */
166  process_add ( &peermux->process );
167 
168  return;
169 
170  err:
171  peermux_close ( peermux, rc );
172 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void intf_shutdown(struct interface *intf, int rc)
Shut down an object interface.
Definition: interface.c:278
u32 info
Definition: ar9003_mac.h:67
A data transfer buffer.
Definition: xferbuf.h:18
#define DBGC(...)
Definition: compiler.h:505
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition: netvsc.h:16
struct peerdist_info_cache cache
Content information cache.
Definition: peermux.h:68
static void peermux_close(struct peerdist_multiplexer *peermux, int rc)
Close PeerDist download multiplexer.
Definition: peermux.c:62
struct process process
Block download initiation process.
Definition: peermux.h:71
ring len
Length.
Definition: dwmac.h:231
Content information.
Definition: pccrc.h:316
int xfer_seek(struct interface *intf, off_t offset)
Seek to position.
Definition: xfer.c:351
void process_add(struct process *process)
Add process to process list.
Definition: process.c:59
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
struct interface xfer
Data transfer interface.
Definition: peermux.h:59
struct xfer_buffer buffer
Content information data transfer buffer.
Definition: peermux.h:66
struct interface info
Content information interface.
Definition: peermux.h:61
struct peerdist_info info
Content information.
Definition: peermux.h:27

References buffer, peerdist_multiplexer::buffer, peerdist_multiplexer::cache, DBGC, peerdist_multiplexer::info, info, peerdist_info_cache::info, intf_shutdown(), len, peermux_close(), peerdist_multiplexer::process, process_add(), rc, strerror(), peerdist_multiplexer::xfer, and xfer_seek().

◆ peermux_step()

static void peermux_step ( struct peerdist_multiplexer peermux)
static

Initiate multiplexed block download.

Parameters
peermuxPeerDist download multiplexer

Definition at line 179 of file peermux.c.

179  {
180  struct peerdist_info *info = &peermux->cache.info;
181  struct peerdist_info_segment *segment = &peermux->cache.segment;
182  struct peerdist_info_block *block = &peermux->cache.block;
183  struct peerdist_multiplexed_block *peermblk;
184  unsigned int next_segment;
185  unsigned int next_block;
186  int rc;
187 
188  /* Stop initiation process if all block downloads are busy */
189  peermblk = list_first_entry ( &peermux->idle,
191  if ( ! peermblk ) {
193  return;
194  }
195 
196  /* Increment block index */
197  next_block = ( block->index + 1 );
198 
199  /* Move to first/next segment, if applicable */
200  if ( next_block >= segment->blocks ) {
201 
202  /* Reset block index */
203  next_block = 0;
204 
205  /* Calculate segment index */
206  next_segment = ( segment->info ? ( segment->index + 1 ) : 0 );
207 
208  /* If we have finished all segments and have no
209  * remaining block downloads, then we are finished.
210  */
211  if ( next_segment >= info->segments ) {
213  if ( list_empty ( &peermux->busy ) )
214  peermux_close ( peermux, 0 );
215  return;
216  }
217 
218  /* Get content information segment */
219  if ( ( rc = peerdist_info_segment ( info, segment,
220  next_segment ) ) != 0 ) {
221  DBGC ( peermux, "PEERMUX %p could not get segment %d "
222  "information: %s\n", peermux, next_segment,
223  strerror ( rc ) );
224  goto err;
225  }
226  }
227 
228  /* Get content information block */
229  if ( ( rc = peerdist_info_block ( segment, block, next_block ) ) != 0 ){
230  DBGC ( peermux, "PEERMUX %p could not get segment %d block "
231  "%d information: %s\n", peermux, segment->index,
232  next_block, strerror ( rc ) );
233  goto err;
234  }
235 
236  /* Ignore block if it lies entirely outside the trimmed range */
237  if ( block->trim.start == block->trim.end ) {
238  DBGC ( peermux, "PEERMUX %p skipping segment %d block %d\n",
239  peermux, segment->index, block->index );
240  return;
241  }
242 
243  /* Start downloading this block */
244  if ( ( rc = peerblk_open ( &peermblk->xfer, peermux->uri,
245  block ) ) != 0 ) {
246  DBGC ( peermux, "PEERMUX %p could not start download for "
247  "segment %d block %d: %s\n", peermux, segment->index,
248  block->index, strerror ( rc ) );
249  goto err;
250  }
251 
252  /* Move to list of busy block downloads */
253  list_del ( &peermblk->list );
254  list_add_tail ( &peermblk->list, &peermux->busy );
255 
256  return;
257 
258  err:
259  peermux_close ( peermux, rc );
260 }
uint16_t segment
Code segment.
Definition: librm.h:138
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
u32 info
Definition: ar9003_mac.h:67
A content information segment.
Definition: pccrc.h:346
#define DBGC(...)
Definition: compiler.h:505
int peerblk_open(struct interface *xfer, struct uri *uri, struct peerdist_info_block *block)
Open PeerDist block download.
Definition: peerblk.c:1433
A PeerDist multiplexed block download.
Definition: peermux.h:35
void process_del(struct process *process)
Remove process from process list.
Definition: process.c:79
struct peerdist_info_cache cache
Content information cache.
Definition: peermux.h:68
struct peerdist_multiplexer * peermux
PeerDist download multiplexer.
Definition: peermux.h:37
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:136
#define list_first_entry(list, type, member)
Get the container of the first entry in a list.
Definition: list.h:333
A content information block.
Definition: pccrc.h:393
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
static void peermux_close(struct peerdist_multiplexer *peermux, int rc)
Close PeerDist download multiplexer.
Definition: peermux.c:62
struct process process
Block download initiation process.
Definition: peermux.h:71
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:93
Content information.
Definition: pccrc.h:316
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
struct list_head list
List of multiplexed blocks.
Definition: peermux.h:39
struct peerdist_info_block block
Content information block.
Definition: peermux.h:31
struct interface xfer
Data transfer interface.
Definition: peermux.h:41
struct list_head idle
List of idle block downloads.
Definition: peermux.h:75
uint8_t block[3][8]
DES-encrypted blocks.
Definition: mschapv2.h:12
struct peerdist_info_segment segment
Content information segment.
Definition: peermux.h:29
struct list_head busy
List of busy block downloads.
Definition: peermux.h:73
struct uri * uri
Original URI.
Definition: peermux.h:63
struct peerdist_info info
Content information.
Definition: peermux.h:27

References block, peerdist_info_cache::block, peerdist_multiplexer::busy, peerdist_multiplexer::cache, DBGC, peerdist_multiplexer::idle, info, peerdist_info_cache::info, peerdist_multiplexed_block::list, list_add_tail, list_del, list_empty, list_first_entry, peerblk_open(), peerdist_multiplexed_block::peermux, peermux_close(), peerdist_multiplexer::process, process_del(), rc, peerdist_info_cache::segment, segment, strerror(), peerdist_multiplexer::uri, and peerdist_multiplexed_block::xfer.

◆ peermux_block_deliver()

static int peermux_block_deliver ( struct peerdist_multiplexed_block peermblk,
struct io_buffer iobuf,
struct xfer_metadata meta 
)
static

Receive data from multiplexed block download.

Parameters
peermblkPeerDist multiplexed block download
iobufI/O buffer
metaData transfer metadata
Return values
rcReturn status code

Definition at line 270 of file peermux.c.

272  {
273  struct peerdist_multiplexer *peermux = peermblk->peermux;
274 
275  /* Sanity check: all block downloads must use absolute
276  * positions for all deliveries, since they run concurrently.
277  */
278  assert ( meta->flags & XFER_FL_ABS_OFFSET );
279 
280  /* We can't use a simple passthrough interface descriptor,
281  * since there are multiple block download interfaces.
282  */
283  return xfer_deliver ( &peermux->xfer, iob_disown ( iobuf ), meta );
284 }
#define XFER_FL_ABS_OFFSET
Offset is absolute.
Definition: xfer.h:47
struct peerdist_multiplexer * peermux
PeerDist download multiplexer.
Definition: peermux.h:37
A PeerDist download multiplexer.
Definition: peermux.h:55
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:216
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
int xfer_deliver(struct interface *intf, struct io_buffer *iobuf, struct xfer_metadata *meta)
Deliver datagram.
Definition: xfer.c:194
struct interface xfer
Data transfer interface.
Definition: peermux.h:59
uint8_t meta
Metadata flags.
Definition: ena.h:14

References assert(), iob_disown, meta, peerdist_multiplexed_block::peermux, peerdist_multiplexer::xfer, xfer_deliver(), and XFER_FL_ABS_OFFSET.

◆ peermux_block_buffer()

static struct xfer_buffer* peermux_block_buffer ( struct peerdist_multiplexed_block peermblk)
static

Get multiplexed block download underlying data transfer buffer.

Parameters
peermblkPeerDist multiplexed download block
Return values
xferbufData transfer buffer, or NULL on error

Definition at line 293 of file peermux.c.

293  {
294  struct peerdist_multiplexer *peermux = peermblk->peermux;
295 
296  /* We can't use a simple passthrough interface descriptor,
297  * since there are multiple block download interfaces.
298  */
299  return xfer_buffer ( &peermux->xfer );
300 }
struct peerdist_multiplexer * peermux
PeerDist download multiplexer.
Definition: peermux.h:37
A PeerDist download multiplexer.
Definition: peermux.h:55
struct xfer_buffer * xfer_buffer(struct interface *intf)
Get underlying data transfer buffer.
Definition: xferbuf.c:305
struct interface xfer
Data transfer interface.
Definition: peermux.h:59

References peerdist_multiplexed_block::peermux, peerdist_multiplexer::xfer, and xfer_buffer().

◆ peermux_block_stat()

static void peermux_block_stat ( struct peerdist_multiplexed_block peermblk,
struct peerdisc_peer peer,
struct list_head peers 
)
static

Record peer discovery statistics.

Parameters
peermblkPeerDist multiplexed block download
peerSelected peer (or NULL)
peersList of available peers

Definition at line 309 of file peermux.c.

311  {
312  struct peerdist_multiplexer *peermux = peermblk->peermux;
313  struct peerdist_statistics *stats = &peermux->stats;
314  struct peerdisc_peer *tmp;
315  unsigned int count = 0;
316 
317  /* Record maximum number of available peers */
318  list_for_each_entry ( tmp, peers, list )
319  count++;
320  if ( count > stats->peers )
321  stats->peers = count;
322 
323  /* Update block counts */
324  if ( peer )
325  stats->local++;
326  stats->total++;
327  DBGC2 ( peermux, "PEERMUX %p downloaded %d/%d from %d peers\n",
328  peermux, stats->local, stats->total, stats->peers );
329 }
PeerDist statistics.
Definition: peermux.h:45
unsigned int peers
Maximum observed number of peers.
Definition: peermux.h:47
struct peerdist_multiplexer * peermux
PeerDist download multiplexer.
Definition: peermux.h:37
unsigned long tmp
Definition: linux_pci.h:64
A PeerDist download multiplexer.
Definition: peermux.h:55
unsigned int total
Number of blocks downloaded in total.
Definition: peermux.h:49
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:431
static unsigned int count
Number of entries.
Definition: dwmac.h:225
struct peerdist_statistics stats
Statistics.
Definition: peermux.h:80
#define DBGC2(...)
Definition: compiler.h:522
unsigned int local
Number of blocks downloaded from peers.
Definition: peermux.h:51
struct mschapv2_challenge peer
Peer challenge.
Definition: mschapv2.h:12
struct list_head list
List of peers.
Definition: peerdisc.h:73
A PeerDist discovery peer.
Definition: peerdisc.h:71

References count, DBGC2, peerdisc_peer::list, list_for_each_entry, peerdist_statistics::local, peer, peerdist_multiplexed_block::peermux, peerdist_statistics::peers, peerdist_multiplexer::stats, tmp, and peerdist_statistics::total.

◆ peermux_block_close()

static void peermux_block_close ( struct peerdist_multiplexed_block peermblk,
int  rc 
)
static

Close multiplexed block download.

Parameters
peermblkPeerDist multiplexed block download
rcReason for close

Definition at line 337 of file peermux.c.

338  {
339  struct peerdist_multiplexer *peermux = peermblk->peermux;
340 
341  /* Move to list of idle downloads */
342  list_del ( &peermblk->list );
343  list_add_tail ( &peermblk->list, &peermux->idle );
344 
345  /* If any error occurred, terminate the whole multiplexer */
346  if ( rc != 0 ) {
347  peermux_close ( peermux, rc );
348  return;
349  }
350 
351  /* Restart data transfer interface */
352  intf_restart ( &peermblk->xfer, rc );
353 
354  /* Restart block download initiation process */
355  process_add ( &peermux->process );
356 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void intf_restart(struct interface *intf, int rc)
Shut down and restart an object interface.
Definition: interface.c:343
struct peerdist_multiplexer * peermux
PeerDist download multiplexer.
Definition: peermux.h:37
A PeerDist download multiplexer.
Definition: peermux.h:55
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
static void peermux_close(struct peerdist_multiplexer *peermux, int rc)
Close PeerDist download multiplexer.
Definition: peermux.c:62
struct process process
Block download initiation process.
Definition: peermux.h:71
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:93
void process_add(struct process *process)
Add process to process list.
Definition: process.c:59
struct list_head list
List of multiplexed blocks.
Definition: peermux.h:39
struct interface xfer
Data transfer interface.
Definition: peermux.h:41
struct list_head idle
List of idle block downloads.
Definition: peermux.h:75

References peerdist_multiplexer::idle, intf_restart(), peerdist_multiplexed_block::list, list_add_tail, list_del, peerdist_multiplexed_block::peermux, peermux_close(), peerdist_multiplexer::process, process_add(), rc, and peerdist_multiplexed_block::xfer.

◆ peermux_filter()

int peermux_filter ( struct interface xfer,
struct interface info,
struct uri uri 
)

Add PeerDist content-encoding filter.

Parameters
xferData transfer interface
infoContent information interface
uriOriginal URI
Return values
rcReturn status code

Definition at line 412 of file peermux.c.

413  {
414  struct peerdist_multiplexer *peermux;
415  struct peerdist_multiplexed_block *peermblk;
416  unsigned int i;
417 
418  /* Allocate and initialise structure */
419  peermux = zalloc ( sizeof ( *peermux ) );
420  if ( ! peermux )
421  return -ENOMEM;
425  peermux->uri = uri_get ( uri );
428  &peermux->refcnt );
431  for ( i = 0 ; i < PEERMUX_MAX_BLOCKS ; i++ ) {
432  peermblk = &peermux->block[i];
433  peermblk->peermux = peermux;
434  list_add_tail ( &peermblk->list, &peermux->idle );
435  intf_init ( &peermblk->xfer, &peermux_block_desc,
436  &peermux->refcnt );
437  }
438 
439  /* Attach to parent interfaces, mortalise self, and return */
442  ref_put ( &peermux->refcnt );
443  return 0;
444 }
u32 info
Definition: ar9003_mac.h:67
static struct uri * uri_get(struct uri *uri)
Increment URI reference count.
Definition: uri.h:194
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition: interface.c:107
A PeerDist multiplexed block download.
Definition: peermux.h:35
static void xferbuf_umalloc_init(struct xfer_buffer *xferbuf)
Initialise umalloc()-based data transfer buffer.
Definition: xferbuf.h:66
struct peerdist_multiplexer * peermux
PeerDist download multiplexer.
Definition: peermux.h:37
static struct interface_descriptor peermux_info_desc
Content information interface descriptor.
Definition: peermux.c:379
A PeerDist download multiplexer.
Definition: peermux.h:55
#define ENOMEM
Not enough space.
Definition: errno.h:534
static void peermux_free(struct refcnt *refcnt)
Free PeerDist download multiplexer.
Definition: peermux.c:47
struct process process
Block download initiation process.
Definition: peermux.h:71
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:93
static struct interface_descriptor peermux_block_desc
Block download data transfer interface descriptor.
Definition: peermux.c:396
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:661
struct list_head list
List of multiplexed blocks.
Definition: peermux.h:39
struct peerdist_multiplexed_block block[PEERMUX_MAX_BLOCKS]
Block downloads.
Definition: peermux.h:77
static void process_init_stopped(struct process *process, struct process_descriptor *desc, struct refcnt *refcnt)
Initialise process without adding to process list.
Definition: process.h:145
struct refcnt refcnt
Reference count.
Definition: peermux.h:57
struct interface xfer
Data transfer interface.
Definition: peermux.h:41
struct list_head idle
List of idle block downloads.
Definition: peermux.h:75
static struct process_descriptor peermux_process_desc
Block download initiation process descriptor.
Definition: peermux.c:401
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
struct interface xfer
Data transfer interface.
Definition: peermux.h:59
static struct interface_descriptor peermux_xfer_desc
Data transfer interface descriptor.
Definition: peermux.c:366
struct list_head busy
List of busy block downloads.
Definition: peermux.h:73
A Uniform Resource Identifier.
Definition: uri.h:64
struct xfer_buffer buffer
Content information data transfer buffer.
Definition: peermux.h:66
#define PEERMUX_MAX_BLOCKS
Maximum number of concurrent block downloads.
Definition: peermux.h:22
struct interface info
Content information interface.
Definition: peermux.h:61
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:203
struct uri * uri
Original URI.
Definition: peermux.h:63
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106

References peerdist_multiplexer::block, peerdist_multiplexer::buffer, peerdist_multiplexer::busy, ENOMEM, peerdist_multiplexer::idle, peerdist_multiplexer::info, info, INIT_LIST_HEAD, intf_init(), intf_plug_plug(), peerdist_multiplexed_block::list, list_add_tail, peerdist_multiplexed_block::peermux, peermux_block_desc, peermux_free(), peermux_info_desc, PEERMUX_MAX_BLOCKS, peermux_process_desc, peermux_xfer_desc, peerdist_multiplexer::process, process_init_stopped(), ref_init, ref_put, peerdist_multiplexer::refcnt, peerdist_multiplexer::uri, uri_get(), peerdist_multiplexed_block::xfer, peerdist_multiplexer::xfer, xferbuf_umalloc_init(), and zalloc().

Referenced by http_peerdist_init().

Variable Documentation

◆ peermux_xfer_operations

struct interface_operation peermux_xfer_operations[]
static
Initial value:
= {
}
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:249
A PeerDist download multiplexer.
Definition: peermux.h:55
static void peermux_close(struct peerdist_multiplexer *peermux, int rc)
Close PeerDist download multiplexer.
Definition: peermux.c:62
static int peermux_progress(struct peerdist_multiplexer *peermux, struct job_progress *progress)
Report progress of PeerDist download.
Definition: peermux.c:87
Job progress.
Definition: job.h:15
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition: interface.h:32

Data transfer interface operations.

Definition at line 359 of file peermux.c.

◆ peermux_xfer_desc

struct interface_descriptor peermux_xfer_desc
static
Initial value:
=
static struct interface_operation peermux_xfer_operations[]
Data transfer interface operations.
Definition: peermux.c:359
u32 info
Definition: ar9003_mac.h:67
A PeerDist download multiplexer.
Definition: peermux.h:55
struct interface xfer
Data transfer interface.
Definition: peermux.h:41
#define INTF_DESC_PASSTHRU(object_type, intf, operations, passthru)
Define an object interface descriptor with pass-through interface.
Definition: interface.h:97

Data transfer interface descriptor.

Definition at line 366 of file peermux.c.

Referenced by peermux_filter().

◆ peermux_info_operations

struct interface_operation peermux_info_operations[]
static
Initial value:
= {
}
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:249
static int peermux_info_deliver(struct peerdist_multiplexer *peermux, struct io_buffer *iobuf, struct xfer_metadata *meta)
Receive content information.
Definition: peermux.c:110
A PeerDist download multiplexer.
Definition: peermux.h:55
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition: interface.h:32
int xfer_deliver(struct interface *intf, struct io_buffer *iobuf, struct xfer_metadata *meta)
Deliver datagram.
Definition: xfer.c:194
static void peermux_info_close(struct peerdist_multiplexer *peermux, int rc)
Close content information interface.
Definition: peermux.c:132

Content information interface operations.

Definition at line 371 of file peermux.c.

◆ peermux_info_desc

struct interface_descriptor peermux_info_desc
static
Initial value:
=
u32 info
Definition: ar9003_mac.h:67
A PeerDist download multiplexer.
Definition: peermux.h:55
struct interface xfer
Data transfer interface.
Definition: peermux.h:41
#define INTF_DESC_PASSTHRU(object_type, intf, operations, passthru)
Define an object interface descriptor with pass-through interface.
Definition: interface.h:97
static struct interface_operation peermux_info_operations[]
Content information interface operations.
Definition: peermux.c:371

Content information interface descriptor.

Definition at line 379 of file peermux.c.

Referenced by peermux_filter().

◆ peermux_block_operations

struct interface_operation peermux_block_operations[]
static
Initial value:
= {
}
static int peermux_block_deliver(struct peerdist_multiplexed_block *peermblk, struct io_buffer *iobuf, struct xfer_metadata *meta)
Receive data from multiplexed block download.
Definition: peermux.c:270
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:249
static void peermux_block_stat(struct peerdist_multiplexed_block *peermblk, struct peerdisc_peer *peer, struct list_head *peers)
Record peer discovery statistics.
Definition: peermux.c:309
A data transfer buffer.
Definition: xferbuf.h:18
A PeerDist multiplexed block download.
Definition: peermux.h:35
void peerdisc_stat(struct interface *intf, struct peerdisc_peer *peer, struct list_head *peers)
Report peer discovery statistics.
Definition: peerdisc.c:100
static void peermux_block_close(struct peerdist_multiplexed_block *peermblk, int rc)
Close multiplexed block download.
Definition: peermux.c:337
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition: interface.h:32
int xfer_deliver(struct interface *intf, struct io_buffer *iobuf, struct xfer_metadata *meta)
Deliver datagram.
Definition: xfer.c:194
static struct xfer_buffer * peermux_block_buffer(struct peerdist_multiplexed_block *peermblk)
Get multiplexed block download underlying data transfer buffer.
Definition: peermux.c:293

Block download data transfer interface operations.

Definition at line 384 of file peermux.c.

◆ peermux_block_desc

struct interface_descriptor peermux_block_desc
static
Initial value:
=
A PeerDist multiplexed block download.
Definition: peermux.h:35
static struct interface_operation peermux_block_operations[]
Block download data transfer interface operations.
Definition: peermux.c:384
struct interface xfer
Data transfer interface.
Definition: peermux.h:41
#define INTF_DESC(object_type, intf, operations)
Define an object interface descriptor.
Definition: interface.h:80

Block download data transfer interface descriptor.

Definition at line 396 of file peermux.c.

Referenced by peermux_filter().

◆ peermux_process_desc

struct process_descriptor peermux_process_desc
static
Initial value:
=
A process.
Definition: process.h:17
A PeerDist download multiplexer.
Definition: peermux.h:55
#define PROC_DESC(object_type, process, _step)
Define a process descriptor.
Definition: process.h:82
static void peermux_step(struct peerdist_multiplexer *peermux)
Initiate multiplexed block download.
Definition: peermux.c:179

Block download initiation process descriptor.

Definition at line 401 of file peermux.c.

Referenced by peermux_filter().