[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r28568 - in msh: . src
From: |
gnunet |
Subject: |
[GNUnet-SVN] r28568 - in msh: . src |
Date: |
Tue, 13 Aug 2013 15:42:40 +0200 |
Author: harsha
Date: 2013-08-13 15:42:40 +0200 (Tue, 13 Aug 2013)
New Revision: 28568
Modified:
msh/configure.ac
msh/src/msh.c
msh/src/mshd-server.c
msh/src/mshd.c
Log:
- fixes
Modified: msh/configure.ac
===================================================================
--- msh/configure.ac 2013-08-13 13:27:39 UTC (rev 28567)
+++ msh/configure.ac 2013-08-13 13:42:40 UTC (rev 28568)
@@ -56,21 +56,41 @@
no)
;;
yes)
- AC_CHECK_HEADERS([gnunet/gnunet_util_lib.h],
[AC_CHECK_LIB([gnunetutil], [GNUNET_SCHEDULER_run], libgnunetutil=1)])
+ AC_CHECK_HEADERS([gnunet/platform.h gnunet/gnunet_util_lib.h],
+ [AC_CHECK_LIB([gnunetutil], [GNUNET_SCHEDULER_run], libgnunetutil=1)],
+ [],
+ [
+ #ifdef HAVE_GNUNET_PLATFORM_H
+ #include <gnunet/platform.h>
+ #endif
+ ])
;;
*)
LDFLAGS="-L$with_gnunet/lib $LDFLAGS"
CPPFLAGS="-I$with_gnunet/include $CPPFLAGS"
- AC_CHECK_HEADERS([gnunet/gnunet_util_lib.h],
+ AC_CHECK_HEADERS([gnunet/platform.h gnunet/gnunet_util_lib.h],
[AC_CHECK_LIB([gnunetutil], [GNUNET_SCHEDULER_run],
[GNUNET_LDFLAGS="-L$with_gnunet/lib"
GNUNET_CPPFLAGS="-I$with_gnunet/include"
- libgnunetutil=1])])
+ libgnunetutil=1])],
+ [],
+ [
+ #ifdef HAVE_GNUNET_PLATFORM_H
+ #include <gnunet/platform.h>
+ #endif
+ ])
;;
esac
],
[AC_MSG_RESULT([--with-gnunet not specified])
- AC_CHECK_HEADERS([gnunet/gnunet_util_lib.h], [AC_CHECK_LIB([gnunetutil],
[GNUNET_SCHEDULER_run], libgnunetutil=1)])])
+ AC_CHECK_HEADERS([gnunet/platform.h gnunet/gnunet_util_lib.h],
+ [AC_CHECK_LIB([gnunetutil], [GNUNET_SCHEDULER_run], libgnunetutil=1)],
+ [], [
+ #ifdef HAVE_GNUNET_PLATFORM_H
+ #include <gnunet/platform.h>
+ #endif
+ ])
+ ])
if test "$libgnunetutil" != 1
then
AC_MSG_ERROR([MSH requires gnunet])
Modified: msh/src/msh.c
===================================================================
--- msh/src/msh.c 2013-08-13 13:27:39 UTC (rev 28567)
+++ msh/src/msh.c 2013-08-13 13:42:40 UTC (rev 28568)
@@ -144,6 +144,11 @@
static GNUNET_SCHEDULER_TaskIdentifier task_fwd_stdout;
/**
+ * Shutdown task to disconnect client connections
+ */
+static GNUNET_SCHEDULER_TaskIdentifier task_shutdown;
+
+/**
* flag to indicate successful completion by setting it to GNUNET_OK
*/
static int result;
@@ -222,11 +227,20 @@
struct MessageQueue *mq;
if (NULL != ctx->tx)
+ {
GNUNET_CLIENT_notify_transmit_ready_cancel (ctx->tx);
+ ctx->tx = NULL;
+ }
if (NULL != ctx->conn)
+ {
GNUNET_CLIENT_disconnect (ctx->conn);
+ ctx->conn = NULL;
+ }
if (NULL != ctx->cfg)
+ {
GNUNET_CONFIGURATION_destroy (ctx->cfg);
+ ctx->cfg = NULL;
+ }
while (NULL != (mq = ctx->mq_head))
{
GNUNET_CONTAINER_DLL_remove (ctx->mq_head, ctx->mq_tail, mq);
@@ -237,6 +251,23 @@
/**
+ * Shutdown task. Disconnect both client connections by destroying both
+ * contexts
+ *
+ * @param cls NULL
+ * @param tc scheduler task context
+ */
+static void
+do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ task_shutdown = GNUNET_SCHEDULER_NO_TASK;
+ LOG_DEBUG ("Shutting down\n");
+ destroy_conn_ctx (&ctx_local);
+ destroy_conn_ctx (&ctx_remote);
+}
+
+
+/**
* Function called to notify a client about the connection
* begin ready to queue more data. "buf" will be
* NULL and "size" zero if the connection was closed for
@@ -283,6 +314,7 @@
GNUNET_assert ( msg_size <= size);
(void) memcpy (buf, mq->msg, msg_size);
wrote = msg_size;
+ LOG_DEBUG ("Message of type %u, size %u sent\n", ntohs (mq->msg->type),
ntohs (mq->msg->size));
GNUNET_free (mq->msg);
GNUNET_CONTAINER_DLL_remove (ctx->mq_head, ctx->mq_tail, mq);
GNUNET_free (mq);
@@ -315,9 +347,7 @@
size = ntohs (msg->size);
mq = GNUNET_malloc (sizeof (struct MessageQueue));
mq->msg = msg;
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Queueing message of type %u, size %u for sending\n", type,
- ntohs (msg->size));
+ LOG_DEBUG ("Queueing message of type %u, size %u for sending\n", type, size);
GNUNET_CONTAINER_DLL_insert_tail (ctx->mq_head, ctx->mq_tail, mq);
if (NULL == ctx->tx)
{
@@ -411,10 +441,9 @@
GNUNET_SCHEDULER_shutdown ();
return GNUNET_SYSERR;;
}
- size = ntohs (msg->header.size);
- GNUNET_break (size ==
- GNUNET_DISK_file_write (fh_stdout, msg->data,
- size - sizeof (struct MSH_MSG_CmdIO)));
+ size = ntohs (msg->header.size);
+ size -= sizeof (struct MSH_MSG_CmdIO);
+ GNUNET_break (size == GNUNET_DISK_file_write (fh_stdout, msg->data, size));
return GNUNET_OK;
}
@@ -457,6 +486,7 @@
{
struct GNUNET_MessageHeader *msg;
+ LOG_DEBUG ("Received CHALLENGE_RESPONSE. Forwarding it to remote MSHD\n");
msg = GNUNET_copy_message (msg_);
queue_message (&ctx_remote, msg);
destroy_conn_ctx (&ctx_local);
@@ -477,7 +507,9 @@
const struct GNUNET_MessageHeader *msg_)
{
struct GNUNET_MessageHeader *msg;
- if (sizeof (struct MSH_MSG_Challenge) >= ntohs (msg_->size))
+
+ LOG_DEBUG ("Received CHALLENGE message. Forwarding it to parent MSHD\n");
+ if (sizeof (struct MSH_MSG_Challenge) > ntohs (msg_->size))
{
GNUNET_break (0);
return GNUNET_SYSERR;
@@ -545,6 +577,8 @@
ip2str (target), msg->emsg);
return GNUNET_SYSERR;
}
+ LOG_DEBUG ("ADDRESS_LOOKUP_REPLY: Service available on %s:%u\n",
+ ip2str (target), target_port);
target_connect ();
return GNUNET_OK;
}
@@ -563,7 +597,10 @@
int ret;
if (NULL == msg)
+ {
+ LOG_ERROR ("Broken IPC connection\n");
goto err_ret;
+ }
switch (ntohs (msg->type))
{
case MSH_MTYPE_ADDRESS_LOOKUP_REPLY:
@@ -586,11 +623,17 @@
ntohs (msg->type));
goto err_ret;
}
- GNUNET_CLIENT_receive (ctx->conn, &dispatch, ctx,
GNUNET_TIME_UNIT_FOREVER_REL);
+ if (GNUNET_SYSERR == ret)
+ goto err_ret;
+
+ /* We destroy local_ctx in handle_challenge_response, hence this check */
+ if (NULL != ctx->conn)
+ GNUNET_CLIENT_receive (ctx->conn, &dispatch, ctx,
GNUNET_TIME_UNIT_FOREVER_REL);
return;
err_ret:
destroy_conn_ctx (ctx);
+ GNUNET_SCHEDULER_shutdown ();
}
@@ -625,6 +668,8 @@
queue_message (&ctx_local, &msg->header);
GNUNET_CLIENT_receive (ctx_local.conn, &dispatch, &ctx_local,
GNUNET_TIME_UNIT_FOREVER_REL);
+ task_shutdown = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+ &do_shutdown, NULL);
}
Modified: msh/src/mshd-server.c
===================================================================
--- msh/src/mshd-server.c 2013-08-13 13:27:39 UTC (rev 28567)
+++ msh/src/mshd-server.c 2013-08-13 13:42:40 UTC (rev 28568)
@@ -170,6 +170,12 @@
* command
*/
struct ExecCtx *exec_ctx;
+
+ /**
+ * Is the client currently suspended? i.e do we have to call receive_done
+ * after transmitting a message to the client?
+ */
+ int suspended;
};
@@ -192,6 +198,8 @@
}
if (GNUNET_SCHEDULER_NO_TASK != ctx->timeout_task)
GNUNET_SCHEDULER_cancel (ctx->timeout_task);
+ if (GNUNET_SCHEDULER_NO_TASK != ctx->fout_task)
+ GNUNET_SCHEDULER_cancel (ctx->fout_task);
GNUNET_free (ctx);
}
@@ -260,7 +268,11 @@
ctx->tx = GNUNET_SERVER_notify_transmit_ready (client, ntohs (msg->size),
MESSAGE_SEND_TIMEOUT (30),
&transmit_ready_cb, ctx);
- GNUNET_SERVER_receive_done (client, GNUNET_YES);
+ if (GNUNET_YES == ctx->suspended)
+ {
+ GNUNET_SERVER_receive_done (client, GNUNET_YES);
+ ctx->suspended = GNUNET_NO;
+ }
return wrote;
}
@@ -270,13 +282,18 @@
*
* @param ctx the context associated with the client
* @param msg the message to queue. Will be consumed
+ * @param suspended is the client suspended at the time of calling
queue_message
*/
static void
-queue_message (struct ClientCtx *ctx, struct GNUNET_MessageHeader *msg)
+queue_message (struct ClientCtx *ctx, struct GNUNET_MessageHeader *msg,
+ int suspended)
{
struct MessageQueue *mq;
struct GNUNET_SERVER_Client *client = ctx->client;
+ GNUNET_assert (!(ctx->suspended && suspended));
+ if (GNUNET_YES == suspended)
+ ctx->suspended = GNUNET_YES;
GNUNET_SERVER_client_keep (client);
mq = GNUNET_malloc (sizeof (struct MessageQueue));
mq->msg = msg;
@@ -299,26 +316,31 @@
static int
parse_strings (const char *buf, size_t size, char ***s)
{
+ const char *p;
+ char **strs;
size_t off;
unsigned int cnt;
- const char *p;
cnt = 0;
- p = NULL;
+ strs = NULL;
+ p = NULL;
for (off = 0; off < size; off++)
{
if ('\0' == buf[off])
{
if (NULL == p)
continue;
- GNUNET_array_append (*s, cnt, GNUNET_strdup (p));
+ GNUNET_array_append (strs, cnt, GNUNET_strdup (p));
p = NULL;
continue;
}
- p = &buf[off];
+ if (NULL != p)
+ continue;
+ p = &buf[off];
}
if (0 < cnt)
- GNUNET_array_append (*s, cnt, NULL);
+ GNUNET_array_append (strs, cnt, NULL);
+ *s = strs;
return cnt;
}
@@ -341,6 +363,7 @@
msg->header.type = htons (MSH_MTYPE_CHALLENGE);
msg->header.size = htons (size);
GNUNET_CRYPTO_hash_to_enc (&ctx->salt, &msg->salt);
+ LOG_DEBUG ("Challenge nonce: %104s\n", msg->salt.encoding);
return &msg->header;
}
@@ -380,7 +403,8 @@
iaddr = reversemap_lookup (rmap, ip);
GNUNET_assert (NULL != iaddr);
port = instance_address_port (iaddr);
-
+ LOG_DEBUG ("Received ADDRESS_LOOKUP message for IP: %s and port %u\n",
+ ip2str (ip), port);
respond:
reply_size = sizeof (struct MSH_MSG_AddressLookupReply);
if (NULL != emsg)
@@ -390,8 +414,8 @@
reply->header.type = htons (MSH_MTYPE_ADDRESS_LOOKUP_REPLY);
reply->port = htons (port);
if (NULL != emsg)
- (void) strcpy (reply->emsg, emsg);
- queue_message (ctx, &reply->header);
+ (void) strcpy (reply->emsg, emsg);
+ queue_message (ctx, &reply->header, GNUNET_YES);
}
@@ -426,22 +450,22 @@
struct ClientCtx *ctx;
const struct MSH_MSG_Challenge *msg;
struct MSH_MSG_ChallengeResponse *reply;
- struct GNUNET_HashCode c;
+ struct GNUNET_HashCode salt;
struct GNUNET_HashCode cred;
ctx = GNUNET_SERVER_client_get_user_context (client, struct ClientCtx);
GNUNET_assert (NULL != ctx);
msg = (const struct MSH_MSG_Challenge *) message;
+ LOG_DEBUG ("Challenge nonce: %104s\n", msg->salt.encoding);
GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_hash_from_string2 (msg->salt.encoding,
- sizeof (msg->salt),
- &c));
- auth_challenge_cred (&c, &cred);
+ GNUNET_CRYPTO_hash_from_string (msg->salt.encoding,
+ &salt));
+ auth_challenge_cred (&salt, &cred);
reply = GNUNET_malloc (sizeof (struct MSH_MSG_ChallengeResponse));
reply->header.size = htons (sizeof (struct MSH_MSG_ChallengeResponse));
reply->header.type = htons (MSH_MTYPE_CHALLENGE_RESPONSE);
GNUNET_CRYPTO_hash_to_enc (&cred, &reply->auth);
- queue_message (ctx, &reply->header);
+ queue_message (ctx, &reply->header, GNUNET_YES);
}
@@ -579,8 +603,6 @@
goto close_conn;
}
msg = (const struct MSH_MSG_RunCmd *) message;
- exec_ctx = GNUNET_malloc (sizeof (struct ExecCtx));
- ctx->exec_ctx = exec_ctx;
if (0 == parse_strings (msg->cmd,
size - sizeof (struct MSH_MSG_RunCmd),
&exec_ctx->args))
@@ -590,7 +612,7 @@
}
reply = create_challenge_message (exec_ctx);
LOG_DEBUG ("Sending AUTH_CHALLENGE\n");
- queue_message (ctx, reply);
+ queue_message (ctx, reply, GNUNET_YES);
return;
close_conn:
@@ -646,7 +668,7 @@
msg->header.type = htons (MSH_MTYPE_CMD_STREAM_STDOUT);
msg->header.size = htons (msize);
memcpy (msg->data, data, size);
- queue_message (ctx->client_ctx, &msg->header);
+ queue_message (ctx->client_ctx, &msg->header, GNUNET_NO);
}
@@ -662,9 +684,6 @@
ctx->pin = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, 0, 0);
ctx->pout = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, 0, 0);
GNUNET_assert ((NULL != ctx->pin && (NULL != ctx->pout)));
- ctx->fin = GNUNET_DISK_pipe_detach_end (ctx->pin,
GNUNET_DISK_PIPE_END_WRITE);
- ctx->fout = GNUNET_DISK_pipe_detach_end (ctx->pin,
GNUNET_DISK_PIPE_END_READ);
- GNUNET_assert ((NULL != ctx->fin && (NULL != ctx->fout)));
ctx->proc = GNUNET_OS_start_process_vap (GNUNET_NO,
GNUNET_OS_INHERIT_STD_NONE,
ctx->pin,
@@ -673,6 +692,9 @@
ctx->args);
if (NULL == ctx->proc)
return GNUNET_SYSERR;
+ ctx->fin = GNUNET_DISK_pipe_detach_end (ctx->pin,
GNUNET_DISK_PIPE_END_WRITE);
+ ctx->fout = GNUNET_DISK_pipe_detach_end (ctx->pout,
GNUNET_DISK_PIPE_END_READ);
+ GNUNET_assert ((NULL != ctx->fin && (NULL != ctx->fout)));
ctx->fout_task =
GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
ctx->fout, read_fout, ctx);
@@ -711,9 +733,12 @@
auth_challenge_cred (&exec_ctx->salt, &cred);
GNUNET_CRYPTO_hash_to_enc (&cred, &enc);
msg = (const struct MSH_MSG_ChallengeResponse *) message;
- if (0 != memcmp (&msg->auth, &cred,
+ if (0 != memcmp (&msg->auth, &enc,
sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)))
{
+ LOG_DEBUG ("Auth failed: \n"
+ " Required: %s\n"
+ " Given: %s\n", enc.encoding, msg->auth.encoding);
GNUNET_break (0);
goto err_ret;
}
@@ -725,8 +750,7 @@
reply = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader));
reply->size = htons (sizeof (struct GNUNET_MessageHeader));
reply->type = htons (MSH_MTYPE_EXEC_BEGIN);
- queue_message (ctx, reply);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ queue_message (ctx, reply, GNUNET_YES);
return;
err_ret:
@@ -753,6 +777,7 @@
struct ExecCtx *exec_ctx;
uint16_t size;
+ LOG_DEBUG ("Received CMD_IO_STDIN message\n");
size = ntohs (message->size);
msg = (const struct MSH_MSG_CmdIO *) message;
ctx = GNUNET_SERVER_client_get_user_context (client, struct ClientCtx);
@@ -804,18 +829,22 @@
destroy_client_ctx (ctx);
}
+static unsigned int conn_cnt;
void
daemon_server_add_connection (struct GNUNET_CONNECTION_Handle *conn,
int conn_fd)
-{
+{
struct ClientCtx *ctx;
struct ExecCtx *exec_ctx;
+ conn_cnt++;
ctx = GNUNET_malloc (sizeof (struct ClientCtx));
exec_ctx = GNUNET_malloc (sizeof (struct ExecCtx));
+
exec_ctx->client_ctx = ctx;
ctx->exec_ctx = exec_ctx;
+
exec_ctx->conn_fd = conn_fd;
ctx->client = GNUNET_SERVER_connect_socket (daemon_serv, conn);
GNUNET_SERVER_client_set_user_context (ctx->client, ctx);
Modified: msh/src/mshd.c
===================================================================
--- msh/src/mshd.c 2013-08-13 13:27:39 UTC (rev 28567)
+++ msh/src/mshd.c 2013-08-13 13:42:40 UTC (rev 28568)
@@ -385,10 +385,7 @@
rctx->in_receive = GNUNET_YES;
GNUNET_CONNECTION_receive (rctx->conn, sizeof (unsigned int),
GNUNET_TIME_UNIT_FOREVER_REL, conn_reader,
rctx);
- GNUNET_CONTAINER_DLL_insert_tail (rhead, rtail, rctx);
- /* resume accepting connections on the listen sock */
- atask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- listen_socket, &accept_task, NULL);
+ GNUNET_CONTAINER_DLL_insert_tail (rhead, rtail, rctx);
break;
case LISTEN_MODE_SERV:
{
@@ -400,13 +397,15 @@
client_sock = GNUNET_NETWORK_socket_accept (listen_socket, NULL, NULL);
client_sock_fd = GNUNET_NETWORK_get_fd (client_sock);
client_conn = GNUNET_CONNECTION_create_from_existing (client_sock);
- daemon_server_add_connection (client_conn);
- GNUNET_break (0);
+ daemon_server_add_connection (client_conn, client_sock_fd);
+ /* FIXME pass client_sock_fd to exec wrapper process */
}
break;
default:
GNUNET_assert (0);
}
+ atask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ listen_socket, &accept_task, NULL);
return;
clo_ret:
@@ -470,11 +469,13 @@
GNUNET_assert (0 < asprintf (&unixpath, "%ju.sock", pid));
setenv (MSHD_SOCK_NAME, unixpath, 1);
init_local_server (unixpath);
- init_daemon_server (listen_socket);
- listen_socket = NULL;
+ init_daemon_server ();
MSH_pmonitor_init ();
shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
&do_shutdown, NULL);
+ GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == atask);
+ atask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ listen_socket, &accept_task, NULL);
if (0 == rank)
{
proc = GNUNET_OS_start_process_vap (GNUNET_NO,
@@ -485,7 +486,7 @@
run_args);
if (NULL == proc)
{
- GNUNET_break (0);
+ LOG_ERROR ("Unable to start process `%s'\n", run_args[0]);
GNUNET_SCHEDULER_shutdown ();
return;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r28568 - in msh: . src,
gnunet <=