#include "gnunet-service-transport_neighbours.h"
#include "gnunet-service-transport_plugins.h"
#include "gnunet-service-transport_validation.h"
+#include "transport.h"
/* globals */
* This function should also be called with "NULL" for the
* message to signal that the other peer disconnected.
*
- * @param cls closure
+ * @param cls closure, const char* with the name of the plugin we received the message from
* @param peer (claimed) identity of the other peer
* @param message the message, NULL if we only care about
* learning about the delay until we should receive again -- FIXME!
- * @param distance in overlay hops; use 1 unless DV (or 0 if message == NULL)
+ * @param ats performance information
+ * @param ats_count number of records in ats
* @param session identifier used for this session (NULL for plugins
* that do not offer bi-directional communication to the sender
* using the same "connection")
*/
static struct GNUNET_TIME_Relative
plugin_env_receive_callback (void *cls,
- const struct
- GNUNET_PeerIdentity *
- peer,
- const struct
- GNUNET_MessageHeader *
- message,
- const struct GNUNET_TRANSPORT_ATS_Information *ats,
- uint32_t ats_count,
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_TRANSPORT_ATS_Information *ats, uint32_t ats_count,
struct Session *session,
const char *sender_address,
uint16_t sender_address_len)
{
- GNUNET_break (0); // FIXME
- return GNUNET_TIME_UNIT_ZERO;
+ const char *plugin_name = cls;
+
+ if (NULL != message)
+ GST_clients_broadcast (message, GNUNET_YES);
+ GNUNET_ATS_address_update (GST_ats,
+ peer,
+ GNUNET_TIME_absolute_get (), /* valid at least until right now... */
+ plugin_name,
+ session,
+ sender_address,
+ sender_address_len,
+ ats, ats_count);
+ return GST_neighbours_calculate_receive_delay (peer,
+ (message == NULL)
+ ? 0
+ : ntohs (message->size));
}
const struct GNUNET_PeerIdentity *peer,
struct Session *session)
{
- GNUNET_break (0); // FIXME
+ GST_neighbours_session_terminated (peer,
+ session);
}
size_t plugin_addr_len,
struct GNUNET_BANDWIDTH_Value32NBO bandwidth)
{
- GNUNET_break (0); // FIXME
+ GST_neighbours_switch_to_address (peer,
+ plugin_name,
+ plugin_addr,
+ plugin_addr_len,
+ session,
+ NULL, 0);
+ GST_neighbours_set_incoming_quota (peer,
+ bandwidth);
}
const struct GNUNET_TRANSPORT_ATS_Information *ats,
uint32_t ats_count)
{
- GNUNET_break (0); // FIXME
+ char buf[sizeof(struct ConnectInfoMessage) + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)];
+ struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage*) buf;
+ struct GNUNET_TRANSPORT_ATS_Information *atsm = &connect_msg->ats;
+
+ connect_msg->header.size = htons (sizeof (buf));
+ connect_msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
+ connect_msg->ats_count = htonl (ats_count);
+ connect_msg->id = *peer;
+ memcpy (&connect_msg->ats, ats, ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
+ atsm[ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
+ atsm[ats_count].value = htonl (0);
+ GST_clients_broadcast (&connect_msg->header,
+ GNUNET_NO);
}
neighbours_disconnect_notification (void *cls,
const struct GNUNET_PeerIdentity *peer)
{
- GNUNET_break (0); // FIXME
+ struct DisconnectInfoMessage disconnect_msg;
+
+ disconnect_msg.header.size = htons (sizeof (struct DisconnectInfoMessage));
+ disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
+ disconnect_msg.reserved = htonl (0);
+ disconnect_msg.peer = *peer;
+ GST_clients_broadcast (&disconnect_msg.header,
+ GNUNET_NO);
}
}
+/**
+ * A session was terminated. Take note.
+ *
+ * @param peer identity of the peer where the session died
+ * @param session session that is gone
+ */
+void
+GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
+ struct Session *session)
+{
+ struct NeighbourMapEntry *n;
+
+ n = lookup_neighbour (peer);
+ if (NULL == n)
+ return;
+ if (session == n->session)
+ n->session = NULL;
+}
+
+
/**
* For an existing neighbour record, set the active connection to
* the given address.
*
+ * @param peer identity of the peer to switch the address for
* @param plugin_name name of transport that delivered the PONG
* @param address address of the other peer, NULL if other peer
* connected to us
* @param address_len number of bytes in address
+ * @param session session to use (or NULL)
* @param ats performance data
* @param ats_count number of entries in ats (excluding 0-termination)
*/
void *cb_cls);
+/**
+ * A session was terminated. Take note.
+ *
+ * @param peer identity of the peer where the session died
+ * @param session session that is gone
+ */
+void
+GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
+ struct Session *session);
+
+
/**
* For an existing neighbour record, set the active connection to
* use the given address.
*
+ * @param peer identity of the peer to switch the address for
* @param plugin_name name of transport that delivered the PONG
* @param address address of the other peer, NULL if other peer
* connected to us
* @param address_len number of bytes in address
+ * @param session session to use (or NULL)
* @param ats performance data
* @param ats_count number of entries in ats (excluding 0-termination)
*/