summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-05-14 15:55:50 +0000
committerBart Polot <bart@net.in.tum.de>2013-05-14 15:55:50 +0000
commit56ca1655cde3c572adc7fd91b5887fbe574c23ae (patch)
tree5cd802597d84dbe0bf2ca9d5ea3c81a306dd4bde /src
parentdd5ab5c9a766b8ee9bb7ddb42afe16a09c2428e0 (diff)
- Added tunnel port parameter
Diffstat (limited to 'src')
-rw-r--r--src/mesh/gnunet-service-mesh-new.c100
-rw-r--r--src/mesh/mesh2.h16
-rw-r--r--src/mesh/mesh2_api.c64
-rw-r--r--src/mesh/mesh2_protocol.h31
4 files changed, 104 insertions, 107 deletions
diff --git a/src/mesh/gnunet-service-mesh-new.c b/src/mesh/gnunet-service-mesh-new.c
index 32ae6998f..49b70319a 100644
--- a/src/mesh/gnunet-service-mesh-new.c
+++ b/src/mesh/gnunet-service-mesh-new.c
@@ -294,6 +294,11 @@ struct MeshTunnel
struct MESH_TunnelID id;
/**
+ * Port of the tunnel.
+ */
+ uint32_t port;
+
+ /**
* State of the tunnel.
*/
enum MeshTunnelState state;
@@ -1196,7 +1201,7 @@ send_create_path (struct MeshTunnel *t)
neighbor = peer_get_short (t->next_hop);
queue_add (t,
GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE,
- sizeof (struct GNUNET_MESH_ManipulatePath) +
+ sizeof (struct GNUNET_MESH_CreateTunnel) +
(t->path->length * sizeof (struct GNUNET_PeerIdentity)),
neighbor,
t);
@@ -2419,7 +2424,7 @@ static size_t
send_core_path_create (void *cls, size_t size, void *buf)
{
struct MeshTunnel *t = cls;
- struct GNUNET_MESH_ManipulatePath *msg;
+ struct GNUNET_MESH_CreateTunnel *msg;
struct GNUNET_PeerIdentity *peer_ptr;
struct MeshPeerPath *p = t->path;
size_t size_needed;
@@ -2428,7 +2433,7 @@ send_core_path_create (void *cls, size_t size, void *buf)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CREATE PATH sending...\n");
size_needed =
- sizeof (struct GNUNET_MESH_ManipulatePath) +
+ sizeof (struct GNUNET_MESH_CreateTunnel) +
p->length * sizeof (struct GNUNET_PeerIdentity);
if (size < size_needed || NULL == buf)
@@ -2436,7 +2441,7 @@ send_core_path_create (void *cls, size_t size, void *buf)
GNUNET_break (0);
return 0;
}
- msg = (struct GNUNET_MESH_ManipulatePath *) buf;
+ msg = (struct GNUNET_MESH_CreateTunnel *) buf;
msg->header.size = htons (size_needed);
msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE);
msg->tid = ntohl (t->id.tid);
@@ -2444,8 +2449,8 @@ send_core_path_create (void *cls, size_t size, void *buf)
opt = 0;
if (GNUNET_YES == t->nobuffer)
opt |= MESH_TUNNEL_OPT_NOBUFFER;
- msg->opt = htonl(opt);
- msg->reserved = 0;
+ msg->opt = htonl (opt);
+ msg->port = htonl (t->port);
peer_ptr = (struct GNUNET_PeerIdentity *) &msg[1];
for (i = 0; i < p->length; i++)
@@ -2871,7 +2876,7 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer,
uint16_t size;
uint16_t i;
MESH_TunnelNumber tid;
- struct GNUNET_MESH_ManipulatePath *msg;
+ struct GNUNET_MESH_CreateTunnel *msg;
struct GNUNET_PeerIdentity *pi;
struct GNUNET_HashCode hash;
struct MeshPeerPath *path;
@@ -2883,13 +2888,13 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer,
"Received a path create msg [%s]\n",
GNUNET_i2s (&my_full_id));
size = ntohs (message->size);
- if (size < sizeof (struct GNUNET_MESH_ManipulatePath))
+ if (size < sizeof (struct GNUNET_MESH_CreateTunnel))
{
GNUNET_break_op (0);
return GNUNET_OK;
}
- size -= sizeof (struct GNUNET_MESH_ManipulatePath);
+ size -= sizeof (struct GNUNET_MESH_CreateTunnel);
if (size % sizeof (struct GNUNET_PeerIdentity))
{
GNUNET_break_op (0);
@@ -2902,7 +2907,7 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer,
return GNUNET_OK;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " path has %u hops.\n", size);
- msg = (struct GNUNET_MESH_ManipulatePath *) message;
+ msg = (struct GNUNET_MESH_CreateTunnel *) message;
tid = ntohl (msg->tid);
pi = (struct GNUNET_PeerIdentity *) &msg[1];
@@ -3023,79 +3028,6 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer,
/**
- * Core handler for path destruction
- *
- * @param cls closure
- * @param message message
- * @param peer peer identity this notification is about
- *
- * @return GNUNET_OK to keep the connection open,
- * GNUNET_SYSERR to close it (signal serious error)
- */
-static int
-handle_mesh_path_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message)
-{
- struct GNUNET_MESH_ManipulatePath *msg;
- struct GNUNET_PeerIdentity *pi;
- struct MeshTunnel *t;
- unsigned int own_pos;
- unsigned int i;
- size_t size;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received a PATH DESTROY msg from %s\n", GNUNET_i2s (peer));
- size = ntohs (message->size);
- if (size < sizeof (struct GNUNET_MESH_ManipulatePath))
- {
- GNUNET_break_op (0);
- return GNUNET_OK;
- }
-
- size -= sizeof (struct GNUNET_MESH_ManipulatePath);
- if (size % sizeof (struct GNUNET_PeerIdentity))
- {
- GNUNET_break_op (0);
- return GNUNET_OK;
- }
- size /= sizeof (struct GNUNET_PeerIdentity);
- if (size < 2)
- {
- GNUNET_break_op (0);
- return GNUNET_OK;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " path has %u hops.\n", size);
-
- msg = (struct GNUNET_MESH_ManipulatePath *) message;
- pi = (struct GNUNET_PeerIdentity *) &msg[1];
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- " path is for tunnel %s [%X].\n", GNUNET_i2s (pi),
- msg->tid);
- t = tunnel_get (pi, ntohl (msg->tid));
- if (NULL == t)
- {
- /* TODO notify back: we don't know this tunnel */
- GNUNET_break_op (0);
- return GNUNET_OK;
- }
- own_pos = 0;
- for (i = 0; i < size; i++)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " %u: %s\n", i, GNUNET_i2s (&pi[i]));
- if (GNUNET_PEER_search (&pi[i]) == myid)
- own_pos = i;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Own position: %u\n", own_pos);
- if (own_pos < size - 1)
- send_prebuilt_message (message, t->next_hop, t);
- else
- send_client_tunnel_destroy (t);
-
- return GNUNET_OK;
-}
-
-
-/**
* Core handler for notifications of broken paths
*
* @param cls closure
@@ -3650,7 +3582,6 @@ handle_mesh_keepalive (void *cls, const struct GNUNET_PeerIdentity *peer,
*/
static struct GNUNET_CORE_MessageHandler core_handlers[] = {
{&handle_mesh_path_create, GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE, 0},
- {&handle_mesh_path_destroy, GNUNET_MESSAGE_TYPE_MESH_PATH_DESTROY, 0},
{&handle_mesh_path_broken, GNUNET_MESSAGE_TYPE_MESH_PATH_BROKEN,
sizeof (struct GNUNET_MESH_PathBroken)},
{&handle_mesh_tunnel_destroy, GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY,
@@ -3994,6 +3925,7 @@ handle_local_tunnel_create (void *cls, struct GNUNET_SERVER_Client *client,
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
+ t->port = ntohl (t->port);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CREATED TUNNEL %s [%x] (%x)\n",
GNUNET_i2s (&my_full_id), t->id.tid, t->local_tid);
diff --git a/src/mesh/mesh2.h b/src/mesh/mesh2.h
index ec2e14a1f..d42a630a0 100644
--- a/src/mesh/mesh2.h
+++ b/src/mesh/mesh2.h
@@ -113,7 +113,9 @@ struct GNUNET_MESH_ClientConnect
*/
struct GNUNET_MessageHeader header;
uint16_t types GNUNET_PACKED;
+ uint16_t ports GNUNET_PACKED;
/* uint16_t list_types[types] */
+ /* uint32_t list_ports[ports] */
};
@@ -125,6 +127,7 @@ struct GNUNET_MESH_ClientConnect
*/
typedef uint32_t MESH_TunnelNumber;
+
/**
* Message for a client to create and destroy tunnels.
*/
@@ -132,7 +135,6 @@ 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)
*/
@@ -147,6 +149,11 @@ struct GNUNET_MESH_TunnelMessage
* Tunnel's peer
*/
struct GNUNET_PeerIdentity peer;
+
+ /**
+ * Port of the tunnel.
+ */
+ uint32_t port GNUNET_PACKED;
};
@@ -173,9 +180,14 @@ struct GNUNET_MESH_TunnelNotification
struct GNUNET_PeerIdentity peer;
/**
+ * Port for this tunnel
+ */
+ uint32_t port GNUNET_PACKED;
+
+ /**
* Tunnel options (speed, buffering)
*/
- uint32_t opt;
+ uint32_t opt GNUNET_PACKED;
};
diff --git a/src/mesh/mesh2_api.c b/src/mesh/mesh2_api.c
index 90a216774..31681bec1 100644
--- a/src/mesh/mesh2_api.c
+++ b/src/mesh/mesh2_api.c
@@ -117,6 +117,21 @@ struct GNUNET_MESH_Handle
*/
const struct GNUNET_MESH_MessageHandler *message_handlers;
+ /**
+ * Number of handlers in the handlers array.
+ */
+ unsigned int n_handlers;
+
+ /**
+ * Ports open.
+ */
+ uint32_t *ports;
+
+ /**
+ * Number of ports.
+ */
+ unsigned int n_ports;
+
/**
* Double linked list of the tunnels this client is connected to, head.
*/
@@ -163,11 +178,6 @@ struct GNUNET_MESH_Handle
MESH_TunnelNumber next_tid;
/**
- * Number of handlers in the handlers array.
- */
- unsigned int n_handlers;
-
- /**
* Have we started the task to receive messages from the service
* yet? We do this after we send the 'MESH_LOCAL_CONNECT' message.
*/
@@ -265,6 +275,11 @@ struct GNUNET_MESH_Tunnel
MESH_TunnelNumber tid;
/**
+ * Port number.
+ */
+ uint32_t port;
+
+ /**
* Other end of the tunnel.
*/
GNUNET_PEER_Id peer;
@@ -633,23 +648,32 @@ send_connect (struct GNUNET_MESH_Handle *h)
char buf[size] GNUNET_ALIGN;
struct GNUNET_MESH_ClientConnect *msg;
uint16_t *types;
- uint16_t ntypes;
+ uint32_t *ports;
+ uint16_t i;
/* build connection packet */
msg = (struct GNUNET_MESH_ClientConnect *) buf;
msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT);
msg->header.size = htons (size);
- types = (uint16_t *) & msg[1];
- for (ntypes = 0; ntypes < h->n_handlers; ntypes++)
+ msg->types = htons (h->n_handlers);
+ msg->ports = htons (h->n_ports);
+ types = (uint16_t *) &msg[1];
+ for (i = 0; i < h->n_handlers; i++)
{
- types[ntypes] = htons (h->message_handlers[ntypes].type);
+ types[i] = htons (h->message_handlers[i].type);
LOG (GNUNET_ERROR_TYPE_DEBUG, " type %u\n",
- h->message_handlers[ntypes].type);
+ h->message_handlers[i].type);
+ }
+ ports = (uint32_t *) &types[h->n_handlers];
+ for (i = 0; i < h->n_ports; i++)
+ {
+ ports[i] = htonl (h->ports[i]);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " port %u\n",
+ h->ports[i]);
}
- msg->types = htons (ntypes);
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Sending %lu bytes long message %d types\n",
- ntohs (msg->header.size), ntypes);
+ "Sending %lu bytes long message %u types and %u ports\n",
+ ntohs (msg->header.size), h->n_handlers, h->n_ports);
send_packet (h, &msg->header, NULL);
}
}
@@ -803,12 +827,13 @@ process_tunnel_created (struct GNUNET_MESH_Handle *h,
GNUNET_PEER_change_rc (t->peer, 1);
t->mesh = h;
t->tid = tid;
+ t->port = ntohl (msg->port);
if ((msg->opt & MESH_TUNNEL_OPT_NOBUFFER) != 0)
t->buffering = GNUNET_NO;
else
t->buffering = GNUNET_YES;
LOG (GNUNET_ERROR_TYPE_DEBUG, " created tunnel %p\n", t);
- t->ctx = h->new_tunnel (h->cls, t, &msg->peer);
+ t->ctx = h->new_tunnel (h->cls, t, &msg->peer, t->port);
LOG (GNUNET_ERROR_TYPE_DEBUG, "User notified\n");
}
else
@@ -1340,7 +1365,8 @@ struct GNUNET_MESH_Handle *
GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls,
GNUNET_MESH_InboundTunnelNotificationHandler new_tunnel,
GNUNET_MESH_TunnelEndHandler cleaner,
- const struct GNUNET_MESH_MessageHandler *handlers)
+ const struct GNUNET_MESH_MessageHandler *handlers,
+ uint32_t *ports)
{
struct GNUNET_MESH_Handle *h;
@@ -1359,6 +1385,7 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls,
}
h->cls = cls;
h->message_handlers = handlers;
+ h->ports = ports;
h->next_tid = GNUNET_MESH_LOCAL_TUNNEL_ID_CLI;
h->reconnect_time = GNUNET_TIME_UNIT_MILLISECONDS;
h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
@@ -1367,6 +1394,9 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls,
for (h->n_handlers = 0;
handlers && handlers[h->n_handlers].type;
h->n_handlers++) ;
+ for (h->n_ports = 0;
+ ports && ports[h->n_ports];
+ h->n_ports++) ;
send_connect (h);
LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_MESH_connect() END\n");
return h;
@@ -1455,7 +1485,8 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle)
struct GNUNET_MESH_Tunnel *
GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h,
void *tunnel_ctx,
- const struct GNUNET_PeerIdentity *peer)
+ const struct GNUNET_PeerIdentity *peer,
+ uint32_t port)
{
struct GNUNET_MESH_Tunnel *t;
struct GNUNET_MESH_TunnelMessage msg;
@@ -1468,6 +1499,7 @@ GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h,
msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE);
msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage));
msg.tunnel_id = htonl (t->tid);
+ msg.port = htonl (port);
msg.peer = *peer;
send_packet (h, &msg.header, t);
return t;
diff --git a/src/mesh/mesh2_protocol.h b/src/mesh/mesh2_protocol.h
index 2a312eff7..b96f43efc 100644
--- a/src/mesh/mesh2_protocol.h
+++ b/src/mesh/mesh2_protocol.h
@@ -45,12 +45,12 @@ extern "C"
GNUNET_NETWORK_STRUCT_BEGIN
/**
- * Message for mesh path management
+ * Message for mesh path creation.
*/
-struct GNUNET_MESH_ManipulatePath
+struct GNUNET_MESH_CreateTunnel
{
/**
- * Type: GNUNET_MESSAGE_TYPE_MESH_PATH_[CREATE|CHANGE|ADD|DESTROY]
+ * Type: GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE
*
* Size: sizeof(struct GNUNET_MESH_ManipulatePath) +
* path_length * sizeof (struct GNUNET_PeerIdentity)
@@ -69,17 +69,38 @@ struct GNUNET_MESH_ManipulatePath
uint32_t opt GNUNET_PACKED;
/**
- * 64 bit alignment padding.
+ * Destination port.
*/
- uint32_t reserved GNUNET_PACKED;
+ uint32_t port GNUNET_PACKED;
/**
+ * FIXME do not add the first hop
* path_length structs defining the *whole* path from the origin [0] to the
* final destination [path_length-1].
*/
/* struct GNUNET_PeerIdentity peers[path_length]; */
};
+/**
+ * Message for mesh path destruction.
+ */
+struct GNUNET_MESH_DestroyTunnel
+{
+ /**
+ * Type: GNUNET_MESSAGE_TYPE_MESH_PATH_DESTROY
+ *
+ * Size: sizeof(struct GNUNET_MESH_ManipulatePath) +
+ * path_length * sizeof (struct GNUNET_PeerIdentity)
+ */
+ struct GNUNET_MessageHeader header;
+
+ /**
+ * Global id of the tunnel this path belongs to,
+ * unique in conjunction with the origin.
+ */
+ uint32_t tid GNUNET_PACKED;
+};
+
/**
* Message for mesh data traffic to a particular destination from origin.