iPXE
Data Structures | Defines | 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...

Defines

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

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.

Detailed Description

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

Definition in file peerblk.h.


Define Documentation

#define peerblk_msg_blk_t (   digestsize,
  len,
  vrf_len,
  blksize 
)
Value:
struct {                                                        \
                struct peerdist_msg_transport_header hdr;               \
                peerdist_msg_blk_t ( digestsize, len, vrf_len,          \
                                     blksize ) msg;                     \
        } __attribute__ (( packed ))

Retrieval protocol block fetch response (including transport header)

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

Definition at line 134 of file peerblk.h.

Referenced by peerblk_parse_block(), peerblk_parse_iv(), peerblk_parse_useless(), and peerblk_retrieval_open().


Enumeration Type Documentation

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.

                                  {
        /** Data before the trimmed content */
        PEERBLK_BEFORE = 0,
        /** Data within the trimmed content */
        PEERBLK_DURING,
        /** Data after the trimmed content */
        PEERBLK_AFTER,
        /** Number of decryption buffers */
        PEERBLK_NUM_BUFFERS
};

Function Documentation

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.

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

Definition at line 1302 of file peerblk.c.

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

Referenced by peermux_step().

                                                       {
        const struct peerdist_info_segment *segment = block->segment;
        const struct peerdist_info *info = segment->info;
        struct digest_algorithm *digest = info->digest;
        struct peerdist_block *peerblk;
        unsigned long timeout;
        size_t digestsize;
        int rc;

        /* Allocate and initialise structure */
        peerblk = zalloc ( sizeof ( *peerblk ) + digest->ctxsize );
        if ( ! peerblk ) {
                rc = -ENOMEM;
                goto err_alloc;
        }
        ref_init ( &peerblk->refcnt, peerblk_free );
        intf_init ( &peerblk->xfer, &peerblk_xfer_desc, &peerblk->refcnt );
        intf_init ( &peerblk->raw, &peerblk_raw_desc, &peerblk->refcnt );
        intf_init ( &peerblk->retrieval, &peerblk_retrieval_desc,
                    &peerblk->refcnt );
        peerblk->uri = uri_get ( uri );
        memcpy ( &peerblk->range, &block->range, sizeof ( peerblk->range ) );
        memcpy ( &peerblk->trim, &block->trim, sizeof ( peerblk->trim ) );
        peerblk->offset = ( block->trim.start - info->trim.start );
        peerblk->digest = info->digest;
        peerblk->digestsize = digestsize = info->digestsize;
        peerblk->digestctx = ( ( ( void * ) peerblk ) + sizeof ( *peerblk ) );
        peerblk->segment = segment->index;
        memcpy ( peerblk->id, segment->id, sizeof ( peerblk->id ) );
        memcpy ( peerblk->secret, segment->secret, sizeof ( peerblk->secret ) );
        peerblk->block = block->index;
        memcpy ( peerblk->hash, block->hash, sizeof ( peerblk->hash ) );
        xferbuf_malloc_init ( &peerblk->buffer );
        process_init_stopped ( &peerblk->process, &peerblk_process_desc,
                               &peerblk->refcnt );
        peerdisc_init ( &peerblk->discovery, &peerblk_discovery_operations );
        timer_init ( &peerblk->timer, peerblk_expired, &peerblk->refcnt );
        DBGC2 ( peerblk, "PEERBLK %p %d.%d id %02x%02x%02x%02x%02x..."
                "%02x%02x%02x [%08zx,%08zx)", peerblk, peerblk->segment,
                peerblk->block, peerblk->id[0], peerblk->id[1], peerblk->id[2],
                peerblk->id[3], peerblk->id[4], peerblk->id[ digestsize - 3 ],
                peerblk->id[ digestsize - 2 ], peerblk->id[ digestsize - 1 ],
                peerblk->range.start, peerblk->range.end );
        if ( ( peerblk->trim.start != peerblk->range.start ) ||
             ( peerblk->trim.end != peerblk->range.end ) ) {
                DBGC2 ( peerblk, " covers [%08zx,%08zx)",
                        peerblk->trim.start, peerblk->trim.end );
        }
        DBGC2 ( peerblk, "\n" );

        /* Open discovery */
        if ( ( rc = peerdisc_open ( &peerblk->discovery, peerblk->id,
                                    peerblk->digestsize ) ) != 0 )
                goto err_open_discovery;

        /* Schedule a retry attempt either immediately (if we already
         * have some peers) or after the discovery timeout.
         */
        timeout = ( list_empty ( &peerblk->discovery.segment->peers ) ?
                    ( peerdisc_timeout_secs * TICKS_PER_SEC ) : 0 );
        start_timer_fixed ( &peerblk->timer, timeout );

        /* Record start time */
        peerblk->started = peerblk_timestamp();

        /* Attach to parent interface, mortalise self, and return */
        intf_plug_plug ( xfer, &peerblk->xfer );
        ref_put ( &peerblk->refcnt );
        return 0;

 err_open_discovery:
        peerblk_close ( peerblk, rc );
 err_alloc:
        return rc;
}