[or-cvs] Add initial interfaces and code for TLS support. Interface...
Nick Mathewson
nickm at seul.org
Thu Sep 4 16:05:12 UTC 2003
Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv15538/src/or
Modified Files:
buffers.c or.h
Log Message:
Add initial interfaces and code for TLS support. Interfaces are right; code needs work and testing.
Index: buffers.c
===================================================================
RCS file: /home/or/cvsroot/src/or/buffers.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- buffers.c 14 Aug 2003 17:13:51 -0000 1.27
+++ buffers.c 4 Sep 2003 16:05:08 -0000 1.28
@@ -86,6 +86,23 @@
}
}
+int read_to_buf_tls(tor_tls *tls, int at_most, char **buf, int *buflen, int *buf_datalen) {
+ int r;
+ assert(tls && *buf && buflen && buf_datalen);
+
+ if (at_most > *buflen - *buf_datalen)
+ at_most = *buflen - *buf_datalen;
+
+ if (at_most == 0)
+ return 0;
+
+ r = tor_tls_read(tls, *buf+*buf_datalen, at_most);
+ if (r<0)
+ return r;
+ *buf_datalen += r;
+ return r;
+}
+
int flush_buf(int s, char **buf, int *buflen, int *buf_flushlen, int *buf_datalen) {
/* push from buf onto s
@@ -125,6 +142,22 @@
// write_result,*buf_flushlen,*buf_datalen);
return *buf_flushlen;
}
+}
+
+int flush_buf_tls(tor_tls *tls, char **buf, int *buflen, int *buf_flushlen, int *buf_datalen)
+{
+ int r;
+ assert(tls && *buf && buflen && buf_datalen);
+ if (*buf_flushlen == 0)
+ return 0;
+ r = tor_tls_write(tls, *buf, *buf_flushlen);
+ if (r < 0) {
+ return r;
+ }
+ *buf_datalen -= r;
+ *buf_flushlen -= r;
+ memmove(*buf, *buf+r, *buf_datalen);
+ return r;
}
int write_to_buf(char *string, int string_len,
Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.110
retrieving revision 1.111
diff -u -d -r1.110 -r1.111
--- or.h 27 Aug 2003 22:42:10 -0000 1.110
+++ or.h 4 Sep 2003 16:05:08 -0000 1.111
@@ -90,6 +90,7 @@
#endif
#include "../common/crypto.h"
+#include "../common/tortls.h"
#include "../common/log.h"
#include "../common/util.h"
@@ -482,18 +483,23 @@
int read_to_buf(int s, int at_most, char **buf, int *buflen, int *buf_datalen, int *reached_eof);
/* grab from s, put onto buf, return how many bytes read */
+int read_to_buf_tls(tor_tls *tls, int at_most, char **buf, int *buflen, int *buf_datalen);
+ /* grab from s, put onto buf, return how many bytes read or a TLS
+ * status (same status codes as tor_tls_read) */
int flush_buf(int s, char **buf, int *buflen, int *buf_flushlen, int *buf_datalen);
/* push from buf onto s
* then memmove to front of buf
* return -1 or how many bytes remain on the buf */
+int flush_buf_tls(tor_tls *tls, char **buf, int *buflen, int *buf_flushlen, int *buf_datalen);
+ /* As flush_buf, but returns number of bytes written or TLS status
+ * (same status codes as tor_tls_write) */
int write_to_buf(char *string, int string_len,
char **buf, int *buflen, int *buf_datalen);
/* append string to buf (growing as needed, return -1 if "too big")
* return total number of bytes on the buf
*/
-
int fetch_from_buf(char *string, int string_len,
char **buf, int *buflen, int *buf_datalen);
More information about the tor-commits
mailing list