[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r6166 - GNUnet/src/server
From: |
gnunet |
Subject: |
[GNUnet-SVN] r6166 - GNUnet/src/server |
Date: |
Wed, 6 Feb 2008 00:24:38 -0700 (MST) |
Author: grothoff
Date: 2008-02-06 00:24:38 -0700 (Wed, 06 Feb 2008)
New Revision: 6166
Modified:
GNUnet/src/server/connection.c
GNUnet/src/server/connection.h
GNUnet/src/server/core.c
Log:
implemented disconnect notification
Modified: GNUnet/src/server/connection.c
===================================================================
--- GNUnet/src/server/connection.c 2008-02-06 07:22:54 UTC (rev 6165)
+++ GNUnet/src/server/connection.c 2008-02-06 07:24:38 UTC (rev 6166)
@@ -70,11 +70,6 @@
#define DEBUG_COLLECT_PRIO GNUNET_NO
/**
- * strictly mark TSessions as down
- */
-#define STRICT_STAT_DOWN GNUNET_YES
-
-/**
* If an attempt to establish a connection is not answered
* within 150s, drop.
*/
@@ -267,7 +262,17 @@
} SendCallbackList;
+struct DisconnectNotificationList {
+
+ struct DisconnectNotificationList * next;
+ GNUNET_NodeIteratorCallback callback;
+
+ void * cls;
+
+};
+
+
typedef struct fENHWrap
{
GNUNET_NodeIteratorCallback method;
@@ -600,6 +605,11 @@
static SendCallbackList * scl_head;
/**
+ * Callbacks for disconnect notifications.
+ */
+static struct DisconnectNotificationList * disconnect_notification_list;
+
+/**
* Lock for the connection module.
*/
static struct GNUNET_Mutex *lock;
@@ -696,6 +706,22 @@
}
/**
+ * Notify all disconnect-callbacks that a peer
+ * was disconnected.
+ */
+static void
+notify_disconnect(BufferEntry * be)
+{
+ struct DisconnectNotificationList * l = disconnect_notification_list;
+ while (l != NULL)
+ {
+ l->callback(&be->session.sender,
+ l->cls);
+ l = l->next;
+ }
+}
+
+/**
* This allocates and initializes a BufferEntry.
* @return the initialized BufferEntry
*/
@@ -1684,10 +1710,9 @@
"Session is DOWN for `%s' due to transport
disconnect\n",
&enc);
#endif
-#if STRICT_STAT_DOWN
be->status = STAT_DOWN;
be->time_established = 0;
-#endif
+ notify_disconnect(be);
if (stats != NULL)
stats->change (stat_closedTransport, 1);
for (i = 0; i < be->sendBufferSize; i++)
@@ -1890,10 +1915,9 @@
#endif
tsession = be->session.tsession;
be->session.tsession = NULL;
-#if STRICT_STAT_DOWN
be->status = STAT_DOWN;
be->time_established = 0;
-#endif
+ notify_disconnect(be);
if (stats != NULL)
stats->change (stat_closedTransport, 1);
transport->disconnect (tsession, __FILE__);
@@ -2208,6 +2232,7 @@
}
be->skey_remote_created = 0;
be->status = STAT_DOWN;
+ notify_disconnect(be);
be->time_established = 0;
be->idealized_limit = MIN_BPM_PER_PEER;
be->max_transmitted_limit = MIN_BPM_PER_PEER;
@@ -4305,6 +4330,87 @@
}
+
+/**
+ * Call the given function whenever we get
+ * disconnected from a particular peer.
+ *
+ * @return GNUNET_OK
+ */
+int
+GNUNET_CORE_connection_register_notify_peer_disconnect(GNUNET_NodeIteratorCallback
callback,
+ void * cls)
+{
+ struct DisconnectNotificationList * l;
+
+ l = GNUNET_malloc(sizeof(struct DisconnectNotificationList));
+ l->callback = callback;
+ l->cls = cls;
+ GNUNET_mutex_lock(lock);
+ l->next = disconnect_notification_list;
+ disconnect_notification_list = l;
+ GNUNET_mutex_unlock(lock);
+ return GNUNET_OK;
+}
+
+/**
+ * Stop calling the given function whenever we get
+ * disconnected from a particular peer.
+ *
+ * @return GNUNET_OK on success, GNUNET_SYSERR
+ * if this callback is not registered
+ */
+int
+GNUNET_CORE_connection_unregister_notify_peer_disconnect(GNUNET_NodeIteratorCallback
callback,
+ void * cls)
+{
+ struct DisconnectNotificationList * pos;
+ struct DisconnectNotificationList * prev;
+
+ prev = NULL;
+ GNUNET_mutex_lock(lock);
+ pos = disconnect_notification_list;
+ while (pos != NULL)
+ {
+ if ( (pos->callback == callback) &&
+ (pos->cls == cls) )
+ {
+ if (prev == NULL)
+ disconnect_notification_list = pos->next;
+ else
+ prev->next = pos->next;
+ GNUNET_free(pos);
+ GNUNET_mutex_unlock(lock);
+ return GNUNET_OK;
+ }
+ prev = pos;
+ pos = pos->next;
+ }
+ GNUNET_mutex_unlock(lock);
+ return GNUNET_SYSERR;
+
+}
+
+/**
+ * Try to reserve downstream bandwidth for a particular peer.
+ *
+ * @param peer with whom should bandwidth be reserved?
+ * @param amount how many bytes should we expect to receive?
+ * (negative amounts can be used to undo a (recent)
+ * reservation request
+ * @param timeframe in what time interval should the other
+ * peer be able to transmit the amount? Use zero
+ * when undoing a reservation
+ * @return amount that could actually be reserved
+ */
+int
+GNUNET_CORE_connection_reserve_downstream_bandwidth(const
GNUNET_NodeIteratorCallback * peer,
+ int amount,
+ GNUNET_CronTime timeframe)
+{
+ return 0; /* not implemented */
+}
+
void __attribute__ ((constructor)) GNUNET_CORE_connection_ltdl_init ()
{
lock = GNUNET_mutex_create (GNUNET_YES);
Modified: GNUnet/src/server/connection.h
===================================================================
--- GNUnet/src/server/connection.h 2008-02-06 07:22:54 UTC (rev 6165)
+++ GNUnet/src/server/connection.h 2008-02-06 07:24:38 UTC (rev 6166)
@@ -346,5 +346,41 @@
int GNUNET_CORE_connection_assert_tsession_unused (GNUNET_TSession *
tsession);
+/**
+ * Call the given function whenever we get
+ * disconnected from a particular peer.
+ *
+ * @return GNUNET_OK
+ */
+int
GNUNET_CORE_connection_register_notify_peer_disconnect(GNUNET_NodeIteratorCallback
callback,
+ void * cls);
+
+/**
+ * Stop calling the given function whenever we get
+ * disconnected from a particular peer.
+ *
+ * @return GNUNET_OK on success, GNUNET_SYSERR
+ * if this callback is not registered
+ */
+int
GNUNET_CORE_connection_unregister_notify_peer_disconnect(GNUNET_NodeIteratorCallback
callback,
+ void * cls);
+
+
+/**
+ * Try to reserve downstream bandwidth for a particular peer.
+ *
+ * @param peer with whom should bandwidth be reserved?
+ * @param amount how many bytes should we expect to receive?
+ * (negative amounts can be used to undo a (recent)
+ * reservation request
+ * @param timeframe in what time interval should the other
+ * peer be able to transmit the amount? Use zero
+ * when undoing a reservation
+ * @return amount that could actually be reserved
+ */
+int GNUNET_CORE_connection_reserve_downstream_bandwidth(const
GNUNET_NodeIteratorCallback * peer,
+ int amount,
+ GNUNET_CronTime
timeframe);
+
#endif
/* end of connection.h */
Modified: GNUnet/src/server/core.c
===================================================================
--- GNUnet/src/server/core.c 2008-02-06 07:22:54 UTC (rev 6165)
+++ GNUnet/src/server/core.c 2008-02-06 07:24:38 UTC (rev 6166)
@@ -532,14 +532,18 @@
applicationCore.myIdentity = NULL; /* for now */
applicationCore.request_service = &GNUNET_CORE_request_service; /*
core.c */
applicationCore.release_service = &GNUNET_CORE_release_service; /*
core.c */
-
+
applicationCore.connection_send_plaintext =
&GNUNET_CORE_connection_send_plaintext; /* connection.c */
applicationCore.unicast = &GNUNET_CORE_connection_unicast; /*
connection.c */
applicationCore.connection_send_using_callback =
&GNUNET_CORE_connection_send_using_callback; /* connection.c */
applicationCore.forAllConnectedNodes =
&GNUNET_CORE_connection_iterate_peers; /* connection.c */
applicationCore.connection_register_send_callback =
&GNUNET_CORE_connection_register_send_callback; /* connection.c */
applicationCore.connection_unregister_send_callback =
&GNUNET_CORE_connection_unregister_send_callback; /* connection.c */
+ applicationCore.reserve_downstream_bandwidth =
&GNUNET_CORE_connection_reserve_downstream_bandwidth; /* connection.c */
+ applicationCore.register_notify_peer_disconnect =
&GNUNET_CORE_connection_register_notify_peer_disconnect; /* connection .c */
+ applicationCore.unregister_notify_peer_disconnect =
&GNUNET_CORE_connection_unregister_notify_peer_disconnect; /* connection .c */
+
applicationCore.connection_register_send_notification_callback =
&GNUNET_CORE_connection_register_send_notification_callback;
applicationCore.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r6166 - GNUnet/src/server,
gnunet <=