Merge pull request #206 from lrbalt/master

Do not panic on connection reset
This commit is contained in:
Sasha Hilton 2018-04-25 20:11:51 +02:00 committed by GitHub
commit ffb7714cb4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 36 additions and 6 deletions

View file

@ -8,7 +8,7 @@ use std::ops::Add;
use core::audio_key::AudioKey; use core::audio_key::AudioKey;
const AUDIO_AESIV: &'static [u8] = &[ const AUDIO_AESIV: &'static [u8] = &[
0x72, 0xe0, 0x67, 0xfb, 0xdd, 0xcb, 0xcf, 0x77, 0xeb, 0xe8, 0xbc, 0x64, 0x3f, 0x63, 0x0d, 0x93 0x72, 0xe0, 0x67, 0xfb, 0xdd, 0xcb, 0xcf, 0x77, 0xeb, 0xe8, 0xbc, 0x64, 0x3f, 0x63, 0x0d, 0x93,
]; ];
pub struct AudioDecrypt<T: io::Read> { pub struct AudioDecrypt<T: io::Read> {

View file

@ -1,7 +1,7 @@
use bit_set::BitSet; use bit_set::BitSet;
use byteorder::{BigEndian, ByteOrder, WriteBytesExt}; use byteorder::{BigEndian, ByteOrder, WriteBytesExt};
use futures::Stream;
use futures::sync::{mpsc, oneshot}; use futures::sync::{mpsc, oneshot};
use futures::Stream;
use futures::{Async, Future, Poll}; use futures::{Async, Future, Poll};
use std::cmp::min; use std::cmp::min;
use std::fs; use std::fs;

View file

@ -25,10 +25,10 @@ where
} }
pub fn next_packet(&mut self) -> Result<Option<VorbisPacket>, VorbisError> { pub fn next_packet(&mut self) -> Result<Option<VorbisPacket>, VorbisError> {
use self::lewton::audio::AudioReadError::AudioIsHeader;
use self::lewton::OggReadError::NoCapturePatternFound; use self::lewton::OggReadError::NoCapturePatternFound;
use self::lewton::VorbisError::BadAudio; use self::lewton::VorbisError::BadAudio;
use self::lewton::VorbisError::OggError; use self::lewton::VorbisError::OggError;
use self::lewton::audio::AudioReadError::AudioIsHeader;
loop { loop {
match self.0.read_dec_packet_itl() { match self.0.read_dec_packet_itl() {
Ok(Some(packet)) => return Ok(Some(VorbisPacket(packet))), Ok(Some(packet)) => return Ok(Some(VorbisPacket(packet))),

View file

@ -301,6 +301,10 @@ impl Future for SpircTask {
loop { loop {
let mut progress = false; let mut progress = false;
if self.session.is_invalid() {
return Ok(Async::Ready(()));
}
if !self.shutdown { if !self.shutdown {
match self.subscription.poll().unwrap() { match self.subscription.poll().unwrap() {
Async::Ready(Some(frame)) => { Async::Ready(Some(frame)) => {

View file

@ -20,6 +20,7 @@ use mercury::MercuryManager;
struct SessionData { struct SessionData {
country: String, country: String,
canonical_username: String, canonical_username: String,
invalid: bool,
} }
struct SessionInternal { struct SessionInternal {
@ -77,7 +78,9 @@ impl Session {
reusable_credentials.username.clone(), reusable_credentials.username.clone(),
); );
handle.spawn(task.map_err(|e| panic!(e))); handle.spawn(task.map_err(|e| {
error!("{:?}", e);
}));
session session
}); });
@ -104,6 +107,7 @@ impl Session {
data: RwLock::new(SessionData { data: RwLock::new(SessionData {
country: String::new(), country: String::new(),
canonical_username: username, canonical_username: username,
invalid: false,
}), }),
tx_connection: sender_tx, tx_connection: sender_tx,
@ -212,6 +216,15 @@ impl Session {
pub fn session_id(&self) -> usize { pub fn session_id(&self) -> usize {
self.0.session_id self.0.session_id
} }
pub fn shutdown(&self) {
debug!("Invalidating session[{}]", self.0.session_id);
self.0.data.write().unwrap().invalid = true;
}
pub fn is_invalid(&self) -> bool {
self.0.data.read().unwrap().invalid
}
} }
#[derive(Clone)] #[derive(Clone)]
@ -240,6 +253,7 @@ where
impl<S> Future for DispatchTask<S> impl<S> Future for DispatchTask<S>
where where
S: Stream<Item = (u8, Bytes)>, S: Stream<Item = (u8, Bytes)>,
<S as Stream>::Error: ::std::fmt::Debug,
{ {
type Item = (); type Item = ();
type Error = S::Error; type Error = S::Error;
@ -251,7 +265,15 @@ where
}; };
loop { loop {
let (cmd, data) = try_ready!(self.0.poll()).expect("connection closed"); let (cmd, data) = match self.0.poll() {
Ok(Async::Ready(t)) => t,
Ok(Async::NotReady) => return Ok(Async::NotReady),
Err(e) => {
session.shutdown();
return Err(From::from(e));
}
}.expect("connection closed");
session.dispatch(cmd, data); session.dispatch(cmd, data);
} }
} }

View file

@ -1,5 +1,5 @@
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
use super::AudioFilter; use super::AudioFilter;
use super::Mixer; use super::Mixer;

View file

@ -341,6 +341,10 @@ impl PlayerInternal {
self.handle_packet(packet, current_normalisation_factor); self.handle_packet(packet, current_normalisation_factor);
} }
} }
if self.session.is_invalid() {
return;
}
} }
} }