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)
 
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 36 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 39 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:18
struct mschapv2_challenge peer
Peer challenge.
Definition: mschapv2.h:12
typeof(acpi_finder=acpi_find)
ACPI table finder.
Definition: acpi.c:45
A PeerDist discovery peer.
Definition: peerdisc.h:71

Definition at line 114 of file peerdisc.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ 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 104 of file peerdisc.h.

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

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 100 of file peerdisc.c.

101  {
102  struct interface *dest;
103  peerdisc_stat_TYPE ( void * ) *op =
105  void *object = intf_object ( dest );
106 
107  if ( op ) {
108  op ( object, peer, peers );
109  } else {
110  /* Default is to do nothing */
111  }
112 
113  intf_put ( dest );
114 }
void * intf_object(struct interface *intf)
Get pointer to object containing object interface.
Definition: interface.c:159
struct interface * intf
Original interface.
Definition: interface.h:158
void peerdisc_stat(struct interface *intf, struct peerdisc_peer *peer, struct list_head *peers)
Report peer discovery statistics.
Definition: peerdisc.c:100
An object interface.
Definition: interface.h:124
static void * dest
Definition: strings.h:176
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
#define peerdisc_stat_TYPE(object_type)
Definition: peerdisc.h:114
void intf_put(struct interface *intf)
Decrement reference count on an object interface.
Definition: interface.c:149
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:269

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 559 of file peerdisc.c.

560  {
561  struct peerdisc_segment *segment;
562  char id_string[ base16_encoded_len ( len ) + 1 /* NUL */ ];
563  char *id_chr;
564  int rc;
565 
566  /* Construct ID string */
567  base16_encode ( id, len, id_string, sizeof ( id_string ) );
568  for ( id_chr = id_string ; *id_chr ; id_chr++ )
569  *id_chr = toupper ( *id_chr );
570 
571  /* Sanity check */
572  assert ( peerdisc->segment == NULL );
573 
574  /* Open socket if this is the first segment */
575  if ( list_empty ( &peerdisc_segments ) &&
576  ( ( rc = peerdisc_socket_open() ) != 0 ) )
577  return rc;
578 
579  /* Find or create segment */
580  if ( ! ( ( segment = peerdisc_find ( id_string ) ) ||
581  ( segment = peerdisc_create ( id_string ) ) ) )
582  return -ENOMEM;
583 
584  /* Add to list of clients */
585  ref_get ( &segment->refcnt );
586  peerdisc->segment = segment;
587  list_add_tail ( &peerdisc->list, &segment->clients );
588 
589  return 0;
590 }
uint16_t segment
Code segment.
Definition: librm.h:252
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
A PeerDist discovery segment.
Definition: peerdisc.h:42
struct list_head list
List of clients.
Definition: peerdisc.h:83
static struct peerdisc_segment * peerdisc_find(const char *id)
Find PeerDist discovery segment.
Definition: peerdisc.c:365
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:136
static size_t base16_encoded_len(size_t raw_len)
Calculate length of base16-encoded data.
Definition: base16.h:24
static int toupper(int character)
Convert character to upper case.
Definition: ctype.h:120
#define ENOMEM
Not enough space.
Definition: errno.h:534
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:93
uint8_t id_string[24]
ID string.
Definition: eltorito.h:24
#define ref_get(refcnt)
Get additional reference to object.
Definition: refcnt.h:92
struct peerdisc_segment * segment
Discovery segment.
Definition: peerdisc.h:81
static struct peerdisc_segment * peerdisc_create(const char *id)
Create PeerDist discovery segment.
Definition: peerdisc.c:450
uint32_t len
Length.
Definition: ena.h:14
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
static int peerdisc_socket_open(void)
Open all PeerDist discovery sockets.
Definition: peerdisc.c:128

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 597 of file peerdisc.c.

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

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 74 of file peerdisc.c.

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