1010
1111struct curvecpr_messager ;
1212
13+
14+ /* The callbacks you need to implement to get a reliable stream transport.
15+ You need to implement the three data structures mentioned below.
16+ Terminology:
17+ sendq (send queue): The data waiting to get sent. When you want to send
18+ something, you divide it into curvecpr_block:s (each at most
19+ messager->my_maximum_send_bytes in size) and put it in this
20+ queue (you have to do this yourself). When you call
21+ curvecpr_messager_process_sendq() it will check
22+ this queue for data ready to be sent. It might not happen
23+ immediately, but at a later invocation depending on the
24+ decongestion algorithm and packets waiting to be resent etc.
25+ sendmarkq (sent-to-be-marked queue): When a curvecpr_block is sent
26+ (using the send() callback function), it is moved from sendq to
27+ sendmarkq (if it wasn't moved earlier and this is just a resend).
28+ It waits here until it has been acknowledged by the recipient.
29+ recvmarkq (received-to-be-marked): Received curvecpr_block:s are stored
30+ here until we have sent an ACK (which happens right after they are
31+ stored actually). You need to assemble the stream data from this
32+ data structure yourself.
33+
34+ */
1335struct curvecpr_messager_ops {
1436 int (* sendq_head )(struct curvecpr_messager * messager , struct curvecpr_block * * block_stored );
1537 int (* sendq_move_to_sendmarkq )(struct curvecpr_messager * messager , const struct curvecpr_block * block , struct curvecpr_block * * block_stored );
@@ -19,17 +41,22 @@ struct curvecpr_messager_ops {
1941 the time at which they were last sent. */
2042 int (* sendmarkq_head )(struct curvecpr_messager * messager , struct curvecpr_block * * block_stored );
2143 int (* sendmarkq_get )(struct curvecpr_messager * messager , crypto_uint32 acknowledging_id , struct curvecpr_block * * block_stored );
44+
45+ /* This is called for all ranges in incoming messages's acknowledge structure */
2246 int (* sendmarkq_remove_range )(struct curvecpr_messager * messager , unsigned long long start , unsigned long long end );
2347 unsigned char (* sendmarkq_is_full )(struct curvecpr_messager * messager );
2448
49+ /* This is called once for each message coming in that is not a pure acknowledgement */
2550 int (* recvmarkq_put )(struct curvecpr_messager * messager , const struct curvecpr_block * block , struct curvecpr_block * * block_stored );
51+
2652 int (* recvmarkq_get_nth_unacknowledged )(struct curvecpr_messager * messager , unsigned int n , struct curvecpr_block * * block_stored );
2753 unsigned char (* recvmarkq_is_empty )(struct curvecpr_messager * messager );
2854 int (* recvmarkq_remove_range )(struct curvecpr_messager * messager , unsigned long long start , unsigned long long end );
2955
3056 int (* send )(struct curvecpr_messager * messager , const unsigned char * buf , size_t num );
3157
3258 void (* put_next_timeout )(struct curvecpr_messager * messager , const long long timeout_ns );
59+ long long (* get_nanoseconds )(void * priv );
3360};
3461
3562struct curvecpr_messager_cf {
@@ -50,6 +77,9 @@ struct curvecpr_messager {
5077 unsigned char my_eof ;
5178 unsigned char my_final ;
5279
80+ /* The client can only send 512 bytes/message until we know that an
81+ initiation packet has reached the server. Then this variable is raised
82+ to 1024 bytes. The server can send 1024 bytes/message from the start. */
5383 size_t my_maximum_send_bytes ;
5484
5585 crypto_uint64 my_sent_bytes ;
@@ -68,6 +98,7 @@ struct curvecpr_messager {
6898
6999void curvecpr_messager_new (struct curvecpr_messager * messager , const struct curvecpr_messager_cf * cf , unsigned char client );
70100int curvecpr_messager_recv (struct curvecpr_messager * messager , const unsigned char * buf , size_t num );
101+ /* Call this function on timeout and when you have added things to sendq if it was empty. */
71102int curvecpr_messager_process_sendq (struct curvecpr_messager * messager );
72103long long curvecpr_messager_next_timeout (struct curvecpr_messager * messager );
73104
0 commit comments