aboutsummaryrefslogtreecommitdiff
path: root/src/psyc
diff options
context:
space:
mode:
authorGabor X Toth <*@tg-x.net>2014-07-10 17:49:53 +0000
committerGabor X Toth <*@tg-x.net>2014-07-10 17:49:53 +0000
commita8133f3ff80aaaccc904e4bbaf69bc53dee499cb (patch)
treec10edd7a8156280c61357ccf9e0f1f27c7a0d6db /src/psyc
parent6c75526e936fcc74ee79b13831b2b6dda57f293d (diff)
PSYC(store), Multicast: use ECDSA slave/member keys; PSYC: add GNUNET_PSYC_message_create()
Diffstat (limited to 'src/psyc')
-rw-r--r--src/psyc/gnunet-service-psyc.c89
-rw-r--r--src/psyc/psyc.h57
-rw-r--r--src/psyc/psyc_api.c33
-rw-r--r--src/psyc/psyc_util_lib.c113
-rw-r--r--src/psyc/test_psyc.c18
5 files changed, 174 insertions, 136 deletions
diff --git a/src/psyc/gnunet-service-psyc.c b/src/psyc/gnunet-service-psyc.c
index 9dcf40e0f3..866275a795 100644
--- a/src/psyc/gnunet-service-psyc.c
+++ b/src/psyc/gnunet-service-psyc.c
@@ -93,7 +93,7 @@ struct TransmitMessage
uint64_t id;
/**
- * Size of @a buf
+ * Size of message.
*/
uint16_t size;
@@ -211,11 +211,6 @@ struct Channel
struct GNUNET_CONTAINER_Heap *recv_msgs;
/**
- * FIXME: needed?
- */
- GNUNET_SCHEDULER_TaskIdentifier tmit_task;
-
- /**
* Public key of the channel.
*/
struct GNUNET_CRYPTO_EddsaPublicKey pub_key;
@@ -264,14 +259,16 @@ struct Channel
uint8_t is_master;
/**
- * Ready to receive messages from client? #GNUNET_YES or #GNUNET_NO
+ * Is this channel ready to receive messages from client?
+ * #GNUNET_YES or #GNUNET_NO
*/
- uint8_t ready;
+ uint8_t is_ready;
/**
- * Is the client disconnected? #GNUNET_YES or #GNUNET_NO
+ * Is the client disconnected?
+ * #GNUNET_YES or #GNUNET_NO
*/
- uint8_t disconnected;
+ uint8_t is_disconnected;
};
@@ -345,12 +342,12 @@ struct Slave
/**
* Private key of the slave.
*/
- struct GNUNET_CRYPTO_EddsaPrivateKey priv_key;
+ struct GNUNET_CRYPTO_EcdsaPrivateKey priv_key;
/**
* Public key of the slave.
*/
- struct GNUNET_CRYPTO_EddsaPublicKey pub_key;
+ struct GNUNET_CRYPTO_EcdsaPublicKey pub_key;
/**
* Hash of @a pub_key.
@@ -390,7 +387,7 @@ struct Slave
/**
* Join decision received from multicast.
*/
- struct SlaveJoinDecision *join_dcsn;
+ struct GNUNET_PSYC_JoinDecisionMessage *join_dcsn;
/**
* Maximum request ID for this channel.
@@ -514,6 +511,7 @@ client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"%p User context is NULL in client_disconnect()\n", chn);
+ GNUNET_break (0);
return;
}
@@ -573,7 +571,7 @@ client_send_msg (const struct Channel *chn,
*/
struct JoinMemTestClosure
{
- struct GNUNET_CRYPTO_EddsaPublicKey slave_key;
+ struct GNUNET_CRYPTO_EcdsaPublicKey slave_key;
struct Channel *chn;
struct GNUNET_MULTICAST_JoinHandle *jh;
struct MasterJoinRequest *master_join_req;
@@ -613,7 +611,7 @@ join_mem_test_cb (void *cls, int64_t result, const char *err_msg)
*/
static void
mcast_recv_join_request (void *cls,
- const struct GNUNET_CRYPTO_EddsaPublicKey *slave_key,
+ const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
const struct GNUNET_MessageHeader *join_msg,
struct GNUNET_MULTICAST_JoinHandle *jh)
{
@@ -670,7 +668,7 @@ mcast_recv_join_decision (void *cls, int is_admitted,
"%p Got join decision: %d\n", slv, is_admitted);
uint16_t join_resp_size = (NULL != join_resp) ? ntohs (join_resp->size) : 0;
- struct SlaveJoinDecision *
+ struct GNUNET_PSYC_JoinDecisionMessage *
dcsn = slv->join_dcsn = GNUNET_malloc (sizeof (*dcsn) + join_resp_size);
dcsn->header.size = htons (sizeof (*dcsn) + join_resp_size);
dcsn->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION);
@@ -682,7 +680,7 @@ mcast_recv_join_decision (void *cls, int is_admitted,
if (GNUNET_YES == is_admitted)
{
- chn->ready = GNUNET_YES;
+ chn->is_ready = GNUNET_YES;
}
else
{
@@ -693,7 +691,7 @@ mcast_recv_join_decision (void *cls, int is_admitted,
static void
mcast_recv_membership_test (void *cls,
- const struct GNUNET_CRYPTO_EddsaPublicKey *slave_key,
+ const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
uint64_t message_id, uint64_t group_generation,
struct GNUNET_MULTICAST_MembershipTestHandle *mth)
{
@@ -703,7 +701,7 @@ mcast_recv_membership_test (void *cls,
static void
mcast_recv_replay_fragment (void *cls,
- const struct GNUNET_CRYPTO_EddsaPublicKey *slave_key,
+ const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
uint64_t fragment_id, uint64_t flags,
struct GNUNET_MULTICAST_ReplayHandle *rh)
@@ -714,7 +712,7 @@ mcast_recv_replay_fragment (void *cls,
static void
mcast_recv_replay_message (void *cls,
- const struct GNUNET_CRYPTO_EddsaPublicKey *slave_key,
+ const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
uint64_t message_id,
uint64_t fragment_offset,
uint64_t flags,
@@ -737,7 +735,7 @@ hash_key_from_nll (struct GNUNET_HashCode *key, uint64_t n)
n = ((n << 8) & 0xFF00FF00FF00FF00ULL) | ((n >> 8) & 0x00FF00FF00FF00FFULL);
n = ((n << 16) & 0xFFFF0000FFFF0000ULL) | ((n >> 16) & 0x0000FFFF0000FFFFULL);
- *key = (struct GNUNET_HashCode) {{ 0 }};
+ *key = (struct GNUNET_HashCode) {};
*((uint64_t *) key)
= (n << 32) | (n >> 32);
}
@@ -753,7 +751,7 @@ hash_key_from_hll (struct GNUNET_HashCode *key, uint64_t n)
#if __BYTE_ORDER == __BIG_ENDIAN
hash_key_from_nll (key, n);
#elif __BYTE_ORDER == __LITTLE_ENDIAN
- *key = (struct GNUNET_HashCode) {{ 0 }};
+ *key = (struct GNUNET_HashCode) {};
*((uint64_t *) key) = n;
#else
#error byteorder undefined
@@ -1225,10 +1223,8 @@ mcast_recv_message (void *cls, const struct GNUNET_MULTICAST_MessageHeader *mmsg
/**
* Incoming request fragment from multicast for a master.
*
- * @param cls Master.
- * @param slave_key Sending slave's public key.
- * @param msg The message.
- * @param flags Request flags.
+ * @param cls Master.
+ * @param req The request.
*/
static void
mcast_recv_request (void *cls,
@@ -1295,7 +1291,7 @@ store_recv_master_counters (void *cls, int result, uint64_t max_fragment_id,
&mcast_recv_replay_message,
&mcast_recv_request,
&mcast_recv_message, chn);
- chn->ready = GNUNET_YES;
+ chn->is_ready = GNUNET_YES;
}
else
{
@@ -1400,7 +1396,7 @@ client_recv_master_start (void *cls, struct GNUNET_SERVER_Client *client,
GNUNET_CONTAINER_multihashmap_put (masters, &chn->pub_key_hash, chn,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
chn->store_op = GNUNET_PSYCSTORE_counters_get (store, &chn->pub_key,
- store_recv_master_counters, mst);
+ store_recv_master_counters, mst);
}
else
{
@@ -1440,10 +1436,10 @@ client_recv_slave_join (void *cls, struct GNUNET_SERVER_Client *client,
const struct SlaveJoinRequest *req
= (const struct SlaveJoinRequest *) msg;
- struct GNUNET_CRYPTO_EddsaPublicKey slv_pub_key;
+ struct GNUNET_CRYPTO_EcdsaPublicKey slv_pub_key;
struct GNUNET_HashCode pub_key_hash, slv_pub_key_hash;
- GNUNET_CRYPTO_eddsa_key_get_public (&req->slave_key, &slv_pub_key);
+ GNUNET_CRYPTO_ecdsa_key_get_public (&req->slave_key, &slv_pub_key);
GNUNET_CRYPTO_hash (&slv_pub_key, sizeof (slv_pub_key), &slv_pub_key_hash);
GNUNET_CRYPTO_hash (&req->channel_key, sizeof (req->channel_key), &pub_key_hash);
@@ -1540,7 +1536,7 @@ client_recv_slave_join (void *cls, struct GNUNET_SERVER_Client *client,
cli->client = client;
GNUNET_CONTAINER_DLL_insert (chn->clients_head, chn->clients_tail, cli);
- GNUNET_SERVER_client_set_user_context (client, &slv->chn);
+ GNUNET_SERVER_client_set_user_context (client, chn);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
@@ -1578,7 +1574,8 @@ client_recv_join_decision (void *cls, struct GNUNET_SERVER_Client *client,
GNUNET_assert (GNUNET_YES == chn->is_master);
struct Master *mst = (struct Master *) chn;
- struct MasterJoinDecision *dcsn = (struct MasterJoinDecision *) msg;
+ struct GNUNET_PSYC_JoinDecisionMessage *
+ dcsn = (struct GNUNET_PSYC_JoinDecisionMessage *) msg;
struct JoinDecisionClosure jcls;
jcls.is_admitted = ntohl (dcsn->is_admitted);
jcls.msg
@@ -1655,19 +1652,15 @@ transmit_notify (void *cls, size_t *data_size, void *data)
GNUNET_CONTAINER_DLL_remove (chn->tmit_head, chn->tmit_tail, tmit_msg);
GNUNET_free (tmit_msg);
- if (0 == chn->tmit_task)
+ if (NULL != chn->tmit_head)
{
- if (NULL != chn->tmit_head)
- {
- transmit_message (chn);
- }
- else if (chn->disconnected)
- {
- /* FIXME: handle partial message (when still in_transmit) */
- cleanup_channel (chn);
- }
+ transmit_message (chn);
+ }
+ else if (GNUNET_YES == chn->is_disconnected)
+ {
+ /* FIXME: handle partial message (when still in_transmit) */
+ cleanup_channel (chn);
}
-
return ret;
}
@@ -1712,8 +1705,6 @@ slave_transmit_notify (void *cls, size_t *data_size, void *data)
static void
master_transmit_message (struct Master *mst)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%p master_transmit_message()\n", mst);
- mst->chn.tmit_task = 0;
if (NULL == mst->tmit_handle)
{
mst->tmit_handle
@@ -1734,7 +1725,6 @@ master_transmit_message (struct Master *mst)
static void
slave_transmit_message (struct Slave *slv)
{
- slv->chn.tmit_task = 0;
if (NULL == slv->tmit_handle)
{
slv->tmit_handle
@@ -1830,6 +1820,8 @@ queue_message (struct Channel *chn,
tmit_msg->size = data_size;
tmit_msg->state = chn->tmit_state;
+ /* FIXME: separate queue per message ID */
+
GNUNET_CONTAINER_DLL_insert_tail (chn->tmit_head, chn->tmit_tail, tmit_msg);
chn->is_master
@@ -1877,10 +1869,11 @@ client_recv_psyc_message (void *cls, struct GNUNET_SERVER_Client *client,
"%p Received message from client.\n", chn);
GNUNET_PSYC_log_message (GNUNET_ERROR_TYPE_DEBUG, msg);
- if (GNUNET_YES != chn->ready)
+ if (GNUNET_YES != chn->is_ready)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "%p Channel is not ready, dropping message from client.\n", chn);
+ "%p Channel is not ready yet, disconnecting client.\n", chn);
+ GNUNET_break (0);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
diff --git a/src/psyc/psyc.h b/src/psyc/psyc.h
index 66c8de8983..995fb1fa45 100644
--- a/src/psyc/psyc.h
+++ b/src/psyc/psyc.h
@@ -78,9 +78,9 @@ struct MasterStartRequest
*/
struct GNUNET_MessageHeader header;
- struct GNUNET_CRYPTO_EddsaPrivateKey channel_key;
-
uint32_t policy GNUNET_PACKED;
+
+ struct GNUNET_CRYPTO_EddsaPrivateKey channel_key;
};
@@ -95,15 +95,17 @@ struct SlaveJoinRequest
struct GNUNET_CRYPTO_EddsaPublicKey channel_key;
- struct GNUNET_CRYPTO_EddsaPrivateKey slave_key;
+ struct GNUNET_CRYPTO_EcdsaPrivateKey slave_key;
struct GNUNET_PeerIdentity origin;
/* Followed by struct GNUNET_PeerIdentity relays[relay_count] */
+
+ /* Followed by struct GNUNET_MessageHeader join_msg */
};
-struct ChannelSlaveAdd
+struct ChannelSlaveAddRequest
{
/**
* Type: GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_SLAVE_ADD
@@ -112,7 +114,7 @@ struct ChannelSlaveAdd
uint32_t reserved;
- struct GNUNET_CRYPTO_EddsaPublicKey *slave_key;
+ struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key;
uint64_t announced_at;
@@ -120,7 +122,7 @@ struct ChannelSlaveAdd
};
-struct ChannelSlaveRemove
+struct ChannelSlaveRemoveRequest
{
/**
* Type: GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_SLAVE_RM
@@ -129,7 +131,7 @@ struct ChannelSlaveRemove
uint32_t reserved;
- struct GNUNET_CRYPTO_EddsaPublicKey *slave_key;
+ struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key;
uint64_t announced_at;
};
@@ -189,6 +191,7 @@ struct CountersResult
uint64_t max_message_id;
};
+
/**
* Answer from service to client about last operation.
*/
@@ -236,50 +239,12 @@ struct MasterJoinRequest
/**
* Public key of the joining slave.
*/
- struct GNUNET_CRYPTO_EddsaPublicKey slave_key;
+ struct GNUNET_CRYPTO_EcdsaPublicKey slave_key;
/* Followed by struct GNUNET_MessageHeader join_request */
};
-struct MasterJoinDecision
-{
- /**
- * Type: GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION
- */
- struct GNUNET_MessageHeader header;
-
- /**
- * #GNUNET_YES if the slave was admitted.
- */
- int32_t is_admitted;
-
- /**
- * Public key of the joining slave.
- */
- struct GNUNET_CRYPTO_EddsaPublicKey slave_key;
-
- /* Followed by struct GNUNET_MessageHeader join_response */
-};
-
-
-struct SlaveJoinDecision
-{
- /**
- * Type: GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION
- */
- struct GNUNET_MessageHeader header;
-
- /**
- * #GNUNET_YES if the slave was admitted.
- */
- int32_t is_admitted;
-
- /* Followed by struct GNUNET_MessageHeader join_response */
-};
-
-
-
GNUNET_NETWORK_STRUCT_END
#endif
diff --git a/src/psyc/psyc_api.c b/src/psyc/psyc_api.c
index bfb6f43fb2..88b007a0fc 100644
--- a/src/psyc/psyc_api.c
+++ b/src/psyc/psyc_api.c
@@ -133,7 +133,7 @@ struct GNUNET_PSYC_Slave
struct GNUNET_PSYC_JoinHandle
{
struct GNUNET_PSYC_Master *mst;
- struct GNUNET_CRYPTO_EddsaPublicKey slave_key;
+ struct GNUNET_CRYPTO_EcdsaPublicKey slave_key;
};
@@ -270,8 +270,8 @@ slave_recv_join_decision (void *cls,
struct GNUNET_PSYC_Slave *
slv = GNUNET_CLIENT_MANAGER_get_user_context_ (client,
sizeof (struct GNUNET_PSYC_Channel));
- const struct SlaveJoinDecision *
- dcsn = (const struct SlaveJoinDecision *) msg;
+ const struct GNUNET_PSYC_JoinDecisionMessage *
+ dcsn = (const struct GNUNET_PSYC_JoinDecisionMessage *) msg;
struct GNUNET_PSYC_MessageHeader *pmsg = NULL;
if (ntohs (dcsn->header.size) <= sizeof (*dcsn) + sizeof (*pmsg))
@@ -285,8 +285,6 @@ slave_recv_join_decision (void *cls,
static struct GNUNET_CLIENT_MANAGER_MessageHandler master_handlers[] =
{
- { &channel_recv_disconnect, NULL, 0, 0, GNUNET_NO },
-
{ &channel_recv_message, NULL,
GNUNET_MESSAGE_TYPE_PSYC_MESSAGE,
sizeof (struct GNUNET_PSYC_MessageHeader), GNUNET_YES },
@@ -303,14 +301,14 @@ static struct GNUNET_CLIENT_MANAGER_MessageHandler master_handlers[] =
GNUNET_MESSAGE_TYPE_PSYC_JOIN_REQUEST,
sizeof (struct MasterJoinRequest), GNUNET_YES },
+ { &channel_recv_disconnect, NULL, 0, 0, GNUNET_NO },
+
{ NULL, NULL, 0, 0, GNUNET_NO }
};
static struct GNUNET_CLIENT_MANAGER_MessageHandler slave_handlers[] =
{
- { &channel_recv_disconnect, NULL, 0, 0, GNUNET_NO },
-
{ &channel_recv_message, NULL,
GNUNET_MESSAGE_TYPE_PSYC_MESSAGE,
sizeof (struct GNUNET_PSYC_MessageHeader), GNUNET_YES },
@@ -325,7 +323,9 @@ static struct GNUNET_CLIENT_MANAGER_MessageHandler slave_handlers[] =
{ &slave_recv_join_decision, NULL,
GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION,
- sizeof (struct SlaveJoinDecision), GNUNET_YES },
+ sizeof (struct GNUNET_PSYC_JoinDecisionMessage), GNUNET_YES },
+
+ { &channel_recv_disconnect, NULL, 0, 0, GNUNET_NO },
{ NULL, NULL, 0, 0, GNUNET_NO }
};
@@ -442,7 +442,7 @@ GNUNET_PSYC_join_decision (struct GNUNET_PSYC_JoinHandle *jh,
const struct GNUNET_PSYC_MessageHeader *join_resp)
{
struct GNUNET_PSYC_Channel *chn = &jh->mst->chn;
- struct MasterJoinDecision *dcsn;
+ struct GNUNET_PSYC_JoinDecisionMessage *dcsn;
uint16_t join_resp_size
= (NULL != join_resp) ? ntohs (join_resp->header.size) : 0;
uint16_t relay_size = relay_count * sizeof (*relays);
@@ -571,7 +571,7 @@ GNUNET_PSYC_master_get_channel (struct GNUNET_PSYC_Master *master)
struct GNUNET_PSYC_Slave *
GNUNET_PSYC_slave_join (const struct GNUNET_CONFIGURATION_Handle *cfg,
const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
- const struct GNUNET_CRYPTO_EddsaPrivateKey *slave_key,
+ const struct GNUNET_CRYPTO_EcdsaPrivateKey *slave_key,
const struct GNUNET_PeerIdentity *origin,
uint32_t relay_count,
const struct GNUNET_PeerIdentity *relays,
@@ -579,10 +579,7 @@ GNUNET_PSYC_slave_join (const struct GNUNET_CONFIGURATION_Handle *cfg,
GNUNET_PSYC_SlaveConnectCallback connect_cb,
GNUNET_PSYC_JoinDecisionCallback join_decision_cb,
void *cls,
- const char *method_name,
- const struct GNUNET_ENV_Environment *env,
- const void *data,
- uint16_t data_size)
+ const struct GNUNET_MessageHeader *join_msg)
{
struct GNUNET_PSYC_Slave *slv = GNUNET_malloc (sizeof (*slv));
struct GNUNET_PSYC_Channel *chn = &slv->chn;
@@ -725,11 +722,11 @@ GNUNET_PSYC_slave_get_channel (struct GNUNET_PSYC_Slave *slv)
*/
void
GNUNET_PSYC_channel_slave_add (struct GNUNET_PSYC_Channel *chn,
- const struct GNUNET_CRYPTO_EddsaPublicKey *slave_key,
+ const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
uint64_t announced_at,
uint64_t effective_since)
{
- struct ChannelSlaveAdd *add = GNUNET_malloc (sizeof (*add));
+ struct ChannelSlaveAddRequest *add = GNUNET_malloc (sizeof (*add));
add->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_SLAVE_ADD);
add->header.size = htons (sizeof (*add));
add->announced_at = GNUNET_htonll (announced_at);
@@ -761,10 +758,10 @@ GNUNET_PSYC_channel_slave_add (struct GNUNET_PSYC_Channel *chn,
*/
void
GNUNET_PSYC_channel_slave_remove (struct GNUNET_PSYC_Channel *chn,
- const struct GNUNET_CRYPTO_EddsaPublicKey *slave_key,
+ const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
uint64_t announced_at)
{
- struct ChannelSlaveRemove *rm = GNUNET_malloc (sizeof (*rm));
+ struct ChannelSlaveRemoveRequest *rm = GNUNET_malloc (sizeof (*rm));
rm->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_SLAVE_RM);
rm->header.size = htons (sizeof (*rm));
rm->announced_at = GNUNET_htonll (announced_at);
diff --git a/src/psyc/psyc_util_lib.c b/src/psyc/psyc_util_lib.c
index a50d99bec9..8ab0bdad2e 100644
--- a/src/psyc/psyc_util_lib.c
+++ b/src/psyc/psyc_util_lib.c
@@ -34,22 +34,6 @@
#define LOG(kind,...) GNUNET_log_from (kind, "psyc-util",__VA_ARGS__)
-/**
- * Message receive states.
- */
-enum GNUNET_PSYC_MessageState
-{
- GNUNET_PSYC_MESSAGE_STATE_START = 0,
- GNUNET_PSYC_MESSAGE_STATE_HEADER = 1,
- GNUNET_PSYC_MESSAGE_STATE_METHOD = 2,
- GNUNET_PSYC_MESSAGE_STATE_MODIFIER = 3,
- GNUNET_PSYC_MESSAGE_STATE_MOD_CONT = 4,
- GNUNET_PSYC_MESSAGE_STATE_DATA = 5,
- GNUNET_PSYC_MESSAGE_STATE_END = 6,
- GNUNET_PSYC_MESSAGE_STATE_CANCEL = 7,
- GNUNET_PSYC_MESSAGE_STATE_ERROR = 8,
-};
-
struct GNUNET_PSYC_TransmitHandle
{
@@ -142,7 +126,7 @@ struct GNUNET_PSYC_ReceiveHandle
/**
* Public key of the slave from which a message is being received.
*/
- struct GNUNET_CRYPTO_EddsaPublicKey slave_key;
+ struct GNUNET_CRYPTO_EcdsaPublicKey slave_key;
/**
* State of the currently being received message from the PSYC service.
@@ -165,6 +149,101 @@ struct GNUNET_PSYC_ReceiveHandle
uint32_t mod_value_size;
};
+/**** Messages ****/
+
+
+/**
+ * Create a PSYC message.
+ *
+ * @param method_name
+ * PSYC method for the message.
+ * @param env
+ * Environment for the message.
+ * @param data
+ * Data payload for the message.
+ * @param data_size
+ * Size of @a data.
+ *
+ * @return Message header with size information,
+ * followed by the message parts.
+ */
+struct GNUNET_MessageHeader *
+GNUNET_PSYC_message_create (const char *method_name,
+ const struct GNUNET_ENV_Environment *env,
+ const void *data,
+ size_t data_size)
+{
+ struct GNUNET_ENV_Modifier *mod = NULL;
+ struct GNUNET_PSYC_MessageMethod *pmeth = NULL;
+ struct GNUNET_PSYC_MessageModifier *pmod = NULL;
+ struct GNUNET_MessageHeader *pmsg = NULL;
+ uint16_t env_size = 0;
+ if (NULL != env)
+ {
+ mod = GNUNET_ENV_environment_head (env);
+ while (NULL != mod)
+ {
+ env_size += sizeof (*pmod) + strlen (mod->name) + 1 + mod->value_size;
+ mod = mod->next;
+ }
+ }
+
+ struct GNUNET_MessageHeader *msg;
+ uint16_t method_name_size = strlen (method_name) + 1;
+ if (method_name_size == 1)
+ return NULL;
+
+ uint16_t msg_size = sizeof (*msg) /* header */
+ + sizeof (*pmeth) + method_name_size /* method */
+ + env_size /* modifiers */
+ + ((0 < data_size) ? sizeof (*pmsg) + data_size : 0)/* data */
+ + sizeof (*pmsg); /* end of message */
+ msg = GNUNET_malloc (msg_size);
+ msg->size = htons (msg_size);
+ msg->type = htons (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE);
+
+ pmeth = (struct GNUNET_PSYC_MessageMethod *) &msg[1];
+ pmeth->header.size = htons (sizeof (*pmeth) + method_name_size);
+ memcpy (pmeth, method_name, method_name_size);
+
+ uint16_t p = sizeof (*msg) + sizeof (*pmeth) + method_name_size;
+ if (NULL != env)
+ {
+ mod = GNUNET_ENV_environment_head (env);
+ while (NULL != mod)
+ {
+ uint16_t mod_name_size = strlen (mod->name) + 1;
+ pmod = (struct GNUNET_PSYC_MessageModifier *) ((char *) msg + p);
+ pmod->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MODIFIER);
+ pmod->header.size = sizeof (*pmod) + mod_name_size + 1 + mod->value_size;
+ p += pmod->header.size;
+ pmod->header.size = htons (pmod->header.size);
+
+ memcpy (&pmod[1], mod->name, mod_name_size);
+ if (0 < mod->value_size)
+ memcpy ((char *) &pmod[1] + mod_name_size, mod->value, mod->value_size);
+
+ mod = mod->next;
+ }
+ }
+
+ if (0 < data_size)
+ {
+ pmsg = (struct GNUNET_MessageHeader *) ((char *) msg + p);
+ pmsg->size = sizeof (*pmsg) + data_size;
+ p += pmsg->size;
+ pmsg->size = htons (pmsg->size);
+ pmsg->type = htons (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_DATA);
+ memcpy (&pmsg[1], data, data_size);
+ }
+
+ pmsg = (struct GNUNET_MessageHeader *) ((char *) msg + p);
+ pmsg->size = htons (sizeof (*pmsg));
+ pmsg->type = htons (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_END);
+
+ return msg;
+}
+
void
GNUNET_PSYC_log_message (enum GNUNET_ErrorType kind,
diff --git a/src/psyc/test_psyc.c b/src/psyc/test_psyc.c
index 6468b8a2b8..0077bc9b77 100644
--- a/src/psyc/test_psyc.c
+++ b/src/psyc/test_psyc.c
@@ -33,11 +33,12 @@
#include "gnunet_util_lib.h"
#include "gnunet_testing_lib.h"
#include "gnunet_env_lib.h"
+#include "gnunet_psyc_util_lib.h"
#include "gnunet_psyc_service.h"
#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
-#define DEBUG_SERVICE 1
+#define DEBUG_SERVICE 0
/**
@@ -56,10 +57,10 @@ static struct GNUNET_PSYC_Master *mst;
static struct GNUNET_PSYC_Slave *slv;
static struct GNUNET_CRYPTO_EddsaPrivateKey *channel_key;
-static struct GNUNET_CRYPTO_EddsaPrivateKey *slave_key;
+static struct GNUNET_CRYPTO_EcdsaPrivateKey *slave_key;
static struct GNUNET_CRYPTO_EddsaPublicKey channel_pub_key;
-static struct GNUNET_CRYPTO_EddsaPublicKey slave_pub_key;
+static struct GNUNET_CRYPTO_EcdsaPublicKey slave_pub_key;
struct GNUNET_PSYC_MasterTransmitHandle *mth;
@@ -414,7 +415,7 @@ join_decision_cb (void *cls, int is_admitted,
static void
-join_request_cb (void *cls, const struct GNUNET_CRYPTO_EddsaPublicKey *slave_key,
+join_request_cb (void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
const struct GNUNET_PSYC_MessageHeader *msg,
struct GNUNET_PSYC_JoinHandle *jh)
{
@@ -449,10 +450,13 @@ slave_join ()
"_foo", "bar baz", 7);
GNUNET_ENV_environment_add (env, GNUNET_ENV_OP_ASSIGN,
"_foo_bar", "foo bar baz", 11);
+ struct GNUNET_MessageHeader *
+ join_msg = GNUNET_PSYC_message_create ("_request_join", env, "some data", 9);
+
slv = GNUNET_PSYC_slave_join (cfg, &channel_pub_key, slave_key, &origin,
0, NULL, &slave_message_cb,
&slave_connect_cb, &join_decision_cb, NULL,
- "_request_join", env, "some data", 9);
+ join_msg);
GNUNET_ENV_environment_destroy (env);
}
@@ -539,10 +543,10 @@ run (void *cls,
end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
channel_key = GNUNET_CRYPTO_eddsa_key_create ();
- slave_key = GNUNET_CRYPTO_eddsa_key_create ();
+ slave_key = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_CRYPTO_eddsa_key_get_public (channel_key, &channel_pub_key);
- GNUNET_CRYPTO_eddsa_key_get_public (slave_key, &slave_pub_key);
+ GNUNET_CRYPTO_ecdsa_key_get_public (slave_key, &slave_pub_key);
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Starting master.\n");
mst = GNUNET_PSYC_master_start (cfg, channel_key, GNUNET_PSYC_CHANNEL_PRIVATE,