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