Exemplo n.º 1
0
void
event_dispatcher_notify_work_submitted (EventDispatcher *self,
                                        WorkResult      *work_result)
{
  ClientInfo *info;

  info = get_client_info ((WorkRequest *) work_result);

  /* @TODO: call virtual method */

  if (self->logger != NULL)
    {
      gchar *entry;
      gchar *date_str;

      date_str = get_timestamp_str ();

      entry = g_strdup_printf ("[%s]\tWORK-SUBMITTED\t\"%s\"\t\"%s\"\t%s\t\"%s\"",
                               date_str,
                               info->user,
                               info->passw,
                               info->remote_addr,
                               info->user_agent);
      g_free (date_str);

      file_logger_log (self->logger, entry);
      g_free (entry);
    }

  client_info_free (info);
}
Exemplo n.º 2
0
/* Serve the connection given by DATA.  Under high load, serve only
   the current command (if any) and then put the connection back into
   THREAD's task pool. */
static void * APR_THREAD_FUNC serve_thread(apr_thread_t *tid, void *data)
{
  svn_boolean_t done;
  connection_t *connection = data;
  svn_error_t *err;

  apr_pool_t *pool = svn_root_pools__acquire_pool(connection_pools);

  /* process the actual request and log errors */
  err = serve_interruptable(&done, connection, is_busy, pool);
  if (err)
    {
      logger__log_error(connection->params->logger, err, NULL,
                        get_client_info(connection->conn, connection->params,
                                        pool));
      svn_error_clear(err);
      done = TRUE;
    }
  svn_root_pools__release_pool(pool, connection_pools);

  /* Close or re-schedule connection. */
  if (done)
    close_connection(connection);
  else
    apr_thread_pool_push(threads, serve_thread, connection, 0, NULL);

  return NULL;
}
Exemplo n.º 3
0
void
event_dispatcher_notify_work_validated (EventDispatcher *self,
                                        WorkResult      *work_result,
                                        guint            error_code,
                                        const gchar     *reason)
{
  ClientInfo *info;

  info = get_client_info ((WorkRequest *) work_result);

  if (self->vtable != NULL)
    {
      self->vtable->work_validated (self,
                                    error_code,
                                    info->user,
                                    info->passw,
                                    self->vtable_user_data);
    }

  if (self->logger != NULL)
    {
      gboolean accepted;
      gchar *date_str;
      gchar *entry;

      date_str = get_timestamp_str ();

      accepted = (error_code == WORK_VALIDATOR_ERROR_SUCCESS);

      if (accepted)
        entry = g_strdup_printf ("[%s]\t%s\t\"%s\"\t\"%s\"\t%s\t\"%s\"",
                                 date_str,
                                 "WORK-ACCEPTED",
                                 info->user,
                                 info->passw,
                                 info->remote_addr,
                                 info->user_agent);
      else
        entry = g_strdup_printf ("[%s]\t%s\t\"%s\"\t\"%s\"\t%s\t\"%s\"\t%s\t\"%s\"",
                                 date_str,
                                 "WORK-REJECTED",
                                 info->user,
                                 info->passw,
                                 info->remote_addr,
                                 info->user_agent,
                                 work_validator_error_names[error_code],
                                 reason);
      g_free (date_str);

      file_logger_log (self->logger, entry);
      g_free (entry);
    }

  client_info_free (info);
}
Exemplo n.º 4
0
/* Wrapper around serve() that takes a socket instead of a connection.
 * This is to off-load work from the main thread in threaded and fork modes.
 *
 * If an error occurs, log it and also return it.
 */
static svn_error_t *
serve_socket(connection_t *connection,
             apr_pool_t *pool)
{
  /* process the actual request and log errors */
  svn_error_t *err = serve_interruptable(NULL, connection, NULL, pool);
  if (err)
    logger__log_error(connection->params->logger, err, NULL,
                      get_client_info(connection->conn, connection->params,
                                      pool));

  return svn_error_trace(err);
}
Exemplo n.º 5
0
void
event_dispatcher_notify_block_found (EventDispatcher *self,
                                     guint            block,
                                     WorkResult      *work_result)
{
  ClientInfo *info;

  info = get_client_info ((WorkRequest *) work_result);

  /*
  info = g_slice_new0 (ClientInfo);
  info->user = g_strdup ("pepe");
  info->passw = g_strdup ("lolo");
  info->remote_addr = g_strdup ("127.0.0.1");
  info->user_agent = g_strdup ("tester");
  */

  if (self->vtable->block_found != NULL)
    {
      self->vtable->block_found (self,
                                 block,
                                 info->user,
                                 info->passw,
                                 self->vtable_user_data);
    }

  if (self->logger != NULL)
    {
      gchar *entry;
      gchar *date_str;

      date_str = get_timestamp_str ();

      entry = g_strdup_printf ("[%s]\tBLOCK-FOUND\t%u\t\"%s\"\t\"%s\"",
                               date_str,
                               block,
                               info->user,
                               info->passw);
      g_free (date_str);

      file_logger_log (self->logger, entry);
      g_free (entry);
    }

  client_info_free (info);
}
Exemplo n.º 6
0
int main(int argc, char *argv[])
{
    int     opt, num_thread;
    char    server_url[URL_LENGTH_MAX], ext[UPLOAD_EXT_LENGTH_MAX];
    double  latency, speed, download_speed, upload_speed;
    int     dsize, sindex;

    sindex      = -1;
    num_thread  = 4;
    dsize       = INIT_DOWNLOAD_FILE_RESOLUTION;
    memset(server_url, 0, sizeof(server_url));
    memset(ext, 0, sizeof(ext));

    while ( (opt = getopt(argc, argv, "p:s:lh")) > 0) {

        switch (opt) {
            case 'p':
                if (atoi(optarg) > THREAD_NUM_MAX) {

                    fprintf(stderr, "Only support %d threads meanwhile", THREAD_NUM_MAX);
                    exit(-1);
                }
                num_thread = atoi(optarg);
                break;
            case 's':
                strncpy(server_url, optarg, URL_LENGTH_MAX);
                break;
            case 'l':
                break;
            case 'h':
                show_usage(argv);
                break;
        }
    }

    if (server_url[0] == 0) {
        printf("Retrieving speedtest.net configuration...\n");
        get_client_info(&client);
        printf("Retrieving speedtest.net server list...\n");
        get_closest_server();
        printf("Testing from %s (%s)...\n", client.isp, client.ip);
        printf("Selecting best server based on ping...\n");
        get_best_server(&sindex);
        sscanf(servers[sindex].url, "http://%[^/]/speedtest/upload.%4s", server_url, ext);
        printf("Bestest server: %s(%0.2fKM)\n", server_url, servers[sindex].distance);
    }

    /* Must initialize libcurl before any threads are started */
    curl_global_init(CURL_GLOBAL_ALL);

    latency = test_latency(server_url);
    if (latency == DBL_MAX)
        exit(-1);
    printf("Server latency is %0.0fms\n", latency);

    speed = test_download(server_url, num_thread, dsize, 0);

    dsize = get_download_filename(speed, num_thread);
    fprintf(stderr, "Testing download speed");
    download_speed = test_download(server_url, num_thread, dsize, 1);

    printf("Download speed: %0.2fMbps\n", ((download_speed*8)/(1024*1024)));

    if (ext[0] == 0 && get_upload_extension(server_url, ext) != OK)
        exit(-1);

    speed = test_upload(server_url, num_thread, speed, ext, 0);

    fprintf(stderr, "Testing upload speed");
    upload_speed = test_upload(server_url, num_thread, speed*SPEEDTEST_TIME_MAX, ext, 1);

    printf("Upload speed: %0.2fMbps\n", ((upload_speed*8)/(1024*1024)));

}
Exemplo n.º 7
0
static int cmd_reg(struct cmd *cmd)
{
  int a=0;

  char *p;
  struct device *d;
  struct db_device *dd;
  char sum[64];
  unsigned int n;
  int type;
  char *pass;
  int port;
  char *bcast;

  int did = cmd->device_id;

  char buf[CMD_MAX];

  NEXT_ARG(p);
  type = atoi(p);

  NEXT_ARG(p);
  pass = p;

  NEXT_ARG(p);
  port = atoi(p);

  NEXT_ARG(p);
  bcast = p;

  /* authenticate the passwd based on id and type */
  n = (unsigned int)cmd->device_id ^ (unsigned int)type;
  cksum(&n, sizeof n, sum);
  if (strcmp(pass, sum) != 0)
  {
    trace_warn("authenticate fail\n");
    return 1;
  }

  if (port <= 0)
    return 1;

  dd = md_find_device(did);
  if( dd )
  {
    /* mark it online even if it's disabled.
     * needed for the manager to identify online devs. */
    dd->online = 1;

    if( !dd->enabled )
    {
      return ERR_DEV_DISABLED;
    }
  }

  d = get_device(did);

  if( !d )
  {
    d = dev_create(did);
  }

  d->type = type;

  d->addr = *cmd->saddr;
  d->addr.sin_port = htons(port);

  d->fileaddr = d->addr;
  d->fileaddr.sin_port = htons(port+1);

  if (strcmp("none", bcast) == 0)
    d->bcast.sin_addr.s_addr = 0;
  else
  {
    d->bcast.sin_addr.s_addr = inet_addr(bcast);
    d->bcast.sin_port = htons(BRCAST_PORT);
  }

  dev_update_data(d);

  if (dev_register(d) != 0)
  {
    /* existing dev ok */
  }

  dev_activate(d);

  if( is_ptc(d) )
  {
    /* re-set ptc if it's restarted. */
    ptc_go_current();
  }

  if( d->type == DEVTYPE_CHAIR )
  {
    manage_notify_chair(d);
  }

  get_client_info(buf, d);

  REP_ADD(cmd, "OK");
  REP_ADD(cmd, buf);
  REP_END(cmd);

  return 0;
}