[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r7997 - GNUnet/src/server
From: |
gnunet |
Subject: |
[GNUnet-SVN] r7997 - GNUnet/src/server |
Date: |
Wed, 10 Dec 2008 14:25:26 -0700 (MST) |
Author: nevans
Date: 2008-12-10 14:25:25 -0700 (Wed, 10 Dec 2008)
New Revision: 7997
Modified:
GNUnet/src/server/connection.c
GNUnet/src/server/connection.h
GNUnet/src/server/core.c
Log:
added peer connect handlers, compiles, will test functionality very soon
Modified: GNUnet/src/server/connection.c
===================================================================
--- GNUnet/src/server/connection.c 2008-12-09 02:16:33 UTC (rev 7996)
+++ GNUnet/src/server/connection.c 2008-12-10 21:25:25 UTC (rev 7997)
@@ -282,10 +282,25 @@
};
+/**
+ * DisconnectNotificationList created first, this is just a copy.
+ * Maybe there should just be a NotificationList that both use?
+ */
+struct ConnectNotificationList
+{
+ struct ConnectNotificationList *next;
+
+ GNUNET_NodeIteratorCallback callback;
+
+ void *cls;
+
+};
+
+
/**
* The other side has decided to terminate the connection. This
- * message MAY be send if the other node decides to be nice. It is
+ * message MAY be sent if the other node decides to be nice. It is
* not required. Mind that the message contains for which host the
* termination is, such that we don't hang up the wrong connection...
* A node can also choose to ignore the HANGUP message, though this is
@@ -625,6 +640,11 @@
static struct DisconnectNotificationList *disconnect_notification_list;
/**
+ * Callbacks for connect notifications.
+ */
+static struct ConnectNotificationList *connect_notification_list;
+
+/**
* Lock for the connection module.
*/
static struct GNUNET_Mutex *lock;
@@ -746,6 +766,22 @@
}
/**
+ * Notify all connect callbacks that a peer
+ * was connected.
+ */
+static void
+notify_connect (BufferEntry * be)
+{
+ struct ConnectNotificationList *l = connect_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
*/
@@ -3366,6 +3402,7 @@
be->status = STAT_UP;
be->lastSequenceNumberReceived = 0;
be->lastSequenceNumberSend = 1;
+ notify_connect (be);
}
}
GNUNET_mutex_unlock (lock);
@@ -4454,7 +4491,67 @@
}
+
/**
+ * Call the given function whenever we
+ * connect to a peer.
+ *
+ * @return GNUNET_OK
+ */
+int
+ GNUNET_CORE_connection_register_notify_peer_connect
+ (GNUNET_NodeIteratorCallback callback, void *cls)
+{
+ struct ConnectNotificationList *l;
+
+ l = GNUNET_malloc (sizeof (struct ConnectNotificationList));
+ l->callback = callback;
+ l->cls = cls;
+ GNUNET_mutex_lock (lock);
+ l->next = connect_notification_list;
+ connect_notification_list = l;
+ GNUNET_mutex_unlock (lock);
+ return GNUNET_OK;
+}
+
+/**
+ * Stop calling the given function whenever we
+ * connect to a peer.
+ *
+ * @return GNUNET_OK on success, GNUNET_SYSERR
+ * if this callback is not registered
+ */
+int
+ GNUNET_CORE_connection_unregister_notify_peer_connect
+ (GNUNET_NodeIteratorCallback callback, void *cls)
+{
+ struct ConnectNotificationList *pos;
+ struct ConnectNotificationList *prev;
+
+ prev = NULL;
+ GNUNET_mutex_lock (lock);
+ pos = connect_notification_list;
+ while (pos != NULL)
+ {
+ if ((pos->callback == callback) && (pos->cls == cls))
+ {
+ if (prev == NULL)
+ connect_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?
Modified: GNUnet/src/server/connection.h
===================================================================
--- GNUnet/src/server/connection.h 2008-12-09 02:16:33 UTC (rev 7996)
+++ GNUnet/src/server/connection.h 2008-12-10 21:25:25 UTC (rev 7997)
@@ -367,8 +367,28 @@
GNUNET_CORE_connection_unregister_notify_peer_disconnect
(GNUNET_NodeIteratorCallback callback, void *cls);
+/**
+ * Call the given function whenever we
+ * connect to a peer.
+ *
+ * @return GNUNET_OK
+ */
+int
+ GNUNET_CORE_connection_register_notify_peer_connect
+ (GNUNET_NodeIteratorCallback callback, void *cls);
/**
+ * Stop calling the given function whenever we
+ * connect to a peer.
+ *
+ * @return GNUNET_OK on success, GNUNET_SYSERR
+ * if this callback is not registered
+ */
+int
+ GNUNET_CORE_connection_unregister_notify_peer_connect
+ (GNUNET_NodeIteratorCallback callback, void *cls);
+
+/**
* Try to reserve downstream bandwidth for a particular peer.
*
* @param peer with whom should bandwidth be reserved?
Modified: GNUnet/src/server/core.c
===================================================================
--- GNUnet/src/server/core.c 2008-12-09 02:16:33 UTC (rev 7996)
+++ GNUnet/src/server/core.c 2008-12-10 21:25:25 UTC (rev 7997)
@@ -564,6 +564,8 @@
applicationCore.p2p_bandwidth_downstream_reserve =
&GNUNET_CORE_connection_reserve_downstream_bandwidth; /* connection.c */
applicationCore.peer_disconnect_notification_register =
&GNUNET_CORE_connection_register_notify_peer_disconnect; /* connection .c
*/
applicationCore.peer_disconnect_notification_unregister =
&GNUNET_CORE_connection_unregister_notify_peer_disconnect; /* connection .c */
+ applicationCore.peer_connect_notification_register =
&GNUNET_CORE_connection_register_notify_peer_connect; /* connection .c */
+ applicationCore.peer_connect_notification_unregister =
&GNUNET_CORE_connection_unregister_notify_peer_connect; /* connection .c
*/
applicationCore.peer_send_notification_register =
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r7997 - GNUnet/src/server,
gnunet <=