#include <ipxe/netdevice.h>
#include <ipxe/timer.h>
#include <ipxe/fault.h>
+#include <ipxe/settings.h>
#include <ipxe/pccrd.h>
#include <ipxe/peerdisc.h>
*/
unsigned int peerdisc_timeout_secs = PEERDISC_DEFAULT_TIMEOUT_SECS;
+/** Hosted cache server */
+static char *peerhost;
+
static struct peerdisc_segment * peerdisc_find ( const char *id );
static int peerdisc_discovered ( struct peerdisc_segment *segment,
const char *location );
char *uuid_copy;
char *id_copy;
unsigned int i;
+ int rc;
/* Generate a random message UUID. This does not require high
* quality randomness.
/* Allocate and initialise structure */
segment = zalloc ( sizeof ( *segment ) + id_len + uuid_len );
if ( ! segment )
- return NULL;
+ goto err_alloc;
id_copy = ( ( ( void * ) segment ) + sizeof ( *segment ) );
memcpy ( id_copy, id, id_len );
uuid_copy = ( ( ( void * ) id_copy ) + id_len );
INIT_LIST_HEAD ( &segment->peers );
INIT_LIST_HEAD ( &segment->clients );
timer_init ( &segment->timer, peerdisc_expired, &segment->refcnt );
- DBGC2 ( segment, "PEERDISC %p discovering %s\n", segment, segment->id );
- /* Start discovery timer */
- start_timer_nodelay ( &segment->timer );
+ /* Add hosted cache server or initiate discovery */
+ if ( peerhost ) {
+
+ /* Add hosted cache server to list of peers */
+ if ( ( rc = peerdisc_discovered ( segment, peerhost ) ) != 0 )
+ goto err_peerhost;
+
+ } else {
+
+ /* Start discovery timer */
+ start_timer_nodelay ( &segment->timer );
+ DBGC2 ( segment, "PEERDISC %p discovering %s\n",
+ segment, segment->id );
+ }
/* Add to list of segments, transfer reference to list, and return */
list_add_tail ( &segment->list, &peerdisc_segments );
return segment;
+
+ err_peerhost:
+ ref_put ( &segment->refcnt );
+ err_alloc:
+ return NULL;
}
/**
if ( list_empty ( &peerdisc_segments ) )
peerdisc_socket_close ( 0 );
}
+
+/******************************************************************************
+ *
+ * Settings
+ *
+ ******************************************************************************
+ */
+
+/** PeerDist hosted cache server setting */
+const struct setting peerhost_setting __setting ( SETTING_MISC, peerhost ) = {
+ .name = "peerhost",
+ .description = "PeerDist hosted cache",
+ .type = &setting_type_string,
+};
+
+/**
+ * Apply PeerDist discovery settings
+ *
+ * @ret rc Return status code
+ */
+static int apply_peerdisc_settings ( void ) {
+
+ /* Free any existing hosted cache server */
+ free ( peerhost );
+ peerhost = NULL;
+
+ /* Fetch hosted cache server */
+ fetch_string_setting_copy ( NULL, &peerhost_setting, &peerhost );
+ if ( peerhost ) {
+ DBGC ( &peerhost, "PEERDISC using hosted cache %s\n",
+ peerhost );
+ }
+
+ return 0;
+}
+
+/** PeerDist discovery settings applicator */
+struct settings_applicator peerdisc_applicator __settings_applicator = {
+ .apply = apply_peerdisc_settings,
+};