Compare commits

..

No commits in common. "9ea54102aff385c782fd6f46d7a5d71e6f756b72" and "401fd144cd666b595cd343cfc7cb45940c1eae08" have entirely different histories.

2 changed files with 7 additions and 20 deletions

View file

@ -277,12 +277,6 @@ impl AccessorySocket {
Ok(packet) Ok(packet)
} }
async fn reconnect(&mut self) -> Result<TcpStream, std::io::Error> {
self.socket.flush().await?;
self.socket.shutdown().await?;
TcpStream::connect(format!("{}:{}", self.ip, self.port)).await
}
async fn get_next(&mut self) -> Result<Vec<u8>, HomekitError> { async fn get_next(&mut self) -> Result<Vec<u8>, HomekitError> {
// max packet size + authtag size + associated data size // max packet size + authtag size + associated data size
let mut buf = [0; 1024 + 16 + 2]; let mut buf = [0; 1024 + 16 + 2];
@ -292,26 +286,19 @@ impl AccessorySocket {
while read_num == 0 { while read_num == 0 {
if tries > 20 { if tries > 20 {
log::error!("reconnect unsuccessful"); log::error!("unsuccessfully tried to reconnect");
return Err(ConnectionError::Http.into()); return Err(ConnectionError::Http.into());
} }
tries += 1; tries += 1;
log::info!("read 0 bytes - about to reconnect"); log::info!("read 0 bytes - about to reconnect");
std::thread::sleep(std::time::Duration::from_millis(200)); std::thread::sleep(std::time::Duration::from_millis(200));
self.socket.flush().await?;
match tokio::time::timeout(Duration::from_secs(5), self.reconnect()).await { log::warn!("reconnecting...");
Ok(Ok(socket)) => self.socket = socket, self.socket = TcpStream::connect(format!("{}:{}", self.ip, self.port)).await?;
_ => continue,
}
read_num = read_num = self.socket.read(&mut buf).await?;
match tokio::time::timeout(Duration::from_secs(5), self.socket.read(&mut buf)).await
{
Ok(Ok(val)) => val,
_ => continue,
}
} }
if let Some(encryption) = self.socket_encryption.as_mut() { if let Some(encryption) = self.socket_encryption.as_mut() {
let associated_data: [u8; 2] = buf[..2].try_into()?; let associated_data: [u8; 2] = buf[..2].try_into()?;
let length = u16::from_le_bytes(associated_data); let length = u16::from_le_bytes(associated_data);

View file

@ -686,7 +686,7 @@ impl From<CharacteristicTypeInner> for CharacteristicType {
fn from(value: CharacteristicTypeInner) -> Self { fn from(value: CharacteristicTypeInner) -> Self {
match value { match value {
CharacteristicTypeInner::Unknown(v) => { CharacteristicTypeInner::Unknown(v) => {
log::info!("unknown characteristic type: {v}"); log::warn!("unknown characteristic type: {v}");
Self::Unknown Self::Unknown
} }
CharacteristicTypeInner::AccessControlLevel => Self::AccessControlLevel, CharacteristicTypeInner::AccessControlLevel => Self::AccessControlLevel,
@ -1206,7 +1206,7 @@ impl From<ServiceTypeInner> for ServiceType {
fn from(value: ServiceTypeInner) -> Self { fn from(value: ServiceTypeInner) -> Self {
match value { match value {
ServiceTypeInner::Unknown(v) => { ServiceTypeInner::Unknown(v) => {
log::info!("unknown service type: {v}"); log::warn!("unknown service type: {v}");
Self::Unknown Self::Unknown
} }
ServiceTypeInner::AccessControl => Self::AccessControl, ServiceTypeInner::AccessControl => Self::AccessControl,