Esempio n. 1
0
void
signal_printer_dcc_chat_failed(gpointer *params)
{
	struct DCC *dcc = params[0];
	server *serv = dcc->serv;
	gchar *portbuf = params[1];
	gchar *error = params[2];

	session_print_format(serv->front_session, "dcc chat failed", dcc->nick, net_ip(dcc->addr), portbuf, error, 0);
	dcc_close(dcc, STAT_FAILED, FALSE);
}
Esempio n. 2
0
static void
dcc_info (struct DCC *dcc)
{
	char tbuf[256];
	snprintf (tbuf, 255, _("      File: %s\n"
				 "   To/From: %s\n"
				 "      Size: %d\n"
				 "      Port: %d\n"
				 " IP Number: %s\n"
				 "Start Time: %s"),
				 dcc->file,
				 dcc->nick,
				 dcc->size,
				 dcc->port,
				 net_ip (dcc->addr), ctime (&dcc->starttime));
	gtkutil_simpledialog (tbuf);
}
Esempio n. 3
0
static as_bool timer_cb (int test_id)
{
	static int count = 1;
	TCPC *c;

	printf ("[%d]   Timer callback %d\n", test_id, count);

	if (count < 5)
	{
		count++;
		return TRUE; /* call us again */
	}

	/* reset count for next test */
	count = 1;
	printf ("[%d]   Timer test completed successfully.\n", test_id);

	/* do a socket event test */
	printf ("[%d] Step 2: Trying TCP connection to 127.0.0.1:1111 with 10 "
	        "second timeout...\n", test_id);

	if (!(c = tcp_open (net_ip ("127.0.0.1"), 1111, FALSE)))
	{
		printf ("[%d]   tcp_open() failed.\n", test_id);
		return FALSE;
	}

	c->udata = (void *)test_id;

	if (input_add (c->fd, (void *)c, INPUT_WRITE,
                   (InputCallback)input_cb, 10 * SECONDS) == 0)
	{
		printf ("[%d]   input_add() failed.\n", test_id);
		tcp_close (c);
		return FALSE;
	}

	return FALSE; /* discard this timer */
}
Esempio n. 4
0
static void
dcc_details_populate (struct DCC *dcc)
{
	char buf[128];

	if (!dcc)
	{
		gtk_label_set_text (GTK_LABEL (dccfwin.file_label), NULL);
		gtk_label_set_text (GTK_LABEL (dccfwin.address_label), NULL);
		return;
	}

	/* full path */
	if (dcc->type == TYPE_RECV)
		gtk_label_set_text (GTK_LABEL (dccfwin.file_label), dcc->destfile);
	else
		gtk_label_set_text (GTK_LABEL (dccfwin.file_label), dcc->file);

	/* address and port */
	snprintf (buf, sizeof (buf), "%s : %d", net_ip (dcc->addr), dcc->port);
	gtk_label_set_text (GTK_LABEL (dccfwin.address_label), buf);
}
static void fst_plugin_connect_next ()
{
	FSTNode *node;
	FSTSession *sess;
	List *l;
	int count = 0, nsessions, nconnecting = 0;

	nsessions = config_get_int (FST_PLUGIN->conf, "main/additional_sessions=0");

	if (nsessions > FST_MAX_ADDITIONAL_SESSIONS)
		nsessions = FST_MAX_ADDITIONAL_SESSIONS;

	/* determine number of currently connecting sessions */
	nconnecting = (FST_PLUGIN->session && FST_PLUGIN->session->state != SessEstablished) ? 1 : 0;
	for (l = FST_PLUGIN->sessions; l; l = l->next)
	{
		assert (l->data);
		if (((FSTSession*)l->data)->state != SessEstablished)
			nconnecting++;
	}

	/* connect to head node in node cache */
	while ((!FST_PLUGIN->session || 
	       list_length (FST_PLUGIN->sessions) <= nsessions) && 
	       nconnecting <= FST_SESSION_MAX_CONCURRENT_ATTEMPTS)
	{
		if (!(node = fst_nodecache_get_front (FST_PLUGIN->nodecache)))
		{
			/* node cache empty */
			FST_ERR ("All attempts at contacting peers have failed. Trying default nodes file.");
			
			if (fst_nodecache_load (FST_PLUGIN->nodecache, 
						stringf ("%s/FastTrack/nodes", platform_data_dir())) <= 0 ||
			    !(node = fst_nodecache_get_front (FST_PLUGIN->nodecache)))
			{
				FST_ERR ("Failed to load default nodes file. Perhaps your installation is corrupt?");
				return;
			}
		}
		
		/* don't connect anywhere we're already connected to */
		if (node->session)
		{
			/* move node to back of cache so next loop
			 * uses a different one */
			fst_nodecache_move (FST_PLUGIN->nodecache, node, NodeInsertBack);
			fst_node_release (node);
			
			/* we've probably run out of nodes at this point, so
			 * wait a while until we get some more (continuing
			 * tends to produce an infinite loop) */
			if (count++ >= list_length (FST_PLUGIN->sessions))
				return;

			continue;
		}
		
		/* don't connect to anywhere too close to an existing node */
		if (dataset_lookup (FST_PLUGIN->peers, &node, sizeof(node)))
		{
#if 0
			FST_DBG_2 ("not connecting to close node %s:%d",
			           node->host, node->port);
#endif

			/* move node to back of cache so next loop
			 * uses a different one */
			fst_nodecache_move (FST_PLUGIN->nodecache, node, NodeInsertBack);
			fst_node_release (node);

			/* we've probably run out of nodes at this point, so
			 * wait a while until we get some more (continuing
			 * tends to produce an infinite loop) */
			if (count++ >= list_length (FST_PLUGIN->sessions))
				return;

			continue;
		}

		/* don't connect to invalid ips */
		if (!fst_utils_ip_routable (net_ip (node->host)))
		{
			FST_DBG_2 ("not connecting to unroutable node %s:%d",
			           node->host, node->port);
			/* remove this node from cache */
			fst_nodecache_remove (FST_PLUGIN->nodecache, node);
			fst_node_release (node);
			continue;
		}

		/* don't connect to banned ips */
		if (config_get_int (FST_PLUGIN->conf, "main/banlist_filter=0") &&
			fst_ipset_contains (FST_PLUGIN->banlist, net_ip (node->host)))
		{
			FST_DBG_2 ("not connecting to banned supernode %s:%d",
			           node->host, node->port);
			/* remove this node from cache */
			fst_nodecache_remove (FST_PLUGIN->nodecache, node);
			fst_node_release (node);
			continue;
		}

		/* create session and connect */
		sess = fst_session_create (fst_plugin_session_callback);
	
		if (!fst_session_connect (sess, node))
		{
			/* free session */
			fst_session_free (sess);
			sess = NULL;

			/* TODO: check if name resolution in fst_session_connect() failed */

			/* network down, wait a while before retrying */
			FST_WARN_1 ("Internet connection seems down, sleeping...",
			            FST_SESSION_NETFAIL_INTERVAL / SECONDS);
			
			/* move node to back of cache so next loop uses a different one; this
			 * won't help if the network really is down, but might under other
			 * circumstances */
			fst_nodecache_move (FST_PLUGIN->nodecache, node, NodeInsertBack);
			fst_node_release (node);

			/* just wait until fst_plugin_try_connect() is next called */
			return;
		}

		/* move node to back of cache so next loop uses a different one */
		fst_nodecache_move (FST_PLUGIN->nodecache, node, NodeInsertBack);
		fst_node_release (node);

		/* We now have a new session object. Use it as primary session if we
		 * don't already have one. Otherwise use it as an additional one. */
		if (!FST_PLUGIN->session)
		{
			FST_PLUGIN->session	= sess;
		} 
		else
		{
			FST_PLUGIN->sessions = list_prepend (FST_PLUGIN->sessions, sess);
		}
		nconnecting++;
	}

	/* don't ping if we're currently connected */
	if (FST_PLUGIN->stats->sessions > 0)
		return;

	/* We started a connection attempt with the head node from nodecache.
	 * Try to quickly find some online nodes with udp in parallel now.
	 */
	if (FST_PLUGIN->discover && FST_PLUGIN->discover->pinged_nodes == 0)
	{
		List *item = FST_PLUGIN->nodecache->list;
		int i = 0;

		while (i < FST_UDP_DISCOVER_MAX_PINGS && item && item->data)
		{
			node = (FSTNode*)item->data;

			if (!fst_udp_discover_ping_node (FST_PLUGIN->discover, node))
			{
				/* This may fail due to the network being down. While 
				 * we could handle this in a special way doing nothing
				 * works fine if being somewhat inefficient. */
			}

			item = item->next;
			i++;
		}

		FST_DBG_1 ("discovery cycle started with %d UDP pings", i);
	}
}