Eric Haumant
Eric Noack <corvus-gnunet@cybertrench.com>
Felix von Leitner [ diet libc snprintf for win32 ]
+Gabor Adam Toth <tg-gnunet@tgbit.net>
Gerd Knorr <kraxel@bytesex.org>
Glenn McGrath <bug1@iinet.net.au>
Hendrik Pagenhardt <Hendrik.Pagenhardt@gmx.net>
const char *
GNUNET_i2s (const struct GNUNET_PeerIdentity *pid);
+/**
+ * Convert a peer identity to a string (for printing debug messages).
+ * This is one of the very few calls in the entire API that is
+ * NOT reentrant!
+ *
+ * @param pid the peer identity
+ * @return string form of the pid; will be overwritten by next
+ * call to GNUNET_i2s.
+ */
+const char *
+GNUNET_i2s_full (const struct GNUNET_PeerIdentity *pid);
/**
* Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string
/**
* Convert ASCII encoding back to GNUNET_CRYPTO_hash
+ *
* @param enc the encoding
+ * @param enclen number of characters in 'enc' (without 0-terminator, which can be missing)
* @param result where to store the GNUNET_CRYPTO_hash code
* @return GNUNET_OK on success, GNUNET_SYSERR if result has the wrong encoding
*/
int
-GNUNET_CRYPTO_hash_from_string (const char *enc, GNUNET_HashCode * result);
+GNUNET_CRYPTO_hash_from_string2 (const char *enc, size_t enclen,
+ GNUNET_HashCode * result);
+
+
+/**
+ * Convert ASCII encoding back to GNUNET_CRYPTO_hash
+ * @param enc the encoding
+ * @param result where to store the GNUNET_CRYPTO_hash code
+ * @return GNUNET_OK on success, GNUNET_SYSERR if result has the wrong encoding
+ */
+#define GNUNET_CRYPTO_hash_from_string(enc, result) \
+ GNUNET_CRYPTO_hash_from_string2 (enc, strlen(enc), result)
/**
struct GNUNET_TIME_Relative timeout);
+/**
+ * Set if a client should finish a pending write when disconnecting.
+ */
+void
+GNUNET_SERVER_client_set_finish_pending_write (struct GNUNET_SERVER_Client *client,
+ int finish);
+
+
/**
* Disable the warning the server issues if a message is not acknowledged
* in a timely fashion. Use this call if a client is intentionally delayed
GNUNET_SERVER_mst_destroy (struct GNUNET_SERVER_MessageStreamTokenizer *mst);
+/**
+ * Signature of a function to create a custom tokenizer.
+ *
+ * @param cls closure from 'GNUNET_SERVER_set_callbacks'
+ * @param client handle to client the tokenzier will be used for
+ * @return handle to custom tokenizer ('mst')
+ */
+typedef void* (*GNUNET_SERVER_MstCreateCallback) (void *cls,
+ struct GNUNET_SERVER_Client *client);
+
+/**
+ * Signature of a function to destroy a custom tokenizer.
+ *
+ * @param cls closure from 'GNUNET_SERVER_set_callbacks'
+ * @param mst custom tokenizer handle
+ */
+typedef void (*GNUNET_SERVER_MstDestroyCallback) (void *cls, void *mst);
+
+/**
+ * Signature of a function to destroy a custom tokenizer.
+ *
+ * @param cls closure from 'GNUNET_SERVER_set_callbacks'
+ * @param mst custom tokenizer handle
+ * @param client_identity ID of client for which this is a buffer,
+ * can be NULL (will be passed back to 'cb')
+ * @param buf input data to add
+ * @param size number of bytes in buf
+ * @param purge should any excess bytes in the buffer be discarded
+ * (i.e. for packet-based services like UDP)
+ * @param one_shot only call callback once, keep rest of message in buffer
+ * @return GNUNET_OK if we are done processing (need more data)
+ * GNUNET_NO if one_shot was set and we have another message ready
+ * GNUNET_SYSERR if the data stream is corrupt
+ */
+typedef int (*GNUNET_SERVER_MstReceiveCallback) (void *cls, void *mst,
+ struct GNUNET_SERVER_Client *client,
+ const char *buf, size_t size,
+ int purge, int one_shot);
+
+
+/**
+ * Change functions used by the server to tokenize the message stream.
+ * (very rarely used).
+ *
+ * @param server server to modify
+ * @param create new tokenizer initialization function
+ * @param destroy new tokenizer destruction function
+ * @param receive new tokenizer receive function
+ * @param cls closure for 'create', 'receive', 'destroy'
+ */
+void
+GNUNET_SERVER_set_callbacks (struct GNUNET_SERVER_Handle *server,
+ GNUNET_SERVER_MstCreateCallback create,
+ GNUNET_SERVER_MstDestroyCallback destroy,
+ GNUNET_SERVER_MstReceiveCallback receive,
+ void *cls);
+
+
#if 0 /* keep Emacsens' auto-indent happy */
{
#endif
return (const char *) ret.encoding;
}
+/**
+ * Convert a peer identity to a string (for printing debug messages).
+ * This is one of the very few calls in the entire API that is
+ * NOT reentrant!
+ *
+ * @param pid the peer identity
+ * @return string form of the pid; will be overwritten by next
+ * call to GNUNET_i2s.
+ */
+const char *
+GNUNET_i2s_full (const struct GNUNET_PeerIdentity *pid)
+{
+ static struct GNUNET_CRYPTO_HashAsciiEncoded ret;
+
+ GNUNET_CRYPTO_hash_to_enc (&pid->hashPubKey, &ret);
+ return (const char *) ret.encoding;
+}
/**
* @return GNUNET_OK on success, GNUNET_SYSERR if result has the wrong encoding
*/
int
-GNUNET_CRYPTO_hash_from_string (const char *enc, GNUNET_HashCode * result)
+GNUNET_CRYPTO_hash_from_string2 (const char *enc, size_t enclen,
+ GNUNET_HashCode * result)
{
unsigned int rpos;
unsigned int wpos;
unsigned int vbit;
int ret;
- if (strlen (enc) != sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1)
+ if (enclen != sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1)
return GNUNET_SYSERR;
vbit = 2; /* padding! */
*/
int clients_ignore_shutdown;
+ GNUNET_SERVER_MstCreateCallback mst_create;
+ GNUNET_SERVER_MstDestroyCallback mst_destroy;
+ GNUNET_SERVER_MstReceiveCallback mst_receive;
+ void *mst_cls;
};
/**
* Processing of incoming data.
*/
- struct GNUNET_SERVER_MessageStreamTokenizer *mst;
+ void *mst;
/**
* Server that this client belongs to.
*/
int receive_pending;
+ /**
+ * Finish pending write when disconnecting?
+ */
+ int finish_pending_write;
+
/**
* Persist the file handle for this client no matter what happens,
* force the OS to close once the process actually dies. Should only
}
+void
+GNUNET_SERVER_set_callbacks (struct GNUNET_SERVER_Handle *server,
+ GNUNET_SERVER_MstCreateCallback create,
+ GNUNET_SERVER_MstDestroyCallback destroy,
+ GNUNET_SERVER_MstReceiveCallback receive,
+ void *cls)
+{
+ server->mst_create = create;
+ server->mst_destroy = destroy;
+ server->mst_receive = receive;
+ server->mst_cls = cls;
+}
+
+
/**
* Task run to warn about missing calls to 'GNUNET_SERVER_receive_done'.
*
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Server processes additional messages instantly.\n");
#endif
- ret =
- GNUNET_SERVER_mst_receive (client->mst, client, NULL, 0, GNUNET_NO,
- GNUNET_YES);
+ if (client->server->mst_receive != NULL)
+ ret =
+ client->server->mst_receive (client->server->mst_cls, client->mst,
+ client, NULL, 0, GNUNET_NO, GNUNET_YES);
+ else
+ ret =
+ GNUNET_SERVER_mst_receive (client->mst, client, NULL, 0, GNUNET_NO,
+ GNUNET_YES);
}
#if DEBUG_SERVER
LOG (GNUNET_ERROR_TYPE_DEBUG,
#endif
GNUNET_SERVER_client_keep (client);
client->last_activity = now;
- ret =
- GNUNET_SERVER_mst_receive (client->mst, client, buf, available, GNUNET_NO,
- GNUNET_YES);
+
+ if (server->mst_receive != NULL)
+ ret =
+ client->server->mst_receive (client->server->mst_cls, client->mst,
+ client, buf, available, GNUNET_NO, GNUNET_YES);
+ else
+ ret =
+ GNUNET_SERVER_mst_receive (client->mst, client, buf, available, GNUNET_NO,
+ GNUNET_YES);
+
process_mst (client, ret);
}
client->receive_pending = GNUNET_YES;
client->callback = NULL;
client->callback_cls = NULL;
+
+ if (server->mst_create != NULL)
+ client->mst =
+ server->mst_create (server->mst_cls, client);
+ else
+ client->mst =
+ GNUNET_SERVER_mst_create (&client_message_tokenizer_callback, server);
+
GNUNET_CONNECTION_receive (client->connection,
GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
client->idle_timeout, &process_incoming, client);
}
+void
+GNUNET_SERVER_client_set_finish_pending_write (struct GNUNET_SERVER_Client *client,
+ int finish)
+{
+ client->finish_pending_write = finish;
+}
+
+
/**
* Notify the server that the given client handle should
* be kept (keeps the connection up if possible, increments
}
rc = client->reference_count;
- if (client->server != NULL)
+ if (client->shutdown_now != GNUNET_YES)
{
server = client->server;
- client->server = NULL;
client->shutdown_now = GNUNET_YES;
prev = NULL;
pos = server->clients;
if (client->persist == GNUNET_YES)
GNUNET_CONNECTION_persist_ (client->connection);
- GNUNET_CONNECTION_destroy (client->connection, GNUNET_NO);
- GNUNET_SERVER_mst_destroy (client->mst);
+ GNUNET_CONNECTION_destroy (client->connection, client->finish_pending_write);
+
+ if (client->server->mst_destroy != NULL)
+ client->server->mst_destroy (client->server->mst_cls, client->mst);
+ else
+ GNUNET_SERVER_mst_destroy (client->mst);
+
GNUNET_free (client);
}
#endif
return;
}
- if (client->server == NULL)
+ if ((client->server == NULL) || (GNUNET_YES == client->shutdown_now))
{
GNUNET_SERVER_client_disconnect (client);
return;