circuit.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. /* Copyright 2001,2002 Roger Dingledine, Matej Pfajfar. */
  2. /* See LICENSE for licensing information */
  3. /* $Id$ */
  4. #include "or.h"
  5. /********* START VARIABLES **********/
  6. static circuit_t *global_circuitlist=NULL;
  7. char *circuit_state_to_string[] = {
  8. "receiving the onion", /* 0 */
  9. "waiting to process create", /* 1 */
  10. "connecting to firsthop", /* 2 */
  11. "open" /* 3 */
  12. };
  13. /********* END VARIABLES ************/
  14. void circuit_add(circuit_t *circ) {
  15. if(!global_circuitlist) { /* first one */
  16. global_circuitlist = circ;
  17. circ->next = NULL;
  18. } else {
  19. circ->next = global_circuitlist;
  20. global_circuitlist = circ;
  21. }
  22. }
  23. void circuit_remove(circuit_t *circ) {
  24. circuit_t *tmpcirc;
  25. assert(circ && global_circuitlist);
  26. if(global_circuitlist == circ) {
  27. global_circuitlist = global_circuitlist->next;
  28. return;
  29. }
  30. for(tmpcirc = global_circuitlist;tmpcirc->next;tmpcirc = tmpcirc->next) {
  31. if(tmpcirc->next == circ) {
  32. tmpcirc->next = circ->next;
  33. return;
  34. }
  35. }
  36. }
  37. circuit_t *circuit_new(aci_t p_aci, connection_t *p_conn) {
  38. circuit_t *circ;
  39. circ = (circuit_t *)malloc(sizeof(circuit_t));
  40. if(!circ)
  41. return NULL;
  42. memset(circ,0,sizeof(circuit_t)); /* zero it out */
  43. circ->p_aci = p_aci;
  44. circ->p_conn = p_conn;
  45. circ->state = CIRCUIT_STATE_ONION_WAIT;
  46. /* ACIs */
  47. circ->p_aci = p_aci;
  48. /* circ->n_aci remains 0 because we haven't identified the next hop yet */
  49. circ->n_receive_circwindow = CIRCWINDOW_START;
  50. circ->p_receive_circwindow = CIRCWINDOW_START;
  51. circuit_add(circ);
  52. return circ;
  53. }
  54. void circuit_free(circuit_t *circ) {
  55. struct data_queue_t *tmpd;
  56. if (circ->n_crypto)
  57. crypto_free_cipher_env(circ->n_crypto);
  58. if (circ->p_crypto)
  59. crypto_free_cipher_env(circ->p_crypto);
  60. if(circ->onion)
  61. free(circ->onion);
  62. if(circ->cpath)
  63. circuit_free_cpath(circ->cpath, circ->cpathlen);
  64. while(circ->data_queue) {
  65. tmpd = circ->data_queue;
  66. circ->data_queue = tmpd->next;
  67. free(tmpd->cell);
  68. free(tmpd);
  69. }
  70. free(circ);
  71. }
  72. void circuit_free_cpath(crypt_path_t **cpath, int cpathlen) {
  73. int i;
  74. for(i=0;i<cpathlen;i++)
  75. free(cpath[i]);
  76. free(cpath);
  77. }
  78. /* return 0 if can't get a unique aci. */
  79. aci_t get_unique_aci_by_addr_port(uint32_t addr, uint16_t port, int aci_type) {
  80. aci_t test_aci;
  81. connection_t *conn;
  82. try_again:
  83. log(LOG_DEBUG,"get_unique_aci_by_addr_port() trying to get a unique aci");
  84. crypto_pseudo_rand(2, (unsigned char *)&test_aci);
  85. if(aci_type == ACI_TYPE_LOWER && test_aci >= (2<<15))
  86. test_aci -= (2<<15);
  87. if(aci_type == ACI_TYPE_HIGHER && test_aci < (2<<15))
  88. test_aci += (2<<15);
  89. /* if aci_type == ACI_BOTH, don't filter any of it */
  90. if(test_aci == 0)
  91. goto try_again;
  92. conn = connection_exact_get_by_addr_port(addr,port);
  93. if(!conn) /* there can't be a conflict -- no connection of that sort yet */
  94. return test_aci;
  95. if(circuit_get_by_aci_conn(test_aci, conn))
  96. goto try_again;
  97. return test_aci;
  98. }
  99. int circuit_init(circuit_t *circ, int aci_type) {
  100. unsigned char iv[16];
  101. unsigned char digest1[20];
  102. unsigned char digest2[20];
  103. struct timeval start, end;
  104. int time_passed;
  105. assert(circ && circ->onion);
  106. log(LOG_DEBUG,"circuit_init(): starting");
  107. circ->n_port = ntohs(*(uint16_t *)(circ->onion+2));
  108. log(LOG_DEBUG,"circuit_init(): Set port to %u.",circ->n_port);
  109. circ->n_addr = ntohl(*(uint32_t *)(circ->onion+4));
  110. circ->p_f = *(circ->onion+1) >> 4; /* backf */
  111. log(LOG_DEBUG,"circuit_init(): Set BACKF to %u.",circ->p_f);
  112. circ->n_f = *(circ->onion+1) & 0x0f; /* forwf */
  113. log(LOG_DEBUG,"circuit_init(): Set FORWF to %u.",circ->n_f);
  114. circ->state = CIRCUIT_STATE_OPEN;
  115. log(LOG_DEBUG,"circuit_init(): aci_type = %u.",aci_type);
  116. gettimeofday(&start,NULL);
  117. circ->n_aci = get_unique_aci_by_addr_port(circ->n_addr, circ->n_port, aci_type);
  118. if(!circ->n_aci) {
  119. log(LOG_ERR,"circuit_init(): failed to get unique aci.");
  120. return -1;
  121. }
  122. gettimeofday(&end,NULL);
  123. if(end.tv_usec < start.tv_usec) {
  124. end.tv_sec--;
  125. end.tv_usec += 1000000;
  126. }
  127. time_passed = ((end.tv_sec - start.tv_sec)*1000000) + (end.tv_usec - start.tv_usec);
  128. if(time_passed > 1000) { /* more than 1ms */
  129. log(LOG_NOTICE,"circuit_init(): get_unique_aci just took %d us!",time_passed);
  130. }
  131. log(LOG_DEBUG,"circuit_init(): Chosen ACI %u.",circ->n_aci);
  132. /* keys */
  133. memset(iv, 0, 16);
  134. crypto_SHA_digest(circ->onion+12,16,digest1);
  135. crypto_SHA_digest(digest1,20,digest2);
  136. crypto_SHA_digest(digest2,20,digest1);
  137. log(LOG_DEBUG,"circuit_init(): Computed keys.");
  138. if (!(circ->p_crypto = create_onion_cipher(circ->p_f,digest2,iv,1))) {
  139. log(LOG_ERR,"Cipher initialization failed (ACI %u).",circ->n_aci);
  140. return -1;
  141. }
  142. if (!(circ->n_crypto = create_onion_cipher(circ->n_f, digest1, iv, 0))) {
  143. log(LOG_ERR,"Cipher initialization failed (ACI %u).",circ->n_aci);
  144. return -1;
  145. }
  146. log(LOG_DEBUG,"circuit_init(): Cipher initialization complete.");
  147. circ->expire = ntohl(*(uint32_t *)(circ->onion+8));
  148. return 0;
  149. }
  150. circuit_t *circuit_enumerate_by_naddr_nport(circuit_t *circ, uint32_t naddr, uint16_t nport) {
  151. if(!circ) /* use circ if it's defined, else start from the beginning */
  152. circ = global_circuitlist;
  153. else
  154. circ = circ->next;
  155. for( ; circ; circ = circ->next) {
  156. if(circ->n_addr == naddr && circ->n_port == nport)
  157. return circ;
  158. }
  159. return NULL;
  160. }
  161. circuit_t *circuit_get_by_aci_conn(aci_t aci, connection_t *conn) {
  162. circuit_t *circ;
  163. connection_t *tmpconn;
  164. for(circ=global_circuitlist;circ;circ = circ->next) {
  165. if(circ->p_aci == aci) {
  166. for(tmpconn = circ->p_conn; tmpconn; tmpconn = tmpconn->next_topic) {
  167. if(tmpconn == conn)
  168. return circ;
  169. }
  170. }
  171. if(circ->n_aci == aci) {
  172. for(tmpconn = circ->n_conn; tmpconn; tmpconn = tmpconn->next_topic) {
  173. if(tmpconn == conn)
  174. return circ;
  175. }
  176. }
  177. }
  178. return NULL;
  179. }
  180. circuit_t *circuit_get_by_conn(connection_t *conn) {
  181. circuit_t *circ;
  182. connection_t *tmpconn;
  183. for(circ=global_circuitlist;circ;circ = circ->next) {
  184. for(tmpconn = circ->p_conn; tmpconn; tmpconn=tmpconn->next_topic)
  185. if(tmpconn == conn)
  186. return circ;
  187. for(tmpconn = circ->n_conn; tmpconn; tmpconn=tmpconn->next_topic)
  188. if(tmpconn == conn)
  189. return circ;
  190. }
  191. return NULL;
  192. }
  193. int circuit_deliver_data_cell_from_edge(cell_t *cell, circuit_t *circ, char edge_type) {
  194. int cell_direction;
  195. log(LOG_DEBUG,"circuit_deliver_data_cell_from_edge(): called, edge_type %d.", edge_type);
  196. if(edge_type == EDGE_AP) { /* i'm the AP */
  197. cell_direction = CELL_DIRECTION_OUT;
  198. if(circ->p_receive_circwindow <= 0) {
  199. log(LOG_DEBUG,"circuit_deliver_data_cell_from_edge(): window 0, queueing for later.");
  200. circ->data_queue = data_queue_add(circ->data_queue, cell);
  201. return 0;
  202. }
  203. circ->p_receive_circwindow--;
  204. } else { /* i'm the exit */
  205. cell_direction = CELL_DIRECTION_IN;
  206. if(circ->n_receive_circwindow <= 0) {
  207. log(LOG_DEBUG,"circuit_deliver_data_cell_from_edge(): window 0, queueing for later.");
  208. circ->data_queue = data_queue_add(circ->data_queue, cell);
  209. return 0;
  210. }
  211. circ->n_receive_circwindow--;
  212. }
  213. if(circuit_deliver_data_cell(cell, circ, cell_direction) < 0) {
  214. return -1;
  215. }
  216. circuit_consider_stop_edge_reading(circ, edge_type); /* has window reached 0? */
  217. return 0;
  218. }
  219. int circuit_deliver_data_cell(cell_t *cell, circuit_t *circ, int cell_direction) {
  220. connection_t *conn;
  221. assert(cell && circ);
  222. assert(cell_direction == CELL_DIRECTION_OUT || cell_direction == CELL_DIRECTION_IN);
  223. if(cell_direction == CELL_DIRECTION_OUT)
  224. conn = circ->n_conn;
  225. else
  226. conn = circ->p_conn;
  227. /* first crypt cell->length */
  228. if(circuit_crypt(circ, &(cell->length), 1, cell_direction) < 0) {
  229. log(LOG_DEBUG,"circuit_deliver_data_cell(): length crypt failed. Dropping connection.");
  230. return -1;
  231. }
  232. /* then crypt the payload */
  233. if(circuit_crypt(circ, (char *)&(cell->payload), CELL_PAYLOAD_SIZE, cell_direction) < 0) {
  234. log(LOG_DEBUG,"circuit_deliver_data_cell(): payload crypt failed. Dropping connection.");
  235. return -1;
  236. }
  237. if((!conn && cell_direction == CELL_DIRECTION_OUT) || (conn && conn->type == CONN_TYPE_EXIT)) {
  238. log(LOG_DEBUG,"circuit_deliver_data_cell(): Sending to exit.");
  239. return connection_exit_process_data_cell(cell, circ);
  240. }
  241. if((!conn && cell_direction == CELL_DIRECTION_IN) || (conn && conn->type == CONN_TYPE_AP)) {
  242. log(LOG_DEBUG,"circuit_deliver_data_cell(): Sending to AP.");
  243. return connection_ap_process_data_cell(cell, circ);
  244. }
  245. /* else send it as a cell */
  246. assert(conn);
  247. //log(LOG_DEBUG,"circuit_deliver_data_cell(): Sending to connection.");
  248. return connection_write_cell_to_buf(cell, conn);
  249. }
  250. int circuit_crypt(circuit_t *circ, char *in, int inlen, char cell_direction) {
  251. char *out;
  252. int i;
  253. crypt_path_t *thishop;
  254. assert(circ && in);
  255. out = (char *)malloc(inlen);
  256. if(!out)
  257. return -1;
  258. if(cell_direction == CELL_DIRECTION_IN) { //crypt_type == 'e') {
  259. if(circ->cpath) { /* we're at the beginning of the circuit. We'll want to do layered crypts. */
  260. for (i=circ->cpathlen-1; i >= 0; i--) /* moving from first to last hop
  261. * Remember : cpath is in reverse order, i.e. last hop first
  262. */
  263. {
  264. thishop = circ->cpath[i];
  265. /* decrypt */
  266. if(crypto_cipher_decrypt(thishop->b_crypto, in, inlen, out)) {
  267. log(LOG_ERR,"Error performing decryption:%s",crypto_perror());
  268. free(out);
  269. return -1;
  270. }
  271. /* copy ciphertext back to buf */
  272. memcpy(in,out,inlen);
  273. }
  274. } else { /* we're in the middle. Just one crypt. */
  275. if(crypto_cipher_encrypt(circ->p_crypto,in, inlen, out)) {
  276. log(LOG_ERR,"circuit_encrypt(): Encryption failed for ACI : %u (%s).",
  277. circ->p_aci, crypto_perror());
  278. free(out);
  279. return -1;
  280. }
  281. memcpy(in,out,inlen);
  282. }
  283. } else if(cell_direction == CELL_DIRECTION_OUT) { //crypt_type == 'd') {
  284. if(circ->cpath) { /* we're at the beginning of the circuit. We'll want to do layered crypts. */
  285. for (i=0; i < circ->cpathlen; i++) /* moving from last to first hop
  286. * Remember : cpath is in reverse order, i.e. last hop first
  287. */
  288. {
  289. thishop = circ->cpath[i];
  290. /* encrypt */
  291. if(crypto_cipher_encrypt(thishop->f_crypto, in, inlen, (unsigned char *)out)) {
  292. log(LOG_ERR,"Error performing encryption:%s",crypto_perror());
  293. free(out);
  294. return -1;
  295. }
  296. /* copy ciphertext back to buf */
  297. memcpy(in,out,inlen);
  298. }
  299. } else { /* we're in the middle. Just one crypt. */
  300. if(crypto_cipher_decrypt(circ->n_crypto,in, inlen, out)) {
  301. log(LOG_ERR,"circuit_crypt(): Decryption failed for ACI : %u (%s).",
  302. circ->n_aci, crypto_perror());
  303. free(out);
  304. return -1;
  305. }
  306. memcpy(in,out,inlen);
  307. }
  308. } else {
  309. log(LOG_ERR,"circuit_crypt(): unknown cell direction %d.", cell_direction);
  310. assert(0);
  311. }
  312. free(out);
  313. return 0;
  314. }
  315. void circuit_resume_edge_reading(circuit_t *circ, int edge_type) {
  316. connection_t *conn;
  317. struct data_queue_t *tmpd;
  318. assert(edge_type == EDGE_EXIT || edge_type == EDGE_AP);
  319. if(edge_type == EDGE_EXIT)
  320. conn = circ->n_conn;
  321. else
  322. conn = circ->p_conn;
  323. /* first, send the queue waiting at circ onto the circuit */
  324. while(circ->data_queue) {
  325. assert(circ->data_queue->cell);
  326. if(edge_type == EDGE_EXIT) {
  327. circ->p_receive_circwindow--;
  328. assert(circ->p_receive_circwindow >= 0);
  329. if(circuit_deliver_data_cell(circ->data_queue->cell, circ, CELL_DIRECTION_IN) < 0) {
  330. circuit_close(circ);
  331. return;
  332. }
  333. } else { /* ap */
  334. circ->p_receive_circwindow--;
  335. assert(circ->p_receive_circwindow >= 0);
  336. if(circuit_deliver_data_cell(circ->data_queue->cell, circ, CELL_DIRECTION_IN) < 0) {
  337. circuit_close(circ);
  338. return;
  339. }
  340. }
  341. tmpd = circ->data_queue;
  342. circ->data_queue = tmpd->next;
  343. free(tmpd->cell);
  344. free(tmpd);
  345. if(circuit_consider_stop_edge_reading(circ, edge_type))
  346. return;
  347. }
  348. for( ; conn; conn=conn->next_topic) {
  349. if((edge_type == EDGE_EXIT && conn->n_receive_topicwindow > 0) ||
  350. (edge_type == EDGE_AP && conn->p_receive_topicwindow > 0)) {
  351. connection_start_reading(conn);
  352. connection_package_raw_inbuf(conn); /* handle whatever might still be on the inbuf */
  353. }
  354. }
  355. circuit_consider_stop_edge_reading(circ, edge_type);
  356. }
  357. /* returns 1 if the window is empty, else 0. If it's empty, tell edge conns to stop reading. */
  358. int circuit_consider_stop_edge_reading(circuit_t *circ, int edge_type) {
  359. connection_t *conn = NULL;
  360. assert(edge_type == EDGE_EXIT || edge_type == EDGE_AP);
  361. if(edge_type == EDGE_EXIT && circ->p_receive_circwindow <= 0)
  362. conn = circ->n_conn;
  363. else if(edge_type == EDGE_AP && circ->n_receive_circwindow <= 0)
  364. conn = circ->p_conn;
  365. else
  366. return 0;
  367. for( ; conn; conn=conn->next_topic)
  368. connection_stop_reading(conn);
  369. return 1;
  370. }
  371. int circuit_consider_sending_sendme(circuit_t *circ, int edge_type) {
  372. cell_t sendme;
  373. assert(circ);
  374. sendme.command = CELL_SENDME;
  375. sendme.length = CIRCWINDOW_INCREMENT;
  376. if(edge_type == EDGE_AP) { /* i'm the AP */
  377. if(circ->n_receive_circwindow < CIRCWINDOW_START-CIRCWINDOW_INCREMENT) {
  378. log(LOG_DEBUG,"circuit_consider_sending_sendme(): Queueing sendme forward.");
  379. circ->n_receive_circwindow += CIRCWINDOW_INCREMENT;
  380. sendme.aci = circ->n_aci;
  381. return connection_write_cell_to_buf(&sendme, circ->n_conn); /* (clobbers sendme) */
  382. }
  383. } else if(edge_type == EDGE_EXIT) { /* i'm the exit */
  384. if(circ->p_receive_circwindow < CIRCWINDOW_START-CIRCWINDOW_INCREMENT) {
  385. log(LOG_DEBUG,"circuit_consider_sending_sendme(): Queueing sendme back.");
  386. circ->p_receive_circwindow += CIRCWINDOW_INCREMENT;
  387. sendme.aci = circ->p_aci;
  388. return connection_write_cell_to_buf(&sendme, circ->p_conn); /* (clobbers sendme) */
  389. }
  390. }
  391. return 0;
  392. }
  393. void circuit_close(circuit_t *circ) {
  394. connection_t *conn;
  395. circuit_remove(circ);
  396. for(conn=circ->n_conn; conn; conn=conn->next_topic) {
  397. connection_send_destroy(circ->n_aci, circ->n_conn);
  398. }
  399. for(conn=circ->p_conn; conn; conn=conn->next_topic) {
  400. connection_send_destroy(circ->p_aci, circ->p_conn);
  401. }
  402. circuit_free(circ);
  403. }
  404. void circuit_about_to_close_connection(connection_t *conn) {
  405. /* send destroys for all circuits using conn */
  406. /* currently, we assume it's too late to flush conn's buf here.
  407. * down the road, maybe we'll consider that eof doesn't mean can't-write
  408. */
  409. circuit_t *circ;
  410. connection_t *prevconn, *tmpconn;
  411. cell_t cell;
  412. int edge_type;
  413. if(!connection_speaks_cells(conn)) {
  414. /* it's an edge conn. need to remove it from the linked list of
  415. * conn's for this circuit. Send an 'end' data topic.
  416. * But don't kill the circuit.
  417. */
  418. circ = circuit_get_by_conn(conn);
  419. if(!circ)
  420. return;
  421. memset(&cell, 0, sizeof(cell_t));
  422. cell.command = CELL_DATA;
  423. cell.length = TOPIC_HEADER_SIZE;
  424. *(uint32_t *)cell.payload = conn->topic_id;
  425. *cell.payload = TOPIC_COMMAND_END;
  426. if(conn == circ->p_conn) {
  427. circ->p_conn = conn->next_topic;
  428. edge_type = EDGE_AP;
  429. goto send_end;
  430. }
  431. if(conn == circ->n_conn) {
  432. circ->n_conn = conn->next_topic;
  433. edge_type = EDGE_EXIT;
  434. goto send_end;
  435. }
  436. for(prevconn = circ->p_conn; prevconn->next_topic && prevconn->next_topic != conn; prevconn = prevconn->next_topic) ;
  437. if(prevconn->next_topic) {
  438. prevconn->next_topic = conn->next_topic;
  439. edge_type = EDGE_AP;
  440. goto send_end;
  441. }
  442. for(prevconn = circ->n_conn; prevconn->next_topic && prevconn->next_topic != conn; prevconn = prevconn->next_topic) ;
  443. if(prevconn->next_topic) {
  444. prevconn->next_topic = conn->next_topic;
  445. edge_type = EDGE_EXIT;
  446. goto send_end;
  447. }
  448. log(LOG_ERR,"circuit_about_to_close_connection(): edge conn not in circuit's list?");
  449. assert(0); /* should never get here */
  450. send_end:
  451. if(edge_type == EDGE_AP) { /* send to circ->n_conn */
  452. log(LOG_INFO,"circuit_about_to_close_connection(): send data end forward (aci %d).",circ->n_aci);
  453. cell.aci = circ->n_aci;
  454. } else { /* send to circ->p_conn */
  455. assert(edge_type == EDGE_EXIT);
  456. log(LOG_INFO,"circuit_about_to_close_connection(): send data end backward (aci %d).",circ->p_aci);
  457. cell.aci = circ->p_aci;
  458. }
  459. if(circuit_deliver_data_cell_from_edge(&cell, circ, edge_type) < 0) {
  460. log(LOG_DEBUG,"circuit_about_to_close_connection(): circuit_deliver_data_cell_from_edge (%d) failed. Closing.", edge_type);
  461. circuit_close(circ);
  462. }
  463. return;
  464. }
  465. while((circ = circuit_get_by_conn(conn))) {
  466. circuit_remove(circ);
  467. if(circ->n_conn == conn) /* it's closing in front of us */
  468. for(tmpconn=circ->p_conn; tmpconn; tmpconn=tmpconn->next_topic) {
  469. connection_send_destroy(circ->p_aci, tmpconn);
  470. }
  471. if(circ->p_conn == conn) /* it's closing behind us */
  472. for(tmpconn=circ->n_conn; tmpconn; tmpconn=tmpconn->next_topic) {
  473. connection_send_destroy(circ->n_aci, tmpconn);
  474. }
  475. circuit_free(circ);
  476. }
  477. }
  478. /* FIXME this now leaves some out */
  479. void circuit_dump_by_conn(connection_t *conn) {
  480. circuit_t *circ;
  481. connection_t *tmpconn;
  482. for(circ=global_circuitlist;circ;circ = circ->next) {
  483. for(tmpconn=circ->p_conn; tmpconn; tmpconn=tmpconn->next_topic) {
  484. if(tmpconn == conn) {
  485. printf("Conn %d has App-ward circuit: aci %d (other side %d), state %d (%s)\n",
  486. conn->poll_index, circ->p_aci, circ->n_aci, circ->state, circuit_state_to_string[circ->state]);
  487. }
  488. }
  489. for(tmpconn=circ->n_conn; tmpconn; tmpconn=tmpconn->next_topic) {
  490. if(tmpconn == conn) {
  491. printf("Conn %d has Exit-ward circuit: aci %d (other side %d), state %d (%s)\n",
  492. conn->poll_index, circ->n_aci, circ->p_aci, circ->state, circuit_state_to_string[circ->state]);
  493. }
  494. }
  495. }
  496. }