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)
 
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
uint32_t blksize
Block size for this segment.
Definition: pccrc.h:24
Retrieval protocol transport response header.
Definition: pccrr.h:180
uint8_t len
Length.
Definition: pcivpd.h:32
uint32_t hdr
Message header.
Definition: intelvf.h:12
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:285

Retrieval protocol block fetch response (including transport header)

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

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 34 of file peerblk.h.

34  {
35  /** Data before the trimmed content */
36  PEERBLK_BEFORE = 0,
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

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ 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 1431 of file peerblk.c.

1432  {
1433  const struct peerdist_info_segment *segment = block->segment;
1434  const struct peerdist_info *info = segment->info;
1435  struct digest_algorithm *digest = info->digest;
1436  struct peerdist_block *peerblk;
1437  unsigned long timeout;
1438  size_t digestsize;
1439  int rc;
1440 
1441  /* Allocate and initialise structure */
1442  peerblk = zalloc ( sizeof ( *peerblk ) + digest->ctxsize );
1443  if ( ! peerblk ) {
1444  rc = -ENOMEM;
1445  goto err_alloc;
1446  }
1447  ref_init ( &peerblk->refcnt, peerblk_free );
1448  intf_init ( &peerblk->xfer, &peerblk_xfer_desc, &peerblk->refcnt );
1449  intf_init ( &peerblk->raw, &peerblk_raw_desc, &peerblk->refcnt );
1451  &peerblk->refcnt );
1452  peerblk->uri = uri_get ( uri );
1453  memcpy ( &peerblk->range, &block->range, sizeof ( peerblk->range ) );
1454  memcpy ( &peerblk->trim, &block->trim, sizeof ( peerblk->trim ) );
1455  peerblk->offset = ( block->trim.start - info->trim.start );
1456  peerblk->digest = info->digest;
1457  peerblk->digestsize = digestsize = info->digestsize;
1458  peerblk->digestctx = ( ( ( void * ) peerblk ) + sizeof ( *peerblk ) );
1459  peerblk->segment = segment->index;
1460  memcpy ( peerblk->id, segment->id, sizeof ( peerblk->id ) );
1461  memcpy ( peerblk->secret, segment->secret, sizeof ( peerblk->secret ) );
1462  peerblk->block = block->index;
1463  memcpy ( peerblk->hash, block->hash, sizeof ( peerblk->hash ) );
1464  xferbuf_malloc_init ( &peerblk->buffer );
1466  &peerblk->refcnt );
1468  INIT_LIST_HEAD ( &peerblk->queued );
1469  timer_init ( &peerblk->timer, peerblk_expired, &peerblk->refcnt );
1470  DBGC2 ( peerblk, "PEERBLK %p %d.%d id %02x%02x%02x%02x%02x..."
1471  "%02x%02x%02x [%08zx,%08zx)", peerblk, peerblk->segment,
1472  peerblk->block, peerblk->id[0], peerblk->id[1], peerblk->id[2],
1473  peerblk->id[3], peerblk->id[4], peerblk->id[ digestsize - 3 ],
1474  peerblk->id[ digestsize - 2 ], peerblk->id[ digestsize - 1 ],
1475  peerblk->range.start, peerblk->range.end );
1476  if ( ( peerblk->trim.start != peerblk->range.start ) ||
1477  ( peerblk->trim.end != peerblk->range.end ) ) {
1478  DBGC2 ( peerblk, " covers [%08zx,%08zx)",
1479  peerblk->trim.start, peerblk->trim.end );
1480  }
1481  DBGC2 ( peerblk, "\n" );
1482 
1483  /* Open discovery */
1484  if ( ( rc = peerdisc_open ( &peerblk->discovery, peerblk->id,
1485  peerblk->digestsize ) ) != 0 )
1486  goto err_open_discovery;
1487 
1488  /* Schedule a retry attempt either immediately (if we already
1489  * have some peers) or after the discovery timeout.
1490  */
1491  timeout = ( list_empty ( &peerblk->discovery.segment->peers ) ?
1493  start_timer_fixed ( &peerblk->timer, timeout );
1494 
1495  /* Record start time */
1496  peerblk->started = peerblk_timestamp();
1497 
1498  /* Attach to parent interface, mortalise self, and return */
1499  intf_plug_plug ( xfer, &peerblk->xfer );
1500  ref_put ( &peerblk->refcnt );
1501  return 0;
1502 
1503  err_open_discovery:
1504  peerblk_close ( peerblk, rc );
1505  err_alloc:
1506  return rc;
1507 }
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
#define TICKS_PER_SEC
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:177
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
size_t start
Start offset.
Definition: pccrc.h:311
uint16_t block
Definition: tftp.h:12
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:102
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:1415
struct peerdisc_client discovery
Discovery client.
Definition: peerblk.h:111
struct process process
Decryption process.
Definition: peerblk.h:102
struct md4_digest digest
Digest of data already processed.
Definition: md4.h:12
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:536
static void peerblk_expired(struct retry_timer *timer, int over __unused)
Handle PeerDist retry timer expiry.
Definition: peerblk.c:1277
unsigned int segment
Segment index.
Definition: peerblk.h:82
struct interface raw
Raw data interface.
Definition: peerblk.h:52
unsigned int block
Block index.
Definition: peerblk.h:88
uint8_t id[PEERDIST_DIGEST_MAX_SIZE]
Segment identifier.
Definition: peerblk.h:84
struct interface xfer
Data transfer interface.
Definition: peerblk.h:50
uint8_t hash[PEERDIST_DIGEST_MAX_SIZE]
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:1419
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:1410
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
#define DBGC2(...)
Definition: compiler.h:522
uint8_t secret[PEERDIST_DIGEST_MAX_SIZE]
Segment secret.
Definition: peerblk.h:86
A message digest algorithm.
Definition: crypto.h:16
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:1400
A Uniform Resource Identifier.
Definition: uri.h:50
void timeout(int)
static struct interface_descriptor peerblk_xfer_desc
PeerDist block download data transfer interface descriptor.
Definition: peerblk.c:1390
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:173
#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, DBGC2, digest, 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, and zalloc().

Referenced by peermux_step().