/* Josh Pieper, (c) 2000 */

/* This file is distributed under the GPL, see file COPYING for details. */

#ifndef PROTOCOL_H
#define PROTOCOL_H

#include <sys/types.h>

#include "gnut_lib.h"
#include "Gnut_List.h"


typedef struct _gnutella_hdr gnutella_hdr;
typedef struct _gnutella_ping gnutella_ping;
typedef struct _gnutella_filereq gnutella_filereq;
typedef struct _gnutella_results gnutella_results;
typedef struct _gnutella_results_name gnutella_results_name;
typedef struct _gnutella_results_suffix gnutella_results_suffix;
typedef struct _gnutella_servent gnutella_servent;
typedef struct _gnutella_push gnutella_push;
typedef struct _gnutella_packet gnutella_packet;


/* First off lets define the critical structures
 * used in the protocol. */

struct _gnutella_hdr {
  uchar guid[16];
  uchar func;
  uchar ttl;
  uchar hops;
  uchar dlen[4];
};  

struct _gnutella_ping{
  uchar d[2];
};

struct _gnutella_filereq {
  uchar guid[16];
  uchar ref[4];
  uchar ip[4];
  uchar port[2];
};

struct _gnutella_results {
  uchar num;
  uchar port[2];
  uchar ip[4];
  uchar speed[4];
};

struct _gnutella_results_name {
  uchar ref[4];
  uchar size[4];
  uchar name[1];
};

struct _gnutella_results_suffix {
  uchar guid[16];
};

struct _gnutella_servent {
  uchar port[2];
  uchar ip[4];
  uchar files[4];
  uchar bytes[4];
};

struct _gnutella_push {
  uchar guid[16];
  uchar ref[4];
  uchar ip[4];
  uchar port[2];
};

struct _gnutella_packet {
  gnutella_hdr gh;
  void * data;
};

typedef struct giud_ref {
  uchar guid[16];
  uchar ref[4];
} guid_ref;

#ifdef __cplusplus
extern "C" {
#endif

  /* Now lets define the functions used to manipulate these structures. */

  void free_gpa(gnutella_packet **x, int bugnum);
  gnutella_packet * gp_reply_make(char *guid, Gnut_List *results,
				  uchar *ip, uint16 port, uint32 speed,
				  char * mguid, int ttl);

  gnutella_packet * gp_pong_make(char *guid, int files,
				 int bytes, uchar *ip, unsigned short port, int ttl);

  gnutella_packet * gp_ping_make(char *mac, int ttl);

  gnutella_packet * gp_request_make(char *mac, char *name, int ttl);

  gnutella_packet * gp_push_make(char *mac, int ttl, char *guid, 
				 uint32 ref, uchar *ip, uint16 port);

  gnutella_packet * gp_dup(gnutella_packet *gp); 

  int gp_print(gnutella_packet *);

#ifdef __cplusplus
}
#endif

#endif
