Mercurial > hg > index.fcgi > gift-gnutella > gift-gnutella-0.0.11-1pba
comparison src/gt_gnutella.c @ 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:5525e01d1f4f |
---|---|
1 /* | |
2 * $Id: gt_gnutella.c,v 1.74 2006/08/06 16:53:36 hexwab Exp $ | |
3 * | |
4 * Copyright (C) 2001-2004 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 #include "gt_gnutella.h" | |
18 | |
19 #include "gt_conf.h" | |
20 #include "sha1.h" | |
21 #include "xml.h" | |
22 | |
23 #include "gt_share.h" | |
24 #include "gt_share_state.h" | |
25 | |
26 #include "gt_accept.h" | |
27 #include "gt_ban.h" | |
28 #include "gt_bind.h" | |
29 | |
30 #include "gt_node.h" | |
31 #include "gt_node_list.h" | |
32 #include "gt_netorg.h" | |
33 | |
34 #include "gt_xfer_obj.h" | |
35 #include "gt_xfer.h" | |
36 | |
37 #include "gt_search.h" | |
38 #include "gt_search_exec.h" | |
39 | |
40 #include "gt_web_cache.h" | |
41 #include "gt_stats.h" | |
42 #include "gt_query_route.h" | |
43 #include "transfer/source.h" /* gnutella_source_{add,remove,cmp} */ | |
44 | |
45 /*****************************************************************************/ | |
46 | |
47 /* giFT protocol pointer */ | |
48 Protocol *GT; | |
49 | |
50 /*****************************************************************************/ | |
51 | |
52 /* The ip address is local if the address is local and the source from which | |
53 * it was discovered was not local */ | |
54 BOOL gt_is_local_ip (in_addr_t ip, in_addr_t src) | |
55 { | |
56 if (ip == 0) | |
57 return TRUE; | |
58 | |
59 if (net_match_host (ip, "LOCAL") && | |
60 (src == 0 || !net_match_host (src, "LOCAL"))) | |
61 { | |
62 return TRUE; | |
63 } | |
64 | |
65 return FALSE; | |
66 } | |
67 | |
68 /*****************************************************************************/ | |
69 | |
70 /* shutdown */ | |
71 static void gnutella_destroy (Protocol *p) | |
72 { | |
73 GT->DBGFN (GT, "entered"); | |
74 | |
75 /* cleanup any network maintenance data */ | |
76 gt_netorg_cleanup (); | |
77 | |
78 /* save the node list to disk */ | |
79 gt_node_list_save (); | |
80 | |
81 /* cleanup any information about banned nodes */ | |
82 gt_ban_cleanup (); | |
83 | |
84 /* destroy query_router tables */ | |
85 gt_query_router_self_destroy (); | |
86 | |
87 /* cleanup remote search data structures */ | |
88 gt_search_cleanup (); | |
89 | |
90 /* cleanup local share state */ | |
91 gt_share_state_local_cleanup (); | |
92 | |
93 /* cleanup local search data structures */ | |
94 gt_search_exec_cleanup (); | |
95 | |
96 /* cleanup XML structures */ | |
97 gt_xml_cleanup (); | |
98 | |
99 /* free and disconnect all nodes */ | |
100 gt_node_remove_all (); | |
101 | |
102 /* destroy web cache information */ | |
103 gt_web_cache_cleanup (); | |
104 | |
105 /* stop binding to the local port */ | |
106 gt_bind_cleanup (); | |
107 | |
108 /* free configuration information */ | |
109 gt_config_cleanup (); | |
110 | |
111 /* free this client's GUID */ | |
112 gt_guid_self_cleanup (); | |
113 } | |
114 | |
115 /*****************************************************************************/ | |
116 | |
117 static unsigned char *gnutella_sha1_hash (const char *path, size_t *len) | |
118 { | |
119 *len = SHA1_BINSIZE; | |
120 return sha1_digest (path, 0); | |
121 } | |
122 | |
123 static char *gnutella_sha1_dsp (unsigned char *hash, size_t len) | |
124 { | |
125 return sha1_string (hash); | |
126 } | |
127 | |
128 /*****************************************************************************/ | |
129 | |
130 static BOOL self_is_too_old (void) | |
131 { | |
132 return FALSE; | |
133 } | |
134 | |
135 static void too_old_error_msg (void) | |
136 { | |
137 GIFT_ERROR (("\nYour version of the Gnutella plugin is more than 1 year\n" | |
138 "old. In order to protect the Gnutella network from \n" | |
139 "older programs, this plugin has deactivated itself.\n\n" | |
140 "Please update the plugin with a new version from \n" | |
141 "http://www.giftproject.org/, or stop running the \n" | |
142 "plugin by runnning gift-setup or removing \"Gnutella\"\n" | |
143 "from the /main/plugins line in $HOME/.giFT/giftd.conf\n" | |
144 "manually.\n\n" | |
145 "Thanks, and sorry for the inconvenience.\n")); | |
146 } | |
147 | |
148 static BOOL gnutella_start (Protocol *p) | |
149 { | |
150 p->DBGFN (p, "Starting Gnutella plugin"); | |
151 | |
152 /* | |
153 * If this node is extremely old, deactivate the plugin, but print a | |
154 * message to the log file. | |
155 * | |
156 * This is a temporary hack to clean out old nodes in the future, just | |
157 * until ultrapeer support is implemented, but we don't want to bother | |
158 * people that are using other plugins and don't care... | |
159 */ | |
160 if (self_is_too_old ()) | |
161 { | |
162 too_old_error_msg (); | |
163 return TRUE; | |
164 } | |
165 | |
166 if (!gt_config_init ()) | |
167 { | |
168 GIFT_ERROR (("Unable to load config file. Please copy it to " | |
169 "~/.giFT/Gnutella/Gnutella.conf")); | |
170 return FALSE; | |
171 } | |
172 | |
173 if (!gt_web_cache_init ()) | |
174 { | |
175 GIFT_ERROR (("Unable to load gwebcaches file. Please copy it to " | |
176 "~/.giFT/Gnutella/gwebcaches")); | |
177 return FALSE; | |
178 } | |
179 | |
180 /* load any banned ip addresses */ | |
181 gt_ban_init (); | |
182 | |
183 /* initialize the GUID for this node */ | |
184 gt_guid_self_init (); | |
185 | |
186 /* listen for connections */ | |
187 gt_bind_init (); | |
188 | |
189 /* load the list of all previously contacted nodes */ | |
190 gt_node_list_load (); | |
191 | |
192 /* initialize query router tables */ | |
193 gt_query_router_self_init (); | |
194 | |
195 /* initialize the local search data structures */ | |
196 gt_search_exec_init (); | |
197 | |
198 /* initialize the local sharing state */ | |
199 gt_share_state_local_init (); | |
200 | |
201 /* initialize the remote search data structures */ | |
202 gt_search_init (); | |
203 | |
204 /* initialize support for xml metadata */ | |
205 gt_xml_init (); | |
206 | |
207 /* startup network maintenance */ | |
208 gt_netorg_init (); | |
209 | |
210 return TRUE; | |
211 } | |
212 | |
213 /* | |
214 * The entry-point for the giFT daemon | |
215 */ | |
216 BOOL Gnutella_init (Protocol *p) | |
217 { | |
218 if (protocol_compat (p, LIBGIFTPROTO_MKVERSION (0, 11, 4)) != 0) | |
219 return FALSE; | |
220 | |
221 p->version_str = STRDUP (GT_VERSION); | |
222 GT = p; | |
223 | |
224 /* gt_gnutella.c: */ | |
225 p->start = gnutella_start; | |
226 | |
227 /* skip initializing if too old. Note that we still need to provide a | |
228 * start function since gift's default handler will return FALSE. The | |
229 * actual error message describing the 'too old' problem is also generated | |
230 * by our start function. | |
231 */ | |
232 if (self_is_too_old ()) | |
233 return TRUE; | |
234 | |
235 /* describe the hash algo */ | |
236 p->hash_handler (p, "SHA1", HASH_PRIMARY, gnutella_sha1_hash, | |
237 gnutella_sha1_dsp); | |
238 | |
239 /* gt_gnutella.c: */ | |
240 p->destroy = gnutella_destroy; | |
241 | |
242 /* gt_search.c: */ | |
243 p->search = gnutella_search; | |
244 #if 0 | |
245 p->browse = gnutella_browse; | |
246 #endif | |
247 p->locate = gnutella_locate; | |
248 p->search_cancel = gnutella_search_cancel; | |
249 | |
250 /* gt_xfer.c: */ | |
251 p->download_start = gnutella_download_start; | |
252 p->download_stop = gnutella_download_stop; | |
253 p->upload_stop = gnutella_upload_stop; | |
254 p->chunk_suspend = gnutella_chunk_suspend; | |
255 p->chunk_resume = gnutella_chunk_resume; | |
256 | |
257 /* transfer/source.c: */ | |
258 p->source_cmp = gnutella_source_cmp; | |
259 p->source_add = gnutella_source_add; | |
260 p->source_remove = gnutella_source_remove; | |
261 | |
262 #if 0 | |
263 p->upload_avail = gnutella_upload_avail; | |
264 p->user_cmp = gnutella_user_cmp; | |
265 #endif | |
266 | |
267 /* gt_share.c: */ | |
268 p->share_new = gnutella_share_new; | |
269 p->share_free = gnutella_share_free; | |
270 p->share_add = gnutella_share_add; | |
271 p->share_remove = gnutella_share_remove; | |
272 p->share_sync = gnutella_share_sync; | |
273 | |
274 /* gt_share_state.c: */ | |
275 p->share_hide = gnutella_share_hide; | |
276 p->share_show = gnutella_share_show; | |
277 | |
278 /* gt_stats.c: */ | |
279 p->stats = gnutella_stats; | |
280 | |
281 return TRUE; | |
282 } |