iPXE
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...
 

Macros

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

Enumerations

enum  peerdist_block_decrypt_index { PEERBLK_BEFORE = 0, PEERBLK_DURING, PEERBLK_AFTER, PEERBLK_NUM_BUFFERS }
 PeerDist retrieval protocol decryption data transfer buffer indices. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
 FILE_SECBOOT (PERMITTED)
 
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,
  len,
  vrf_len,
  blksize 
)
Value:
struct { \
peerdist_msg_blk_t ( digestsize, len, vrf_len, \
blksize ) msg; \
} __attribute__ (( packed ))
#define __attribute__(x)
Definition: compiler.h:10
void msg(unsigned int row, const char *fmt,...)
Print message centred on specified row.
Definition: message.c:62
struct golan_inbox_hdr hdr
Message header.
Definition: CIB_PRM.h:28
Retrieval protocol transport response header.
Definition: pccrr.h:180
uint8_t len
Length.
Definition: pcivpd.h:32
uint32_t blksize
Cipher block size.
Definition: pccrr.h:15
uint32_t digestsize
Digest size (i.e.
Definition: pccrr.h:15

Retrieval protocol block fetch response (including transport header)

Parameters
digestsizeDigest size
lenData block length
vrf_lenLength of uselessness
blksizeCipher block size

Definition at line 159 of file peerblk.h.

Enumeration Type Documentation

◆ peerdist_block_decrypt_index

PeerDist retrieval protocol decryption data transfer buffer indices.

Enumerator
PEERBLK_BEFORE 

Data before the trimmed content.

PEERBLK_DURING 

Data within the trimmed content.

PEERBLK_AFTER 

Data after the trimmed content.

PEERBLK_NUM_BUFFERS 

Number of decryption buffers.

Definition at line 35 of file peerblk.h.

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

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ peerblk_open()

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

Open PeerDist block download.

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

Definition at line 1434 of file peerblk.c.

1435  {
1436  const struct peerdist_info_segment *segment = block->segment;
1437  const struct peerdist_info *info = segment->info;
1438  struct digest_algorithm *digest = info->digest;
1439  struct peerdist_block *peerblk;
1440  unsigned long timeout;
1441  size_t digestsize;
1442  int rc;
1443 
1444  /* Allocate and initialise structure */
1445  peerblk = zalloc ( sizeof ( *peerblk ) + digest->ctxsize );
1446  if ( ! peerblk ) {
1447  rc = -ENOMEM;
1448  goto err_alloc;
1449  }
1450  ref_init ( &peerblk->refcnt, peerblk_free );
1451  intf_init ( &peerblk->xfer, &peerblk_xfer_desc, &peerblk->refcnt );
1452  intf_init ( &peerblk->raw, &peerblk_raw_desc, &peerblk->refcnt );
1454  &peerblk->refcnt );
1455  peerblk->uri = uri_get ( uri );
1456  memcpy ( &peerblk->range, &block->range, sizeof ( peerblk->range ) );
1457  memcpy ( &peerblk->trim, &block->trim, sizeof ( peerblk->trim ) );
1458  peerblk->offset = ( block->trim.start - info->trim.start );
1459  peerblk->digest = info->digest;
1460  peerblk->digestsize = digestsize = info->digestsize;
1461  peerblk->digestctx = ( ( ( void * ) peerblk ) + sizeof ( *peerblk ) );
1462  peerblk->segment = segment->index;
1463  memcpy ( peerblk->id, segment->id, sizeof ( peerblk->id ) );
1464  memcpy ( peerblk->secret, segment->secret, sizeof ( peerblk->secret ) );
1465  peerblk->block = block->index;
1466  memcpy ( peerblk->hash, block->hash, sizeof ( peerblk->hash ) );
1467  xferbuf_malloc_init ( &peerblk->buffer );
1469  &peerblk->refcnt );
1471  INIT_LIST_HEAD ( &peerblk->queued );
1472  timer_init ( &peerblk->timer, peerblk_expired, &peerblk->refcnt );
1473  DBGC2 ( peerblk, "PEERBLK %p %d.%d id %02x%02x%02x%02x%02x..."
1474  "%02x%02x%02x [%08zx,%08zx)", peerblk, peerblk->segment,
1475  peerblk->block, peerblk->id[0], peerblk->id[1], peerblk->id[2],
1476  peerblk->id[3], peerblk->id[4], peerblk->id[ digestsize - 3 ],
1477  peerblk->id[ digestsize - 2 ], peerblk->id[ digestsize - 1 ],
1478  peerblk->range.start, peerblk->range.end );
1479  if ( ( peerblk->trim.start != peerblk->range.start ) ||
1480  ( peerblk->trim.end != peerblk->range.end ) ) {
1481  DBGC2 ( peerblk, " covers [%08zx,%08zx)",
1482  peerblk->trim.start, peerblk->trim.end );
1483  }
1484  DBGC2 ( peerblk, "\n" );
1485 
1486  /* Open discovery */
1487  if ( ( rc = peerdisc_open ( &peerblk->discovery, peerblk->id,
1488  peerblk->digestsize ) ) != 0 )
1489  goto err_open_discovery;
1490 
1491  /* Schedule a retry attempt either immediately (if we already
1492  * have some peers) or after the discovery timeout.
1493  */
1494  timeout = ( list_empty ( &peerblk->discovery.segment->peers ) ?
1496  start_timer_fixed ( &peerblk->timer, timeout );
1497 
1498  /* Record start time */
1499  peerblk->started = peerblk_timestamp();
1500 
1501  /* Attach to parent interface, mortalise self, and return */
1502  intf_plug_plug ( xfer, &peerblk->xfer );
1503  ref_put ( &peerblk->refcnt );
1504  return 0;
1505 
1506  err_open_discovery:
1507  peerblk_close ( peerblk, rc );
1508  err_alloc:
1509  return rc;
1510 }
struct list_head peers
List of discovered peers.
Definition: peerdisc.h:64
uint16_t segment
Code segment.
Definition: librm.h:138
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define TICKS_PER_SEC
Number of ticks per second.
Definition: timer.h:16
u32 info
Definition: ar9003_mac.h:24
A content information segment.
Definition: pccrc.h:347
struct xfer_buffer buffer
Data buffer.
Definition: peerblk.h:100
static struct uri * uri_get(struct uri *uri)
Increment URI reference count.
Definition: uri.h:195
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:65
size_t start
Start offset.
Definition: pccrc.h:311
struct interface retrieval
Retrieval protocol interface.
Definition: peerblk.h:55
void * digestctx
Digest context (statically allocated at instantiation time)
Definition: peerblk.h:75
size_t offset
Offset of first byte in trimmed range within overall download.
Definition: peerblk.h:64
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition: interface.c:108
static void peerdisc_init(struct peerdisc_client *peerdisc, struct peerdisc_client_operations *op)
Initialise PeerDist discovery.
Definition: peerdisc.h:105
static struct process_descriptor peerblk_process_desc
PeerDist block download decryption process descriptor.
Definition: peerblk.c:1418
struct peerdisc_client discovery
Discovery client.
Definition: peerblk.h:112
struct process process
Decryption process.
Definition: peerblk.h:103
static unsigned long peerblk_timestamp(void)
Get profiling timestamp.
Definition: peerblk.c:139
struct digest_algorithm * digest
Digest algorithm.
Definition: peerblk.h:67
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:137
struct uri * uri
Original URI.
Definition: peerblk.h:58
struct peerdist_range range
Content range of this block.
Definition: peerblk.h:60
#define ENOMEM
Not enough space.
Definition: errno.h:535
void * memcpy(void *dest, const void *src, size_t len) __nonnull
A PeerDist block download.
Definition: peerblk.h:47
int peerdisc_open(struct peerdisc_client *peerdisc, const void *id, size_t len)
Open PeerDist discovery client.
Definition: peerdisc.c:560
static void peerblk_expired(struct retry_timer *timer, int over __unused)
Handle PeerDist retry timer expiry.
Definition: peerblk.c:1280
unsigned int segment
Segment index.
Definition: peerblk.h:83
struct interface raw
Raw data interface.
Definition: peerblk.h:53
static void xferbuf_malloc_init(struct xfer_buffer *xferbuf)
Initialise malloc()-based data transfer buffer.
Definition: xferbuf.h:54
unsigned int block
Block index.
Definition: peerblk.h:89
uint8_t id[PEERDIST_DIGEST_MAX_SIZE]
Segment identifier.
Definition: peerblk.h:85
struct interface xfer
Data transfer interface.
Definition: peerblk.h:51
uint8_t hash[PEERDIST_DIGEST_MAX_SIZE]
Block hash.
Definition: peerblk.h:91
Content information.
Definition: pccrc.h:317
static struct peerdisc_client_operations peerblk_discovery_operations
PeerDist block download discovery operations.
Definition: peerblk.c:1422
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:662
static void peerblk_free(struct refcnt *refcnt)
Free PeerDist block download.
Definition: peerblk.c:153
size_t digestsize
Digest size.
Definition: peerblk.h:73
unsigned long started
Time at which block download was started.
Definition: peerblk.h:127
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:146
struct list_head queued
List of queued block downloads.
Definition: peerblk.h:118
static struct interface_descriptor peerblk_retrieval_desc
PeerDist block download retrieval protocol interface descriptor.
Definition: peerblk.c:1413
struct peerdisc_segment * segment
Discovery segment.
Definition: peerdisc.h:82
struct refcnt refcnt
Reference count.
Definition: peerblk.h:49
void start_timer_fixed(struct retry_timer *timer, unsigned long timeout)
Start timer with a specified timeout.
Definition: retry.c:65
struct retry_timer timer
Retry timer.
Definition: peerblk.h:120
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:46
static void peerblk_close(struct peerdist_block *peerblk, int rc)
Close PeerDist block download.
Definition: peerblk.c:206
size_t ctxsize
Context size.
Definition: crypto.h:23
#define DBGC2(...)
Definition: compiler.h:522
uint8_t block[3][8]
DES-encrypted blocks.
Definition: mschapv2.h:12
uint8_t secret[PEERDIST_DIGEST_MAX_SIZE]
Segment secret.
Definition: peerblk.h:87
A message digest algorithm.
Definition: crypto.h:19
struct peerdist_range trim
Trimmed range of this block.
Definition: peerblk.h:62
static struct interface_descriptor peerblk_raw_desc
PeerDist block download raw data interface descriptor.
Definition: peerblk.c:1403
A Uniform Resource Identifier.
Definition: uri.h:65
void timeout(int)
static struct interface_descriptor peerblk_xfer_desc
PeerDist block download data transfer interface descriptor.
Definition: peerblk.c:1393
uint32_t digestsize
Digest size (i.e.
Definition: pccrr.h:15
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:204
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:107
size_t end
End offset.
Definition: pccrc.h:313
unsigned int peerdisc_timeout_secs
Recommended discovery timeout (in seconds)
Definition: peerdisc.c:75

References block, peerdist_block::block, peerdist_block::buffer, digest_algorithm::ctxsize, DBGC2, peerdist_block::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().