Ejemplo n.º 1
0
struct peer_manager *peerman_seed(bool use_dns)
{
	struct peer_manager *peers;

	peers = peerman_new();
	if (!peers)
		return NULL;

	/* make DNS query for seed data */
	clist *tmp, *seedlist = NULL;
	if (use_dns)
		seedlist = bu_dns_seed_addrs();

	log_debug("peerman: DNS returned %zu addresses",
		clist_length(seedlist));

	clist_shuffle(seedlist);

	/* import seed data into peerman */
	tmp = seedlist;
	while (tmp) {
		struct bp_address *addr = tmp->data;
		tmp = tmp->next;

		peerman_add_addr(peers, addr, true);
		free(addr);
	}
	clist_free(seedlist);

	return peers;
}
Ejemplo n.º 2
0
struct peer_manager *peerman_read(void *peers_file)
{
	char *filename = peers_file;
	if (!filename)
		return NULL;

	struct peer_manager *peers;

	peers = peerman_new();
	if (!peers)
		return NULL;

	int fd = file_seq_open(filename);
	if (fd < 0) {
		log_error("peerman: %s: %s",
			filename,
			strerror(errno));
		goto err_out;
	}

	struct p2p_message msg = {};
	bool read_ok = true;

	while (fread_message(fd, &msg, &read_ok)) {
		if (!peerman_read_rec(peers, &msg)) {
			log_error("peerman: read record failed");
			goto err_out_fd;
		}
	}

	if (!read_ok) {
		log_error("peerman: read I/O failed");
		goto err_out_fd;
	}

	free(msg.data);
	close(fd);

	return peers;

err_out_fd:
	free(msg.data);
	close(fd);
err_out:
	peerman_free(peers);
	return NULL;
}
Ejemplo n.º 3
0
struct peer_manager *peerman_read(void)
{
	char *filename = setting("peers");
	if (!filename)
		return NULL;

	struct peer_manager *peers;

	peers = peerman_new();
	if (!peers)
		return NULL;

	int fd = file_seq_open(filename);
	if (fd < 0) {
		perror(filename);
		goto err_out;
	}

	struct p2p_message msg = {};
	bool read_ok = true;

	while (fread_message(fd, &msg, &read_ok)) {
		if (!peerman_read_rec(peers, &msg)) {
			fprintf(stderr, "peerman: read record failed\n");
			goto err_out;
		}
	}

	if (!read_ok) {
		fprintf(stderr, "peerman: read I/O failed\n");
		goto err_out;
	}

	free(msg.data);
	close(fd);

	return peers;

err_out:
	peerman_free(peers);
	return NULL;
}