paulo@0: /* paulo@0: * $Id: gt_search.h,v 1.19 2004/01/18 05:43:13 hipnod Exp $ paulo@0: * paulo@0: * Copyright (C) 2001-2003 giFT project (gift.sourceforge.net) paulo@0: * paulo@0: * This program is free software; you can redistribute it and/or modify it paulo@0: * under the terms of the GNU General Public License as published by the paulo@0: * Free Software Foundation; either version 2, or (at your option) any paulo@0: * later version. paulo@0: * paulo@0: * This program is distributed in the hope that it will be useful, but paulo@0: * WITHOUT ANY WARRANTY; without even the implied warranty of paulo@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU paulo@0: * General Public License for more details. paulo@0: */ paulo@0: paulo@0: #ifndef GIFT_GT_SEARCH_H_ paulo@0: #define GIFT_GT_SEARCH_H_ paulo@0: paulo@0: /******************************************************************************/ paulo@0: paulo@0: struct tcp_conn; paulo@0: struct file_share; paulo@0: paulo@0: typedef enum paulo@0: { paulo@0: GT_SEARCH_HASH, paulo@0: GT_SEARCH_KEYWORD, paulo@0: } gt_search_type_t; paulo@0: paulo@0: /* paulo@0: * These flags exist in what used to be the MinSpeed field of paulo@0: * queries. The documentation for this field is arranged as two paulo@0: * bytes in big-endian order, but this uses it in little-endian paulo@0: * order so as to be consistent with the rest of the protocol. paulo@0: */ paulo@0: typedef enum gt_query_flags paulo@0: { paulo@0: QF_WANTS_XML = 0x0020, /* servent wants XML metadata */ paulo@0: QF_ONLY_NON_FW = 0x0040, /* source desires non-firewalled hits only */ paulo@0: QF_HAS_FLAGS = 0x0080, /* this query has this interpretation */ paulo@0: } gt_query_flags_t; paulo@0: paulo@0: typedef struct gt_search paulo@0: { paulo@0: /* giFT event */ paulo@0: IFEvent *event; paulo@0: paulo@0: /* what kind of search this is */ paulo@0: gt_search_type_t type; paulo@0: paulo@0: /* the guid used to identify the search */ paulo@0: char *guid; paulo@0: paulo@0: /* the query used for the search */ paulo@0: char *query; paulo@0: paulo@0: /* the hash to look for this search if a URN query XXX should use gt_urn_t paulo@0: * here, but the interface is just too borked */ paulo@0: char *hash; paulo@0: paulo@0: /* the realm used for this query, if any */ paulo@0: char *realm; paulo@0: paulo@0: /* expires the search according to critieria: see paulo@0: * gt_search.c:search_timeout */ paulo@0: timer_id timeout_timer; paulo@0: paulo@0: /* when the search was started */ paulo@0: time_t start; paulo@0: paulo@0: /* how many nodes this search has been submitted to */ paulo@0: size_t submitted; paulo@0: paulo@0: /* the last time we submitted to a node */ paulo@0: time_t last_submit; paulo@0: paulo@0: /* time the last result for this search was seen */ paulo@0: time_t last_result; paulo@0: paulo@0: /* results count */ paulo@0: size_t results; paulo@0: } GtSearch; paulo@0: paulo@0: /* the default ttl for searches */ paulo@0: #define GT_SEARCH_TTL (5) paulo@0: paulo@0: /******************************************************************************/ paulo@0: paulo@0: GtSearch *gt_search_new (IFEvent *event, char *query, paulo@0: gt_search_type_t type); paulo@0: void gt_search_free (GtSearch *search); paulo@0: void gt_search_disable (IFEvent *event); paulo@0: void gt_search_reply (GtSearch *search, struct tcp_conn *c, paulo@0: in_addr_t ip, in_port_t gt_port, paulo@0: gt_guid_t *client_guid, int availability, paulo@0: BOOL firewalled, struct file_share *file); paulo@0: GtSearch *gt_search_find (gt_guid_t *guid); paulo@0: paulo@0: /* submit active searches to a node after a timeout */ paulo@0: void gt_searches_submit (struct tcp_conn *c, time_t delay); paulo@0: paulo@0: /******************************************************************************/ paulo@0: paulo@0: BOOL gnutella_search (Protocol *p, IFEvent *event, char *query, paulo@0: char *exclude, char *realm, Dataset *meta); paulo@0: paulo@0: BOOL gnutella_locate (Protocol *p, IFEvent *event, char *htype, paulo@0: char *hash); paulo@0: paulo@0: void gnutella_search_cancel (Protocol *p, IFEvent *event); paulo@0: paulo@0: /******************************************************************************/ paulo@0: paulo@0: void gt_search_init (void); paulo@0: void gt_search_cleanup (void); paulo@0: paulo@0: /******************************************************************************/ paulo@0: paulo@0: #endif /* GIFT_GT_SEARCH_H_ */