Exemple #1
0
int serval_open_keyring(const char *keyring_path,
			const size_t keyring_len,
			keyring_file **_keyring) {
  
  char keyring_path_str[PATH_MAX] = {0};
  
  if (keyring_path == NULL || keyring_len == 0) { // if no keyring specified, use default keyring
    strcpy(keyring_path_str,serval_path);
    if (serval_path[strlen(serval_path) - 1] != '/')
      strcat(keyring_path_str,"/");
    strcat(keyring_path_str,"serval.keyring");
    // Fetching SAS keys requires setting the SERVALINSTANCE_PATH environment variable
    CHECK_ERR(setenv("SERVALINSTANCE_PATH",serval_path,1) == 0,"Failed to set SERVALINSTANCE_PATH env variable");
  }
  else { // otherwise, use specified keyring (NOTE: if keyring does not exist, it will be created)
    CHECK(keyring_len < PATH_MAX,"Keyring length too long");
    strncpy(keyring_path_str,keyring_path,keyring_len);
    keyring_path_str[keyring_len] = '\0';
  }
  
  CHECK_ERR((*_keyring = keyring_open(keyring_path_str)),"Failed to open specified keyring file");

  if (keyring_enter_pin(*_keyring, KEYRING_PIN) <= 0) {
    /* put initial identity in if we don't have any visible */
    CHECK_ERR(keyring_seed(*_keyring) == 0,"Failed to seed keyring");
  }
  
  return 1;
error:
  return 0;
}
Exemple #2
0
int
serval_open_keyring(svl_crypto_ctx *ctx)
{
  CHECK_ERR(ctx,"Invalid ctx");
  if (ctx->keyring_len == 0) {
    // if no keyring specified, use default keyring
    CHECK(serval_path,"Default Serval path not initialized");
    char keyring_path_str[PATH_MAX] = {0};
    strcpy(keyring_path_str, serval_path);
    if (serval_path[strlen(serval_path) - 1] != '/')
      strcat(keyring_path_str, "/");
    strcat(keyring_path_str, "serval.keyring");
    // Fetching SAS keys requires setting the SERVALINSTANCE_PATH environment variable
    CHECK_ERR(setenv("SERVALINSTANCE_PATH", serval_path, 1) == 0,
	      "Failed to set SERVALINSTANCE_PATH env variable");
    ctx->keyring_len = strlen(keyring_path_str);
    ctx->keyring_path = h_malloc(ctx->keyring_len + 1);
    strcpy(ctx->keyring_path,keyring_path_str);
    hattach(ctx->keyring_path,ctx);
  } else {
    // otherwise, use specified keyring (NOTE: if keyring does not exist, it will be created)
    CHECK(ctx->keyring_len < PATH_MAX, "Keyring length too long");
  }
  
  ctx->keyring_file = keyring_open(ctx->keyring_path);
  CHECK_ERR(ctx->keyring_file, "Failed to open specified keyring file");

  if (keyring_enter_pin(ctx->keyring_file, KEYRING_PIN) <= 0) {
    // put initial identity in if we don't have any visible
    CHECK_ERR(keyring_seed(ctx->keyring_file) == 0, "Failed to seed keyring");
  }
  
  return 1;
error:
  return 0;
}
Exemple #3
0
int overlayServerMode()
{
  /* In overlay mode we need to listen to all of our sockets, and also to
     send periodic traffic. This means we need to */
  INFO("Running in overlay mode.");

  /* Make sure rhizome configured settings are known. */
  if (rhizome_fetch_interval_ms < 1)
    rhizome_configure();

  /* Get keyring available for use.
     Required for MDP, and very soon as a complete replacement for the
     HLR for DNA lookups, even in non-overlay mode. */
  keyring=keyring_open_with_pins("");
  if (!keyring) {
    return WHY("Could not open serval keyring file.");
  }
  /* put initial identity in if we don't have any visible */
  keyring_seed(keyring);

  /* Set default congestion levels for queues */
  int i;
  for(i=0;i<OQ_MAX;i++) {
    overlay_tx[i].maxLength=100;
    overlay_tx[i].latencyTarget=1000; /* Keep packets in queue for 1 second by default */
    overlay_tx[i].transmit_delay=10; /* Hold onto packets for 10ms before trying to send a full packet */
    overlay_tx[i].grace_period=100; /* Delay sending a packet for up to 100ms if servald has other processing to do */
  }
  /* expire voice/video call packets much sooner, as they just aren't any use if late */
  overlay_tx[OQ_ISOCHRONOUS_VOICE].latencyTarget=500;
  overlay_tx[OQ_ISOCHRONOUS_VIDEO].latencyTarget=500;

  /* try to send voice packets without any delay, and before other background processing */
  overlay_tx[OQ_ISOCHRONOUS_VOICE].transmit_delay=0;
  overlay_tx[OQ_ISOCHRONOUS_VOICE].grace_period=0;

  /* opportunistic traffic can be significantly delayed */
  overlay_tx[OQ_OPPORTUNISTIC].transmit_delay=200;
  overlay_tx[OQ_OPPORTUNISTIC].grace_period=500;
  
  /* Get the set of socket file descriptors we need to monitor.
     Note that end-of-file will trigger select(), so we cannot run select() if we 
     have any dummy interfaces running. So we do an ugly hack of just waiting no more than
     5ms between checks if we have a dummy interface running.  This is a reasonable simulation
     of wifi latency anyway, so we'll live with it.  Larger values will affect voice transport,
     and smaller values would affect CPU and energy use, and make the simulation less realistic. */

#define SCHEDULE(X, Y, D) { \
static struct sched_ent _sched_##X; \
static struct profile_total _stats_##X; \
bzero(&_sched_##X, sizeof(struct sched_ent)); \
bzero(&_stats_##X, sizeof(struct profile_total)); \
_sched_##X.stats = &_stats_##X; \
_sched_##X.function=X;\
_stats_##X.name="" #X "";\
_sched_##X.alarm=gettime_ms()+Y;\
_sched_##X.deadline=_sched_##X.alarm+D;\
schedule(&_sched_##X); }
  
  /* Periodically check for server shut down */
  SCHEDULE(server_shutdown_check, 0, 100);
  
  /* Setup up MDP & monitor interface unix domain sockets */
  overlay_mdp_setup_sockets();
  monitor_setup_sockets();
  
  olsr_init_socket();

  /* Get rhizome server started BEFORE populating fd list so that
     the server's listen socket is in the list for poll() */
  if (rhizome_enabled()) 
    /* Rhizome http server needs to know which callback to attach
       to client sockets, so provide it here, along with the name to
       appear in time accounting statistics. */
    rhizome_http_server_start(rhizome_server_parse_http_request,
			      "rhizome_server_parse_http_request",
			      RHIZOME_HTTP_PORT,RHIZOME_HTTP_PORT_MAX);
  
  // start the dna helper if configured
  dna_helper_start();
  
  // preload directory service information
  directory_service_init();
  
  /* Pick next rhizome files to grab every few seconds
     from the priority list continuously being built from observed
     bundle announcements */
  SCHEDULE(rhizome_enqueue_suggestions, rhizome_fetch_interval_ms, rhizome_fetch_interval_ms*3);

  /* Periodically check for new interfaces */
  SCHEDULE(overlay_interface_discover, 1, 100);

  /* Periodically update route table. */
  SCHEDULE(overlay_route_tick, 100, 100);

  /* Show CPU usage stats periodically */
  if (debug&DEBUG_TIMING){
    SCHEDULE(fd_periodicstats, 3000, 500);
  }

#undef SCHEDULE
  
  while(1) {
    /* Check for activitiy and respond to it */
    fd_poll();
  }

  return 0;
}