*/
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.
*/
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.
*/
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.
/**
- * 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
{
&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);
* @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;
/**
- * 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);
/**
* @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)
*/
(*GNUNET_CORE_MessageCallback) (void *cls,
const struct GNUNET_PeerIdentity * other,
const struct GNUNET_MessageHeader *
- message);
+ message,
+ struct GNUNET_TIME_Relative latency,
+ uint32_t distance);
/**
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,
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);
* @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);
/**
* @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);
/**
GNUNET_CORE_notify_transmit_ready (struct
GNUNET_CORE_Handle
*handle,
- unsigned
- int
- priority,
+ uint32_t priority,
struct
GNUNET_TIME_Relative
maxdelay,
message,
struct GNUNET_TIME_Relative
latency,
- unsigned int distance);
+ uint32_t distance);
/**
(*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
*handle,
const struct GNUNET_PeerIdentity
*target, size_t size,
- unsigned int priority,
+ uint32_t priority,
struct GNUNET_TIME_Relative
timeout,
GNUNET_CONNECTION_TransmitReadyNotify
$(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 \
--- /dev/null
+/*
+ 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 */
--- /dev/null
+*
+ 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"
+
* 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.
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,