Quota compliance testcases should ready to be commited...
[oweals/gnunet.git] / src / core / core.h
index 9f520bf402677397beccdfe6ebc2740010bd5507..a8d90b81a6b50ce13671d48e06d0c7cca2d96550 100644 (file)
@@ -1,10 +1,10 @@
 /*
      This file is part of GNUnet.
-     (C) 2009 Christian Grothoff (and other contributing authors)
+     (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 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
  * @file core/core.h
  * @brief common internal definitions for core service
  * @author Christian Grothoff
+ *
+ * TODO:
+ * - bound message queue size
+ * - on disconnect from core, signal disconnect for all peers
+ *   and clean up peer records
+ * - create / destroy peer records on connect/disconnect events
+ * - implement iterator API
+ * - implement re-configure API
+ * - check on peer-related events that connection is known
+ *   (if not, GNUNET_break + reconnect)
+ * - handle atsi records
  */
+#include "gnunet_bandwidth_lib.h"
 #include "gnunet_crypto_lib.h"
 #include "gnunet_time_lib.h"
 
-#define DEBUG_CORE GNUNET_YES
+/**
+ * General core debugging.
+ */
+#define DEBUG_CORE GNUNET_NO
+
+/**
+ * Debugging interaction core-clients.
+ */
+#define DEBUG_CORE_CLIENT GNUNET_NO
 
 /**
  * Definition of bits in the InitMessage's options field that specify
@@ -37,7 +57,7 @@
 #define GNUNET_CORE_OPTION_NOTHING             0
 #define GNUNET_CORE_OPTION_SEND_CONNECT        1
 #define GNUNET_CORE_OPTION_SEND_DISCONNECT     2
-#define GNUNET_CORE_OPTION_SEND_BFC            4
+#define GNUNET_CORE_OPTION_SEND_STATUS_CHANGE  4
 #define GNUNET_CORE_OPTION_SEND_FULL_INBOUND   8
 #define GNUNET_CORE_OPTION_SEND_HDR_INBOUND   16
 #define GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND 32
@@ -93,22 +113,25 @@ struct InitReplyMessage
 
 /**
  * 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.
    */
   struct GNUNET_MessageHeader header;
 
   /**
-   * Available bandwidth to this peer; zero for disconnect.
-   * [TODO: currently set to hard-coded constant and hence
-   * not really useful, right?]
+   * Number of ATS key-value pairs that follow this struct
+   * (excluding the 0-terminator).
    */
-  uint32_t bpm_available GNUNET_PACKED;
+  uint32_t ats_count GNUNET_PACKED;
+
+  /**
+   * Currently observed latency.
+   */
+  struct GNUNET_TIME_RelativeNBO latency;
 
   /**
    * Identity of the connecting peer.
@@ -116,15 +139,83 @@ struct ConnectNotifyMessage
   struct GNUNET_PeerIdentity peer;
 
   /**
-   * Time of our last interaction with the peer; close
-   * to "now" for connect messages.
-   * [TODO: is this useful?]
+   * First of the ATS information blocks (we must have at least
+   * one due to the 0-termination requirement).
    */
-  struct GNUNET_TIME_AbsoluteNBO last_activity;
+  struct GNUNET_TRANSPORT_ATS_Information ats;
 
 };
 
 
+/**
+ * Message sent by the service to clients to notify them
+ * about a peer changing status.
+ */
+struct PeerStatusNotifyMessage
+{
+  /**
+   * Header with type GNUNET_MESSAGE_TYPE_CORE_NOTIFY_PEER_STATUS
+   */
+  struct GNUNET_MessageHeader header;
+
+  /**
+   * Number of ATS key-value pairs that follow this struct
+   * (excluding the 0-terminator).
+   */
+  uint32_t ats_count GNUNET_PACKED;
+
+  /**
+   * When the peer would time out (unless we see activity)
+   */
+  struct GNUNET_TIME_AbsoluteNBO timeout;
+
+  /**
+   * Available bandwidth from the peer.
+   */
+  struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in;
+
+  /**
+   * Available bandwidth to the peer.
+   */
+  struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out;
+
+  /**
+   * Identity of the peer.
+   */
+  struct GNUNET_PeerIdentity peer;
+
+  /**
+   * First of the ATS information blocks (we must have at least
+   * one due to the 0-termination requirement).
+   */
+  struct GNUNET_TRANSPORT_ATS_Information ats;
+
+};
+
+
+/**
+ * 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;
+
+  /**
+   * Identity of the connecting peer.
+   */
+  struct GNUNET_PeerIdentity peer;
+
+};
+
 
 /**
  * Message sent by the service to clients to notify them about
@@ -144,15 +235,27 @@ struct NotifyTrafficMessage
   struct GNUNET_MessageHeader header;
 
   /**
-   * Always zero.
+   * Number of ATS key-value pairs that follow this struct
+   * (excluding the 0-terminator).
    */
-  uint32_t reserved GNUNET_PACKED;
+  uint32_t ats_count GNUNET_PACKED;
+
+  /**
+   * Currently observed latency.
+   */
+  struct GNUNET_TIME_RelativeNBO latency;
 
   /**
    * Identity of the receiver or sender.
    */
   struct GNUNET_PeerIdentity peer;
 
+  /**
+   * First of the ATS information blocks (we must have at least
+   * one due to the 0-termination requirement).
+   */
+  struct GNUNET_TRANSPORT_ATS_Information ats;
+
 };
 
 
@@ -160,7 +263,7 @@ struct NotifyTrafficMessage
  * Message sent to the core asking for configuration
  * information and possibly preference changes.
  */
-struct RequestConfigureMessage
+struct RequestInfoMessage
 {
   /**
    * Header with type GNUNET_MESSAGE_TYPE_CORE_REQUEST_CONFIGURE
@@ -168,16 +271,16 @@ struct RequestConfigureMessage
   struct GNUNET_MessageHeader header;
 
   /**
-   * Always zero.
+   * Unique request ID.
    */
-  uint32_t reserved GNUNET_PACKED;
+  uint32_t rim_id 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).
    */
-  uint32_t limit_outbound_bpm GNUNET_PACKED;
+  struct GNUNET_BANDWIDTH_Value32NBO limit_outbound;
 
   /**
    * Number of bytes of inbound traffic to reserve, can
@@ -190,7 +293,7 @@ struct RequestConfigureMessage
    * the specified amont.  The traffic preference is used to determine
    * the share of bandwidth this peer will typcially be assigned.
    */
-  double preference_change GNUNET_PACKED;
+  uint64_t preference_change GNUNET_PACKED;
 
   /**
    * Identity of the peer being configured.
@@ -201,7 +304,7 @@ struct RequestConfigureMessage
 
 
 /**
- * Response from the core to a "RequestConfigureMessage"
+ * Response from the core to a "RequestInfoMessage"
  * providing traffic status information for a peer.
  */
 struct ConfigurationInfoMessage
@@ -219,56 +322,102 @@ struct ConfigurationInfoMessage
   int32_t reserved_amount GNUNET_PACKED;
 
   /**
-   * Available bandwidth in (in bytes per minute) for this peer.
+   * Unique request ID.
+   */
+  uint32_t rim_id GNUNET_PACKED;
+
+  /**
+   * Available bandwidth out for this peer,
    * 0 if we have been disconnected.
    */
-  uint32_t bpm_in GNUNET_PACKED;
+  struct GNUNET_BANDWIDTH_Value32NBO bw_out;
 
   /**
-   * Available bandwidth out (in bytes per minute) for this peer,
+   * Current traffic preference for the peer.
    * 0 if we have been disconnected.
    */
-  uint32_t bpm_out GNUNET_PACKED;
+  uint64_t preference;
 
   /**
-   * Latest transport latency estimate for the peer.
-   * FOREVER if we have been disconnected.
+   * Identity of the peer.
    */
-  struct GNUNET_TIME_RelativeNBO latency;
+  struct GNUNET_PeerIdentity peer;
+
+};
 
+
+/**
+ * Client notifying core about the maximum-priority
+ * message it has in the queue for a particular target.
+ */
+struct SendMessageRequest
+{
   /**
-   * Current traffic preference for the peer.
-   * 0 if we have been disconnected.
+   * Header with type GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST
    */
-  double preference;
+  struct GNUNET_MessageHeader header;
 
   /**
-   * Identity of the receiver or sender.
+   * How important is this message?
+   */
+  uint32_t priority GNUNET_PACKED;
+
+  /**
+   * By what time would the sender really like to see this
+   * message transmitted?
+   */
+  struct GNUNET_TIME_AbsoluteNBO deadline;
+
+  /**
+   * Identity of the intended target.
    */
   struct GNUNET_PeerIdentity peer;
 
+  /**
+   * How large is the client's message queue for this peer?
+   */
+  uint32_t queue_size GNUNET_PACKED;
+
+  /**
+   * How large is the message?
+   */
+  uint16_t size GNUNET_PACKED;
+
+  /**
+   * Counter for this peer to match SMRs to replies.
+   */
+  uint16_t smr_id GNUNET_PACKED;
+
 };
 
 
 /**
- * Core asking a client to generate traffic for a particular
- * target.
+ * 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 SolicitTrafficMessage
+struct SendMessageReady
 {
   /**
-   * Header with type GNUNET_MESSAGE_TYPE_CORE_SOLICIT_TRAFFIC
-   * or GNUNET_MESSAGE_TYPE_CORE_RECV_OK
+   * Header with type GNUNET_MESSAGE_TYPE_CORE_SEND_READY
    */
   struct GNUNET_MessageHeader header;
 
   /**
-   * Number of bytes of traffic being solicited.
+   * 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.).
    */
-  uint32_t solicit_size GNUNET_PACKED;
+  uint16_t size GNUNET_PACKED;
 
   /**
-   * Identity of the receiver or sender.
+   * smr_id from the request.
+   */
+  uint16_t smr_id GNUNET_PACKED;
+
+  /**
+   * Identity of the intended target.
    */
   struct GNUNET_PeerIdentity peer;
 
@@ -276,8 +425,8 @@ struct SolicitTrafficMessage
 
 
 /**
- * Client asking core to transmit a particular message to
- * a particular target.  Does NOT have to be solicited.
+ * Client asking core to transmit a particular message to a particular
+ * target (responsde to GNUNET_MESSAGE_TYPE_CORE_SEND_READY).
  */
 struct SendMessage
 {
@@ -305,4 +454,36 @@ struct SendMessage
 };
 
 
+/**
+ * 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
+{
+  /**
+   * Header with type GNUNET_MESSAGE_TYPE_REQUEST_CONNECT or
+   * GNUNET_MESSAGE_TYPE_REQUEST_DISCONNECT.
+   */
+  struct GNUNET_MessageHeader header;
+
+  /**
+   * For alignment.
+   */
+  uint32_t reserved GNUNET_PACKED;
+
+  /**
+   * When to time out.
+   */
+  struct GNUNET_TIME_RelativeNBO timeout;
+
+  /**
+   * Identity of the other peer.
+   */
+  struct GNUNET_PeerIdentity peer;
+
+};
+
 /* end of core.h */