Implemented link padding and receiver token buckets
Each socket reads at most 'bandwidth' bytes per second sustained, but
can handle bursts of up to 10*bandwidth bytes.
Cells are now sent out at evenly-spaced intervals, with padding sent
out otherwise. Set Linkpadding=0 in the rc file to send cells as soon
as they're available (and to never send padding cells).
Added license/copyrights statements at the top of most files.
router->min and router->max have been merged into a single 'bandwidth'
value. We should make the routerinfo_t reflect this (want to do that,
Mat?)
As the bandwidth increases, and we want to stop sleeping more and more
frequently to send a single cell, cpu usage goes up. At 128kB/s we're
pretty much calling poll with a timeout of 1ms or even 0ms. The current
code takes a timeout of 0-9ms and makes it 10ms. prepare_for_poll()
handles everything that should have happened in the past, so as long as
our buffers don't get too full in that 10ms, we're ok.
Speaking of too full, if you run three servers at 100kB/s with -l debug,
it spends too much time printing debugging messages to be able to keep
up with the cells. The outbuf ultimately fills up and it kills that
connection. If you run with -l err, it works fine up through 500kB/s and
probably beyond. Down the road we'll want to teach it to recognize when
an outbuf is getting full, and back off.
svn:r50
2002-07-16 03:12:15 +02:00
|
|
|
/* Copyright 2001,2002 Roger Dingledine, Matej Pfajfar. */
|
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
/* $Id$ */
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
|
|
|
|
#include "or.h"
|
|
|
|
|
|
|
|
extern int global_role; /* from main.c */
|
|
|
|
|
|
|
|
int connection_ap_process_inbuf(connection_t *conn) {
|
|
|
|
|
|
|
|
assert(conn && conn->type == CONN_TYPE_AP);
|
|
|
|
|
|
|
|
if(conn->inbuf_reached_eof) {
|
|
|
|
/* eof reached, kill it. */
|
|
|
|
log(LOG_DEBUG,"connection_ap_process_inbuf(): conn reached eof. Closing.");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2002-07-22 06:08:37 +02:00
|
|
|
// log(LOG_DEBUG,"connection_ap_process_inbuf(): state %d.",conn->state);
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
|
|
|
|
switch(conn->state) {
|
2002-09-22 13:09:07 +02:00
|
|
|
case AP_CONN_STATE_SOCKS_WAIT:
|
|
|
|
return ap_handshake_process_socks(conn);
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
case AP_CONN_STATE_OPEN:
|
|
|
|
return connection_package_raw_inbuf(conn);
|
|
|
|
default:
|
|
|
|
log(LOG_DEBUG,"connection_ap_process_inbuf() called in state where I'm waiting. Ignoring buf for now.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-09-22 13:09:07 +02:00
|
|
|
int ap_handshake_process_socks(connection_t *conn) {
|
|
|
|
char c;
|
|
|
|
socks4_t socks4_info;
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
|
|
|
|
assert(conn);
|
|
|
|
|
2002-09-22 13:09:07 +02:00
|
|
|
log(LOG_DEBUG,"ap_handshake_process_socks() entered.");
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
|
2002-09-22 13:09:07 +02:00
|
|
|
if(!conn->socks_version) { /* try to pull it in */
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
|
2002-09-22 13:09:07 +02:00
|
|
|
if(conn->inbuf_datalen < sizeof(socks4_t)) /* basic info available? */
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
return 0; /* not yet */
|
|
|
|
|
2002-09-22 13:09:07 +02:00
|
|
|
if(connection_fetch_from_buf((char *)&socks4_info,sizeof(socks4_t),conn) < 0)
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
return -1;
|
|
|
|
|
2002-09-22 13:09:07 +02:00
|
|
|
log(LOG_DEBUG,"ap_handshake_process_socks(): Successfully read socks info.");
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
|
2002-09-22 13:09:07 +02:00
|
|
|
if(socks4_info.version != 4) {
|
|
|
|
log(LOG_NOTICE,"ap_handshake_process_socks(): Unrecognized version %d.",socks4_info.version);
|
|
|
|
ap_handshake_socks_reply(conn, SOCKS4_REQUEST_REJECT);
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2002-09-22 13:09:07 +02:00
|
|
|
conn->socks_version = socks4_info.version;
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
|
2002-09-22 13:09:07 +02:00
|
|
|
if(socks4_info.command != 1) { /* not a connect? we don't support it. */
|
|
|
|
log(LOG_NOTICE,"ap_handshake_process_socks(): command %d not '1'.",socks4_info.command);
|
|
|
|
ap_handshake_socks_reply(conn, SOCKS4_REQUEST_REJECT);
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2002-09-22 13:09:07 +02:00
|
|
|
conn->dest_port = ntohs(*(uint16_t*)&socks4_info.destport);
|
|
|
|
if(!conn->dest_port) {
|
|
|
|
log(LOG_NOTICE,"ap_handshake_process_socks(): Port is zero.");
|
|
|
|
ap_handshake_socks_reply(conn, SOCKS4_REQUEST_REJECT);
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2002-09-22 13:09:07 +02:00
|
|
|
log(LOG_NOTICE,"ap_handshake_process_socks(): Dest port is %d.",conn->dest_port);
|
|
|
|
|
|
|
|
if(socks4_info.destip[0] ||
|
|
|
|
socks4_info.destip[1] ||
|
|
|
|
socks4_info.destip[2] ||
|
|
|
|
!socks4_info.destip[3]) { /* must be in form 0.0.0.x, at least for now */
|
|
|
|
log(LOG_NOTICE,"ap_handshake_process_socks(): destip not in form 0.0.0.x.");
|
|
|
|
ap_handshake_socks_reply(conn, SOCKS4_REQUEST_REJECT);
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
return -1;
|
2002-09-22 13:09:07 +02:00
|
|
|
}
|
|
|
|
log(LOG_DEBUG,"ap_handshake_process_socks(): Successfully read destip (0.0.0.x.)");
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-09-22 13:09:07 +02:00
|
|
|
if(!conn->read_username) { /* the socks spec says we've got to read stuff until we get a null */
|
2002-09-23 03:04:59 +02:00
|
|
|
for(;;) {
|
|
|
|
if(!conn->inbuf_datalen)
|
|
|
|
return 0; /* maybe next time */
|
2002-09-22 13:09:07 +02:00
|
|
|
if(connection_fetch_from_buf((char *)&c,1,conn) < 0)
|
|
|
|
return -1;
|
|
|
|
if(!c) {
|
|
|
|
conn->read_username = 1;
|
|
|
|
log(LOG_DEBUG,"ap_handshake_process_socks(): Successfully read username.");
|
|
|
|
break;
|
|
|
|
}
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-22 13:09:07 +02:00
|
|
|
if(!conn->dest_addr) { /* no dest_addr found yet */
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
|
2002-09-23 03:04:59 +02:00
|
|
|
for(;;) {
|
|
|
|
if(!conn->inbuf_datalen)
|
|
|
|
return 0; /* maybe next time */
|
2002-09-22 13:09:07 +02:00
|
|
|
if(connection_fetch_from_buf((char *)&c,1,conn) < 0)
|
|
|
|
return -1;
|
2002-09-23 03:04:59 +02:00
|
|
|
conn->dest_tmp[conn->dest_tmplen++] = c;
|
|
|
|
if(conn->dest_tmplen > 500) {
|
2002-09-22 13:09:07 +02:00
|
|
|
log(LOG_NOTICE,"ap_handshake_process_socks(): dest_addr too long!");
|
|
|
|
ap_handshake_socks_reply(conn, SOCKS4_REQUEST_REJECT);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if(!c) { /* we found the null; we're done */
|
2002-09-23 03:04:59 +02:00
|
|
|
conn->dest_addr = strdup(conn->dest_tmp);
|
2002-09-22 13:09:07 +02:00
|
|
|
log(LOG_NOTICE,"ap_handshake_process_socks(): successfully read dest addr '%s'",
|
|
|
|
conn->dest_addr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* now we're all ready to make an onion, etc */
|
|
|
|
return ap_handshake_create_onion(conn);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ap_handshake_create_onion(connection_t *conn) {
|
|
|
|
int i;
|
|
|
|
int routelen = 0; /* length of the route */
|
|
|
|
unsigned int *route = NULL; /* hops in the route as an array of indexes into rarray */
|
|
|
|
unsigned char *onion = NULL; /* holds the onion */
|
|
|
|
int onionlen = 0; /* onion length in host order */
|
|
|
|
crypt_path_t **cpath = NULL; /* defines the crypt operations that need to be performed on incoming/outgoing data */
|
|
|
|
|
|
|
|
assert(conn);
|
|
|
|
|
|
|
|
/* choose a route */
|
|
|
|
route = (unsigned int *)router_new_route(&routelen);
|
|
|
|
if (!route) {
|
|
|
|
log(LOG_ERR,"ap_handshake_create_onion(): Error choosing a route through the OR network.");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
log(LOG_DEBUG,"ap_handshake_create_onion(): Chosen a route of length %u : ",routelen);
|
|
|
|
#if 0
|
|
|
|
for (i=routelen-1;i>=0;i--)
|
|
|
|
{
|
|
|
|
log(LOG_DEBUG,"ap_handshake_process_ss() : %u : %s:%u, %u",routelen-i,(routerarray[route[i]])->address,ntohs((routerarray[route[i]])->port),RSA_size((routerarray[route[i]])->pkey));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* allocate memory for the crypt path */
|
|
|
|
cpath = malloc(routelen * sizeof(crypt_path_t *));
|
|
|
|
if (!cpath) {
|
|
|
|
log(LOG_ERR,"ap_handshake_create_onion(): Error allocating memory for cpath.");
|
|
|
|
free(route);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create an onion and calculate crypto keys */
|
|
|
|
onion = router_create_onion(route,routelen,&onionlen,cpath);
|
|
|
|
if (!onion) {
|
|
|
|
log(LOG_ERR,"ap_handshake_create_onion(): Error creating an onion.");
|
|
|
|
free(route);
|
|
|
|
free(cpath); /* it's got nothing in it, since !onion */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
log(LOG_DEBUG,"ap_handshake_create_onion(): Created an onion of size %u bytes.",onionlen);
|
|
|
|
log(LOG_DEBUG,"ap_handshake_create_onion(): Crypt path :");
|
|
|
|
for (i=0;i<routelen;i++) {
|
|
|
|
log(LOG_DEBUG,"ap_handshake_create_onion() : %u/%u",(cpath[i])->forwf, (cpath[i])->backf);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ap_handshake_establish_circuit(conn, route, routelen, onion, onionlen, cpath);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ap_handshake_establish_circuit(connection_t *conn, unsigned int *route, int routelen, char *onion,
|
|
|
|
int onionlen, crypt_path_t **cpath) {
|
|
|
|
routerinfo_t *firsthop;
|
|
|
|
connection_t *n_conn;
|
|
|
|
circuit_t *circ;
|
|
|
|
|
|
|
|
/* now see if we're already connected to the first OR in 'route' */
|
|
|
|
firsthop = router_get_first_in_route(route, routelen);
|
|
|
|
assert(firsthop); /* should always be defined */
|
|
|
|
free(route); /* we don't need it anymore */
|
|
|
|
|
|
|
|
circ = circuit_new(0, conn); /* sets circ->p_aci and circ->p_conn */
|
|
|
|
circ->state = CIRCUIT_STATE_OR_WAIT;
|
|
|
|
circ->onion = onion;
|
|
|
|
circ->onionlen = onionlen;
|
|
|
|
circ->cpath = cpath;
|
|
|
|
circ->cpathlen = routelen;
|
|
|
|
|
|
|
|
log(LOG_DEBUG,"ap_handshake_establish_circuit(): Looking for firsthop '%s:%u'",
|
2002-08-24 09:55:49 +02:00
|
|
|
firsthop->address,firsthop->or_port);
|
2002-07-08 10:59:15 +02:00
|
|
|
n_conn = connection_twin_get_by_addr_port(firsthop->addr,firsthop->or_port);
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
if(!n_conn) { /* not currently connected */
|
2002-07-19 01:44:57 +02:00
|
|
|
circ->n_addr = firsthop->addr;
|
|
|
|
circ->n_port = firsthop->or_port;
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
if(global_role & ROLE_OR_CONNECT_ALL) { /* we would be connected if he were up. but he's not. */
|
|
|
|
log(LOG_DEBUG,"ap_handshake_establish_circuit(): Route's firsthop isn't connected.");
|
|
|
|
circuit_close(circ);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ok, launch the connection */
|
|
|
|
n_conn = connect_to_router_as_op(firsthop);
|
|
|
|
if(!n_conn) { /* connect failed, forget the whole thing */
|
|
|
|
log(LOG_DEBUG,"ap_handshake_establish_circuit(): connect to firsthop failed. Closing.");
|
|
|
|
circuit_close(circ);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
conn->state = AP_CONN_STATE_OR_WAIT;
|
2002-07-19 01:44:57 +02:00
|
|
|
connection_stop_reading(conn); /* Stop listening for input from the AP! */
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
return 0; /* return success. The onion/circuit/etc will be taken care of automatically
|
|
|
|
* (may already have been) whenever n_conn reaches OR_CONN_STATE_OPEN.
|
|
|
|
*/
|
2002-07-19 01:44:57 +02:00
|
|
|
} else { /* it (or a twin) is already open. use it. */
|
|
|
|
circ->n_addr = n_conn->addr;
|
|
|
|
circ->n_port = n_conn->port;
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
return ap_handshake_send_onion(conn, n_conn, circ);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find the circ that's waiting on me, if any, and get it to send its onion */
|
|
|
|
int ap_handshake_n_conn_open(connection_t *or_conn) {
|
|
|
|
circuit_t *circ;
|
|
|
|
|
|
|
|
log(LOG_DEBUG,"ap_handshake_n_conn_open(): Starting.");
|
|
|
|
circ = circuit_get_by_naddr_nport(or_conn->addr, or_conn->port);
|
|
|
|
if(!circ)
|
2002-07-19 01:44:57 +02:00
|
|
|
return 0; /* i'm ok with that. no need to close the connection or anything. */
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
|
|
|
|
if(circ->p_conn->state != AP_CONN_STATE_OR_WAIT) {
|
|
|
|
log(LOG_DEBUG,"Bug: ap_handshake_n_conn_open() got an ap_conn not in OR_WAIT state.");
|
|
|
|
}
|
2002-07-19 01:44:57 +02:00
|
|
|
connection_start_reading(circ->p_conn); /* resume listening for reads */
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
log(LOG_DEBUG,"ap_handshake_n_conn_open(): Found circ, sending onion.");
|
|
|
|
return ap_handshake_send_onion(circ->p_conn, or_conn, circ);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ap_handshake_send_onion(connection_t *ap_conn, connection_t *n_conn, circuit_t *circ) {
|
|
|
|
cell_t cell;
|
|
|
|
int tmpbuflen, dataleft;
|
|
|
|
char *tmpbuf;
|
|
|
|
|
|
|
|
circ->n_aci = get_unique_aci_by_addr_port(circ->n_addr, circ->n_port, ACI_TYPE_BOTH);
|
|
|
|
circ->n_conn = n_conn;
|
2002-08-24 09:55:49 +02:00
|
|
|
log(LOG_DEBUG,"ap_handshake_send_onion(): n_conn is %s:%u",n_conn->address,n_conn->port);
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
|
|
|
|
/* deliver the onion as one or more create cells */
|
|
|
|
cell.command = CELL_CREATE;
|
|
|
|
cell.aci = circ->n_aci;
|
|
|
|
|
|
|
|
tmpbuflen = circ->onionlen+4;
|
|
|
|
tmpbuf = malloc(tmpbuflen);
|
|
|
|
if(!tmpbuf)
|
|
|
|
return -1;
|
2002-08-24 09:55:49 +02:00
|
|
|
*(uint32_t*)tmpbuf = htonl(circ->onionlen);
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
memcpy(tmpbuf+4, circ->onion, circ->onionlen);
|
|
|
|
|
|
|
|
dataleft = tmpbuflen;
|
|
|
|
while(dataleft) {
|
|
|
|
cell.command = CELL_CREATE;
|
|
|
|
cell.aci = circ->n_aci;
|
|
|
|
log(LOG_DEBUG,"ap_handshake_send_onion(): Sending a create cell for the onion...");
|
|
|
|
if(dataleft >= CELL_PAYLOAD_SIZE) {
|
|
|
|
cell.length = CELL_PAYLOAD_SIZE;
|
|
|
|
memcpy(cell.payload, tmpbuf + tmpbuflen - dataleft, CELL_PAYLOAD_SIZE);
|
|
|
|
connection_write_cell_to_buf(&cell, n_conn); /* clobbers cell */
|
|
|
|
dataleft -= CELL_PAYLOAD_SIZE;
|
|
|
|
} else { /* last cell */
|
|
|
|
cell.length = dataleft;
|
|
|
|
memcpy(cell.payload, tmpbuf + tmpbuflen - dataleft, dataleft);
|
|
|
|
connection_write_cell_to_buf(&cell, n_conn); /* clobbers cell */
|
|
|
|
dataleft = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(tmpbuf);
|
|
|
|
|
2002-09-22 13:09:07 +02:00
|
|
|
#if 0
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
/* deliver the ss in a data cell */
|
|
|
|
cell.command = CELL_DATA;
|
|
|
|
cell.aci = circ->n_aci;
|
|
|
|
cell.length = sizeof(ss_t);
|
|
|
|
memcpy(cell.payload, &ap_conn->ss, sizeof(ss_t));
|
|
|
|
log(LOG_DEBUG,"ap_handshake_send_onion(): Sending a data cell for ss...");
|
|
|
|
if(circuit_deliver_data_cell(&cell, circ, circ->n_conn, 'e') < 0) {
|
|
|
|
log(LOG_DEBUG,"ap_handshake_send_onion(): failed to deliver ss cell. Closing.");
|
|
|
|
circuit_close(circ);
|
|
|
|
return -1;
|
|
|
|
}
|
2002-09-22 13:09:07 +02:00
|
|
|
#endif
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
|
|
|
|
/* deliver the dest_addr in a data cell */
|
|
|
|
cell.command = CELL_DATA;
|
|
|
|
cell.aci = circ->n_aci;
|
2002-09-22 13:09:07 +02:00
|
|
|
strncpy(cell.payload, ap_conn->dest_addr, CELL_PAYLOAD_SIZE);
|
|
|
|
cell.length = strlen(cell.payload)+1;
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
log(LOG_DEBUG,"ap_handshake_send_onion(): Sending a data cell for addr...");
|
|
|
|
if(circuit_deliver_data_cell(&cell, circ, circ->n_conn, 'e') < 0) {
|
|
|
|
log(LOG_DEBUG,"ap_handshake_send_onion(): failed to deliver addr cell. Closing.");
|
|
|
|
circuit_close(circ);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* deliver the dest_port in a data cell */
|
|
|
|
cell.command = CELL_DATA;
|
|
|
|
cell.aci = circ->n_aci;
|
2002-09-22 13:09:07 +02:00
|
|
|
snprintf(cell.payload, CELL_PAYLOAD_SIZE, "%d", ap_conn->dest_port);
|
|
|
|
cell.length = strlen(cell.payload)+1;
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
log(LOG_DEBUG,"ap_handshake_send_onion(): Sending a data cell for port...");
|
|
|
|
if(circuit_deliver_data_cell(&cell, circ, circ->n_conn, 'e') < 0) {
|
|
|
|
log(LOG_DEBUG,"ap_handshake_send_onion(): failed to deliver port cell. Closing.");
|
|
|
|
circuit_close(circ);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
circ->state = CIRCUIT_STATE_OPEN;
|
|
|
|
ap_conn->state = AP_CONN_STATE_OPEN;
|
2002-07-22 06:08:37 +02:00
|
|
|
log(LOG_INFO,"ap_handshake_send_onion(): Address/port sent, ap socket %d, n_aci %d",ap_conn->s,circ->n_aci);
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
|
|
|
|
/* FIXME should set circ->expire to something here */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-09-22 13:09:07 +02:00
|
|
|
int ap_handshake_socks_reply(connection_t *conn, char result) {
|
|
|
|
socks4_t socks4_info;
|
2002-09-17 10:14:37 +02:00
|
|
|
|
|
|
|
assert(conn);
|
|
|
|
|
2002-09-22 13:09:07 +02:00
|
|
|
socks4_info.version = 4;
|
|
|
|
socks4_info.command = result;
|
|
|
|
socks4_info.destport[0] = socks4_info.destport[1] = 0;
|
|
|
|
socks4_info.destip[0] = socks4_info.destip[1] = socks4_info.destip[2] = socks4_info.destip[3] = 0;
|
|
|
|
|
|
|
|
connection_write_to_buf((char *)&socks4_info, sizeof(socks4_t), conn);
|
|
|
|
return connection_flush_buf(conn); /* try to flush it, in case we're about to close the conn */
|
|
|
|
}
|
|
|
|
|
|
|
|
int connection_ap_send_connected(connection_t *conn) {
|
|
|
|
assert(conn);
|
|
|
|
|
|
|
|
return ap_handshake_socks_reply(conn, SOCKS4_REQUEST_GRANTED);
|
2002-09-17 10:14:37 +02:00
|
|
|
}
|
|
|
|
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
int connection_ap_process_data_cell(cell_t *cell, connection_t *conn) {
|
|
|
|
|
|
|
|
/* an incoming data cell has arrived */
|
|
|
|
|
|
|
|
assert(conn && conn->type == CONN_TYPE_AP);
|
|
|
|
|
2002-07-18 08:37:58 +02:00
|
|
|
if(conn->state != AP_CONN_STATE_OPEN) {
|
|
|
|
/* we should not have gotten this cell */
|
|
|
|
log(LOG_DEBUG,"connection_ap_process_data_cell(): Got a data cell when not in 'open' state. Closing.");
|
|
|
|
return -1;
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
}
|
|
|
|
|
2002-07-22 06:08:37 +02:00
|
|
|
// log(LOG_DEBUG,"connection_ap_process_data_cell(): In state 'open', writing to buf.");
|
2002-07-18 08:37:58 +02:00
|
|
|
|
|
|
|
if(connection_write_to_buf(cell->payload, cell->length, conn) < 0)
|
|
|
|
return -1;
|
|
|
|
return connection_consider_sending_sendme(conn);
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int connection_ap_finished_flushing(connection_t *conn) {
|
|
|
|
|
|
|
|
assert(conn && conn->type == CONN_TYPE_AP);
|
|
|
|
|
|
|
|
switch(conn->state) {
|
|
|
|
case AP_CONN_STATE_OPEN:
|
|
|
|
/* FIXME down the road, we'll clear out circuits that are pending to close */
|
2002-07-18 08:37:58 +02:00
|
|
|
connection_stop_writing(conn);
|
2002-09-09 06:06:59 +02:00
|
|
|
return connection_consider_sending_sendme(conn);
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
default:
|
|
|
|
log(LOG_DEBUG,"Bug: connection_ap_finished_flushing() called in unexpected state.");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-08-22 09:30:03 +02:00
|
|
|
int connection_ap_create_listener(crypto_pk_env_t *prkey, struct sockaddr_in *local) {
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
log(LOG_DEBUG,"connection_create_ap_listener starting");
|
|
|
|
return connection_create_listener(prkey, local, CONN_TYPE_AP_LISTENER);
|
|
|
|
}
|
|
|
|
|
|
|
|
int connection_ap_handle_listener_read(connection_t *conn) {
|
2002-09-22 13:09:07 +02:00
|
|
|
log(LOG_NOTICE,"AP: Received a connection request. Waiting for socksinfo.");
|
|
|
|
return connection_handle_listener_read(conn, CONN_TYPE_AP, AP_CONN_STATE_SOCKS_WAIT);
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
}
|
|
|
|
|