iPXE
peerdisc.h
Go to the documentation of this file.
00001 #ifndef _IPXE_PEERDISC_H
00002 #define _IPXE_PEERDISC_H
00003 
00004 /** @file
00005  *
00006  * Peer Content Caching and Retrieval (PeerDist) protocol peer discovery
00007  *
00008  */
00009 
00010 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00011 
00012 #include <stdint.h>
00013 #include <ipxe/refcnt.h>
00014 #include <ipxe/list.h>
00015 #include <ipxe/tables.h>
00016 #include <ipxe/retry.h>
00017 #include <ipxe/socket.h>
00018 #include <ipxe/interface.h>
00019 #include <ipxe/pccrc.h>
00020 
00021 /** A PeerDist discovery socket */
00022 struct peerdisc_socket {
00023         /** Name */
00024         const char *name;
00025         /** Data transfer interface */
00026         struct interface xfer;
00027         /** Socket address */
00028         union {
00029                 struct sockaddr sa;
00030                 struct sockaddr_in sin;
00031                 struct sockaddr_in6 sin6;
00032         } address;
00033 };
00034 
00035 /** PeerDist discovery socket table */
00036 #define PEERDISC_SOCKETS __table ( struct peerdisc_socket, "peerdisc_sockets" )
00037 
00038 /** Declare a PeerDist discovery socket */
00039 #define __peerdisc_socket __table_entry ( PEERDISC_SOCKETS, 01 )
00040 
00041 /** A PeerDist discovery segment */
00042 struct peerdisc_segment {
00043         /** Reference count */
00044         struct refcnt refcnt;
00045         /** List of segments */
00046         struct list_head list;
00047         /** Segment identifier string
00048          *
00049          * This is MS-PCCRC's "HoHoDk", transcribed as an upper-case
00050          * Base16-encoded string.
00051          */
00052         const char *id;
00053         /** Message UUID string */
00054         const char *uuid;
00055         /** List of discovered peers
00056          *
00057          * The list of peers may be appended to during the lifetime of
00058          * the discovery segment.  Discovered peers will not be
00059          * removed from the list until the last discovery has been
00060          * closed; this allows users to safely maintain a pointer to a
00061          * current position within the list.
00062          */
00063         struct list_head peers;
00064         /** List of active clients */
00065         struct list_head clients;
00066         /** Transmission timer */
00067         struct retry_timer timer;
00068 };
00069 
00070 /** A PeerDist discovery peer */
00071 struct peerdisc_peer {
00072         /** List of peers */
00073         struct list_head list;
00074         /** Peer location */
00075         char location[0];
00076 };
00077 
00078 /** A PeerDist discovery client */
00079 struct peerdisc_client {
00080         /** Discovery segment */
00081         struct peerdisc_segment *segment;
00082         /** List of clients */
00083         struct list_head list;
00084         /** Operations */
00085         struct peerdisc_client_operations *op;
00086 };
00087 
00088 /** PeerDist discovery client operations */
00089 struct peerdisc_client_operations {
00090         /** New peers have been discovered
00091          *
00092          * @v peerdisc          PeerDist discovery client
00093          */
00094         void ( * discovered ) ( struct peerdisc_client *peerdisc );
00095 };
00096 
00097 /**
00098  * Initialise PeerDist discovery
00099  *
00100  * @v peerdisc          PeerDist discovery client
00101  * @v op                Discovery operations
00102  */
00103 static inline __attribute__ (( always_inline )) void
00104 peerdisc_init ( struct peerdisc_client *peerdisc,
00105                 struct peerdisc_client_operations *op ) {
00106 
00107         peerdisc->op = op;
00108 }
00109 
00110 extern unsigned int peerdisc_timeout_secs;
00111 
00112 extern void peerdisc_stat ( struct interface *intf, struct peerdisc_peer *peer,
00113                             struct list_head *peers );
00114 #define peerdisc_stat_TYPE( object_type )                               \
00115         typeof ( void ( object_type, struct peerdisc_peer *peer,        \
00116                         struct list_head *peers ) )
00117 
00118 extern int peerdisc_open ( struct peerdisc_client *peerdisc, const void *id,
00119                            size_t len );
00120 extern void peerdisc_close ( struct peerdisc_client *peerdisc );
00121 
00122 #endif /* _IPXE_PEERDISC_H */