/*-*-linux-c-*-*/

/*
 *  gnewtellium - Newtella for Unix
 *  Copyright (C) 2001 Elias Athanasopoulos
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef NEWTELLA_H
#define NEWTELLA_H

#include <gtk/gtk.h>

#include "guid.h"
#include "global.h"
#include "connection.h"
#include "memory.h"
#include "gnutella.h"

struct host_info {
	//guint32 ip;
	uint8_t ip[16];
	guint16 port;
	guint32 file_count,
		files_total_size;
	gchar  *host_name;
	gchar   used;
};

typedef struct {
	guint16 len;
	gchar buf[MAX_PACKET_LENGTH];
	guint32 _time;
} packet;

struct file_found {
	gchar guid[GUID_LEN];
	gchar *file_name;
	gchar servent[4];
	gchar busy;
	gchar push;
	guint32 index;
	guint32 size;
	guint32 speed;
	//guint32 ip;
	uint8_t ip[16];
        guint16 port;
	guint16 des;               /* file descriptor */
};

int newtella_sched(void);

int newtella_init_server(guint16 port);
int newtella_kill_server(void);
int newtella_welcome_client(gpointer gdata, gint s, GdkInputCondition cond);

int newtella_guess_ip(gint s);
//int newtella_force_connect(guint32 ip, guint16 port);
int newtella_force_connect(uint8_t *ip, guint16 port);

void newtella_connect(gpointer gdata, gint s, GdkInputCondition cond);
void newtella_read(gpointer gdata, gint s, GdkInputCondition cond);
void newtella_write(gpointer gdata, gint s, GdkInputCondition cond);

int newtella_handshake_sucks(char *buf, int len);
int newtella_packet_sucks(struct gnutella_header *gh);

//gchar *ip2str(guint32 ip);
gchar *ip2str(uint8_t *ip);
//guint32 str2ip(gchar *str);
uint8_t *str2ip(gchar *str);

#endif










