-preparatory steps for transport API change
[oweals/gnunet.git] / src / core / core.h
index 7332f43b7379b1673ae690cdd786e4ce0c03afa4..7c3a5bdd8e0648bd2dd8a09593a8028c7d9a18d8 100644 (file)
@@ -1,10 +1,10 @@
 /*
      This file is part of GNUnet.
-     (C) 2009 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2009-2014 GNUnet e.V.
 
      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
+     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
@@ -14,8 +14,8 @@
 
      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.
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
 */
 
 /**
  * @brief common internal definitions for core service
  * @author Christian Grothoff
  */
+#ifndef CORE_H
+#define CORE_H
+
+#include "gnunet_bandwidth_lib.h"
+#include "gnunet_transport_service.h"
 #include "gnunet_crypto_lib.h"
 #include "gnunet_time_lib.h"
 
 /**
  * General core debugging.
  */
-#define DEBUG_CORE GNUNET_NO
-
-/**
- * Debugging interaction core-clients.
- */
-#define DEBUG_CORE_CLIENT GNUNET_YES
+#define DEBUG_CORE GNUNET_EXTRA_LOGGING
 
 /**
  * Definition of bits in the InitMessage's options field that specify
  * transmitted to the client.
  */
 #define GNUNET_CORE_OPTION_NOTHING             0
-#define GNUNET_CORE_OPTION_SEND_PRE_CONNECT    1
-#define GNUNET_CORE_OPTION_SEND_CONNECT        2
-#define GNUNET_CORE_OPTION_SEND_DISCONNECT     4
+
+/**
+ * Client cares about connectivity changes.
+ */
+#define GNUNET_CORE_OPTION_SEND_STATUS_CHANGE  4
+
+/**
+ * Client wants all inbound messages in full.
+ */
 #define GNUNET_CORE_OPTION_SEND_FULL_INBOUND   8
+
+/**
+ * Client just wants the 4-byte message headers of
+ * all inbound messages.
+ */
 #define GNUNET_CORE_OPTION_SEND_HDR_INBOUND   16
+
+/**
+ * Client wants all outbound messages in full.
+ */
 #define GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND 32
+
+/**
+ * Client just wants the 4-byte message headers of
+ * all outbound messages.
+ */
 #define GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND  64
 
 
+GNUNET_NETWORK_STRUCT_BEGIN
+
 /**
  * Message transmitted core clients to gnunet-service-core
  * to start the interaction.  This header is followed by
@@ -62,7 +84,7 @@ struct InitMessage
 {
 
   /**
-   * Header with type GNUNET_MESSAGE_TYPE_CORE_INIT.
+   * Header with type #GNUNET_MESSAGE_TYPE_CORE_INIT.
    */
   struct GNUNET_MessageHeader header;
 
@@ -82,7 +104,7 @@ struct InitReplyMessage
 {
 
   /**
-   * Header with type GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY
+   * Header with type #GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY
    */
   struct GNUNET_MessageHeader header;
 
@@ -94,32 +116,26 @@ struct InitReplyMessage
   /**
    * Public key of the local peer.
    */
-  struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded publicKey;
+  struct GNUNET_PeerIdentity my_identity;
 
 };
 
 
 /**
  * Message sent by the service to clients to notify them
- * about a peer connecting or disconnecting.
+ * about a peer connecting.
  */
 struct ConnectNotifyMessage
 {
   /**
-   * Header with type GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT
-   * or GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT.
+   * Header with type #GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT
    */
   struct GNUNET_MessageHeader header;
 
   /**
-   * Distance to the peer.
-   */
-  uint32_t distance GNUNET_PACKED;
-
-  /**
-   * Currently observed latency.
+   * Always zero.
    */
-  struct GNUNET_TIME_RelativeNBO latency;
+  uint32_t reserved GNUNET_PACKED;
 
   /**
    * Identity of the connecting peer.
@@ -129,7 +145,6 @@ struct ConnectNotifyMessage
 };
 
 
-
 /**
  * Message sent by the service to clients to notify them
  * about a peer disconnecting.
@@ -137,7 +152,7 @@ struct ConnectNotifyMessage
 struct DisconnectNotifyMessage
 {
   /**
-   * Header with type GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT.
+   * Header with type #GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT.
    */
   struct GNUNET_MessageHeader header;
 
@@ -154,7 +169,6 @@ struct DisconnectNotifyMessage
 };
 
 
-
 /**
  * Message sent by the service to clients to notify them about
  * messages being received or transmitted.  This overall message is
@@ -167,111 +181,92 @@ struct DisconnectNotifyMessage
 struct NotifyTrafficMessage
 {
   /**
-   * Header with type GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND
-   * or GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND.
+   * Header with type #GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND
+   * or #GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND.
    */
   struct GNUNET_MessageHeader header;
 
-  /**
-   * Distance to the peer.
-   */
-  uint32_t distance GNUNET_PACKED;
-
-  /**
-   * Currently observed latency.
-   */
-  struct GNUNET_TIME_RelativeNBO latency;
-
   /**
    * Identity of the receiver or sender.
    */
   struct GNUNET_PeerIdentity peer;
 
+  /* Followed by payload (message or just header), variable size */
 };
 
 
 /**
- * Message sent to the core asking for configuration
- * information and possibly preference changes.
+ * Client notifying core about the maximum-priority
+ * message it has in the queue for a particular target.
  */
-struct RequestInfoMessage
+struct SendMessageRequest
 {
   /**
-   * Header with type GNUNET_MESSAGE_TYPE_CORE_REQUEST_CONFIGURE
+   * Header with type #GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST
    */
   struct GNUNET_MessageHeader header;
 
   /**
-   * Always zero.
+   * How important is this message?
    */
-  uint32_t reserved GNUNET_PACKED;
+  uint32_t priority GNUNET_PACKED;
 
   /**
-   * Limit the number of bytes of outbound traffic to this
-   * peer to at most the specified amount (naturally, the
-   * amount is also limited by the receiving peer).
+   * By what time would the sender really like to see this
+   * message transmitted?
    */
-  uint32_t limit_outbound_bpm GNUNET_PACKED;
+  struct GNUNET_TIME_AbsoluteNBO deadline;
 
   /**
-   * Number of bytes of inbound traffic to reserve, can
-   * be negative (to unreserve).  NBO.
+   * Identity of the intended target.
    */
-  int32_t reserve_inbound GNUNET_PACKED;
+  struct GNUNET_PeerIdentity peer;
 
   /**
-   * Increment the current traffic preference for the given peer by
-   * the specified amont.  The traffic preference is used to determine
-   * the share of bandwidth this peer will typcially be assigned.
+   * Always zero.
    */
-  uint64_t preference_change GNUNET_PACKED;
+  uint32_t reserved GNUNET_PACKED;
 
   /**
-   * Identity of the peer being configured.
+   * How large is the message?
    */
-  struct GNUNET_PeerIdentity peer;
+  uint16_t size GNUNET_PACKED;
+
+  /**
+   * Counter for this peer to match SMRs to replies.
+   */
+  uint16_t smr_id GNUNET_PACKED;
 
 };
 
 
 /**
- * Response from the core to a "RequestInfoMessage"
- * providing traffic status information for a peer.
+ * Core notifying client that it is allowed to now
+ * transmit a message to the given target
+ * (response to #GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST).
  */
-struct ConfigurationInfoMessage
+struct SendMessageReady
 {
   /**
-   * Header with type GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO
+   * Header with type #GNUNET_MESSAGE_TYPE_CORE_SEND_READY
    */
   struct GNUNET_MessageHeader header;
 
   /**
-   * Amount of traffic (inbound number of bytes) that was reserved in
-   * response to the configuration change request.  Negative for
-   * "unreserved" bytes.
+   * How many bytes are allowed for transmission?
+   * Guaranteed to be at least as big as the requested size,
+   * or ZERO if the request is rejected (will timeout,
+   * peer disconnected, queue full, etc.).
    */
-  int32_t reserved_amount GNUNET_PACKED;
+  uint16_t size GNUNET_PACKED;
 
   /**
-   * Available bandwidth in (in bytes per minute) for this peer.
-   * 0 if we have been disconnected.
+   * smr_id from the request.
    */
-  uint32_t bpm_in GNUNET_PACKED;
+  uint16_t smr_id GNUNET_PACKED;
 
   /**
-   * Available bandwidth out (in bytes per minute) for this peer,
-   * 0 if we have been disconnected.
-   */
-  uint32_t bpm_out GNUNET_PACKED;
-
-  /**
-   * Current traffic preference for the peer.
-   * 0 if we have been disconnected.
-   */
-  uint64_t preference;
-
-  /**
-   * Identity of the receiver or sender.
+   * Identity of the intended target.
    */
   struct GNUNET_PeerIdentity peer;
 
@@ -279,13 +274,13 @@ struct ConfigurationInfoMessage
 
 
 /**
- * Client asking core to transmit a particular message to
- * a particular target.  
+ * Client asking core to transmit a particular message to a particular
+ * target (response to #GNUNET_MESSAGE_TYPE_CORE_SEND_READY).
  */
 struct SendMessage
 {
   /**
-   * Header with type GNUNET_MESSAGE_TYPE_CORE_SEND
+   * Header with type #GNUNET_MESSAGE_TYPE_CORE_SEND
    */
   struct GNUNET_MessageHeader header;
 
@@ -301,38 +296,52 @@ struct SendMessage
   struct GNUNET_TIME_AbsoluteNBO deadline;
 
   /**
-   * Identity of the receiver or sender.
+   * Identity of the intended receiver.
    */
   struct GNUNET_PeerIdentity peer;
 
+  /**
+   * #GNUNET_YES if corking is allowed, #GNUNET_NO if not.
+   */
+  uint32_t cork GNUNET_PACKED;
+
+  /**
+   * Always 0.
+   */
+  uint32_t reserved GNUNET_PACKED;
+
 };
 
 
 /**
- * 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).
+ * Message sent by the service to monitor clients to notify them
+ * about a peer changing status.
  */
-struct ConnectMessage
+struct MonitorNotifyMessage
 {
   /**
-   * Header with type GNUNET_MESSAGE_TYPE_REQUEST_CONNECT or
-   * GNUNET_MESSAGE_TYPE_REQUEST_DISCONNECT.
+   * Header with type #GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY
    */
   struct GNUNET_MessageHeader header;
 
   /**
-   * For alignment.
+   * New peer state, an `enum GNUNET_CORE_KxState` in NBO.
    */
-  uint32_t reserved GNUNET_PACKED;
+  uint32_t state GNUNET_PACKED;
 
   /**
-   * Identity of the other peer.
+   * Identity of the peer.
    */
   struct GNUNET_PeerIdentity peer;
 
+  /**
+   * How long will we stay in this state (if nothing else happens)?
+   */
+  struct GNUNET_TIME_AbsoluteNBO timeout;
+
 };
 
+
+GNUNET_NETWORK_STRUCT_END
+#endif
 /* end of core.h */