gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r10087 - in gnunet/src: core include transport


From: gnunet
Subject: [GNUnet-SVN] r10087 - in gnunet/src: core include transport
Date: Thu, 21 Jan 2010 15:06:06 +0100

Author: grothoff
Date: 2010-01-21 15:06:06 +0100 (Thu, 21 Jan 2010)
New Revision: 10087

Added:
   gnunet/src/transport/gnunet-service-transport_blacklist.c
   gnunet/src/transport/gnunet-service-transport_blacklist.h
Modified:
   gnunet/src/core/core.h
   gnunet/src/core/core_api_peer_get_info.c
   gnunet/src/include/gnunet_core_service.h
   gnunet/src/include/gnunet_transport_service.h
   gnunet/src/transport/Makefile.am
   gnunet/src/transport/plugin_transport.h
Log:
stuff

Modified: gnunet/src/core/core.h
===================================================================
--- gnunet/src/core/core.h      2010-01-21 13:48:14 UTC (rev 10086)
+++ gnunet/src/core/core.h      2010-01-21 14:06:06 UTC (rev 10087)
@@ -112,6 +112,36 @@
   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.
    */
   uint32_t reserved GNUNET_PACKED;
@@ -143,11 +173,16 @@
   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.
    */
   struct GNUNET_PeerIdentity peer;
@@ -230,12 +265,6 @@
   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 @@
 
 
 /**
- * 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
 {

Modified: gnunet/src/core/core_api_peer_get_info.c
===================================================================
--- gnunet/src/core/core_api_peer_get_info.c    2010-01-21 13:48:14 UTC (rev 
10086)
+++ gnunet/src/core/core_api_peer_get_info.c    2010-01-21 14:06:06 UTC (rev 
10087)
@@ -88,7 +88,6 @@
               &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 @@
  * @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;

Modified: gnunet/src/include/gnunet_core_service.h
===================================================================
--- gnunet/src/include/gnunet_core_service.h    2010-01-21 13:48:14 UTC (rev 
10086)
+++ gnunet/src/include/gnunet_core_service.h    2010-01-21 14:06:06 UTC (rev 
10087)
@@ -51,18 +51,33 @@
 
 
 /**
- * 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);
+
+
+/**
  * Functions with this signature are called whenever a message is
  * received or transmitted.
  *
@@ -70,6 +85,8 @@
  * @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 @@
   (*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 @@
                      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 @@
                                                 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 @@
  * @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 @@
  * @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 @@
 GNUNET_CORE_notify_transmit_ready (struct
                                   GNUNET_CORE_Handle
                                   *handle,
-                                  unsigned
-                                  int
-                                  priority,
+                                  uint32_t priority,
                                   struct
                                   GNUNET_TIME_Relative
                                   maxdelay,

Modified: gnunet/src/include/gnunet_transport_service.h
===================================================================
--- gnunet/src/include/gnunet_transport_service.h       2010-01-21 13:48:14 UTC 
(rev 10086)
+++ gnunet/src/include/gnunet_transport_service.h       2010-01-21 14:06:06 UTC 
(rev 10087)
@@ -68,7 +68,7 @@
                                                   message,
                                                  struct GNUNET_TIME_Relative
                                                   latency,
-                                                 unsigned int distance);
+                                                 uint32_t distance);
 
 
 /**
@@ -91,7 +91,7 @@
   (*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 @@
                                            *handle,
                                            const struct GNUNET_PeerIdentity
                                            *target, size_t size,
-                                          unsigned int priority,
+                                          uint32_t priority,
                                            struct GNUNET_TIME_Relative
                                            timeout,
                                            
GNUNET_CONNECTION_TransmitReadyNotify

Modified: gnunet/src/transport/Makefile.am
===================================================================
--- gnunet/src/transport/Makefile.am    2010-01-21 13:48:14 UTC (rev 10086)
+++ gnunet/src/transport/Makefile.am    2010-01-21 14:06:06 UTC (rev 10087)
@@ -39,7 +39,8 @@
   $(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 \

Added: gnunet/src/transport/gnunet-service-transport_blacklist.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport_blacklist.c                   
        (rev 0)
+++ gnunet/src/transport/gnunet-service-transport_blacklist.c   2010-01-21 
14:06:06 UTC (rev 10087)
@@ -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 */

Added: gnunet/src/transport/gnunet-service-transport_blacklist.h
===================================================================
--- gnunet/src/transport/gnunet-service-transport_blacklist.h                   
        (rev 0)
+++ gnunet/src/transport/gnunet-service-transport_blacklist.h   2010-01-21 
14:06:06 UTC (rev 10087)
@@ -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"
+

Modified: gnunet/src/transport/plugin_transport.h
===================================================================
--- gnunet/src/transport/plugin_transport.h     2010-01-21 13:48:14 UTC (rev 
10086)
+++ gnunet/src/transport/plugin_transport.h     2010-01-21 14:06:06 UTC (rev 
10087)
@@ -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 @@
                                         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,





reply via email to

[Prev in Thread] Current Thread [Next in Thread]