10
10
11
11
struct curvecpr_messager ;
12
12
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
+ */
13
35
struct curvecpr_messager_ops {
14
36
int (* sendq_head )(struct curvecpr_messager * messager , struct curvecpr_block * * block_stored );
15
37
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 {
19
41
the time at which they were last sent. */
20
42
int (* sendmarkq_head )(struct curvecpr_messager * messager , struct curvecpr_block * * block_stored );
21
43
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 */
22
46
int (* sendmarkq_remove_range )(struct curvecpr_messager * messager , unsigned long long start , unsigned long long end );
23
47
unsigned char (* sendmarkq_is_full )(struct curvecpr_messager * messager );
24
48
49
+ /* This is called once for each message coming in that is not a pure acknowledgement */
25
50
int (* recvmarkq_put )(struct curvecpr_messager * messager , const struct curvecpr_block * block , struct curvecpr_block * * block_stored );
51
+
26
52
int (* recvmarkq_get_nth_unacknowledged )(struct curvecpr_messager * messager , unsigned int n , struct curvecpr_block * * block_stored );
27
53
unsigned char (* recvmarkq_is_empty )(struct curvecpr_messager * messager );
28
54
int (* recvmarkq_remove_range )(struct curvecpr_messager * messager , unsigned long long start , unsigned long long end );
29
55
30
56
int (* send )(struct curvecpr_messager * messager , const unsigned char * buf , size_t num );
31
57
32
58
void (* put_next_timeout )(struct curvecpr_messager * messager , const long long timeout_ns );
59
+ long long (* get_nanoseconds )(void * priv );
33
60
};
34
61
35
62
struct curvecpr_messager_cf {
@@ -50,6 +77,9 @@ struct curvecpr_messager {
50
77
unsigned char my_eof ;
51
78
unsigned char my_final ;
52
79
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. */
53
83
size_t my_maximum_send_bytes ;
54
84
55
85
crypto_uint64 my_sent_bytes ;
@@ -68,6 +98,7 @@ struct curvecpr_messager {
68
98
69
99
void curvecpr_messager_new (struct curvecpr_messager * messager , const struct curvecpr_messager_cf * cf , unsigned char client );
70
100
int 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. */
71
102
int curvecpr_messager_process_sendq (struct curvecpr_messager * messager );
72
103
long long curvecpr_messager_next_timeout (struct curvecpr_messager * messager );
73
104
0 commit comments