From 143cde208ce477883102bf23f67a1d31aaa4ed11 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 25 Jan 2011 22:58:30 +0000 Subject: [PATCH] hdrs --- src/fs/gnunet-service-fs.c | 2 +- src/fs/gnunet-service-fs.h | 55 ++++++++++ src/fs/gnunet-service-fs_cp.h | 188 ++++++++++++++++++++++++++++++++ src/fs/gnunet-service-fs_lc.h | 119 ++++++++++++++++++++ src/fs/gnunet-service-fs_pe.h | 59 ++++++++++ src/fs/gnunet-service-fs_pr.h | 197 ++++++++++++++++++++++++++++++++++ 6 files changed, 619 insertions(+), 1 deletion(-) create mode 100644 src/fs/gnunet-service-fs.h create mode 100644 src/fs/gnunet-service-fs_cp.h create mode 100644 src/fs/gnunet-service-fs_lc.h create mode 100644 src/fs/gnunet-service-fs_pe.h create mode 100644 src/fs/gnunet-service-fs_pr.h diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c index 80445e9bf..fb275f1b4 100644 --- a/src/fs/gnunet-service-fs.c +++ b/src/fs/gnunet-service-fs.c @@ -719,7 +719,7 @@ struct PendingRequest int8_t local_only; /** - * GNUNET_YES if we should not forward this request to other peers. + * GNUNET_YES if we should not forward this request to other peers. (HUH?) */ int8_t forward_only; diff --git a/src/fs/gnunet-service-fs.h b/src/fs/gnunet-service-fs.h new file mode 100644 index 000000000..a66339b91 --- /dev/null +++ b/src/fs/gnunet-service-fs.h @@ -0,0 +1,55 @@ +/* + This file is part of GNUnet. + (C) 2009, 2010 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/** + * @file fs/gnunet-service-fs.h + * @brief shared data structures of gnunet-service-fs.c + * @author Christian Grothoff + */ +#ifndef GNUNET_SERVICE_FS_H +#define GNUNET_SERVICE_FS_H + +/** + * A connected peer. + */ +struct GSF_ConnectedPeer; + + +/** + * An active request. + */ +struct GSF_PendingRequest; + + +/** + * A local client. + */ +struct GSF_LocalClient; + + +/** + * Entry in the query transmission plan. + */ +struct GSF_PlanEntry; + + + +#endif +/* end of gnunet-service-fs.h */ diff --git a/src/fs/gnunet-service-fs_cp.h b/src/fs/gnunet-service-fs_cp.h new file mode 100644 index 000000000..f6d6e7a0a --- /dev/null +++ b/src/fs/gnunet-service-fs_cp.h @@ -0,0 +1,188 @@ +/* + This file is part of GNUnet. + (C) 2011 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/** + * @file fs/gnunet-service-fs_cp.h + * @brief API to handle 'connected peers' + * @author Christian Grothoff + */ +#ifndef GNUNET_SERVICE_FS_CP_H +#define GNUNET_SERVICE_FS_CP_H + +#include "gnunet-service-fs.h" + + +/** + * A peer connected to us. Setup the connected peer + * records. + * + * @param peer identity of peer that connected + * @param atsi performance data for the connection + * @return handle to connected peer entry + */ +struct GSF_ConnectedPeer * +GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_TRANSPORT_ATS_Information *atsi); + + +/** + * Function called to get a message for transmission. + * + * @param cls closure + * @param buf_size number of bytes available in buf + * @param buf where to copy the message, NULL on error (peer disconnect) + * @return number of bytes copied to 'buf', can be 0 (without indicating an error) + */ +typedef size_t (*GSF_GetMessageCallback)(void *cls, + size_t buf_size, + void *buf); + + +/** + * Transmit a message to the given peer as soon as possible. + * If the peer disconnects before the transmission can happen, + * the callback is invoked with a 'NULL' buffer. + * + * @param peer target peer + * @param size number of bytes we would like to send to the peer + * @param gmc function to call to get the message + * @param gmc_cls closure for gmc + */ +void +GSF_peer_transmit_ (struct GSF_ConnectedPeer *peer, + size_t size, + GSF_GetMessageCallback gmc, + void *gmc_cls); + + +/** + * Method called whenever a given peer has a status change. + * + * @param cls closure + * @param peer peer identity this notification is about + * @param bandwidth_in available amount of inbound bandwidth + * @param bandwidth_out available amount of outbound bandwidth + * @param timeout absolute time when this peer will time out + * unless we see some further activity from it + * @param atsi status information + */ +void +GSF_peer_status_handler_ (void *cls, + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, + struct GNUNET_TIME_Absolute timeout, + const struct GNUNET_TRANSPORT_ATS_Information *atsi); + + +/** + * A peer disconnected from us. Tear down the connected peer + * record. + * + * @param cls unused + * @param peer identity of peer that connected + */ +void +GSF_peer_disconnect_handler_ (void *cls, + const struct GNUNET_PeerIdentity *peer); + + +/** + * Signature of function called on a connected peer. + * + * @param cls closure + * @param peer identity of the peer + * @param cp handle to the connected peer record + */ +typedef void (*GSF_ConnectedPeerIterator)(void *cls, + const struct GNUNET_PeerIdentity *peer, + struct GSF_ConnectedPeer *cp); + + +/** + * Iterate over all connected peers. + * + * @param it function to call for each peer + * @param it_cls closure for it + */ +void +GSF_iterate_connected_peers_ (GSF_ConnectedPeerIterator it, + void *it_cls); + + +/** + * Register callback to invoke on peer disconnect. + * + * @param cp peer to monitor + * @param it function to call on disconnect + * @param it_cls closure for it + */ +void +GSF_connected_peer_register_disconnect_callback_ (struct GSF_ConnectedPeer *cp, + GSF_ConnectedPeerIterator it, + void *it_cls); + + +/** + * Unregister callback to invoke on peer disconnect. + * + * @param cp peer to stop monitoring + * @param it function to no longer call on disconnect + * @param it_cls closure for it + */ +void +GSF_connected_peer_unregister_disconnect_callback_ (struct GSF_ConnectedPeer *cp, + GSF_ConnectedPeerIterator it, + void *it_cls); + + +/** + * Signature of function called on a reservation success. + * + * @param cls closure + * @param cp handle to the connected peer record + */ +typedef void (*GSF_PeerReserveCallback)(void *cls, + struct GSF_ConnectedPeer *cp); + + +/** + * Try to reserve bandwidth (to receive data FROM the given peer). + * This function must only be called ONCE per connected peer at a + * time; it can be called again after the 'rc' callback was invoked. + * If the peer disconnects, the request is (silently!) ignored (and + * the requester is responsible to register for notification about the + * peer disconnect if any special action needs to be taken in this + * case). + * + * @param cp peer to reserve bandwidth from + * @param size number of bytes to reserve + * @param rc function to call upon reservation success + * @param rc_cls closure for rc + */ +void +GSF_connected_peer_reserve_ (struct GSF_ConnectedPeer *cp, + size_t size, + GSF_PeerReserveCallback rc, + void *rc_cls); + + +#endif +/* end of gnunet-service-fs_cp.h */ diff --git a/src/fs/gnunet-service-fs_lc.h b/src/fs/gnunet-service-fs_lc.h new file mode 100644 index 000000000..edc199fd8 --- /dev/null +++ b/src/fs/gnunet-service-fs_lc.h @@ -0,0 +1,119 @@ +/* + This file is part of GNUnet. + (C) 2011 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/** + * @file fs/gnunet-service-fs_lc.h + * @brief API to handle 'connected peers' + * @author Christian Grothoff + */ +#ifndef GNUNET_SERVICE_FS_LC_H +#define GNUNET_SERVICE_FS_LC_H + +#include "gnunet-service-fs.h" + + +/** + * Look up a local client record or create one if it + * doesn't exist yet. + * + * @param client handle of the client + * @return handle to local client entry + */ +struct GSF_LocalClient * +GSF_local_client_lookup_ (struct GNUNET_SERVER_Client *client); + + +/** + * Handle START_SEARCH-message (search request from local client). + * + * @param cls closure + * @param client identification of the client + * @param message the actual message + */ +void +GSF_local_client_start_search_handler_ (void *cls, + struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *message); + + +/** + * Transmit a message to the given local client as soon as possible. + * If the client disconnects before transmission, the message is + * simply discarded. + * + * @param lc recipient + * @param msg message to transmit to client + */ +void +GSF_local_client_transmit_ (struct GSF_LocalClient *lc, + const struct GNUNET_MessageHeader *msg); + + +/** + * A local client disconnected from us. Tear down the local client + * record. + * + * @param cls unused + * @param client handle of the client + */ +void +GSF_local_client_disconnect_handler_ (void *cls, + const struct GNUNET_SERVER_Client *client); + + + +/** + * Signature of function called on a local client + * + * @param cls closure + * @param lc local client handle + */ +typedef int (*GSF_LocalClientIterator)(void *cls, + struct GSF_LocalClient *lc); + + + +/** + * Register callback to invoke on local client disconnect. + * + * @param lc client to monitor + * @param it function to call on disconnect + * @param it_cls closure for it + */ +void +GSF_local_client_register_disconnect_callback_ (struct GSF_LocalClient *lc, + GSF_LocalClientIterator it, + void *it_cls); + + +/** + * Register callback to invoke on local client disconnect. + * + * @param lc client to stop monitoring + * @param it function to no longer call on disconnect + * @param it_cls closure for it + */ +void +GSF_connected_peer_unregister_disconnect_callback_ (struct GSF_ConnectedPeer *cp, + GSF_PendingRequestIterator it, + void *it_cls); + +#endif +/* end of gnunet-service-fs_lc.h */ diff --git a/src/fs/gnunet-service-fs_pe.h b/src/fs/gnunet-service-fs_pe.h new file mode 100644 index 000000000..9f62ece76 --- /dev/null +++ b/src/fs/gnunet-service-fs_pe.h @@ -0,0 +1,59 @@ +/* + This file is part of GNUnet. + (C) 2011 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/** + * @file fs/gnunet-service-fs_pe.h + * @brief API to manage query plan + * @author Christian Grothoff + */ +#ifndef GNUNET_SERVICE_FS_PE_H +#define GNUNET_SERVICE_FS_PE_H + +#include "gnunet-service-fs.h" + + +/** + * Create a new query plan entry. + * + * @param cp peer with the entry + * @param pr request with the entry + * @param position position of the entry in the cp queue + * @return handle for the new plan entry + */ +struct GSF_PlanEntry * +GSF_plan_entry_create_ (struct GSF_ConnectedPeer *cp, + struct GSF_PendingRequest *pr, + unsigned int position); + + +/** + * Get the first plan entry for the given connected peer. + * FIXME... + * + * @param cp connected peer + * @return NULL if there is no request planned for this peer + */ +struct GSF_PendingRequest * +GSF_plan_get_ (struct GSF_ConnectedPeer *cp); + + + +#endif +/* end of gnunet-service-fs_pe.h */ diff --git a/src/fs/gnunet-service-fs_pr.h b/src/fs/gnunet-service-fs_pr.h new file mode 100644 index 000000000..b4dd82839 --- /dev/null +++ b/src/fs/gnunet-service-fs_pr.h @@ -0,0 +1,197 @@ +/* + This file is part of GNUnet. + (C) 2009, 2010 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/** + * @file fs/gnunet-service-fs_pr.h + * @brief API to handle pending requests + * @author Christian Grothoff + */ +#ifndef GNUNET_SERVICE_FS_PR_H +#define GNUNET_SERVICE_FS_PR_H + +#include "gnunet-service-fs.h" + + +/** + * Options for pending requests (bits to be ORed). + */ +enum GSF_PendingRequestOptions + { + /** + * Request must only be processed locally. + */ + GSF_PRO_LOCAL_ONLY = 1, + + /** + * Request must only be forwarded (no routing) + */ + GSF_PRO_FORWARD_ONLY = 2, + + /** + * Request persists indefinitely (no expiration). + */ + GSF_PRO_REQUEST_EXPIRES = 4, + + /** + * Request is allowed to refresh bloomfilter and change mingle value. + */ + GSF_PRO_BLOOMFILTER_FULL_REFRESH = 8, + + /** + * Request priority is allowed to be exceeded. + */ + GSF_PRO_PRIORITY_UNLIMITED = 16, + + /** + * Option mask for typical local requests. + */ + GSF_PRO_LOCAL_REQUEST = (GSF_PRO_BLOOMFILTER_FULL_REFRESH | GSF_PRO_PRIORITY_UNLIMITED) + }; + + +/** + * Handle a reply to a pending request. Also called if a request + * expires (then with data == NULL). The handler may be called + * many times (depending on the request type), but will not be + * called during or after a call to GSF_pending_request_cancel + * and will also not be called anymore after a call signalling + * expiration. + * + * @param cls user-specified closure + * @param pr handle to the original pending request + * @param data response data, NULL on request expiration + * @param data_len number of bytes in data + */ +typedef void (*GSF_PendingRequestReplyHandler)(void *cls, + struct GSF_PendingRequest *pr, + const void *data, + size_t data_len); + + +/** + * Create a new pending request. + * + * @param options request options + * @param type type of the block that is being requested + * @param query key for the lookup + * @param namespace namespace to lookup, NULL for no namespace + * @param target preferred target for the request, NULL for none + * @param bf bloom filter for known replies, can be NULL + * @param mingle mingle value for bf + * @param anonymity_level desired anonymity level + * @param priority maximum outgoing cummulative request priority to use + * @param replies_seen hash codes of known local replies + * @param replies_seen_count size of the 'replies_seen' array + * @param rh handle to call when we get a reply + * @param rh_cls closure for rh + * @return handle for the new pending request + */ +struct GSF_PendingRequest * +GSF_pending_request_create_ (enum GSF_PendingRequestOptions options, + enum GNUNET_BLOCK_Type type, + const GNUNET_HashCode *query, + const GNUNET_HashCode *namespace, + const struct GNUNET_PeerIdentity *target, + struct GNUNET_CONTAINER_BloomFilter *bf, + int32_t mingle, + uint32_t anonymity_level, + uint32_t priority, + const GNUNET_HashCode *replies_seen, + unsigned int replies_seen_count, + GSF_PendingRequestReplyHandler rh, + void *rh_cls); + + +/** + * Generate the message corresponding to the given pending request for + * transmission to other peers (or at least determine its size). + * + * @param pr request to generate the message for + * @param buf_size number of bytes available in buf + * @param buf where to copy the message (can be NULL) + * @return number of bytes needed (if > buf_size) or used + */ +size_t +GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr, + size_t buf_size, + void *buf); + + +/** + * Explicitly cancel a pending request. + * + * @param pr request to cancel + */ +void +GSF_pending_request_cancel_ (struct GSF_PendingRequest *pr); + + +/** + * Signature of function called on each request. + * + * @param cls closure + * @param key query for the request + * @param pr handle to the pending request + */ +typedef int (*GSF_PendingRequestIterator)(void *cls, + const GNUNET_HashCode *key, + struct GSF_PendingRequest *pr); + + +/** + * Iterate over all pending requests. + * + * @param it function to call for each request + * @param cls closure for it + */ +void +GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it, + void *cls); + + + +/** + * Register callback to invoke on request destruction. + * + * @param pr request to monitor + * @param it function to call on destruction + * @param it_cls closure for it + */ +void +GSF_pending_request_register_destroy_callback_ (struct GSF_PendingRequest *pr, + GSF_PendingRequestIterator it, + void *it_cls); + + +/** + * Unregister callback to invoke on request destruction. + * + * @param pr request to stop monitoring + * @param it function to no longer call on destruction + * @param it_cls closure for it + */ +void +GSF_pending_request_unregister_destroy_callback_ (struct GSF_PendingRequest *pr, + GSF_PendingRequestIterator it, + void *it_cls); + + +#endif +/* end of gnunet-service-fs_pr.h */ -- 2.25.1