annotate 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
rev   line source
paulo@0 1 /*
paulo@0 2 * $Id: gt_node.h,v 1.36 2005/01/04 15:00:51 mkern Exp $
paulo@0 3 *
paulo@0 4 * Copyright (C) 2001-2003 giFT project (gift.sourceforge.net)
paulo@0 5 *
paulo@0 6 * This program is free software; you can redistribute it and/or modify it
paulo@0 7 * under the terms of the GNU General Public License as published by the
paulo@0 8 * Free Software Foundation; either version 2, or (at your option) any
paulo@0 9 * later version.
paulo@0 10 *
paulo@0 11 * This program is distributed in the hope that it will be useful, but
paulo@0 12 * WITHOUT ANY WARRANTY; without even the implied warranty of
paulo@0 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
paulo@0 14 * General Public License for more details.
paulo@0 15 */
paulo@0 16
paulo@0 17 #ifndef GIFT_GT_NODE_H_
paulo@0 18 #define GIFT_GT_NODE_H_
paulo@0 19
paulo@0 20 /*****************************************************************************/
paulo@0 21
paulo@0 22 #define MAX_NODES gt_config_get_int("main/max_nodes=2000")
paulo@0 23
paulo@0 24 /*****************************************************************************/
paulo@0 25
paulo@0 26 struct gt_query_router;
paulo@0 27 struct gt_packet;
paulo@0 28 struct gt_vendor_msg;
paulo@0 29 struct gt_rx_stack;
paulo@0 30 struct gt_tx_stack;
paulo@0 31
paulo@0 32 typedef enum gt_node_state
paulo@0 33 {
paulo@0 34 GT_NODE_DISCONNECTED = 0x00, /* functionless node */
paulo@0 35 GT_NODE_CONNECTING_1 = 0x01, /* pending */
paulo@0 36 GT_NODE_CONNECTING_2 = 0x02, /* waiting for first ping response */
paulo@0 37 GT_NODE_CONNECTED = 0x08, /* first packet is seen */
paulo@0 38 GT_NODE_ANY = 0xFF, /* any state */
paulo@0 39 } gt_node_state_t;
paulo@0 40
paulo@0 41 typedef enum gt_node_class
paulo@0 42 {
paulo@0 43 GT_NODE_NONE = 0x00,
paulo@0 44 GT_NODE_LEAF = 0x01, /* plain 0.6 or 0.4 nodes */
paulo@0 45 GT_NODE_ULTRA = 0x02, /* ultrapeers */
paulo@0 46 GT_NODE_DEAD = 0x04, /* node is marked for deletion (unused) */
paulo@0 47 } gt_node_class_t;
paulo@0 48
paulo@0 49 typedef struct gt_node
paulo@0 50 {
paulo@0 51 in_addr_t ip;
paulo@0 52
paulo@0 53 /* the gnutella port of the other side */
paulo@0 54 in_port_t gt_port;
paulo@0 55
paulo@0 56 /* the port the other side came from, could be the same as gt_port */
paulo@0 57 in_port_t peer_port;
paulo@0 58
paulo@0 59 /* IP address used in communication with this node */
paulo@0 60 in_addr_t my_ip;
paulo@0 61
paulo@0 62 /* HTTP headers the other node sent on 0.6 connection in stage-2 of
paulo@0 63 * the 3-way handshake */
paulo@0 64 Dataset *hdr;
paulo@0 65
paulo@0 66 /* Contains all the vendor messages supported by this node */
paulo@0 67 Dataset *vmsgs_supported;
paulo@0 68
paulo@0 69 unsigned int incoming : 1; /* incoming connection */
paulo@0 70 unsigned int verified : 1; /* port has been verified */
paulo@0 71 unsigned int firewalled : 1; /* firewalled connection */
paulo@0 72 unsigned int tried_connect : 1; /* used internally by gt_netorg.c */
paulo@0 73 unsigned int rx_inflated : 1; /* incoming traffic compressed */
paulo@0 74 unsigned int tx_deflated : 1; /* outgoing traffic compressed */
paulo@0 75 unsigned int vmsgs_sent : 1; /* sent our initial batch of vmsgs */
paulo@0 76
paulo@0 77 /* current state of the given connection */
paulo@0 78 gt_node_state_t state;
paulo@0 79
paulo@0 80 /* node classification that this connection is communicating with */
paulo@0 81 gt_node_class_t klass;
paulo@0 82
paulo@0 83 /* TCPC a node uses. could be null */
paulo@0 84 TCPC *c;
paulo@0 85
paulo@0 86 /* consecutive number of pings the host has not replied to */
paulo@0 87 unsigned int pings_with_noreply;
paulo@0 88
paulo@0 89 /* push proxy address, which may be different from peer address if remote
paulo@0 90 * end is multi-homed */
paulo@0 91 in_addr_t push_proxy_ip;
paulo@0 92 in_port_t push_proxy_port;
paulo@0 93
paulo@0 94 /* Data source for packets being read in */
paulo@0 95 struct gt_rx_stack *rx_stack;
paulo@0 96 /* Data source for packets being sent out */
paulo@0 97 struct gt_tx_stack *tx_stack;
paulo@0 98
paulo@0 99 /* TCPC used for port verification */
paulo@0 100 TCPC *gt_port_verify;
paulo@0 101
paulo@0 102 /* identifier for this node in the GUID cache */
paulo@0 103 unsigned long id;
paulo@0 104
paulo@0 105 /* stats information */
paulo@0 106 unsigned long size_kb;
paulo@0 107 unsigned long files;
paulo@0 108
paulo@0 109 /* timers for node things */
paulo@0 110 timer_id handshake_timer;
paulo@0 111 timer_id search_timer;
paulo@0 112 timer_id query_route_timer;
paulo@0 113
paulo@0 114 /* around the time of the last connect to this node */
paulo@0 115 time_t vitality;
paulo@0 116
paulo@0 117 /* number of disconnections from this node */
paulo@0 118 unsigned int disconnect_cnt;
paulo@0 119
paulo@0 120 /* guid of the last ping from this node */
paulo@0 121 gt_guid_t *ping_guid;
paulo@0 122
paulo@0 123 /* time of the last ping from this node */
paulo@0 124 time_t last_ping_time;
paulo@0 125
paulo@0 126 /* start of the last connect to this node */
paulo@0 127 time_t start_connect_time;
paulo@0 128
paulo@0 129 /* time the last connection made to this node lasted */
paulo@0 130 time_t last_connect_duration;
paulo@0 131
paulo@0 132 /* total amount of time we have been connected to this node */
paulo@0 133 time_t total_connect_duration;
paulo@0 134
paulo@0 135 /* status of shares submitted to this node */
paulo@0 136 struct gt_share_state *share_state;
paulo@0 137
paulo@0 138 /* router for query packets */
paulo@0 139 struct gt_query_router *query_router;
paulo@0 140
paulo@0 141 /* version of the query router table submitted to this node currently */
paulo@0 142 int query_router_counter;
paulo@0 143 } GtNode;
paulo@0 144
paulo@0 145 /*****************************************************************************/
paulo@0 146
paulo@0 147 #define GT_NODE(c) ((GtNode *)c->udata)
paulo@0 148 #define GT_CONN(node) ((TCPC *) node->c)
paulo@0 149
paulo@0 150 /*****************************************************************************/
paulo@0 151
paulo@0 152 GtNode *gt_node_new (void);
paulo@0 153 GtNode *gt_node_instantiate (TCPC *c);
paulo@0 154 void gt_node_free (GtNode *node);
paulo@0 155 BOOL gt_node_freeable (GtNode *node);
paulo@0 156
paulo@0 157 char *gt_node_str (GtNode *node);
paulo@0 158 void gt_node_connect (GtNode *node, TCPC *c);
paulo@0 159 void gt_node_disconnect (TCPC *c);
paulo@0 160 void gt_node_error (TCPC *c, const char *fmt, ...);
paulo@0 161
paulo@0 162 void gt_node_remove_all (void);
paulo@0 163
paulo@0 164 /*****************************************************************************/
paulo@0 165
paulo@0 166 void gt_node_state_set (GtNode *node, gt_node_state_t state);
paulo@0 167 void gt_node_class_set (GtNode *node, gt_node_class_t klass);
paulo@0 168
paulo@0 169 char *gt_node_class_str (gt_node_class_t klass);
paulo@0 170 char *gt_node_state_str (gt_node_state_t state);
paulo@0 171
paulo@0 172 /*****************************************************************************/
paulo@0 173
paulo@0 174 GtNode *gt_node_lookup (in_addr_t ip, in_port_t port);
paulo@0 175 GtNode *gt_node_register (in_addr_t ip, in_port_t port,
paulo@0 176 gt_node_class_t klass);
paulo@0 177
paulo@0 178 /*****************************************************************************/
paulo@0 179
paulo@0 180 BOOL gt_node_send_if_supported (GtNode *node, struct gt_packet *pkt);
paulo@0 181 BOOL gt_node_send (GtNode *node, struct gt_packet *pkt);
paulo@0 182
paulo@0 183 /*****************************************************************************/
paulo@0 184
paulo@0 185 #endif /* GIFT_GT_NODE_H_ */