From 87b254030acd37b6714565c5ac2e803da743d777 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 21 Jan 2010 14:06:06 +0000 Subject: [PATCH] stuff --- src/core/core.h | 55 +++-- src/core/core_api_peer_get_info.c | 19 +- src/include/gnunet_core_service.h | 66 +++--- src/include/gnunet_transport_service.h | 6 +- src/transport/Makefile.am | 3 +- .../gnunet-service-transport_blacklist.c | 202 ++++++++++++++++++ .../gnunet-service-transport_blacklist.h | 30 +++ src/transport/plugin_transport.h | 16 +- 8 files changed, 337 insertions(+), 60 deletions(-) create mode 100644 src/transport/gnunet-service-transport_blacklist.c create mode 100644 src/transport/gnunet-service-transport_blacklist.h diff --git a/src/core/core.h b/src/core/core.h index 30130b84b..20c3ddc4b 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -111,6 +111,36 @@ struct ConnectNotifyMessage */ struct GNUNET_MessageHeader header; + /** + * Distance to the peer. + */ + uint32_t distance GNUNET_PACKED; + + /** + * Currently observed latency. + */ + struct GNUNET_TIME_RelativeNBO latency; + + /** + * Identity of the connecting peer. + */ + struct GNUNET_PeerIdentity peer; + +}; + + + +/** + * Message sent by the service to clients to notify them + * about a peer disconnecting. + */ +struct DisconnectNotifyMessage +{ + /** + * Header with type GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT. + */ + struct GNUNET_MessageHeader header; + /** * Always zero. */ @@ -143,9 +173,14 @@ struct NotifyTrafficMessage struct GNUNET_MessageHeader header; /** - * Always zero. + * Distance to the peer. */ - uint32_t reserved GNUNET_PACKED; + uint32_t distance GNUNET_PACKED; + + /** + * Currently observed latency. + */ + struct GNUNET_TIME_RelativeNBO latency; /** * Identity of the receiver or sender. @@ -229,12 +264,6 @@ struct ConfigurationInfoMessage */ uint32_t bpm_out GNUNET_PACKED; - /** - * Latest transport latency estimate for the peer. - * FOREVER if we have been disconnected. - */ - struct GNUNET_TIME_RelativeNBO latency; - /** * Current traffic preference for the peer. * 0 if we have been disconnected. @@ -280,11 +309,11 @@ struct SendMessage /** - * Client asking core to transmit a particular message to a particular - * target. There is no response from the core to this type of request - * (however, if an actual connection is created or destroyed, be it - * because of this type request or not, the core generally needs to - * notify the clients). + * Client asking core to connect to a particular target. There is no + * response from the core to this type of request (however, if an + * actual connection is created or destroyed, be it because of this + * type request or not, the core generally needs to notify the + * clients). */ struct ConnectMessage { diff --git a/src/core/core_api_peer_get_info.c b/src/core/core_api_peer_get_info.c index 23ae04f01..f6ce31110 100644 --- a/src/core/core_api_peer_get_info.c +++ b/src/core/core_api_peer_get_info.c @@ -88,7 +88,6 @@ receive_info (void *cls, &cim->peer, ntohl (cim->bpm_in), ntohl (cim->bpm_out), - GNUNET_TIME_relative_ntoh (cim->latency), ntohl (cim->reserved_amount), GNUNET_ntohll (cim->preference)); GNUNET_CLIENT_disconnect (irc->client); @@ -122,15 +121,15 @@ receive_info (void *cls, * @return NULL on error */ struct GNUNET_CORE_InformationRequestContext * -GNUNET_CORE_peer_get_info (struct GNUNET_SCHEDULER_Handle *sched, - const struct GNUNET_CONFIGURATION_Handle *cfg, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_TIME_Relative timeout, - uint32_t bpm_out, - int32_t amount, - uint64_t preference, - GNUNET_CORE_PeerConfigurationInfoCallback info, - void *info_cls) +GNUNET_CORE_peer_change_preference (struct GNUNET_SCHEDULER_Handle *sched, + const struct GNUNET_CONFIGURATION_Handle *cfg, + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_TIME_Relative timeout, + uint32_t bpm_out, + int32_t amount, + uint64_t preference, + GNUNET_CORE_PeerConfigurationInfoCallback info, + void *info_cls) { struct GNUNET_CORE_InformationRequestContext *irc; struct RequestInfoMessage rim; diff --git a/src/include/gnunet_core_service.h b/src/include/gnunet_core_service.h index cffdf0a14..3ba4ef137 100644 --- a/src/include/gnunet_core_service.h +++ b/src/include/gnunet_core_service.h @@ -51,15 +51,30 @@ struct GNUNET_CORE_Handle; /** - * Method called whenever a given peer either connects or - * disconnects (or list of connections was requested). + * Method called whenever a given peer either connects. * * @param cls closure * @param peer peer identity this notification is about + * @param latency reported latency of the connection with 'other' + * @param distance reported distance (DV) to 'other' */ -typedef void (*GNUNET_CORE_ClientEventHandler) (void *cls, - const struct - GNUNET_PeerIdentity * peer); +typedef void (*GNUNET_CORE_ConnectEventHandler) (void *cls, + const struct + GNUNET_PeerIdentity * peer, + struct GNUNET_TIME_Relative latency, + uint32_t distance); + + + +/** + * Method called whenever a given peer either disconnects. + * + * @param cls closure + * @param peer peer identity this notification is about + */ +typedef void (*GNUNET_CORE_DisconnectEventHandler) (void *cls, + const struct + GNUNET_PeerIdentity * peer); /** @@ -70,6 +85,8 @@ typedef void (*GNUNET_CORE_ClientEventHandler) (void *cls, * @param peer the other peer involved (sender or receiver, NULL * for loopback messages where we are both sender and receiver) * @param message the actual message + * @param latency reported latency of the connection with 'other' + * @param distance reported distance (DV) to 'other' * @return GNUNET_OK to keep the connection open, * GNUNET_SYSERR to close it (signal serious error) */ @@ -77,7 +94,9 @@ typedef int (*GNUNET_CORE_MessageCallback) (void *cls, const struct GNUNET_PeerIdentity * other, const struct GNUNET_MessageHeader * - message); + message, + struct GNUNET_TIME_Relative latency, + uint32_t distance); /** @@ -159,9 +178,9 @@ GNUNET_CORE_connect (struct GNUNET_SCHEDULER_Handle *sched, struct GNUNET_TIME_Relative timeout, void *cls, GNUNET_CORE_StartupCallback init, - GNUNET_CORE_ClientEventHandler pre_connects, - GNUNET_CORE_ClientEventHandler connects, - GNUNET_CORE_ClientEventHandler disconnects, + GNUNET_CORE_ConnectEventHandler pre_connects, + GNUNET_CORE_ConnectEventHandler connects, + GNUNET_CORE_DisconnectEventHandler disconnects, GNUNET_CORE_MessageCallback inbound_notify, int inbound_hdr_only, GNUNET_CORE_MessageCallback outbound_notify, @@ -270,9 +289,8 @@ typedef void GNUNET_PeerIdentity * peer, unsigned int bpm_in, unsigned int bpm_out, - struct GNUNET_TIME_Relative - latency, int amount, - unsigned long long preference); + int amount, + uint64_t preference); @@ -307,15 +325,15 @@ struct GNUNET_CORE_InformationRequestContext; * @return NULL on error */ struct GNUNET_CORE_InformationRequestContext * -GNUNET_CORE_peer_get_info (struct GNUNET_SCHEDULER_Handle *sched, - const struct GNUNET_CONFIGURATION_Handle *cfg, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_TIME_Relative timeout, - uint32_t bpm_out, - int32_t amount, - uint64_t preference, - GNUNET_CORE_PeerConfigurationInfoCallback info, - void *info_cls); +GNUNET_CORE_peer_change_preference (struct GNUNET_SCHEDULER_Handle *sched, + const struct GNUNET_CONFIGURATION_Handle *cfg, + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_TIME_Relative timeout, + uint32_t bpm_out, + int32_t amount, + uint64_t preference, + GNUNET_CORE_PeerConfigurationInfoCallback info, + void *info_cls); /** @@ -324,7 +342,7 @@ GNUNET_CORE_peer_get_info (struct GNUNET_SCHEDULER_Handle *sched, * @param irc context returned by the original GNUNET_CORE_peer_get_info call */ void -GNUNET_CORE_peer_get_info_cancel (struct GNUNET_CORE_InformationRequestContext *irc); +GNUNET_CORE_peer_change_preference_cancel (struct GNUNET_CORE_InformationRequestContext *irc); /** @@ -355,9 +373,7 @@ struct GNUNET_CORE_TransmitHandle * GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle, - unsigned - int - priority, + uint32_t priority, struct GNUNET_TIME_Relative maxdelay, diff --git a/src/include/gnunet_transport_service.h b/src/include/gnunet_transport_service.h index 0d378cbd3..b86bb1663 100644 --- a/src/include/gnunet_transport_service.h +++ b/src/include/gnunet_transport_service.h @@ -68,7 +68,7 @@ typedef void (*GNUNET_TRANSPORT_ReceiveCallback) (void *cls, message, struct GNUNET_TIME_Relative latency, - unsigned int distance); + uint32_t distance); /** @@ -91,7 +91,7 @@ typedef void (*GNUNET_TRANSPORT_NotifyConnect) (void *cls, const struct GNUNET_PeerIdentity * peer, struct GNUNET_TIME_Relative latency, - unsigned int distance); + uint32_t distance); /** * Function called to notify transport users that another @@ -204,7 +204,7 @@ struct GNUNET_TRANSPORT_TransmitHandle *handle, const struct GNUNET_PeerIdentity *target, size_t size, - unsigned int priority, + uint32_t priority, struct GNUNET_TIME_Relative timeout, GNUNET_CONNECTION_TransmitReadyNotify diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index 87860c202..a612fa4f4 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am @@ -39,7 +39,8 @@ gnunet_transport_LDADD = \ $(GN_LIBINTL) gnunet_service_transport_SOURCES = \ - gnunet-service-transport.c plugin_transport.h + gnunet-service-transport.c plugin_transport.h \ + gnunet-service-transport_blacklist.c gnunet-service-transport_blacklist.h gnunet_service_transport_LDADD = \ $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ $(top_builddir)/src/util/libgnunetutil.la \ diff --git a/src/transport/gnunet-service-transport_blacklist.c b/src/transport/gnunet-service-transport_blacklist.c new file mode 100644 index 000000000..a1b13f33e --- /dev/null +++ b/src/transport/gnunet-service-transport_blacklist.c @@ -0,0 +1,202 @@ +/* + This file is part of GNUnet. + (C) 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 2, 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 transport/gnunet-service-transport_blacklist.c + * @brief low-level P2P messaging + * @author Christian Grothoff + */ +#include "platform.h" +#include "gnunet_protocols.h" +#include "gnunet_service_lib.h" +#include "transport.h" +#include "gnunet-service-transport_blacklist.h" + + +/** + * Information kept for each blacklisted peer. + */ +struct BlacklistEntry +{ + /** + * How long until this entry times out? + */ + struct GNUNET_TIME_Absolute until; + + /** + * Task scheduled to run the moment the time does run out. + */ + GNUNET_SCHEDULER_TaskIdentifier timeout_task; +}; + + +/** + * Entry in list of notifications still to transmit to + * a client. + */ +struct PendingNotificationList +{ + + /** + * This is a linked list. + */ + struct PendingNotificationList *next; + + /** + * Identity of the peer to send notification about. + */ + struct GNUNET_PeerIdentity peer; + +}; + + +/** + * List of clients to notify whenever the blacklist changes. + */ +struct BlacklistNotificationList +{ + + /** + * This is a linked list. + */ + struct BlacklistNotificationList *next; + + /** + * Client to notify. + */ + struct GNUNET_SERVER_Client *client; + + /** + * Pending request for transmission to client, or NULL. + */ + struct GNUNET_CONNECTION_TransmitHandle *req; + + /** + * Blacklist entries that still need to be submitted. + */ + struct PendingNotificationList *pending; + +}; + + +/** + * Map of blacklisted peers (maps from peer identities + * to 'struct BlacklistEntry*' values). + */ +static struct GNUNET_CONTAINER_MultiHashMap *blacklist; + +/** + * Linked list of clients to notify whenever the blacklist changes. + */ +static struct BlacklistNotificationList *blacklist_notifiers; + +/** + * Our scheduler. + */ +static struct GNUNET_SCHEDULER_Handle *sched; + + +/** + * Free the entries in the blacklist hash map. + * + * @param cls closure, unused + * @param key current key code + * @param value value in the hash map + * @return GNUNET_YES if we should continue to + * iterate, + * GNUNET_NO if not. + */ +static int +free_blacklist_entry (void *cls, + const GNUNET_HashCode *key, + void *value) +{ + struct BlacklistEntry *be = value; + + GNUNET_SCHEDULER_cancel (sched, + be->timeout_task); + GNUNET_free (be); + return GNUNET_YES; +} + + +static void +shutdown_task (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + GNUNET_CONTAINER_multihashmap_iterate (blacklist, + &free_blacklist_entry, + NULL); + GNUNET_CONTAINER_multihashmap_destroy (blacklist); +} + + +/** + * Handle a request to blacklist a peer. + */ +void +GNUNET_TRANSPORT_handle_blacklist (void *cls, + struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *message) +{ +} + + +/** + * Handle a request for notification of blacklist changes. + */ +void +GNUNET_TRANSPORT_handle_blacklist_notify (void *cls, + struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *message) +{ +} + + +/** + * Is the given peer currently blacklisted? + * + * @param id identity of the peer + * @return GNUNET_YES if the peer is blacklisted, GNUNET_NO if not + */ +int +GNUNET_TRANSPORT_blacklist_check (const struct GNUNET_PeerIdentity *id) +{ + return GNUNET_CONTAINER_multihashmap_contains (blacklist, &id->hashPubKey); +} + + +/** + * Initialize the blacklisting subsystem. + * + * @param s scheduler to use + */ +void +GNUNET_TRANSPORT_blacklist_init (struct GNUNET_SCHEDULER_Handle *s) +{ + sched = s; + blacklist = GNUNET_CONTAINER_multihashmap_create (4); + GNUNET_SCHEDULER_add_delayed (sched, + GNUNET_TIME_UNIT_FOREVER_REL, + &shutdown_task, + NULL); +} + +/* end of gnunet-service-transport_blacklist.c */ diff --git a/src/transport/gnunet-service-transport_blacklist.h b/src/transport/gnunet-service-transport_blacklist.h new file mode 100644 index 000000000..95a86dc9a --- /dev/null +++ b/src/transport/gnunet-service-transport_blacklist.h @@ -0,0 +1,30 @@ +* + This file is part of GNUnet. + (C) 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 2, 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 transport/gnunet-service-transport_blacklist.h + * @brief internal API for blacklisting functionality + * @author Christian Grothoff + */ +#include "platform.h" +#include "gnunet_protocols.h" +#include "gnunet_service_lib.h" +#include "transport.h" + diff --git a/src/transport/plugin_transport.h b/src/transport/plugin_transport.h index b04cab990..2b3a87f3b 100644 --- a/src/transport/plugin_transport.h +++ b/src/transport/plugin_transport.h @@ -50,24 +50,24 @@ * message to signal that the other peer disconnected. * * @param cls closure + * @param peer (claimed) identity of the other peer + * @param message the message, NULL if peer was disconnected * @param distance in overlay hops; use 1 unless DV * @param sender_address binary address of the sender (if observed) * @param sender_address_len number of bytes in sender_address - * @param peer (claimed) identity of the other peer - * @param message the message, NULL if peer was disconnected */ -typedef void (*GNUNET_TRANSPORT_PluginReceiveCallback) (void *cls, const struct - GNUNET_MessageHeader * - message, +typedef void (*GNUNET_TRANSPORT_PluginReceiveCallback) (void *cls, const struct GNUNET_PeerIdentity * peer, - unsigned int distance, + const struct + GNUNET_MessageHeader * + message, + uint32_t distance, const char *sender_address, size_t sender_address_len); - /** * Function that will be called for each address the transport * is aware that it might be reachable under. @@ -198,7 +198,7 @@ typedef ssize_t const struct GNUNET_PeerIdentity * target, const struct GNUNET_MessageHeader *msg, - unsigned int priority, + uint32_t priority, struct GNUNET_TIME_Relative timeout, const void *addr, size_t addrlen, -- 2.25.1