aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-06-22 07:22:50 +0000
committerChristian Grothoff <christian@grothoff.org>2010-06-22 07:22:50 +0000
commit09082d4872f060aedf1364fb5ebc1584ee4c47d6 (patch)
tree005d7dc42a1c38d6c79a522d6384035e18db4c93
parentc7f9e2399e5d703f0137ebb0038173c56894b8e2 (diff)
downloadgnunet-09082d4872f060aedf1364fb5ebc1584ee4c47d6.tar.gz
gnunet-09082d4872f060aedf1364fb5ebc1584ee4c47d6.zip
refine API to make it usable for server itself
-rw-r--r--TODO5
-rw-r--r--src/include/gnunet_server_lib.h28
-rw-r--r--src/util/server_mst.c34
3 files changed, 51 insertions, 16 deletions
diff --git a/TODO b/TODO
index 07fbc23cc..da54c87aa 100644
--- a/TODO
+++ b/TODO
@@ -5,11 +5,6 @@
5* TRANSPORT: 5* TRANSPORT:
6 - HTTP backend [MW] 6 - HTTP backend [MW]
7* DV: [Nate] 7* DV: [Nate]
8 - write DV API (need to move declarations from dv_api.c to gnunet_dv_service.h!)
9 - implement DV service
10 - implement DV library (looks done)
11 - implement DV transport plugin
12 - implement testcases
13 - implement performance tests (needs tbench) 8 - implement performance tests (needs tbench)
14* UTIL: 9* UTIL:
15 - only connect() sockets that are ready (select()) [Nils] 10 - only connect() sockets that are ready (select()) [Nils]
diff --git a/src/include/gnunet_server_lib.h b/src/include/gnunet_server_lib.h
index 7af133b89..070d254ad 100644
--- a/src/include/gnunet_server_lib.h
+++ b/src/include/gnunet_server_lib.h
@@ -657,14 +657,36 @@ GNUNET_SERVER_mst_create (size_t maxbuf,
657 * @param size number of bytes in buf 657 * @param size number of bytes in buf
658 * @param purge should any excess bytes in the buffer be discarded 658 * @param purge should any excess bytes in the buffer be discarded
659 * (i.e. for packet-based services like UDP) 659 * (i.e. for packet-based services like UDP)
660 * @return GNUNET_NO if the data stream is corrupt 660 * @param one_shot only call callback once, keep rest of message in buffer
661 * GNUNET_SYSERR if the data stream is corrupt beyond repair 661 * @return GNUNET_OK if we are done processing (need more data)
662 * GNUNET_NO if one_shot was set and we have another message ready
663 * GNUNET_SYSERR if the data stream is corrupt
662 */ 664 */
663int 665int
664GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst, 666GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
665 const char *buf, 667 const char *buf,
666 size_t size, 668 size_t size,
667 int purge); 669 int purge,
670 int one_shot);
671
672
673/**
674 * Read incoming data into the receive buffer and call the
675 * callback for all complete messages.
676 *
677 * @param mst tokenizer to use
678 * @param sock socket to read from (must be ready according to select)
679 * @param purge should any excess bytes in the buffer be discarded
680 * (i.e. for packet-based services like UDP)
681 * @return GNUNET_NO if the data stream is corrupt
682 * GNUNET_SYSERR if the data stream is corrupt beyond repair
683 */
684int
685GNUNET_SERVER_mst_read (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
686 const char *buf,
687 size_t size,
688 int purge);
689
668 690
669/** 691/**
670 * Destroys a tokenizer. 692 * Destroys a tokenizer.
diff --git a/src/util/server_mst.c b/src/util/server_mst.c
index 53cae7035..8df4e4b7d 100644
--- a/src/util/server_mst.c
+++ b/src/util/server_mst.c
@@ -92,14 +92,17 @@ GNUNET_SERVER_mst_create (size_t maxbuf,
92 * @param size number of bytes in buf 92 * @param size number of bytes in buf
93 * @param purge should any excess bytes in the buffer be discarded 93 * @param purge should any excess bytes in the buffer be discarded
94 * (i.e. for packet-based services like UDP) 94 * (i.e. for packet-based services like UDP)
95 * @return GNUNET_NO if the data stream is corrupt 95 * @param one_shot only call callback once, keep rest of message in buffer
96 * GNUNET_SYSERR if the data stream is corrupt beyond repair 96 * @return GNUNET_OK if we are done processing (need more data)
97 * GNUNET_NO if one_shot was set and we have another message ready
98 * GNUNET_SYSERR if the data stream is corrupt
97 */ 99 */
98int 100int
99GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst, 101GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
100 const char *buf, 102 const char *buf,
101 size_t size, 103 size_t size,
102 int purge) 104 int purge,
105 int one_shot)
103{ 106{
104 const struct GNUNET_MessageHeader *hdr; 107 const struct GNUNET_MessageHeader *hdr;
105 size_t delta; 108 size_t delta;
@@ -107,7 +110,9 @@ GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
107 char *ibuf; 110 char *ibuf;
108 int need_align; 111 int need_align;
109 unsigned long offset; 112 unsigned long offset;
113 int ret;
110 114
115 ret = GNUNET_OK;
111 ibuf = (char*) &mst->hdr; 116 ibuf = (char*) &mst->hdr;
112 if (mst->off > 0) 117 if (mst->off > 0)
113 { 118 {
@@ -133,8 +138,6 @@ GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
133 if (want < sizeof (struct GNUNET_MessageHeader)) 138 if (want < sizeof (struct GNUNET_MessageHeader))
134 { 139 {
135 GNUNET_break_op (0); 140 GNUNET_break_op (0);
136 if (purge)
137 return GNUNET_NO;
138 return GNUNET_SYSERR; 141 return GNUNET_SYSERR;
139 } 142 }
140 if (want < mst->off) 143 if (want < mst->off)
@@ -154,6 +157,13 @@ GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
154 mst->off = 0; 157 mst->off = 0;
155 return GNUNET_OK; 158 return GNUNET_OK;
156 } 159 }
160 if (one_shot == GNUNET_SYSERR)
161 {
162 ret = GNUNET_NO;
163 goto copy;
164 }
165 if (one_shot == GNUNET_YES)
166 one_shot = GNUNET_SYSERR;
157 mst->cb (mst->cb_cls, mst->client_identity, &mst->hdr); 167 mst->cb (mst->cb_cls, mst->client_identity, &mst->hdr);
158 mst->off = 0; 168 mst->off = 0;
159 } 169 }
@@ -174,6 +184,13 @@ GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
174 want = ntohs (hdr->size); 184 want = ntohs (hdr->size);
175 if (size < want) 185 if (size < want)
176 break; /* or not, buffer incomplete... */ 186 break; /* or not, buffer incomplete... */
187 if (one_shot == GNUNET_SYSERR)
188 {
189 ret = GNUNET_NO;
190 goto copy;
191 }
192 if (one_shot == GNUNET_YES)
193 one_shot = GNUNET_SYSERR;
177 mst->cb (mst->cb_cls, mst->client_identity, hdr); 194 mst->cb (mst->cb_cls, mst->client_identity, hdr);
178 buf += want; 195 buf += want;
179 size -= want; 196 size -= want;
@@ -184,15 +201,16 @@ GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
184 goto do_align; 201 goto do_align;
185 } 202 }
186 } 203 }
204 copy:
187 if ( (size > 0) && (! purge) ) 205 if ( (size > 0) && (! purge) )
188 { 206 {
189 memcpy (&mst->hdr, buf, size); 207 memcpy (&ibuf[mst->off], buf, size);
190 mst->off = size; 208 mst->off += size;
191 size = 0; 209 size = 0;
192 } 210 }
193 if (purge) 211 if (purge)
194 mst->off = 0; 212 mst->off = 0;
195 return GNUNET_OK; 213 return ret;
196} 214}
197 215
198 216