[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] move connection_array accessors from main.c to connection.c
- To: or-cvs@freehaven.net
- Subject: [or-cvs] move connection_array accessors from main.c to connection.c
- From: arma@seul.org (Roger Dingledine)
- Date: Tue, 30 Sep 2003 15:06:25 -0400 (EDT)
- Delivered-to: archiver@seul.org
- Delivered-to: or-cvs-outgoing@seul.org
- Delivered-to: or-cvs@seul.org
- Delivery-date: Tue, 30 Sep 2003 15:06:34 -0400
- Reply-to: or-dev@freehaven.net
- Sender: owner-or-cvs@freehaven.net
Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/home2/arma/work/onion/cvs/src/or
Modified Files:
main.c connection.c or.h
Log Message:
move connection_array accessors from main.c to connection.c
(leave poll_array accessors in main.c)
Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.113
retrieving revision 1.114
diff -u -d -r1.113 -r1.114
--- main.c 30 Sep 2003 08:18:08 -0000 1.113
+++ main.c 30 Sep 2003 19:06:22 -0000 1.114
@@ -131,91 +131,9 @@
return 0;
}
-connection_t *connection_twin_get_by_addr_port(uint32_t addr, uint16_t port) {
- /* Find a connection to the router described by addr and port,
- * or alternately any router which knows its key.
- * This connection *must* be in 'open' state.
- * If not, return NULL.
- */
- int i;
- connection_t *conn;
- routerinfo_t *router;
-
- /* first check if it's there exactly */
- conn = connection_exact_get_by_addr_port(addr,port);
- if(conn && connection_state_is_open(conn)) {
- log(LOG_INFO,"connection_twin_get_by_addr_port(): Found exact match.");
- return conn;
- }
-
- /* now check if any of the other open connections are a twin for this one */
-
- router = router_get_by_addr_port(addr,port);
- if(!router)
- return NULL;
-
- for(i=0;i<nfds;i++) {
- conn = connection_array[i];
- assert(conn);
- if(connection_state_is_open(conn) &&
- !conn->marked_for_close &&
- !crypto_pk_cmp_keys(conn->onion_pkey, router->onion_pkey)) {
- log(LOG_INFO,"connection_twin_get_by_addr_port(): Found twin (%s).",conn->address);
- return conn;
- }
- }
- /* guess not */
- return NULL;
-
-}
-
-connection_t *connection_exact_get_by_addr_port(uint32_t addr, uint16_t port) {
- int i;
- connection_t *conn;
-
- for(i=0;i<nfds;i++) {
- conn = connection_array[i];
- if(conn->addr == addr && conn->port == port && !conn->marked_for_close)
- return conn;
- }
- return NULL;
-}
-
-connection_t *connection_get_by_type(int type) {
- int i;
- connection_t *conn;
-
- for(i=0;i<nfds;i++) {
- conn = connection_array[i];
- if(conn->type == type && !conn->marked_for_close)
- return conn;
- }
- return NULL;
-}
-
-connection_t *connection_get_by_type_state(int type, int state) {
- int i;
- connection_t *conn;
-
- for(i=0;i<nfds;i++) {
- conn = connection_array[i];
- if(conn->type == type && conn->state == state && !conn->marked_for_close)
- return conn;
- }
- return NULL;
-}
-
-connection_t *connection_get_by_type_state_lastwritten(int type, int state) {
- int i;
- connection_t *conn, *best=NULL;
-
- for(i=0;i<nfds;i++) {
- conn = connection_array[i];
- if(conn->type == type && conn->state == state && !conn->marked_for_close)
- if(!best || conn->timestamp_lastwritten < best->timestamp_lastwritten)
- best = conn;
- }
- return best;
+void get_connection_array(connection_t ***array, int *n) {
+ *array = connection_array;
+ *n = nfds;
}
void connection_watch_events(connection_t *conn, short events) {
@@ -740,7 +658,6 @@
circuit_dump_by_conn(conn); /* dump info about all the circuits using this conn */
printf("\n");
}
-
}
int dump_router_to_string(char *s, int maxlen, routerinfo_t *router,
Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection.c,v
retrieving revision 1.110
retrieving revision 1.111
diff -u -d -r1.110 -r1.111
--- connection.c 30 Sep 2003 18:45:54 -0000 1.110
+++ connection.c 30 Sep 2003 19:06:22 -0000 1.111
@@ -510,6 +510,99 @@
return write_to_buf(string, len, conn->outbuf);
}
+connection_t *connection_exact_get_by_addr_port(uint32_t addr, uint16_t port) {
+ int i, n;
+ connection_t *conn;
+ connection_t **carray;
+
+ get_connection_array(&carray,&n);
+ for(i=0;i<n;i++) {
+ conn = carray[i];
+ if(conn->addr == addr && conn->port == port && !conn->marked_for_close)
+ return conn;
+ }
+ return NULL;
+}
+
+connection_t *connection_twin_get_by_addr_port(uint32_t addr, uint16_t port) {
+ /* Find a connection to the router described by addr and port,
+ * or alternately any router which knows its key.
+ * This connection *must* be in 'open' state.
+ * If not, return NULL.
+ */
+ int i, n;
+ connection_t *conn;
+ routerinfo_t *router;
+ connection_t **carray;
+
+ /* first check if it's there exactly */
+ conn = connection_exact_get_by_addr_port(addr,port);
+ if(conn && connection_state_is_open(conn)) {
+ log(LOG_INFO,"connection_twin_get_by_addr_port(): Found exact match.");
+ return conn;
+ }
+
+ /* now check if any of the other open connections are a twin for this one */
+
+ router = router_get_by_addr_port(addr,port);
+ if(!router)
+ return NULL;
+
+ get_connection_array(&carray,&n);
+ for(i=0;i<n;i++) {
+ conn = carray[i];
+ assert(conn);
+ if(connection_state_is_open(conn) &&
+ !conn->marked_for_close &&
+ !crypto_pk_cmp_keys(conn->onion_pkey, router->onion_pkey)) {
+ log(LOG_INFO,"connection_twin_get_by_addr_port(): Found twin (%s).",conn->address);
+ return conn;
+ }
+ }
+ return NULL;
+}
+
+connection_t *connection_get_by_type(int type) {
+ int i, n;
+ connection_t *conn;
+ connection_t **carray;
+
+ get_connection_array(&carray,&n);
+ for(i=0;i<n;i++) {
+ conn = carray[i];
+ if(conn->type == type && !conn->marked_for_close)
+ return conn;
+ }
+ return NULL;
+}
+
+connection_t *connection_get_by_type_state(int type, int state) {
+ int i, n;
+ connection_t *conn;
+ connection_t **carray;
+
+ for(i=0;i<n;i++) {
+ conn = carray[i];
+ if(conn->type == type && conn->state == state && !conn->marked_for_close)
+ return conn;
+ }
+ return NULL;
+}
+
+connection_t *connection_get_by_type_state_lastwritten(int type, int state) {
+ int i, n;
+ connection_t *conn, *best=NULL;
+ connection_t **carray;
+
+ for(i=0;i<n;i++) {
+ conn = carray[i];
+ if(conn->type == type && conn->state == state && !conn->marked_for_close)
+ if(!best || conn->timestamp_lastwritten < best->timestamp_lastwritten)
+ best = conn;
+ }
+ return best;
+}
+
int connection_receiver_bucket_should_increase(connection_t *conn) {
assert(conn);
Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.146
retrieving revision 1.147
diff -u -d -r1.146 -r1.147
--- or.h 30 Sep 2003 18:45:54 -0000 1.146
+++ or.h 30 Sep 2003 19:06:22 -0000 1.147
@@ -540,6 +540,13 @@
int connection_handle_write(connection_t *conn);
int connection_write_to_buf(const char *string, int len, connection_t *conn);
+connection_t *connection_twin_get_by_addr_port(uint32_t addr, uint16_t port);
+connection_t *connection_exact_get_by_addr_port(uint32_t addr, uint16_t port);
+
+connection_t *connection_get_by_type(int type);
+connection_t *connection_get_by_type_state(int type, int state);
+connection_t *connection_get_by_type_state_lastwritten(int type, int state);
+
int connection_receiver_bucket_should_increase(connection_t *conn);
#define connection_speaks_cells(conn) ((conn)->type == CONN_TYPE_OR)
@@ -612,13 +619,6 @@
int connection_add(connection_t *conn);
int connection_remove(connection_t *conn);
void connection_set_poll_socket(connection_t *conn);
-
-connection_t *connection_twin_get_by_addr_port(uint32_t addr, uint16_t port);
-connection_t *connection_exact_get_by_addr_port(uint32_t addr, uint16_t port);
-
-connection_t *connection_get_by_type(int type);
-connection_t *connection_get_by_type_state(int type, int state);
-connection_t *connection_get_by_type_state_lastwritten(int type, int state);
void connection_watch_events(connection_t *conn, short events);
int connection_is_reading(connection_t *conn);