|
|
@ -143,34 +143,37 @@ impl VentedServer {
|
|
|
|
let event_handler = Arc::clone(&self.event_handler);
|
|
|
|
let event_handler = Arc::clone(&self.event_handler);
|
|
|
|
let connections = Arc::clone(&self.connections);
|
|
|
|
let connections = Arc::clone(&self.connections);
|
|
|
|
let pool = Arc::clone(&self.sender_pool);
|
|
|
|
let pool = Arc::clone(&self.sender_pool);
|
|
|
|
|
|
|
|
let known_nodes = Arc::clone(&self.known_nodes);
|
|
|
|
|
|
|
|
|
|
|
|
move |event| {
|
|
|
|
move |event| {
|
|
|
|
let payload = event.get_payload::<RedirectPayload>().ok()?;
|
|
|
|
let payload = event.get_payload::<RedirectPayload>().ok()?;
|
|
|
|
let event = Event::from_bytes(&mut &payload.content[..]).ok()?;
|
|
|
|
let event = Event::from_bytes(&mut &payload.content[..]).ok()?;
|
|
|
|
let proxy_stream = connections.lock().get(&payload.proxy)?.clone();
|
|
|
|
let proxy_stream = connections.lock().get(&payload.proxy)?.clone();
|
|
|
|
|
|
|
|
|
|
|
|
pool.lock().execute({
|
|
|
|
if known_nodes.lock().contains_key(&payload.source) {
|
|
|
|
let event_handler = Arc::clone(&event_handler);
|
|
|
|
pool.lock().execute({
|
|
|
|
move || {
|
|
|
|
let event_handler = Arc::clone(&event_handler);
|
|
|
|
let response = event_handler.lock().handle_event(event);
|
|
|
|
move || {
|
|
|
|
let event = response.first().cloned().map(|mut value| {
|
|
|
|
let response = event_handler.lock().handle_event(event);
|
|
|
|
Event::with_payload(
|
|
|
|
let event = response.first().cloned().map(|mut value| {
|
|
|
|
REDIRECT_EVENT,
|
|
|
|
Event::with_payload(
|
|
|
|
&RedirectPayload::new(
|
|
|
|
REDIRECT_EVENT,
|
|
|
|
payload.target,
|
|
|
|
&RedirectPayload::new(
|
|
|
|
payload.proxy,
|
|
|
|
payload.target,
|
|
|
|
payload.source,
|
|
|
|
payload.proxy,
|
|
|
|
value.as_bytes(),
|
|
|
|
payload.source,
|
|
|
|
),
|
|
|
|
value.as_bytes(),
|
|
|
|
)
|
|
|
|
),
|
|
|
|
});
|
|
|
|
)
|
|
|
|
if let Some(event) = event {
|
|
|
|
});
|
|
|
|
proxy_stream
|
|
|
|
if let Some(event) = event {
|
|
|
|
.send(event)
|
|
|
|
proxy_stream
|
|
|
|
.expect("Failed to respond to redirected event.");
|
|
|
|
.send(event)
|
|
|
|
|
|
|
|
.expect("Failed to respond to redirected event.");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
None
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|