From 49b07dccadd47a8eab6add761bcf7e57726eb5fe Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Fri, 20 Jul 2012 12:49:06 +0000 Subject: [PATCH] - partial change, broken build system on laptop --- src/include/gnunet_mesh_service.h | 24 +++++++++++ src/include/gnunet_protocols.h | 10 +++++ src/mesh/gnunet-service-mesh.c | 71 +++++++++++++++++++++++++++++++ src/mesh/mesh.h | 1 + src/mesh/mesh_api.c | 53 +++++++++++++++++++++++ src/mesh/mesh_protocol.h | 9 +++- 6 files changed, 166 insertions(+), 2 deletions(-) diff --git a/src/include/gnunet_mesh_service.h b/src/include/gnunet_mesh_service.h index 11bf246b4..e1cd03005 100644 --- a/src/include/gnunet_mesh_service.h +++ b/src/include/gnunet_mesh_service.h @@ -226,6 +226,10 @@ typedef void (*GNUNET_MESH_PeerConnectHandler) (void *cls, /** * Announce to ther peer the availability of services described by the regex, * in order to be reachable to other peers via connect_by_string. + * + * Note that the first 8 characters are considered to be part of a prefix, + * (for instance 'gnunet://'). If you put a variable part in there (*, +. ()), + * all matching strings will be stored in the DHT. * * @param h handle to mesh. * @param regex string with the regular expression describing local services. @@ -261,6 +265,26 @@ void GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tunnel); +/** + * Request that the tunnel data rate is limited to the speed of the slowest + * receiver. + * + * @param tunnel Tunnel affected. + */ +void +GNUNET_MESH_tunnel_speed_min (struct GNUNET_MESH_Tunnel *tunnel); + + +/** + * Request that the tunnel data rate is limited to the speed of the fastest + * receiver. This is the default behavior. + * + * @param tunnel Tunnel affected. + */ +void +GNUNET_MESH_tunnel_speed_max (struct GNUNET_MESH_Tunnel *tunnel); + + /** * Request that a peer should be added to the tunnel. The connect handler * will be called when the peer connects diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index 9039d0f1b..652630bcc 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h @@ -845,6 +845,16 @@ extern "C" */ #define GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_UNBLACKLIST 281 +/** + * Set tunnel speed to slowest peer + */ +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_MIN 282 + +/** + * Set tunnel speed to fastest peer + */ +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_MAX 283 + /** * 640kb should be enough for everybody */ diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index cd2308898..496520125 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c @@ -336,6 +336,16 @@ struct MeshTunnel unsigned int queue_max; /** + * Is the speed on the tunnel limited to the slowest peer? + */ + int speed_min; + + /** + * Is buffering allowed in the tunnel? + */ + int buffering; + + /** * Flag to signal the destruction of the tunnel. * If this is set GNUNET_YES the tunnel will be destroyed * when the queue is empty. @@ -5038,6 +5048,61 @@ handle_local_tunnel_destroy (void *cls, struct GNUNET_SERVER_Client *client, } +/** + * Handler for requests of seeting tunnel's speed. + * + * @param cls Closure (unused). + * @param client Identification of the client. + * @param message The actual message. + */ +static void +handle_local_tunnel_speed (void *cls, struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *message) +{ + struct GNUNET_MESH_TunnelMessage *tunnel_msg; + struct MeshClient *c; + struct MeshTunnel *t; + MESH_TunnelNumber tid; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Got a SPEED request from client!\n"); + + /* Sanity check for client registration */ + if (NULL == (c = client_get (client))) + { + GNUNET_break (0); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id); + tunnel_msg = (struct GNUNET_MESH_TunnelMessage *) message; + + /* Retrieve tunnel */ + tid = ntohl (tunnel_msg->tunnel_id); + t = tunnel_get_by_local_id(c, tid); + if (NULL == t) + { + GNUNET_break (0); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, " tunnel %X not found\n", tid); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } + + switch (ntohs(message->type)) + { + case GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_MIN: + t->speed_min = GNUNET_YES; + break; + case GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_MAX: + t->speed_min = GNUNET_NO; + break; + default: + GNUNET_break (0); + } +} + + /** * Handler for connection requests to new peers * @@ -5787,6 +5852,12 @@ static struct GNUNET_SERVER_MessageHandler client_handlers[] = { {&handle_local_tunnel_destroy, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY, sizeof (struct GNUNET_MESH_TunnelMessage)}, + {&handle_local_tunnel_speed, NULL, + GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_MIN, + sizeof (struct GNUNET_MESH_TunnelMessage)}, + {&handle_local_tunnel_speed, NULL, + GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_MAX, + sizeof (struct GNUNET_MESH_TunnelMessage)}, {&handle_local_connect_add, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD, sizeof (struct GNUNET_MESH_PeerControl)}, diff --git a/src/mesh/mesh.h b/src/mesh/mesh.h index fd9de27d8..f00c5b256 100644 --- a/src/mesh/mesh.h +++ b/src/mesh/mesh.h @@ -122,6 +122,7 @@ struct GNUNET_MESH_TunnelMessage { /** * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_[CREATE|DESTROY] + * GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_[MAX|MIN] * * Size: sizeof(struct GNUNET_MESH_TunnelMessage) */ diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c index b12fdc1fe..185b63a66 100644 --- a/src/mesh/mesh_api.c +++ b/src/mesh/mesh_api.c @@ -299,6 +299,11 @@ struct GNUNET_MESH_Tunnel */ unsigned int napps; + /** + * Is the tunnel throttled to the slowest peer? + */ + int speed_min; + }; @@ -1386,6 +1391,10 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) /** * Announce to ther peer the availability of services described by the regex, * in order to be reachable to other peers via connect_by_string. + * + * Note that the first 8 characters are considered to be part of a prefix, + * (for instance 'gnunet://'). If you put a variable part in there (*, +. ()), + * all matching strings will be stored in the DHT. * * @param h handle to mesh. * @param regex string with the regular expression describing local services. @@ -1484,6 +1493,50 @@ GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tunnel) send_packet (h, &msg.header, NULL); } +/** + * Request that the tunnel data rate is limited to the speed of the slowest + * receiver. + * + * @param tunnel Tunnel affected. + */ +void +GNUNET_MESH_tunnel_speed_min (struct GNUNET_MESH_Tunnel *tunnel) +{ + struct GNUNET_MESH_TunnelMessage msg; + struct GNUNET_MESH_Handle *h; + + h = tunnel->mesh; + tunnel->speed_min = GNUNET_YES; + + msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_MIN); + msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); + msg.tunnel_id = htonl (tunnel->tid); + + send_packet (h, &msg.header, NULL); +} + + +/** + * Request that the tunnel data rate is limited to the speed of the fastest + * receiver. This is the default behavior. + * + * @param tunnel Tunnel affected. + */ +void +GNUNET_MESH_tunnel_speed_max (struct GNUNET_MESH_Tunnel *tunnel) +{ + struct GNUNET_MESH_TunnelMessage msg; + struct GNUNET_MESH_Handle *h; + + h = tunnel->mesh; + tunnel->speed_min = GNUNET_NO; + + msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_MAX); + msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); + msg.tunnel_id = htonl (tunnel->tid); + + send_packet (h, &msg.header, NULL); +} /** * Request that a peer should be added to the tunnel. The existing diff --git a/src/mesh/mesh_protocol.h b/src/mesh/mesh_protocol.h index a699d1897..033276e25 100644 --- a/src/mesh/mesh_protocol.h +++ b/src/mesh/mesh_protocol.h @@ -273,9 +273,14 @@ struct GNUNET_MESH_SpeedNotify struct GNUNET_PeerIdentity oid; /** - * Slowest link down the path (above minimum speed requirement). + * Is the speed limited by the slowest peer?. */ - uint32_t speed_min; + int16_t speed_min; + + /** + * Is the buffering allowed?. + */ + int16_t buffering; }; GNUNET_NETWORK_STRUCT_END -- 2.25.1