Example #1
0
/**
 * Called when a row of the upload stats should be updated
 */
void
upload_stats_gui_update_model(struct ul_stats *us)
{
	GtkCList *clist = clist_ul_stats();
	enum c_us i;
	int row;

	row = ul_stats_get_row(us);
	g_return_if_fail(row >= 0);

	for (i = 0; i < c_us_num; i++) {
		const char *text = NULL;
		char tmpstr[16];

		switch (i) {
		case c_us_filename:
		case c_us_size:
			/* Never updated, only initialized */
			continue;
		case c_us_attempts:
			text = uint64_to_string(us->attempts);
			break;
		case c_us_complete:
			text = uint64_to_string(us->complete);
			break;
		case c_us_norm:
			gm_snprintf(tmpstr, sizeof tmpstr, "%.3f", us->norm);
			text = tmpstr;
			break;
		case c_us_rtime:
			text = us->rtime ? timestamp_to_string(us->rtime) : "";
			break;
		case c_us_dtime:
			text = us->dtime ? timestamp_to_string(us->dtime) : "";
			break;
		case c_us_num:
			text = NULL;
			g_assert_not_reached();
		}
		gtk_clist_set_text(clist, row, i, text);
	}

	/* FIXME: use auto-sort? */
	if (0 == clist->freeze_count) {
		gtk_clist_sort(clist);
		clist_sync_rows(clist, on_clist_ul_stats_row_moved);
	}
}
Example #2
0
static ssize_t data_timestamp_t_convert_to(data_t *src, fastcall_convert_to *fargs){ // {{{
	ssize_t                ret;
	char                   buffer[DEF_BUFFER_SIZE];
	uintmax_t              buffer_size       = sizeof(buffer);
	uintmax_t              transfered        = 0;
	timestamp_t           *fdata             = (timestamp_t *)src->ptr;
	time_t                 time_val          = timestamp_gettime(fdata);
	
	if(fargs->dest == NULL || fdata == NULL)
		return -EINVAL;
	
	switch( fargs->format ){
		case FORMAT(native):;
		case FORMAT(packed):;
			fastcall_write r_write = { { 5, ACTION_WRITE }, 0, &time_val, sizeof(time_val) };
			ret        = data_query(fargs->dest, &r_write);
			transfered = r_write.buffer_size;
			break;
		
		default:
			if( (ret = timestamp_to_string(time_val, buffer, &buffer_size, fargs->format)) != 0)
				return ret;
			
			fastcall_write r_write2 = { { 5, ACTION_WRITE }, 0, &buffer, buffer_size };
			ret        = data_query(fargs->dest, &r_write2);
			transfered = r_write.buffer_size;
			break;
	}
	if(fargs->header.nargs >= 5)
		fargs->transfered = transfered;
	
	return ret;
} // }}}
Example #3
0
static void
cell_renderer_func(GtkTreeViewColumn *column,
	GtkCellRenderer *cell, GtkTreeModel *model, GtkTreeIter *iter,
	gpointer udata)
{
	static const GValue zero_value;
	const struct upload_data *data;
	const gchar *text = NULL;
	gchar buf[64];
	GValue value;

	if (!gtk_tree_view_column_get_visible(column))
		return;

	value = zero_value;
	gtk_tree_model_get_value(model, iter, 0, &value);
	data = g_value_get_pointer(&value);
	switch ((enum c_us) GPOINTER_TO_UINT(udata)) {
	case c_us_filename:
		text = data->filename;
		break;
	case c_us_size:
		text = short_size(data->us->size, show_metric_units());
		break;
	case c_us_attempts:
		text = uint64_to_string(data->us->attempts);
		break;
	case c_us_complete:
		text = uint64_to_string(data->us->attempts);
		break;
	case c_us_norm:
		str_bprintf(buf, sizeof buf, "%1.3f", data->us->norm);
		text = buf;
		break;
	case c_us_rtime:
		text = data->us->rtime ? timestamp_to_string(data->us->rtime) : NULL;
		break;
	case c_us_dtime:
		text = data->us->dtime ? timestamp_to_string(data->us->dtime) : NULL;
		break;
	case c_us_num:
		g_assert_not_reached();
	}
	g_object_set(cell, "text", text, (void *) 0);
}
Example #4
0
/**
 * Emit the configuration preamble.
 */
void
file_config_preamble(FILE *out, const char *what)
{
	time_t now = tm_time();

	g_assert(out);

	fputs("# THIS FILE IS AUTOMATICALLY GENERATED -- DO NOT EDIT\n", out);
	fprintf(out, "#\n# %s saved on %s\n#\n\n", what, timestamp_to_string(now));
}
Example #5
0
void logger::start() {
#if CAF_LOG_LEVEL >= 0
  parent_thread_ = std::this_thread::get_id();
  if (level_ == CAF_LOG_LEVEL_QUIET)
    return;
  t0_ = make_timestamp();
  auto f = get_or(system_.config(), "logger.file-name",
                  defaults::logger::file_name);
  if (f.empty()) {
    // No need to continue if console and log file are disabled.
    if (has(console_output_flag))
      return;
  } else {
    // Replace placeholders.
    const char pid[] = "[PID]";
    auto i = std::search(f.begin(), f.end(), std::begin(pid),
                         std::end(pid) - 1);
    if (i != f.end()) {
      auto id = std::to_string(detail::get_process_id());
      f.replace(i, i + sizeof(pid) - 1, id);
    }
    const char ts[] = "[TIMESTAMP]";
    i = std::search(f.begin(), f.end(), std::begin(ts), std::end(ts) - 1);
    if (i != f.end()) {
      auto t0_str = timestamp_to_string(t0_);
      f.replace(i, i + sizeof(ts) - 1, t0_str);
    }
    const char node[] = "[NODE]";
    i = std::search(f.begin(), f.end(), std::begin(node), std::end(node) - 1);
    if (i != f.end()) {
      auto nid = to_string(system_.node());
      f.replace(i, i + sizeof(node) - 1, nid);
    }
    file_.open(f, std::ios::out | std::ios::app);
    if (!file_) {
      std::cerr << "unable to open log file " << f << std::endl;
      return;
    }
  }
  if (has(inline_output_flag))
    log_first_line();
  else
    thread_ = std::thread{[this] {
      this->system_.thread_started();
      this->run();
      this->system_.thread_terminates();
    }};
#endif
}
Example #6
0
static void			sessions_del(struct session *elt)
{
  struct tcp_stream		*tcp;

  if (NULL == elt)
    return;
  --sessions_count;
  if ((bonus_time || verbose) && (!elt->parent_id || verbose > 1))
    printf("Session #%d (%s) closed at %s (active sessions total: %d)\n",
	elt->parent_id ? elt->parent_id : elt->id,
	type2string(elt->type, 1),
	timestamp_to_string(&nids_last_pcap_header->ts),
	sessions_count);
  if (NULL != elt->next)
    elt->next->prev = elt->prev;
  if (NULL != elt->prev)
    elt->prev->next = elt->next;
  else
    first_session = elt->next;

  /*
   * If this is a TCP connection, tell libnids we do not
   * want to be notified of new data in this connection.
   *
   * We must not do it when the stream is already in a
   * closing state (NIDS_CLOSE, NIDS_TIMED_OUT, NIDS_RESET
   * or NIDS_EXITING) because nids_free_tcp_stream() would
   * then be called twice, resulting in a crash.
   */
  if ((elt->type & TYPE_TCP) &&
      (NULL != (tcp = nids_find_tcp_stream(&elt->addr))) &&
      (NIDS_DATA == tcp->nids_state))
    nids_free_tcp_stream(tcp);

# ifdef HAVE_LIBOSIPPARSER2
  /*
   * If this is a SIP session, finally free the memory
   * allocated for the call ID (couldn't be done before)
   */
  if (elt->type & TYPE_SIP)
    if (NULL != elt->u.sip_params.call_id)
      osip_call_id_free(elt->u.sip_params.call_id);
# endif

  dumper_close(elt->dumper);
  free(elt);
}
Example #7
0
static struct session		*sessions_add(enum type t, struct tuple4 *addr, struct session *parent)
{
  struct session		*elt;
  static uint32_t		counter = 0;

  if (!(t & sessions_track_types))
    return NULL;
  elt = calloc(1, sizeof (struct session));
  elt->addr = *addr;
  elt->type = t;
  elt->id = ++counter;
  if (sessions_expiration_delay)
    elt->timeout = nids_last_pcap_header->ts.tv_sec + sessions_expiration_delay;
  if (t & TYPE_SIP)
    elt->callback = sip_callback;
  else
    if (t & TYPE_H225_RAS)
      elt->callback = h225_ras_callback;
    else
      if (t & TYPE_H225_CS)
	elt->callback = h225_cs_callback;
      else
	elt->callback = NULL;
  if (NULL != parent) {
    elt->parent_id = parent->id;
    elt->dumper = parent->dumper;
    elt->dumper->references++;
  } else
    elt->dumper = sessions_file_format ? dumper_open(t, elt->id) : NULL;
  elt->next = first_session;
  if (NULL != elt->next)
    elt->next->prev = elt;
  elt->prev = NULL;
  first_session = elt;
  ++sessions_count;
  if (verbose && (!elt->parent_id || verbose > 1))
    printf("Session #%d (%s) opened at %s (active sessions total: %d)\n",
	elt->parent_id ? elt->parent_id : elt->id,
	type2string(t, 1),
	timestamp_to_string(&nids_last_pcap_header->ts),
	sessions_count);
  return elt;
}
Example #8
0
static void
cell_renderer(GtkTreeViewColumn *column, GtkCellRenderer *cell, 
	GtkTreeModel *model, GtkTreeIter *iter, gpointer udata)
{
	const struct result_data *data;
    const struct results_set *rs;
	const gchar *text;
	enum c_sr_columns id;

	if (!gtk_tree_view_column_get_visible(column))
		return;

	text = NULL;	/* default to nothing */
	id = GPOINTER_TO_UINT(udata);
	data = get_result_data(model, iter);
    rs = data->record->results_set;

	switch (id) {
	case c_sr_filename:
		text = data->record->utf8_name;
		break;
	case c_sr_ext:
		text = data->record->ext;
		break;
	case c_sr_mime:
		text = mime_type_to_string(mime_type_from_extension(data->record->ext));
		break;
	case c_sr_vendor:
		if (!(ST_LOCAL & rs->status))
			text = vendor_code_get_name(rs->vendor);
		break;
	case c_sr_info:
		text = data->record->info;
		break;
	case c_sr_size:
		text = compact_size(data->record->size, show_metric_units());
		break;
	case c_sr_count:
		text = data->children ? uint32_to_string(1 + data->children) : NULL;
		break;
	case c_sr_loc:
		if (ISO3166_INVALID != rs->country)
			text = iso3166_country_cc(rs->country);
		break;
	case c_sr_charset:
		if (!(ST_LOCAL & rs->status))
			text = data->record->charset;
		break;
	case c_sr_route:
		text = search_gui_get_route(rs);
		break;
	case c_sr_protocol:
		if (!((ST_LOCAL | ST_BROWSE) & rs->status))
			text = ST_UDP & rs->status ?
				(ST_SR_UDP & rs->status ? N_("UDP (semi-reliable)") : "UDP")
				: "TCP";
		break;
	case c_sr_hops:
		if (!((ST_LOCAL | ST_BROWSE) & rs->status))
			text = uint32_to_string(rs->hops);
		break;
	case c_sr_ttl:
		if (!((ST_LOCAL | ST_BROWSE) & rs->status))
			text = uint32_to_string(rs->ttl);
		break;
	case c_sr_spam:
		if (SR_SPAM & data->record->flags) {
			text = "S";	/* Spam */
		} else if (ST_SPAM & rs->status) {
			text = "maybe";	/* maybe spam */
		}
		break;
	case c_sr_owned:
		if (SR_OWNED & data->record->flags) {
			text = _("owned");
		} else if (SR_PARTIAL & data->record->flags) {
			text = _("partial");
		} else if (SR_SHARED & data->record->flags) {
			text = _("shared");
		}
		break;
	case c_sr_hostile:
		if (ST_HOSTILE & rs->status) {
			text = "H";
		}
		break;
	case c_sr_sha1:
		if (data->record->sha1) {
			text = sha1_base32(data->record->sha1);
		}
		break;
	case c_sr_ctime:
		if ((time_t) -1 != data->record->create_time) {
			text = timestamp_to_string(data->record->create_time);
		}
		break;
	case c_sr_num:
		g_assert_not_reached();
		break;
	}
	g_object_set(cell,
		"text", text,
		"foreground-gdk", gui_color_get(data->color),
		"background-gdk", gui_color_get(GUI_COLOR_BACKGROUND),
		(void *) 0);
}
Example #9
0
void				sessions_exit(void)
{
  struct session		*elt;
  struct session		*elt_next;
  time_t			one_minute_later = 0;

  /*
   * Last pass to close timeout'd session... It is needed
   * because the last packet of a session marked for
   * deletion can be followed only by non-IP packets, so
   * it won't be deleted by ip_callback and would otherwise
   * appear as unclosed in the report generated below.
   * We jump forward one minute in order to timeout TCP
   * sessions that were opened during the last minute
   * of capture, which were given 60 seconds to complete
   * handshake but failed to do so.
   *
   * Also close SIP sessions that did not result in a call:
   * it happens often and the resulting spam in the report
   * generated below can be really annoying.
   */
  if (NULL != nids_last_pcap_header)
    one_minute_later = nids_last_pcap_header->ts.tv_sec + 60;
  for (elt = first_session; NULL != elt; elt = elt_next) {
    elt_next = elt->next;
    if (elt->timeout && (one_minute_later >= elt->timeout)) {
      sessions_del(elt);
      continue;
    }
# ifdef HAVE_LIBOSIPPARSER2
    if ((elt->type & TYPE_SIP) && !elt->u.sip_params.picked_up)
      sessions_del(elt);
# endif
  }

  /*
   * Print a report about unclosed sessions.
   */
  if (sessions_count) {
    fprintf(stderr,
	    "%d unclosed %s (id, type, last, source, destination, bytes):\n",
	    sessions_count, sessions_count > 1 ? "sessions" : "session");
    while (NULL != first_session) {
      fprintf(stderr, "#%d\t", first_session->id);
      fprintf(stderr, "%s\t", type2string(first_session->type, 1));
      fprintf(stderr, "%s\t", timestamp_to_string(&first_session->lastseen));
      fprintf(stderr, "%15s:%-5d\t",
	  inet_ntoa(*((struct in_addr *)&first_session->addr.saddr)),
	  first_session->addr.source);
      fprintf(stderr, "%15s:%-5d\t",
	  inet_ntoa(*((struct in_addr *)&first_session->addr.daddr)),
	  first_session->addr.dest);
      fprintf(stderr, "%12d\n", first_session->bytes);
      dumper_close(first_session->dumper);
      if (NULL != first_session->next) {
	first_session = first_session->next;
	free(first_session->prev);
	first_session->prev = NULL;
      } else {
	free(first_session);
	first_session = NULL;
      }
      --sessions_count;
    }
  }
  track_sessions = 0;
  nids_exit();
}
Example #10
0
static enum shell_reply
shell_exec_download_show(struct gnutella_shell *sh,
	int argc, const char *argv[])
{
	fileinfo_t *fi;
	struct guid guid;
	const char *id, *property;
	gnet_fi_status_t status;
	gnet_fi_info_t *info;
	int i;

	shell_check(sh);
	g_assert(argv);
	g_assert(argc > 0);

	if (argc < 3) {
		shell_set_msg(sh, "parameter missing");
		goto error;
	}
	id = argv[2];

	if (!hex_to_guid(id, &guid)) {
		shell_set_msg(sh, "Unparsable ID");
		goto error;
	}

	fi = file_info_by_guid(&guid);
	if (NULL == fi) {
		shell_set_msg(sh, "Invalid ID");
		goto error;
	}

	info = guc_fi_get_info(fi->fi_handle);
	guc_fi_get_status(fi->fi_handle, &status);

	for (i = 3; i < argc; i++) {
		property = argv[i];

		if (0 == strcmp(property, "id")) {
			show_property(sh, property, guid_to_string(info->guid));
		} else if (0 == strcmp(property, "filename")) {
			show_property(sh, property, info->filename);
		} else if (0 == strcmp(property, "pathname")) {
			show_property(sh, property, fi->pathname);
		} else if (0 == strcmp(property, "size")) {
			show_property(sh, property, filesize_to_string(info->size));
		} else if (0 == strcmp(property, "sha1")) {
			show_property(sh, property,
				info->sha1 ? sha1_to_urn_string(info->sha1) : "");
		} else if (0 == strcmp(property, "tth")) {
			show_property(sh, property,
				info->tth ? tth_to_urn_string(info->tth) : "");
		} else if (0 == strcmp(property, "bitprint")) {
			show_property(sh, property,
				(info->sha1 && info->tth)
					? bitprint_to_urn_string(info->sha1, info->tth) : "");
		} else if (0 == strcmp(property, "created")) {
			show_property(sh, property,
				info->created ? timestamp_to_string(info->created) : "");
		} else if (0 == strcmp(property, "modified")) {
			show_property(sh, property,
				status.modified ? timestamp_to_string(status.modified) : "");
		} else if (0 == strcmp(property, "downloaded")) {
			show_property(sh, property, filesize_to_string(status.done));
		} else if (0 == strcmp(property, "uploaded")) {
			show_property(sh, property, uint64_to_string(status.uploaded));
		} else if (0 == strcmp(property, "paused")) {
			show_property(sh, property, boolean_to_string(status.paused));
		} else if (0 == strcmp(property, "seeding")) {
			show_property(sh, property, boolean_to_string(status.seeding));
		} else if (0 == strcmp(property, "verifying")) {
			show_property(sh, property, boolean_to_string(status.verifying));
		} else if (0 == strcmp(property, "finished")) {
			show_property(sh, property, boolean_to_string(status.finished));
		} else if (0 == strcmp(property, "complete")) {
			show_property(sh, property, boolean_to_string(status.complete));
		} else if (0 == strcmp(property, "magnet")) {
			char *magnet = file_info_build_magnet(fi->fi_handle);
			show_property(sh, property, EMPTY_STRING(magnet));
			HFREE_NULL(magnet);
		}
	}
	guc_fi_free_info(info);
	return REPLY_READY;

error:
	return REPLY_ERROR;
}
Example #11
0
/**
 * Called after GUI initialized to warn them about an ancient version.
 * (over a year old).
 *
 * If the version being ran is not a stable one, warn after 60 days, otherwise
 * warn after a year.  If we're not "expired" yet but are approaching the
 * deadline, start to remind them.
 */
void
version_ancient_warn(void)
{
	time_t now = tm_time();
	time_delta_t lifetime, remain, elapsed;
	time_t s;

	g_assert(our_version.timestamp != 0);	/* version_init() called */

	/*
	 * Must reset the property to FALSE so that if it changes and becomes
	 * TRUE, then the necessary GUI callbacks will get triggered.  Indeed,
	 * setting a property to its ancient value is not considered a change,
	 * and rightfully so!
	 */

	gnet_prop_set_boolean_val(PROP_ANCIENT_VERSION, FALSE);

	elapsed = delta_time(now, our_version.timestamp);

	if (elapsed > VERSION_ANCIENT_WARN || tok_is_ancient(now)) {
		static bool warned = FALSE;
		if (GNET_PROPERTY(version_debug)) {
			g_debug("VERSION our_version = %s (elapsed = %ld, token %s)",
				timestamp_to_string(our_version.timestamp),
				(long) elapsed, tok_is_ancient(now) ? "ancient" : "ok");
		}
		if (!warned) {
			g_warning("version of gtk-gnutella is too old, please upgrade!");
			warned = TRUE;
		}
        gnet_prop_set_boolean_val(PROP_ANCIENT_VERSION, TRUE);
		return;
	}

	/*
	 * Check whether we're nearing ancient version status, to warn them
	 * beforehand that the version will become old soon.
	 */

	lifetime = VERSION_ANCIENT_WARN;
	remain = delta_time(lifetime, elapsed);

	g_assert(remain >= 0);		/* None of the checks above have fired */

	/*
	 * Try to see whether the token will expire within the next
	 * VERSION_ANCIENT_REMIND secs, looking for the minimum cutoff date.
	 *
	 * Indeed, it is possible to emit new versions without issuing a
	 * new set of token keys, thereby constraining the lifetime of the
	 * version.  This is usually what happens for bug-fixing releases
	 * that do not introduce significant Gnutella features.
	 */

	s = time_advance(now, VERSION_ANCIENT_REMIND);
	for (/* NOTHING */; delta_time(s, now) > 0; s -= SECS_PER_DAY) {
		if (!tok_is_ancient(s))
			break;
	}

	remain = MIN(remain, delta_time(s, now));

	/*
	 * Let them know when version will expire soon...
	 */

	if (remain < VERSION_ANCIENT_REMIND) {
        gnet_prop_set_guint32_val(PROP_ANCIENT_VERSION_LEFT_DAYS,
			remain / SECS_PER_DAY);
	}
}