diff src/gt_node.h @ 0:d39e1d0d75b6

initial add
author paulo@hit-nxdomain.opendns.com
date Sat, 20 Feb 2010 21:18:28 -0800
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/gt_node.h	Sat Feb 20 21:18:28 2010 -0800
     1.3 @@ -0,0 +1,185 @@
     1.4 +/*
     1.5 + * $Id: gt_node.h,v 1.36 2005/01/04 15:00:51 mkern Exp $
     1.6 + *
     1.7 + * Copyright (C) 2001-2003 giFT project (gift.sourceforge.net)
     1.8 + *
     1.9 + * This program is free software; you can redistribute it and/or modify it
    1.10 + * under the terms of the GNU General Public License as published by the
    1.11 + * Free Software Foundation; either version 2, or (at your option) any
    1.12 + * later version.
    1.13 + *
    1.14 + * This program is distributed in the hope that it will be useful, but
    1.15 + * WITHOUT ANY WARRANTY; without even the implied warranty of
    1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.17 + * General Public License for more details.
    1.18 + */
    1.19 +
    1.20 +#ifndef GIFT_GT_NODE_H_
    1.21 +#define GIFT_GT_NODE_H_
    1.22 +
    1.23 +/*****************************************************************************/
    1.24 +
    1.25 +#define MAX_NODES               gt_config_get_int("main/max_nodes=2000")
    1.26 +
    1.27 +/*****************************************************************************/
    1.28 +
    1.29 +struct gt_query_router;
    1.30 +struct gt_packet;
    1.31 +struct gt_vendor_msg;
    1.32 +struct gt_rx_stack;
    1.33 +struct gt_tx_stack;
    1.34 +
    1.35 +typedef enum gt_node_state
    1.36 +{
    1.37 +	GT_NODE_DISCONNECTED  = 0x00, /* functionless node */
    1.38 +	GT_NODE_CONNECTING_1  = 0x01, /* pending */
    1.39 +	GT_NODE_CONNECTING_2  = 0x02, /* waiting for first ping response */
    1.40 +	GT_NODE_CONNECTED     = 0x08, /* first packet is seen */
    1.41 +	GT_NODE_ANY           = 0xFF, /* any state */
    1.42 +} gt_node_state_t;
    1.43 +
    1.44 +typedef enum gt_node_class
    1.45 +{
    1.46 +	GT_NODE_NONE   = 0x00,
    1.47 +	GT_NODE_LEAF   = 0x01,        /* plain 0.6 or 0.4 nodes */
    1.48 +	GT_NODE_ULTRA  = 0x02,        /* ultrapeers */
    1.49 +	GT_NODE_DEAD   = 0x04,        /* node is marked for deletion (unused) */
    1.50 +} gt_node_class_t;
    1.51 +
    1.52 +typedef struct gt_node
    1.53 +{
    1.54 +	in_addr_t       ip;
    1.55 +
    1.56 +	/* the gnutella port of the other side */
    1.57 +	in_port_t       gt_port;
    1.58 +
    1.59 +	/* the port the other side came from, could be the same as gt_port */
    1.60 +	in_port_t       peer_port;
    1.61 +
    1.62 +	/* IP address used in communication with this node */
    1.63 +	in_addr_t       my_ip;
    1.64 +
    1.65 +	/* HTTP headers the other node sent on 0.6 connection in stage-2 of
    1.66 +	 * the 3-way handshake */
    1.67 +	Dataset        *hdr;
    1.68 +
    1.69 +	/* Contains all the vendor messages supported by this node */
    1.70 +	Dataset        *vmsgs_supported;
    1.71 +
    1.72 +	unsigned int    incoming      : 1;    /* incoming connection */
    1.73 +	unsigned int    verified      : 1;    /* port has been verified */
    1.74 +	unsigned int    firewalled    : 1;    /* firewalled connection */
    1.75 +	unsigned int    tried_connect : 1;    /* used internally by gt_netorg.c */
    1.76 +	unsigned int    rx_inflated   : 1;    /* incoming traffic compressed */
    1.77 +	unsigned int    tx_deflated   : 1;    /* outgoing traffic compressed */
    1.78 +	unsigned int    vmsgs_sent    : 1;    /* sent our initial batch of vmsgs */
    1.79 +
    1.80 +	/* current state of the given connection */
    1.81 +	gt_node_state_t state;
    1.82 +
    1.83 +	/* node classification that this connection is communicating with */
    1.84 +	gt_node_class_t klass;
    1.85 +
    1.86 +	/* TCPC a node uses. could be null */
    1.87 +	TCPC           *c;
    1.88 +
    1.89 +	/* consecutive number of pings the host has not replied to */
    1.90 +	unsigned int    pings_with_noreply;
    1.91 +
    1.92 +	/* push proxy address, which may be different from peer address if remote
    1.93 +	 * end is multi-homed */
    1.94 +	in_addr_t       push_proxy_ip;
    1.95 +	in_port_t       push_proxy_port;
    1.96 +
    1.97 +	/* Data source for packets being read in */
    1.98 +	struct gt_rx_stack      *rx_stack;
    1.99 +	/* Data source for packets being sent out */
   1.100 +	struct gt_tx_stack      *tx_stack;
   1.101 +
   1.102 +	/* TCPC used for port verification */
   1.103 +	TCPC          *gt_port_verify;
   1.104 +
   1.105 +	/* identifier for this node in the GUID cache */
   1.106 +	unsigned long  id;
   1.107 +
   1.108 +	/* stats information */
   1.109 +	unsigned long  size_kb;
   1.110 +	unsigned long  files;
   1.111 +
   1.112 +	/* timers for node things */
   1.113 +	timer_id       handshake_timer;
   1.114 +	timer_id       search_timer;
   1.115 +	timer_id       query_route_timer;
   1.116 +
   1.117 +	/* around the time of the last connect to this node */
   1.118 +	time_t         vitality;
   1.119 +
   1.120 +	/* number of disconnections from this node */
   1.121 +	unsigned int   disconnect_cnt;
   1.122 +
   1.123 +	/* guid of the last ping from this node */
   1.124 +	gt_guid_t     *ping_guid;
   1.125 +
   1.126 +	/* time of the last ping from this node */
   1.127 +	time_t         last_ping_time;
   1.128 +
   1.129 +	/* start of the last connect to this node */
   1.130 +	time_t         start_connect_time;
   1.131 +
   1.132 +	/* time the last connection made to this node lasted */
   1.133 +	time_t         last_connect_duration;
   1.134 +
   1.135 +	/* total amount of time we have been connected to this node */
   1.136 +	time_t         total_connect_duration;
   1.137 +
   1.138 +	/* status of shares submitted to this node */
   1.139 +	struct gt_share_state    *share_state;
   1.140 +
   1.141 +	/* router for query packets */
   1.142 +	struct gt_query_router   *query_router;
   1.143 +
   1.144 +	/* version of the query router table submitted to this node currently */
   1.145 +	int                       query_router_counter;
   1.146 +} GtNode;
   1.147 +
   1.148 +/*****************************************************************************/
   1.149 +
   1.150 +#define GT_NODE(c)         ((GtNode *)c->udata)
   1.151 +#define GT_CONN(node)      ((TCPC *) node->c)
   1.152 +
   1.153 +/*****************************************************************************/
   1.154 +
   1.155 +GtNode       *gt_node_new         (void);
   1.156 +GtNode       *gt_node_instantiate (TCPC *c);
   1.157 +void          gt_node_free        (GtNode *node);
   1.158 +BOOL          gt_node_freeable    (GtNode *node);
   1.159 +
   1.160 +char         *gt_node_str         (GtNode *node);
   1.161 +void          gt_node_connect     (GtNode *node, TCPC *c);
   1.162 +void          gt_node_disconnect  (TCPC *c);
   1.163 +void          gt_node_error       (TCPC *c, const char *fmt, ...);
   1.164 +
   1.165 +void          gt_node_remove_all  (void);
   1.166 +
   1.167 +/*****************************************************************************/
   1.168 +
   1.169 +void          gt_node_state_set   (GtNode *node, gt_node_state_t state);
   1.170 +void          gt_node_class_set   (GtNode *node, gt_node_class_t klass);
   1.171 +
   1.172 +char         *gt_node_class_str   (gt_node_class_t klass);
   1.173 +char         *gt_node_state_str   (gt_node_state_t state);
   1.174 +
   1.175 +/*****************************************************************************/
   1.176 +
   1.177 +GtNode       *gt_node_lookup      (in_addr_t ip, in_port_t port);
   1.178 +GtNode       *gt_node_register    (in_addr_t ip, in_port_t port,
   1.179 +                                   gt_node_class_t klass);
   1.180 +
   1.181 +/*****************************************************************************/
   1.182 +
   1.183 +BOOL          gt_node_send_if_supported (GtNode *node, struct gt_packet *pkt);
   1.184 +BOOL          gt_node_send              (GtNode *node, struct gt_packet *pkt);
   1.185 +
   1.186 +/*****************************************************************************/
   1.187 +
   1.188 +#endif /* GIFT_GT_NODE_H_ */