|
@@ -37,14 +37,14 @@ namespace Astrogate {
|
|
|
private async void handle_connection(SocketConnection connection) {
|
|
|
try {
|
|
|
var port = ((InetSocketAddress)connection.get_local_address()).port;
|
|
|
- print(@"New connection (port $(port))\n");
|
|
|
var buffer = yield HeaderReader.read_sample(connection.input_stream);
|
|
|
var type = HeaderReader.determine_type(buffer);
|
|
|
if(type == ConnectionType.INVALID) {
|
|
|
- print("Invalid connection type.\n");
|
|
|
+ print(@"Could not determine type of incoming connection on port $port.\n");
|
|
|
yield connection.close_async();
|
|
|
return;
|
|
|
}
|
|
|
+ print(@"New $type connection on port $(port)\n");
|
|
|
var name = HeaderReader.read_name(buffer, type);
|
|
|
if(name != null) {
|
|
|
var entry = get_entry(type, (uint16)port, name);
|
|
@@ -92,8 +92,9 @@ namespace Astrogate {
|
|
|
yield proxy.output_stream.write_async(initial_buffer.to_array(), 0);
|
|
|
yield proxy.output_stream.flush_async(0);
|
|
|
|
|
|
- proxy.output_stream.splice_async.begin(connection.input_stream, OutputStreamSpliceFlags.CLOSE_SOURCE | OutputStreamSpliceFlags.CLOSE_TARGET, 0);
|
|
|
- connection.output_stream.splice_async.begin(proxy.input_stream, OutputStreamSpliceFlags.CLOSE_SOURCE | OutputStreamSpliceFlags.CLOSE_TARGET, 0);
|
|
|
+ var cancellation_token = new Cancellable();
|
|
|
+ proxy.output_stream.splice_async.begin(connection.input_stream, OutputStreamSpliceFlags.CLOSE_SOURCE | OutputStreamSpliceFlags.CLOSE_TARGET, 0, cancellation_token, () => cancellation_token.cancel());
|
|
|
+ connection.output_stream.splice_async.begin(proxy.input_stream, OutputStreamSpliceFlags.CLOSE_SOURCE | OutputStreamSpliceFlags.CLOSE_TARGET, 0, cancellation_token, () => cancellation_token.cancel());
|
|
|
}
|
|
|
|
|
|
private async SocketConnection connect_round_robin(ConfigurationItem entry) throws Error {
|
|
@@ -141,7 +142,7 @@ namespace Astrogate {
|
|
|
return;
|
|
|
}
|
|
|
catch(Error e) {
|
|
|
- print(@"Failure during connect-first (aka. fastest), could not connect to peer: $(e.message)\n");
|
|
|
+ print(@"Failure during connect-first (aka. fastest): $(e.message)\n");
|
|
|
}
|
|
|
in_flight--;
|
|
|
connect_first_responder.callback();
|
|
@@ -156,6 +157,9 @@ namespace Astrogate {
|
|
|
print(@"In flight requests: $(in_flight)\n");
|
|
|
yield;
|
|
|
}
|
|
|
+ if(connection == null) {
|
|
|
+ throw new IOError.HOST_UNREACHABLE("Could not reach any specified forwarding host");
|
|
|
+ }
|
|
|
cancel_token.cancel();
|
|
|
return connection;
|
|
|
}
|