iPXE
Functions | Variables
peermux.c File Reference

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

#include <stdlib.h>
#include <stdio.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 46 of file peermux.c.

46  {
47  struct peerdist_multiplexer *peermux =
49 
50  uri_put ( peermux->uri );
51  xferbuf_free ( &peermux->buffer );
52  free ( peermux );
53 }
static void uri_put(struct uri *uri)
Decrement URI reference count.
Definition: uri.h:188
void xferbuf_free(struct xfer_buffer *xferbuf)
Free data transfer buffer.
Definition: xferbuf.c:58
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 61 of file peermux.c.

61  {
62  unsigned int i;
63 
64  /* Stop block download initiation process */
65  process_del ( &peermux->process );
66 
67  /* Shut down all block downloads */
68  for ( i = 0 ; i < PEERMUX_MAX_BLOCKS ; i++ )
69  intf_shutdown ( &peermux->block[i].xfer, rc );
70 
71  /* Shut down all other interfaces (which may be connected to
72  * the same object).
73  */
74  intf_nullify ( &peermux->info ); /* avoid potential loops */
75  intf_shutdown ( &peermux->xfer, rc );
76  intf_shutdown ( &peermux->info, rc );
77 }
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:273
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:124
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 86 of file peermux.c.

87  {
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 }
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 109 of file peermux.c.

111  {
112  int rc;
113 
114  /* Add data to buffer */
115  if ( ( rc = xferbuf_deliver ( &peermux->buffer, iobuf, meta ) ) != 0 )
116  goto err;
117 
118  return 0;
119 
120  err:
121  peermux_close ( peermux, rc );
122  return rc;
123 }
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:152
static void peermux_close(struct peerdist_multiplexer *peermux, int rc)
Close PeerDist download multiplexer.
Definition: peermux.c:61
int meta(WINDOW *, bool)
struct xfer_buffer buffer
Content information data transfer buffer.
Definition: peermux.h:66

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 131 of file peermux.c.

131  {
132  struct peerdist_info *info = &peermux->cache.info;
133  size_t len;
134 
135  /* Terminate download on error */
136  if ( rc != 0 )
137  goto err;
138 
139  /* Successfully closing the content information interface
140  * indicates that the content information has been fully
141  * received, and initiates the actual PeerDist download.
142  */
143 
144  /* Shut down content information interface */
145  intf_shutdown ( &peermux->info, rc );
146 
147  /* Parse content information */
148  if ( ( rc = peerdist_info ( info->raw.data, peermux->buffer.len,
149  info ) ) != 0 ) {
150  DBGC ( peermux, "PEERMUX %p could not parse content info: %s\n",
151  peermux, strerror ( rc ) );
152  goto err;
153  }
154 
155  /* Notify recipient of total download size */
156  len = ( info->trim.end - info->trim.start );
157  if ( ( rc = xfer_seek ( &peermux->xfer, len ) ) != 0 ) {
158  DBGC ( peermux, "PEERMUX %p could not presize buffer: %s\n",
159  peermux, strerror ( rc ) );
160  goto err;
161  }
162  xfer_seek ( &peermux->xfer, 0 );
163 
164  /* Start block download process */
165  process_add ( &peermux->process );
166 
167  return;
168 
169  err:
170  peermux_close ( peermux, rc );
171 }
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:273
u32 info
Definition: ar9003_mac.h:67
#define DBGC(...)
Definition: compiler.h:505
struct peerdist_info_cache cache
Content information cache.
Definition: peermux.h:68
size_t len
Size of data.
Definition: xferbuf.h:23
static void peermux_close(struct peerdist_multiplexer *peermux, int rc)
Close PeerDist download multiplexer.
Definition: peermux.c:61
struct process process
Block download initiation process.
Definition: peermux.h:71
Content information.
Definition: pccrc.h:317
int xfer_seek(struct interface *intf, off_t offset)
Seek to position.
Definition: xfer.c:350
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
uint32_t len
Length.
Definition: ena.h:14
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 peerdist_multiplexer::buffer, peerdist_multiplexer::cache, DBGC, peerdist_multiplexer::info, info, peerdist_info_cache::info, intf_shutdown(), len, xfer_buffer::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 178 of file peermux.c.

178  {
179  struct peerdist_info *info = &peermux->cache.info;
180  struct peerdist_info_segment *segment = &peermux->cache.segment;
181  struct peerdist_info_block *block = &peermux->cache.block;
182  struct peerdist_multiplexed_block *peermblk;
183  unsigned int next_segment;
184  unsigned int next_block;
185  int rc;
186 
187  /* Stop initiation process if all block downloads are busy */
188  peermblk = list_first_entry ( &peermux->idle,
190  if ( ! peermblk ) {
192  return;
193  }
194 
195  /* Increment block index */
196  next_block = ( block->index + 1 );
197 
198  /* Move to first/next segment, if applicable */
199  if ( next_block >= segment->blocks ) {
200 
201  /* Reset block index */
202  next_block = 0;
203 
204  /* Calculate segment index */
205  next_segment = ( segment->info ? ( segment->index + 1 ) : 0 );
206 
207  /* If we have finished all segments and have no
208  * remaining block downloads, then we are finished.
209  */
210  if ( next_segment >= info->segments ) {
212  if ( list_empty ( &peermux->busy ) )
213  peermux_close ( peermux, 0 );
214  return;
215  }
216 
217  /* Get content information segment */
218  if ( ( rc = peerdist_info_segment ( info, segment,
219  next_segment ) ) != 0 ) {
220  DBGC ( peermux, "PEERMUX %p could not get segment %d "
221  "information: %s\n", peermux, next_segment,
222  strerror ( rc ) );
223  goto err;
224  }
225  }
226 
227  /* Get content information block */
228  if ( ( rc = peerdist_info_block ( segment, block, next_block ) ) != 0 ){
229  DBGC ( peermux, "PEERMUX %p could not get segment %d block "
230  "%d information: %s\n", peermux, segment->index,
231  next_block, strerror ( rc ) );
232  goto err;
233  }
234 
235  /* Ignore block if it lies entirely outside the trimmed range */
236  if ( block->trim.start == block->trim.end ) {
237  DBGC ( peermux, "PEERMUX %p skipping segment %d block %d\n",
238  peermux, segment->index, block->index );
239  return;
240  }
241 
242  /* Start downloading this block */
243  if ( ( rc = peerblk_open ( &peermblk->xfer, peermux->uri,
244  block ) ) != 0 ) {
245  DBGC ( peermux, "PEERMUX %p could not start download for "
246  "segment %d block %d: %s\n", peermux, segment->index,
247  block->index, strerror ( rc ) );
248  goto err;
249  }
250 
251  /* Move to list of busy block downloads */
252  list_del ( &peermblk->list );
253  list_add_tail ( &peermblk->list, &peermux->busy );
254 
255  return;
256 
257  err:
258  peermux_close ( peermux, rc );
259 }
uint16_t segment
Code segment.
Definition: librm.h:252
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
u32 info
Definition: ar9003_mac.h:67
A content information segment.
Definition: pccrc.h:347
uint16_t block
Definition: tftp.h:12
#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:1431
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:394
#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:61
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:317
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
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 269 of file peermux.c.

271  {
272  struct peerdist_multiplexer *peermux = peermblk->peermux;
273 
274  /* Sanity check: all block downloads must use absolute
275  * positions for all deliveries, since they run concurrently.
276  */
277  assert ( meta->flags & XFER_FL_ABS_OFFSET );
278 
279  /* We can't use a simple passthrough interface descriptor,
280  * since there are multiple block download interfaces.
281  */
282  return xfer_deliver ( &peermux->xfer, iob_disown ( iobuf ), meta );
283 }
#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:208
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
int meta(WINDOW *, bool)
int xfer_deliver(struct interface *intf, struct io_buffer *iobuf, struct xfer_metadata *meta)
Deliver datagram.
Definition: xfer.c:193
struct interface xfer
Data transfer interface.
Definition: peermux.h:59

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 292 of file peermux.c.

292  {
293  struct peerdist_multiplexer *peermux = peermblk->peermux;
294 
295  /* We can't use a simple passthrough interface descriptor,
296  * since there are multiple block download interfaces.
297  */
298  return xfer_buffer ( &peermux->xfer );
299 }
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:301
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 308 of file peermux.c.

310  {
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 }
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
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:420
uint8_t * tmp
Definition: entropy.h:156
struct peerdist_statistics stats
Statistics.
Definition: peermux.h:80
#define DBGC2(...)
Definition: compiler.h:522
uint16_t count
Number of entries.
Definition: ena.h:22
unsigned int local
Number of blocks downloaded from peers.
Definition: peermux.h:51
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, 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 336 of file peermux.c.

337  {
338  struct peerdist_multiplexer *peermux = peermblk->peermux;
339 
340  /* Move to list of idle downloads */
341  list_del ( &peermblk->list );
342  list_add_tail ( &peermblk->list, &peermux->idle );
343 
344  /* If any error occurred, terminate the whole multiplexer */
345  if ( rc != 0 ) {
346  peermux_close ( peermux, rc );
347  return;
348  }
349 
350  /* Restart data transfer interface */
351  intf_restart ( &peermblk->xfer, rc );
352 
353  /* Restart block download initiation process */
354  process_add ( &peermux->process );
355 }
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:337
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:61
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 411 of file peermux.c.

412  {
413  struct peerdist_multiplexer *peermux;
414  struct peerdist_multiplexed_block *peermblk;
415  unsigned int i;
416 
417  /* Allocate and initialise structure */
418  peermux = zalloc ( sizeof ( *peermux ) );
419  if ( ! peermux )
420  return -ENOMEM;
424  peermux->uri = uri_get ( uri );
425  xferbuf_umalloc_init ( &peermux->buffer,
426  &peermux->cache.info.raw.data );
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
userptr_t data
Data buffer.
Definition: pccrc.h:303
static struct uri * uri_get(struct uri *uri)
Increment URI reference count.
Definition: uri.h:177
#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:102
A PeerDist multiplexed block download.
Definition: peermux.h:35
struct peerdist_info_cache cache
Content information cache.
Definition: peermux.h:68
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:378
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:46
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:395
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
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:400
#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:365
struct list_head busy
List of busy block downloads.
Definition: peermux.h:73
A Uniform Resource Identifier.
Definition: uri.h:50
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 peerdist_raw raw
Raw content information.
Definition: pccrc.h:319
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:173
struct uri * uri
Original URI.
Definition: peermux.h:63
struct peerdist_info info
Content information.
Definition: peermux.h:27
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106

References peerdist_multiplexer::block, peerdist_multiplexer::buffer, peerdist_multiplexer::busy, peerdist_multiplexer::cache, peerdist_raw::data, ENOMEM, peerdist_multiplexer::idle, peerdist_multiplexer::info, info, peerdist_info_cache::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(), peerdist_info::raw, ref_init, ref_put, peerdist_multiplexer::refcnt, peerdist_multiplexer::uri, uri_get(), peerdist_multiplexed_block::xfer, peerdist_multiplexer::xfer, 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:244
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:61
static int peermux_progress(struct peerdist_multiplexer *peermux, struct job_progress *progress)
Report progress of PeerDist download.
Definition: peermux.c:86
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 358 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:358
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:82

Data transfer interface descriptor.

Definition at line 365 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:244
static int peermux_info_deliver(struct peerdist_multiplexer *peermux, struct io_buffer *iobuf, struct xfer_metadata *meta)
Receive content information.
Definition: peermux.c:109
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:193
static void peermux_info_close(struct peerdist_multiplexer *peermux, int rc)
Close content information interface.
Definition: peermux.c:131

Content information interface operations.

Definition at line 370 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:82
static struct interface_operation peermux_info_operations[]
Content information interface operations.
Definition: peermux.c:370

Content information interface descriptor.

Definition at line 378 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:269
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:244
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:308
A data transfer buffer.
Definition: xferbuf.h:19
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:97
static void peermux_block_close(struct peerdist_multiplexed_block *peermblk, int rc)
Close multiplexed block download.
Definition: peermux.c:336
#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:193
static struct xfer_buffer * peermux_block_buffer(struct peerdist_multiplexed_block *peermblk)
Get multiplexed block download underlying data transfer buffer.
Definition: peermux.c:292

Block download data transfer interface operations.

Definition at line 383 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:383
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:65

Block download data transfer interface descriptor.

Definition at line 395 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:178

Block download initiation process descriptor.

Definition at line 400 of file peermux.c.

Referenced by peermux_filter().