iPXE
Data Structures | Macros | Functions | Variables
peerdisc.h File Reference

Peer Content Caching and Retrieval (PeerDist) protocol peer discovery. More...

#include <stdint.h>
#include <ipxe/refcnt.h>
#include <ipxe/list.h>
#include <ipxe/tables.h>
#include <ipxe/retry.h>
#include <ipxe/socket.h>
#include <ipxe/interface.h>
#include <ipxe/pccrc.h>

Go to the source code of this file.

Data Structures

struct  peerdisc_socket
 A PeerDist discovery socket. More...
 
struct  peerdisc_segment
 A PeerDist discovery segment. More...
 
struct  peerdisc_peer
 A PeerDist discovery peer. More...
 
struct  peerdisc_client
 A PeerDist discovery client. More...
 
struct  peerdisc_client_operations
 PeerDist discovery client operations. More...
 

Macros

#define PEERDISC_SOCKETS   __table ( struct peerdisc_socket, "peerdisc_sockets" )
 PeerDist discovery socket table. More...
 
#define __peerdisc_socket   __table_entry ( PEERDISC_SOCKETS, 01 )
 Declare a PeerDist discovery socket. More...
 
#define peerdisc_stat_TYPE(object_type)
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
 FILE_SECBOOT (PERMITTED)
 
static void peerdisc_init (struct peerdisc_client *peerdisc, struct peerdisc_client_operations *op)
 Initialise PeerDist discovery. More...
 
void peerdisc_stat (struct interface *intf, struct peerdisc_peer *peer, struct list_head *peers)
 Report peer discovery statistics. More...
 
int peerdisc_open (struct peerdisc_client *peerdisc, const void *id, size_t len)
 Open PeerDist discovery client. More...
 
void peerdisc_close (struct peerdisc_client *peerdisc)
 Close PeerDist discovery client. More...
 

Variables

unsigned int peerdisc_timeout_secs
 Recommended discovery timeout (in seconds) More...
 

Detailed Description

Peer Content Caching and Retrieval (PeerDist) protocol peer discovery.

Definition in file peerdisc.h.

Macro Definition Documentation

◆ PEERDISC_SOCKETS

#define PEERDISC_SOCKETS   __table ( struct peerdisc_socket, "peerdisc_sockets" )

PeerDist discovery socket table.

Definition at line 37 of file peerdisc.h.

◆ __peerdisc_socket

struct peerdisc_socket peerdisc_socket_ipv6 __peerdisc_socket   __table_entry ( PEERDISC_SOCKETS, 01 )

Declare a PeerDist discovery socket.

PeerDist discovery IPv6 socket.

Definition at line 40 of file peerdisc.h.

◆ peerdisc_stat_TYPE

#define peerdisc_stat_TYPE (   object_type)
Value:
typeof ( void ( object_type, struct peerdisc_peer *peer, \
struct list_head *peers ) )
A doubly-linked list entry (or list head)
Definition: list.h:19
struct mschapv2_challenge peer
Peer challenge.
Definition: mschapv2.h:12
typeof(acpi_finder=acpi_find)
ACPI table finder.
Definition: acpi.c:48
A PeerDist discovery peer.
Definition: peerdisc.h:72

Definition at line 115 of file peerdisc.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ peerdisc_init()

static void peerdisc_init ( struct peerdisc_client peerdisc,
struct peerdisc_client_operations op 
)
inlinestatic

Initialise PeerDist discovery.

Parameters
peerdiscPeerDist discovery client
opDiscovery operations

Definition at line 105 of file peerdisc.h.

106  {
107 
108  peerdisc->op = op;
109 }
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
struct peerdisc_client_operations * op
Operations.
Definition: peerdisc.h:86

References peerdisc_client::op, and op.

Referenced by peerblk_open().

◆ peerdisc_stat()

void peerdisc_stat ( struct interface intf,
struct peerdisc_peer peer,
struct list_head peers 
)

Report peer discovery statistics.

Parameters
intfInterface
peerSelected peer (or NULL)
peersList of available peers

Definition at line 101 of file peerdisc.c.

102  {
103  struct interface *dest;
104  peerdisc_stat_TYPE ( void * ) *op =
106  void *object = intf_object ( dest );
107 
108  if ( op ) {
109  op ( object, peer, peers );
110  } else {
111  /* Default is to do nothing */
112  }
113 
114  intf_put ( dest );
115 }
void * intf_object(struct interface *intf)
Get pointer to object containing object interface.
Definition: interface.c:160
struct interface * intf
Original interface.
Definition: interface.h:159
void peerdisc_stat(struct interface *intf, struct peerdisc_peer *peer, struct list_head *peers)
Report peer discovery statistics.
Definition: peerdisc.c:101
An object interface.
Definition: interface.h:125
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
#define peerdisc_stat_TYPE(object_type)
Definition: peerdisc.h:115
void intf_put(struct interface *intf)
Decrement reference count on an object interface.
Definition: interface.c:150
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" return dest
Definition: string.h:151
struct mschapv2_challenge peer
Peer challenge.
Definition: mschapv2.h:12
#define intf_get_dest_op(intf, type, dest)
Get object interface destination and operation method.
Definition: interface.h:270

References dest, interface::intf, intf_get_dest_op, intf_object(), intf_put(), op, peer, peerdisc_stat(), and peerdisc_stat_TYPE.

Referenced by peerblk_done(), and peerdisc_stat().

◆ peerdisc_open()

int peerdisc_open ( struct peerdisc_client peerdisc,
const void *  id,
size_t  len 
)

Open PeerDist discovery client.

Parameters
peerdiscPeerDist discovery client
idSegment ID
lenLength of segment ID
Return values
rcReturn status code

Definition at line 560 of file peerdisc.c.

561  {
562  struct peerdisc_segment *segment;
563  char id_string[ base16_encoded_len ( len ) + 1 /* NUL */ ];
564  char *id_chr;
565  int rc;
566 
567  /* Construct ID string */
568  base16_encode ( id, len, id_string, sizeof ( id_string ) );
569  for ( id_chr = id_string ; *id_chr ; id_chr++ )
570  *id_chr = toupper ( *id_chr );
571 
572  /* Sanity check */
573  assert ( peerdisc->segment == NULL );
574 
575  /* Open socket if this is the first segment */
576  if ( list_empty ( &peerdisc_segments ) &&
577  ( ( rc = peerdisc_socket_open() ) != 0 ) )
578  return rc;
579 
580  /* Find or create segment */
581  if ( ! ( ( segment = peerdisc_find ( id_string ) ) ||
582  ( segment = peerdisc_create ( id_string ) ) ) )
583  return -ENOMEM;
584 
585  /* Add to list of clients */
586  ref_get ( &segment->refcnt );
587  peerdisc->segment = segment;
588  list_add_tail ( &peerdisc->list, &segment->clients );
589 
590  return 0;
591 }
uint16_t segment
Code segment.
Definition: librm.h:138
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
A PeerDist discovery segment.
Definition: peerdisc.h:43
struct list_head list
List of clients.
Definition: peerdisc.h:84
static struct peerdisc_segment * peerdisc_find(const char *id)
Find PeerDist discovery segment.
Definition: peerdisc.c:366
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:137
static size_t base16_encoded_len(size_t raw_len)
Calculate length of base16-encoded data.
Definition: base16.h:25
static int toupper(int character)
Convert character to upper case.
Definition: ctype.h:121
#define ENOMEM
Not enough space.
Definition: errno.h:535
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:94
ring len
Length.
Definition: dwmac.h:231
uint8_t id_string[24]
ID string.
Definition: eltorito.h:24
#define ref_get(refcnt)
Get additional reference to object.
Definition: refcnt.h:93
struct peerdisc_segment * segment
Discovery segment.
Definition: peerdisc.h:82
static struct peerdisc_segment * peerdisc_create(const char *id)
Create PeerDist discovery segment.
Definition: peerdisc.c:451
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
static int peerdisc_socket_open(void)
Open all PeerDist discovery sockets.
Definition: peerdisc.c:129

References assert(), base16_encoded_len(), ENOMEM, id_string, len, peerdisc_client::list, list_add_tail, list_empty, NULL, peerdisc_create(), peerdisc_find(), peerdisc_socket_open(), rc, ref_get, peerdisc_client::segment, segment, and toupper().

Referenced by peerblk_open().

◆ peerdisc_close()

void peerdisc_close ( struct peerdisc_client peerdisc)

Close PeerDist discovery client.

Parameters
peerdiscPeerDist discovery client

Definition at line 598 of file peerdisc.c.

598  {
599  struct peerdisc_segment *segment = peerdisc->segment;
600 
601  /* Ignore if discovery is already closed */
602  if ( ! segment )
603  return;
604 
605  /* If no peers were discovered, reduce the recommended
606  * discovery timeout to minimise delays on future requests.
607  */
608  if ( list_empty ( &segment->peers ) && peerdisc_timeout_secs ) {
610  DBGC ( segment, "PEERDISC %p reducing timeout to %d "
611  "seconds\n", peerdisc, peerdisc_timeout_secs );
612  }
613 
614  /* Remove from list of clients */
615  peerdisc->segment = NULL;
616  list_del ( &peerdisc->list );
617  ref_put ( &segment->refcnt );
618 
619  /* If this was the last clients, destroy the segment */
620  if ( list_empty ( &segment->clients ) )
622 
623  /* If there are no more segments, close the socket */
624  if ( list_empty ( &peerdisc_segments ) )
625  peerdisc_socket_close ( 0 );
626 }
uint16_t segment
Code segment.
Definition: librm.h:138
static void peerdisc_socket_close(int rc)
Close all PeerDist discovery sockets.
Definition: peerdisc.c:289
A PeerDist discovery segment.
Definition: peerdisc.h:43
#define DBGC(...)
Definition: compiler.h:505
struct list_head list
List of clients.
Definition: peerdisc.h:84
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:137
#define list_del(list)
Delete an entry from a list.
Definition: list.h:120
struct peerdisc_segment * segment
Discovery segment.
Definition: peerdisc.h:82
static void peerdisc_destroy(struct peerdisc_segment *segment)
Destroy PeerDist discovery segment.
Definition: peerdisc.c:532
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:107
unsigned int peerdisc_timeout_secs
Recommended discovery timeout (in seconds)
Definition: peerdisc.c:75

References DBGC, peerdisc_client::list, list_del, list_empty, NULL, peerdisc_destroy(), peerdisc_socket_close(), peerdisc_timeout_secs, ref_put, peerdisc_client::segment, and segment.

Referenced by peerblk_close().

Variable Documentation

◆ peerdisc_timeout_secs

unsigned int peerdisc_timeout_secs

Recommended discovery timeout (in seconds)

We reduce the recommended discovery timeout whenever a segment fails to discover any peers, and restore the default value whenever a valid discovery reply is received. We continue to send discovery requests even if the recommended timeout is reduced to zero.

This strategy is intended to minimise discovery delays when no peers are available on the network, while allowing downloads to quickly switch back to using PeerDist acceleration if new peers become available.

Definition at line 75 of file peerdisc.c.

Referenced by peerblk_open(), peerdisc_close(), and peerdisc_socket_rx().