Data Structures | Macros | Enumerations | Functions
peerblk.h File Reference

Peer Content Caching and Retrieval (PeerDist) protocol block downloads. More...

#include <stdint.h>
#include <ipxe/refcnt.h>
#include <ipxe/interface.h>
#include <ipxe/crypto.h>
#include <ipxe/aes.h>
#include <ipxe/xferbuf.h>
#include <ipxe/retry.h>
#include <ipxe/process.h>
#include <ipxe/pccrc.h>
#include <ipxe/peerdisc.h>

Go to the source code of this file.

Data Structures

struct  peerdist_block_decrypt
 A PeerDist retrieval protocol decryption buffer descriptor. More...
struct  peerdist_block
 A PeerDist block download. More...
struct  peerdist_block_queue
 PeerDist block download queue. More...


#define peerblk_msg_blk_t(digestsize, len, vrf_len, blksize)
 Retrieval protocol block fetch response (including transport header) More...


 PeerDist retrieval protocol decryption data transfer buffer indices. More...


int peerblk_open (struct interface *xfer, struct uri *uri, struct peerdist_info_block *block)
 Open PeerDist block download. More...

Detailed Description

Peer Content Caching and Retrieval (PeerDist) protocol block downloads.

Definition in file peerblk.h.

Macro Definition Documentation

◆ peerblk_msg_blk_t

#define peerblk_msg_blk_t (   digestsize,
struct { \
peerdist_msg_blk_t ( digestsize, len, vrf_len, \
blksize ) msg; \
} __attribute__ (( packed ))
#define __attribute__(x)
Definition: compiler.h:10
struct golan_inbox_hdr hdr
Message header.
Definition: CIB_PRM.h:28
uint32_t blksize
Block size for this segment.
Definition: pccrc.h:24
Retrieval protocol transport response header.
Definition: pccrr.h:180
uint8_t len
Definition: pcivpd.h:32
uint32_t digestsize
Digest size (i.e.
Definition: pccrr.h:14
static void msg(unsigned int row, const char *fmt,...)
Print message centred on specified row.
Definition: settings_ui.c:291

Retrieval protocol block fetch response (including transport header)

digestsizeDigest size
lenData block length
vrf_lenLength of uselessness
blksizeCipher block size

Definition at line 158 of file peerblk.h.

Enumeration Type Documentation

◆ peerdist_block_decrypt_index

PeerDist retrieval protocol decryption data transfer buffer indices.


Data before the trimmed content.


Data within the trimmed content.


Data after the trimmed content.


Number of decryption buffers.

Definition at line 34 of file peerblk.h.

34  {
35  /** Data before the trimmed content */
37  /** Data within the trimmed content */
39  /** Data after the trimmed content */
41  /** Number of decryption buffers */
43 };
Data after the trimmed content.
Definition: peerblk.h:40
Data before the trimmed content.
Definition: peerblk.h:36
Data within the trimmed content.
Definition: peerblk.h:38
Number of decryption buffers.
Definition: peerblk.h:42

Function Documentation



◆ peerblk_open()

int peerblk_open ( struct interface xfer,
struct uri uri,
struct peerdist_info_block block 

Open PeerDist block download.

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

Definition at line 1432 of file peerblk.c.

1433  {
1434  const struct peerdist_info_segment *segment = block->segment;
1435  const struct peerdist_info *info = segment->info;
1436  struct digest_algorithm *digest = info->digest;
1437  struct peerdist_block *peerblk;
1438  unsigned long timeout;
1439  size_t digestsize;
1440  int rc;
1442  /* Allocate and initialise structure */
1443  peerblk = zalloc ( sizeof ( *peerblk ) + digest->ctxsize );
1444  if ( ! peerblk ) {
1445  rc = -ENOMEM;
1446  goto err_alloc;
1447  }
1448  ref_init ( &peerblk->refcnt, peerblk_free );
1449  intf_init ( &peerblk->xfer, &peerblk_xfer_desc, &peerblk->refcnt );
1450  intf_init ( &peerblk->raw, &peerblk_raw_desc, &peerblk->refcnt );
1452  &peerblk->refcnt );
1453  peerblk->uri = uri_get ( uri );
1454  memcpy ( &peerblk->range, &block->range, sizeof ( peerblk->range ) );
1455  memcpy ( &peerblk->trim, &block->trim, sizeof ( peerblk->trim ) );
1456  peerblk->offset = ( block->trim.start - info->trim.start );
1457  peerblk->digest = info->digest;
1458  peerblk->digestsize = digestsize = info->digestsize;
1459  peerblk->digestctx = ( ( ( void * ) peerblk ) + sizeof ( *peerblk ) );
1460  peerblk->segment = segment->index;
1461  memcpy ( peerblk->id, segment->id, sizeof ( peerblk->id ) );
1462  memcpy ( peerblk->secret, segment->secret, sizeof ( peerblk->secret ) );
1463  peerblk->block = block->index;
1464  memcpy ( peerblk->hash, block->hash, sizeof ( peerblk->hash ) );
1465  xferbuf_malloc_init ( &peerblk->buffer );
1467  &peerblk->refcnt );
1469  INIT_LIST_HEAD ( &peerblk->queued );
1470  timer_init ( &peerblk->timer, peerblk_expired, &peerblk->refcnt );
1471  DBGC2 ( peerblk, "PEERBLK %p %d.%d id %02x%02x%02x%02x%02x..."
1472  "%02x%02x%02x [%08zx,%08zx)", peerblk, peerblk->segment,
1473  peerblk->block, peerblk->id[0], peerblk->id[1], peerblk->id[2],
1474  peerblk->id[3], peerblk->id[4], peerblk->id[ digestsize - 3 ],
1475  peerblk->id[ digestsize - 2 ], peerblk->id[ digestsize - 1 ],
1476  peerblk->range.start, peerblk->range.end );
1477  if ( ( peerblk->trim.start != peerblk->range.start ) ||
1478  ( peerblk->trim.end != peerblk->range.end ) ) {
1479  DBGC2 ( peerblk, " covers [%08zx,%08zx)",
1480  peerblk->trim.start, peerblk->trim.end );
1481  }
1482  DBGC2 ( peerblk, "\n" );
1484  /* Open discovery */
1485  if ( ( rc = peerdisc_open ( &peerblk->discovery, peerblk->id,
1486  peerblk->digestsize ) ) != 0 )
1487  goto err_open_discovery;
1489  /* Schedule a retry attempt either immediately (if we already
1490  * have some peers) or after the discovery timeout.
1491  */
1492  timeout = ( list_empty ( &peerblk->discovery.segment->peers ) ?
1494  start_timer_fixed ( &peerblk->timer, timeout );
1496  /* Record start time */
1497  peerblk->started = peerblk_timestamp();
1499  /* Attach to parent interface, mortalise self, and return */
1500  intf_plug_plug ( xfer, &peerblk->xfer );
1501  ref_put ( &peerblk->refcnt );
1502  return 0;
1504  err_open_discovery:
1505  peerblk_close ( peerblk, rc );
1506  err_alloc:
1507  return rc;
1508 }
struct list_head peers
List of discovered peers.
Definition: peerdisc.h:63
uint16_t segment
Code segment.
Definition: librm.h:252
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
Number of ticks per second.
Definition: timer.h:15
u32 info
Definition: ar9003_mac.h:67
A content information segment.
Definition: pccrc.h:347
struct xfer_buffer buffer
Data buffer.
Definition: peerblk.h:99
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
size_t start
Start offset.
Definition: pccrc.h:311
struct interface retrieval
Retrieval protocol interface.
Definition: peerblk.h:54
void * digestctx
Digest context (statically allocated at instantiation time)
Definition: peerblk.h:74
size_t offset
Offset of first byte in trimmed range within overall download.
Definition: peerblk.h:63
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition: interface.c:107
static void peerdisc_init(struct peerdisc_client *peerdisc, struct peerdisc_client_operations *op)
Initialise PeerDist discovery.
Definition: peerdisc.h:104
static struct process_descriptor peerblk_process_desc
PeerDist block download decryption process descriptor.
Definition: peerblk.c:1416
struct peerdisc_client discovery
Discovery client.
Definition: peerblk.h:111
struct process process
Decryption process.
Definition: peerblk.h:102
static unsigned long peerblk_timestamp(void)
Get profiling timestamp.
Definition: peerblk.c:137
struct digest_algorithm * digest
Digest algorithm.
Definition: peerblk.h:66
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:136
struct uri * uri
Original URI.
Definition: peerblk.h:57
struct peerdist_range range
Content range of this block.
Definition: peerblk.h:59
#define ENOMEM
Not enough space.
Definition: errno.h:534
void * memcpy(void *dest, const void *src, size_t len) __nonnull
A PeerDist block download.
Definition: peerblk.h:46
int peerdisc_open(struct peerdisc_client *peerdisc, const void *id, size_t len)
Open PeerDist discovery client.
Definition: peerdisc.c:559
static void struct digest_algorithm * digest
HMAC-MD5 digest.
Definition: crypto.h:308
static void peerblk_expired(struct retry_timer *timer, int over __unused)
Handle PeerDist retry timer expiry.
Definition: peerblk.c:1278
unsigned int segment
Segment index.
Definition: peerblk.h:82
struct interface raw
Raw data interface.
Definition: peerblk.h:52
static void xferbuf_malloc_init(struct xfer_buffer *xferbuf)
Initialise malloc()-based data transfer buffer.
Definition: xferbuf.h:76
unsigned int block
Block index.
Definition: peerblk.h:88
Segment identifier.
Definition: peerblk.h:84
struct interface xfer
Data transfer interface.
Definition: peerblk.h:50
Block hash.
Definition: peerblk.h:90
Content information.
Definition: pccrc.h:317
static struct peerdisc_client_operations peerblk_discovery_operations
PeerDist block download discovery operations.
Definition: peerblk.c:1420
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
static void peerblk_free(struct refcnt *refcnt)
Free PeerDist block download.
Definition: peerblk.c:151
size_t digestsize
Digest size.
Definition: peerblk.h:72
unsigned long started
Time at which block download was started.
Definition: peerblk.h:126
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 list_head queued
List of queued block downloads.
Definition: peerblk.h:117
static struct interface_descriptor peerblk_retrieval_desc
PeerDist block download retrieval protocol interface descriptor.
Definition: peerblk.c:1411
struct peerdisc_segment * segment
Discovery segment.
Definition: peerdisc.h:81
struct refcnt refcnt
Reference count.
Definition: peerblk.h:48
void start_timer_fixed(struct retry_timer *timer, unsigned long timeout)
Start timer with a specified timeout.
Definition: retry.c:64
struct retry_timer timer
Retry timer.
Definition: peerblk.h:119
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
static void peerblk_close(struct peerdist_block *peerblk, int rc)
Close PeerDist block download.
Definition: peerblk.c:204
size_t ctxsize
Context size.
Definition: crypto.h:21
#define DBGC2(...)
Definition: compiler.h:522
uint8_t block[3][8]
DES-encrypted blocks.
Definition: mschapv2.h:12
Segment secret.
Definition: peerblk.h:86
A message digest algorithm.
Definition: crypto.h:17
struct peerdist_range trim
Trimmed range of this block.
Definition: peerblk.h:61
static struct interface_descriptor peerblk_raw_desc
PeerDist block download raw data interface descriptor.
Definition: peerblk.c:1401
A Uniform Resource Identifier.
Definition: uri.h:64
void timeout(int)
static struct interface_descriptor peerblk_xfer_desc
PeerDist block download data transfer interface descriptor.
Definition: peerblk.c:1391
uint32_t digestsize
Digest size (i.e.
Definition: pccrr.h:14
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:203
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106
size_t end
End offset.
Definition: pccrc.h:313
unsigned int peerdisc_timeout_secs
Recommended discovery timeout (in seconds)
Definition: peerdisc.c:74

References block, peerdist_block::block, peerdist_block::buffer, digest_algorithm::ctxsize, DBGC2, peerdist_block::digest, digest, peerdist_block::digestctx, digestsize, peerdist_block::digestsize, peerdist_block::discovery, peerdist_range::end, ENOMEM, peerdist_block::hash, peerdist_block::id, info, INIT_LIST_HEAD, intf_init(), intf_plug_plug(), list_empty, memcpy(), peerdist_block::offset, peerblk_close(), peerblk_discovery_operations, peerblk_expired(), peerblk_free(), peerblk_process_desc, peerblk_raw_desc, peerblk_retrieval_desc, peerblk_timestamp(), peerblk_xfer_desc, peerdisc_init(), peerdisc_open(), peerdisc_timeout_secs, peerdisc_segment::peers, peerdist_block::process, process_init_stopped(), peerdist_block::queued, peerdist_block::range, peerdist_block::raw, rc, ref_init, ref_put, peerdist_block::refcnt, peerdist_block::retrieval, peerdist_block::secret, peerdisc_client::segment, peerdist_block::segment, segment, peerdist_range::start, start_timer_fixed(), peerdist_block::started, TICKS_PER_SEC, timeout(), peerdist_block::timer, peerdist_block::trim, peerdist_block::uri, uri_get(), peerdist_block::xfer, xferbuf_malloc_init(), and zalloc().

Referenced by peermux_step().