aboutsummaryrefslogtreecommitdiff
path: root/src/or/connection_or.c
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2003-09-12 22:45:31 +0000
committerRoger Dingledine <arma@torproject.org>2003-09-12 22:45:31 +0000
commit31bf3ec420a91817fcda84ee2bc897641e712dee (patch)
tree7cf8dcd740931a14f4725ead50bec02de66c8e32 /src/or/connection_or.c
parent1738af96202ebf0a9830893d627c5913a04984a3 (diff)
downloadtor-31bf3ec420a91817fcda84ee2bc897641e712dee.tar
tor-31bf3ec420a91817fcda84ee2bc897641e712dee.tar.gz
reshuffle functions for cleaner organization
svn:r451
Diffstat (limited to 'src/or/connection_or.c')
-rw-r--r--src/or/connection_or.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/or/connection_or.c b/src/or/connection_or.c
index f9bd2f848..9adaa8a0e 100644
--- a/src/or/connection_or.c
+++ b/src/or/connection_or.c
@@ -683,6 +683,106 @@ conn_or_init_crypto(connection_t *conn) {
}
#endif
+int connection_write_cell_to_buf(const cell_t *cellp, connection_t *conn) {
+ char networkcell[CELL_NETWORK_SIZE];
+ char *n = networkcell;
+
+ cell_pack(n, cellp);
+
+#ifndef USE_TLS
+ if(connection_encrypt_cell(n,conn)<0) {
+ return -1;
+ }
+#endif
+
+ return connection_write_to_buf(n, CELL_NETWORK_SIZE, conn);
+}
+
+int connection_process_cell_from_inbuf(connection_t *conn) {
+ /* check if there's a whole cell there.
+ * * if yes, pull it off, decrypt it if we're not doing TLS, and process it.
+ * */
+#ifndef USE_TLS
+ char networkcell[CELL_NETWORK_SIZE];
+#endif
+ char buf[CELL_NETWORK_SIZE];
+// int x;
+ cell_t cell;
+
+ if(conn->inbuf_datalen < CELL_NETWORK_SIZE) /* entire response available? */
+ return 0; /* not yet */
+
+#ifdef USE_TLS
+ connection_fetch_from_buf(buf, CELL_NETWORK_SIZE, conn);
+#else
+ connection_fetch_from_buf(networkcell, CELL_NETWORK_SIZE, conn);
+#if 0
+ printf("Cell header crypttext: ");
+ for(x=0;x<8;x++) {
+ printf("%u ",crypted[x]);
+ }
+ printf("\n");
+#endif
+ /* decrypt */
+ if(crypto_cipher_decrypt(conn->b_crypto, networkcell, CELL_NETWORK_SIZE, buf)) {
+ log_fn(LOG_ERR,"Decryption failed, dropping.");
+ return connection_process_inbuf(conn); /* process the remainder of the buffer */
+ }
+// log_fn(LOG_DEBUG,"Cell decrypted (%d bytes).",outlen);
+#if 0
+ printf("Cell header plaintext: ");
+ for(x=0;x<8;x++) {
+ printf("%u ",outbuf[x]);
+ }
+ printf("\n");
+#endif
+#endif
+
+ /* retrieve cell info from buf (create the host-order struct from the network-order string) */
+ cell_unpack(&cell, buf);
+
+// log_fn(LOG_DEBUG,"Decrypted cell is of type %u (ACI %u).",cellp->command,cellp->aci);
+ command_process_cell(&cell, conn);
+
+ return connection_process_inbuf(conn); /* process the remainder of the buffer */
+}
+
+
+#ifndef USE_TLS
+int connection_encrypt_cell(char *cellp, connection_t *conn) {
+ char cryptcell[CELL_NETWORK_SIZE];
+#if 0
+ int x;
+ char *px;
+
+ printf("Sending: Cell header plaintext: ");
+ px = (char *)cellp;
+ for(x=0;x<8;x++) {
+ printf("%u ",px[x]);
+ }#
+ printf("\n");
+#endif
+
+ assert(conn);
+
+ if(crypto_cipher_encrypt(conn->f_crypto, cellp, CELL_NETWORK_SIZE, cryptcell)) {
+ log(LOG_ERR,"Could not encrypt cell for connection %s:%u.",conn->address,conn->port);
+ return -1;
+ }
+#if 0
+ printf("Sending: Cell header crypttext: ");
+ px = (char *)&newcell;
+ for(x=0;x<8;x++) {
+ printf("%u ",px[x]);
+ }
+ printf("\n");
+#endif
+
+ memcpy(cellp,cryptcell,CELL_NETWORK_SIZE);
+ return 0;
+}
+#endif
+
/*