diff --git a/Dockerfile b/Dockerfile index 34c52ed..376aa1e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,8 +8,6 @@ FROM docker.io/rust:slim-bookworm AS build ARG TARGETPLATFORM ENV DEBIAN_FRONTEND=noninteractive - - WORKDIR /usr/local/src/neolink COPY . /usr/local/src/neolink @@ -85,6 +83,8 @@ RUN gst-inspect-1.0; \ "/usr/local/bin/neolink" --version && \ mkdir -m 0700 /root/.config/ # Location that the push notifications are cached to -CMD ["/usr/local/bin/neolink", "rtsp", "--config", "/etc/neolink.toml"] +ENV NEO_LINK_MODE="rtsp" NEO_LINK_PORT=8554 + +CMD /usr/local/bin/neolink ${NEO_LINK_MODE} --config /etc/neolink.toml ENTRYPOINT ["/entrypoint.sh"] -EXPOSE 8554 +EXPOSE ${NEO_LINK_PORT} diff --git a/README.md b/README.md index 7d69c01..84f3a6f 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ features not yet in upstream master. **Minor Features**: - Improved error messages when missing gstreamer plugins -- Protocol more closely follows offical reolink format +- Protocol more closely follows official reolink format - Possibly can handle more simulatenous connections - More ways to connect to the camera. Including Relaying through reolink servers @@ -50,7 +50,7 @@ Install the latest [gstreamer](https://gstreamer.freedesktop.org/download/) (1.20.5 as of writing this). - **Windows**: ensure you install `full` when prompted in the MSI options. -- **Mac**: Install the dpkg version on the offical gstreamer website over +- **Mac**: Install the dpkg version on the official gstreamer website over the brew version - **Ubuntu/Debian**: These packages should work @@ -269,7 +269,7 @@ reflected in the rtsp These include changing the: -- Avaliable users +- Available users ```toml [[users]] @@ -284,7 +284,7 @@ These include changing the: permitted_users = [ "me" ] ``` -- Avaliable streams +- Available streams ```toml [[cameras]] @@ -324,7 +324,7 @@ enable_motion = false # motion detection # (limited battery drain since it # is a passive listening connection) # -enable_light = false # flood lights only avaliable on some camera +enable_light = false # flood lights only available on some camera # (limited battery drain since it # is a passive listening connection) # @@ -355,7 +355,7 @@ must be manually specified. features = ["floodlight"] ``` -Avaliable features are: +Available features are: - `floodlight`: This adds a light control to home assistant - `camera`: This adds a camera preview to home assistant. It is only updated @@ -456,6 +456,10 @@ docker pull quantumentangledandy/neolink # network=host, notably macos lacks this option. docker run --network host --volume=$PWD/config.toml:/etc/neolink.toml quantumentangledandy/neolink ``` +#### Environmental Variables +There are currently 2 environmental variables available as part of the container: +- `NEO_LINK_MODE`: defaults to `"rtsp"` if not set, other options are "mqtt" or "mqtt-rtsp". +- `NEO_LINK_PORT`: defaults to `8554`, set this to your required port value. ### Image diff --git a/crates/core/src/bc/de.rs b/crates/core/src/bc/de.rs index 05dffd4..d650a0f 100644 --- a/crates/core/src/bc/de.rs +++ b/crates/core/src/bc/de.rs @@ -448,7 +448,7 @@ mod tests { #[test] // B800 seems to have a different header to the E1 and swann cameras - // the stream_type and message_num do not seem to set in the offical clients + // the stream_type and message_num do not seem to set in the official clients // // They also have extra streams fn test_bc_b800_externstream() { @@ -492,7 +492,7 @@ mod tests { #[test] // B800 seems to have a different header to the E1 and swann cameras - // the stream_type and message_num do not seem to set in the offical clients + // the stream_type and message_num do not seem to set in the official clients // // They also have extra streams fn test_bc_b800_substream() { @@ -536,7 +536,7 @@ mod tests { #[test] // B800 seems to have a different header to the E1 and swann cameras - // the stream_type and message_num do not seem to set in the offical clients + // the stream_type and message_num do not seem to set in the official clients // // They also have extra streams fn test_bc_b800_mainstream() { diff --git a/crates/core/src/bc/xml.rs b/crates/core/src/bc/xml.rs index 4a56e34..b0eaaaf 100644 --- a/crates/core/src/bc/xml.rs +++ b/crates/core/src/bc/xml.rs @@ -280,7 +280,7 @@ pub struct Extension { #[serde(rename = "binaryData", skip_serializing_if = "Option::is_none")] pub binary_data: Option, /// Certain requests such `AbilitySupport` require to know which user this - /// ability support request is for (why camera dosen't know this based on who + /// ability support request is for (why camera doesn't know this based on who /// is logged in is unknown... Possible security hole) #[serde(rename = "userName", skip_serializing_if = "Option::is_none")] pub user_name: Option, diff --git a/crates/core/src/bc_protocol/abilityinfo.rs b/crates/core/src/bc_protocol/abilityinfo.rs index cbf97a7..4bd750a 100644 --- a/crates/core/src/bc_protocol/abilityinfo.rs +++ b/crates/core/src/bc_protocol/abilityinfo.rs @@ -30,7 +30,7 @@ impl BcCamera { sub_get.send(get).await?; let msg = sub_get.recv().await?; if msg.meta.response_code != 200 { - return Err(Error::CameraServiceUnavaliable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); } if let BcBody::ModernMsg(ModernMsg { diff --git a/crates/core/src/bc_protocol/connection/discovery.rs b/crates/core/src/bc_protocol/connection/discovery.rs index 804e81c..8c5434a 100644 --- a/crates/core/src/bc_protocol/connection/discovery.rs +++ b/crates/core/src/bc_protocol/connection/discovery.rs @@ -248,7 +248,7 @@ impl Discoverer { tokio::select! { v = async { loop { - let (reply, addr) = reply.next().await.ok_or(Error::ConnectionUnavaliable)??; + let (reply, addr) = reply.next().await.ok_or(Error::ConnectionUnavailable)??; if let Some(result) = map(reply, addr) { return Ok(result); } diff --git a/crates/core/src/bc_protocol/credentials.rs b/crates/core/src/bc_protocol/credentials.rs index ccff7e2..19eb411 100644 --- a/crates/core/src/bc_protocol/credentials.rs +++ b/crates/core/src/bc_protocol/credentials.rs @@ -7,7 +7,7 @@ use std::convert::TryInto; pub struct Credentials { /// The username to login to the camera with pub username: String, - /// The password to use for login. Some camera allow this to be ommited + /// The password to use for login. Some camera allow this to be omitted pub password: Option, } diff --git a/crates/core/src/bc_protocol/errors.rs b/crates/core/src/bc_protocol/errors.rs index e3ade19..dea3489 100644 --- a/crates/core/src/bc_protocol/errors.rs +++ b/crates/core/src/bc_protocol/errors.rs @@ -36,8 +36,8 @@ pub enum Error { }, /// Raised when the camera responds with a status code over than OK - #[error("Camera responded with Service Unavaliable: {}", _0)] - CameraServiceUnavaliable(u16), + #[error("Camera responded with Service Unavaliable: {0}")] + CameraServiceUnavailable(u16), /// Raised when the camera responds with a status code over than OK during login #[error("Camera responded with Err during login")] @@ -115,7 +115,7 @@ pub enum Error { /// Raised when the camera cannot be found #[error("Camera Not Findable")] - ConnectionUnavaliable, + ConnectionUnavailable, /// Raised when the subscription id dropped too soon #[error("Dropped Subscriber")] diff --git a/crates/core/src/bc_protocol/floodlight.rs b/crates/core/src/bc_protocol/floodlight.rs index 76b320f..0e59715 100644 --- a/crates/core/src/bc_protocol/floodlight.rs +++ b/crates/core/src/bc_protocol/floodlight.rs @@ -129,7 +129,7 @@ impl BcCamera { sub_get.send(get).await?; let msg = sub_get.recv().await?; if msg.meta.response_code != 200 { - return Err(Error::CameraServiceUnavaliable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); } if let BcBody::ModernMsg(ModernMsg { @@ -181,7 +181,7 @@ impl BcCamera { sub_get.send(get).await?; let msg = sub_get.recv().await?; if msg.meta.response_code != 200 { - return Err(Error::CameraServiceUnavaliable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); } Ok(()) diff --git a/crates/core/src/bc_protocol/keepalive.rs b/crates/core/src/bc_protocol/keepalive.rs index 3de5cbc..b1c7f31 100644 --- a/crates/core/src/bc_protocol/keepalive.rs +++ b/crates/core/src/bc_protocol/keepalive.rs @@ -2,7 +2,7 @@ use super::{BcCamera, Result}; use crate::bc::model::*; impl BcCamera { - /// Create a handller to respond to keep alive messages + /// Create a handler to respond to keep alive messages /// These messages are sent by the camera so we listen to /// a message ID rather than setting a message number and /// responding to it diff --git a/crates/core/src/bc_protocol/ledstate.rs b/crates/core/src/bc_protocol/ledstate.rs index a2a8d26..c6a01da 100644 --- a/crates/core/src/bc_protocol/ledstate.rs +++ b/crates/core/src/bc_protocol/ledstate.rs @@ -29,7 +29,7 @@ impl BcCamera { sub_get.send(get).await?; let msg = sub_get.recv().await?; if msg.meta.response_code != 200 { - return Err(Error::CameraServiceUnavaliable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); } if let BcBody::ModernMsg(ModernMsg { diff --git a/crates/core/src/bc_protocol/link.rs b/crates/core/src/bc_protocol/link.rs index f81c0ec..10db6ff 100644 --- a/crates/core/src/bc_protocol/link.rs +++ b/crates/core/src/bc_protocol/link.rs @@ -27,7 +27,7 @@ impl BcCamera { sub_get.send(get).await?; let msg = sub_get.recv().await?; if msg.meta.response_code != 200 { - return Err(Error::CameraServiceUnavaliable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); } if let BcBody::ModernMsg(ModernMsg { diff --git a/crates/core/src/bc_protocol/pirstate.rs b/crates/core/src/bc_protocol/pirstate.rs index a5242e0..94b5ffb 100644 --- a/crates/core/src/bc_protocol/pirstate.rs +++ b/crates/core/src/bc_protocol/pirstate.rs @@ -39,10 +39,10 @@ impl BcCamera { reties += 1; continue; } else { - return Err(Error::CameraServiceUnavaliable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); } } else if msg.meta.response_code != 200 { - return Err(Error::CameraServiceUnavaliable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); } else { // Valid message with response_code == 200 if let BcBody::ModernMsg(ModernMsg { @@ -101,7 +101,7 @@ impl BcCamera { { let msg = reply?; if msg.meta.response_code != 200 { - return Err(Error::CameraServiceUnavaliable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); } if let BcMeta { diff --git a/crates/core/src/bc_protocol/ptz.rs b/crates/core/src/bc_protocol/ptz.rs index 985df32..d5e979e 100644 --- a/crates/core/src/bc_protocol/ptz.rs +++ b/crates/core/src/bc_protocol/ptz.rs @@ -325,7 +325,7 @@ impl BcCamera { sub_get.send(get).await?; let msg = sub_get.recv().await?; if msg.meta.response_code != 200 { - return Err(Error::CameraServiceUnavaliable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); } if let BcBody::ModernMsg(ModernMsg { diff --git a/crates/core/src/bc_protocol/pushinfo.rs b/crates/core/src/bc_protocol/pushinfo.rs index 9da38b3..9b9d46e 100644 --- a/crates/core/src/bc_protocol/pushinfo.rs +++ b/crates/core/src/bc_protocol/pushinfo.rs @@ -64,7 +64,7 @@ impl BcCamera { sub.send(msg).await?; let msg = sub.recv().await?; if msg.meta.response_code != 200 { - return Err(Error::CameraServiceUnavaliable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); } Ok(()) diff --git a/crates/core/src/bc_protocol/siren.rs b/crates/core/src/bc_protocol/siren.rs index 5e664a4..06c0fa3 100644 --- a/crates/core/src/bc_protocol/siren.rs +++ b/crates/core/src/bc_protocol/siren.rs @@ -39,7 +39,7 @@ impl BcCamera { sub_get.send(get).await?; let msg = sub_get.recv().await?; if msg.meta.response_code != 200 { - return Err(Error::CameraServiceUnavaliable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); } Ok(()) diff --git a/crates/core/src/bc_protocol/snap.rs b/crates/core/src/bc_protocol/snap.rs index e199d8c..958f142 100644 --- a/crates/core/src/bc_protocol/snap.rs +++ b/crates/core/src/bc_protocol/snap.rs @@ -41,7 +41,7 @@ impl BcCamera { sub_get.send(get).await?; let msg = sub_get.recv().await?; if msg.meta.response_code != 200 { - return Err(Error::CameraServiceUnavaliable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); } if let BcBody::ModernMsg(ModernMsg { @@ -132,7 +132,7 @@ impl BcCamera { } } else { // anything else is an error - return Err(Error::CameraServiceUnavaliable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); } // let binary_stream = sub_get.payload_stream(); diff --git a/crates/core/src/bc_protocol/stream.rs b/crates/core/src/bc_protocol/stream.rs index 60bbfd7..9572434 100644 --- a/crates/core/src/bc_protocol/stream.rs +++ b/crates/core/src/bc_protocol/stream.rs @@ -17,7 +17,7 @@ pub enum StreamKind { Sub, /// This stream represents a balance between SD and HD /// - /// It is only avaliable on some camera. If the camera dosen't + /// It is only available on some camera. If the camera doesn't /// support it the stream will be the same as the SD stream Extern, } @@ -155,7 +155,7 @@ impl BcCamera { StreamKind::Extern => 0, }; - // Theses are the numbers used with the offical client + // Theses are the numbers used with the official client // On an E1 and swann cameras: // - mainStream always has a value of 0 // - subStream always has a value of 1 @@ -271,7 +271,7 @@ impl BcCamera { msg_id: MSG_ID_VIDEO_STOP, .. } = msg.meta { - return Err(Error::CameraServiceUnavaliable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); } } } => v, @@ -313,7 +313,7 @@ impl BcCamera { StreamKind::Extern => 0, }; - // Theses are the numbers used with the offical client + // Theses are the numbers used with the official client // On an E1 and swann cameras: // - mainStream always has a value of 0 // - subStream always has a value of 1 @@ -352,7 +352,7 @@ impl BcCamera { let reply = sub_video.recv().await?; if reply.meta.response_code != 200 { - return Err(Error::CameraServiceUnavaliable(reply.meta.response_code)); + return Err(Error::CameraServiceUnavailable(reply.meta.response_code)); } Ok(()) diff --git a/crates/core/src/bc_protocol/stream_info.rs b/crates/core/src/bc_protocol/stream_info.rs index af34614..0abc60d 100644 --- a/crates/core/src/bc_protocol/stream_info.rs +++ b/crates/core/src/bc_protocol/stream_info.rs @@ -27,7 +27,7 @@ impl BcCamera { sub_get.send(get).await?; let msg = sub_get.recv().await?; if msg.meta.response_code != 200 { - return Err(Error::CameraServiceUnavaliable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); } if let BcBody::ModernMsg(ModernMsg { diff --git a/crates/core/src/bc_protocol/support.rs b/crates/core/src/bc_protocol/support.rs index 20df452..5adf6cf 100644 --- a/crates/core/src/bc_protocol/support.rs +++ b/crates/core/src/bc_protocol/support.rs @@ -26,7 +26,7 @@ impl BcCamera { sub_get.send(get).await?; let msg = sub_get.recv().await?; if msg.meta.response_code != 200 { - return Err(Error::CameraServiceUnavaliable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); } if let BcBody::ModernMsg(ModernMsg { diff --git a/crates/core/src/bc_protocol/talk.rs b/crates/core/src/bc_protocol/talk.rs index df787ab..de0cb0a 100644 --- a/crates/core/src/bc_protocol/talk.rs +++ b/crates/core/src/bc_protocol/talk.rs @@ -323,7 +323,7 @@ impl BcCamera { let full_block_size = block_size + 4; // Block size + predictor state let msg_num = self.new_message_num(); - let sub = connection.subscribe(MSG_ID_TALK, msg_num).await?; + let mut sub = connection.subscribe(MSG_ID_TALK, msg_num).await?; const BLOCK_PER_PAYLOAD: usize = 1; const BLOCK_HEADER_SIZE: usize = 4; @@ -333,9 +333,10 @@ impl BcCamera { let target_chunks = full_block_size as usize * BLOCK_PER_PAYLOAD; - let mut payload_bytes = vec![]; let mut end_of_stream = false; + let mut expected_stream_end = std::time::Instant::now(); while !end_of_stream { + let mut payload_bytes = vec![]; while payload_bytes.len() < target_chunks { let mut buffer = vec![255; target_chunks - payload_bytes.len()]; if let Ok(read) = buffered_recv.read(&mut buffer) { @@ -373,8 +374,6 @@ impl BcCamera { break; }; - payload_bytes = vec![]; - // Time to play the sample in seconds let play_length = samples_sent as f32 / sample_rate as f32; @@ -397,11 +396,22 @@ impl BcCamera { }), }; + let time_sent = std::time::Instant::now(); sub.send(msg).await?; - - std::thread::sleep(std::time::Duration::from_secs_f32(play_length * 0.95)); + let play_length = std::time::Duration::from_secs_f32(play_length); + if time_sent > expected_stream_end { + expected_stream_end = time_sent + play_length; + } else { + expected_stream_end += play_length; + } + let _ = sub.recv().await?; } + // Chunks are still being played, while talk_stop will interrupt them. Wait until we expect + // the stream to end (+ and extra 100ms) before issuing talk_stop. + let remaining_stream_duration = expected_stream_end - std::time::Instant::now(); + std::thread::sleep(remaining_stream_duration + std::time::Duration::from_secs_f32(0.1)); + self.talk_stop().await?; Ok(()) diff --git a/crates/core/src/bc_protocol/time.rs b/crates/core/src/bc_protocol/time.rs index fd28306..ae64db7 100644 --- a/crates/core/src/bc_protocol/time.rs +++ b/crates/core/src/bc_protocol/time.rs @@ -33,7 +33,7 @@ impl BcCamera { sub_get_general.send(get).await?; let msg = sub_get_general.recv().await?; if msg.meta.response_code != 200 { - return Err(Error::CameraServiceUnavaliable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); } if let BcBody::ModernMsg(ModernMsg { diff --git a/crates/core/src/bc_protocol/uid.rs b/crates/core/src/bc_protocol/uid.rs index 553172a..252047d 100644 --- a/crates/core/src/bc_protocol/uid.rs +++ b/crates/core/src/bc_protocol/uid.rs @@ -25,7 +25,7 @@ impl BcCamera { sub_get.send(get).await?; let msg = sub_get.recv().await?; if msg.meta.response_code != 200 { - return Err(Error::CameraServiceUnavaliable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); } if let BcBody::ModernMsg(ModernMsg { diff --git a/crates/core/src/bc_protocol/version.rs b/crates/core/src/bc_protocol/version.rs index ef73345..5e33670 100644 --- a/crates/core/src/bc_protocol/version.rs +++ b/crates/core/src/bc_protocol/version.rs @@ -27,7 +27,7 @@ impl BcCamera { let modern_reply = sub_version.recv().await?; if modern_reply.meta.response_code != 200 { - return Err(Error::CameraServiceUnavaliable( + return Err(Error::CameraServiceUnavailable( modern_reply.meta.response_code, )); } diff --git a/crates/core/src/bcmedia/codex.rs b/crates/core/src/bcmedia/codex.rs index e2e9763..4679ac0 100644 --- a/crates/core/src/bcmedia/codex.rs +++ b/crates/core/src/bcmedia/codex.rs @@ -39,7 +39,7 @@ impl Decoder for BcMediaCodex { type Item = BcMedia; type Error = Error; - /// Since frames can cross EOF boundaries we overload this so it dosen't error if + /// Since frames can cross EOF boundaries we overload this so it doesn't error if /// there are bytes left on the stream fn decode_eof(&mut self, buf: &mut BytesMut) -> Result> { match self.decode(buf)? { diff --git a/crates/core/src/bcudp/codex.rs b/crates/core/src/bcudp/codex.rs index 8bb6276..fb54e6e 100644 --- a/crates/core/src/bcudp/codex.rs +++ b/crates/core/src/bcudp/codex.rs @@ -34,7 +34,7 @@ impl Decoder for BcUdpCodex { type Item = BcUdp; type Error = Error; - /// Since frames can cross EOF boundaries we overload this so it dosen't error if + /// Since frames can cross EOF boundaries we overload this so it doesn't error if /// there are bytes left on the stream // fn decode_eof(&mut self, buf: &mut BytesMut) -> Result> { // match self.decode(buf)? { diff --git a/dissector/README.md b/dissector/README.md new file mode 100644 index 0000000..66055fb --- /dev/null +++ b/dissector/README.md @@ -0,0 +1,25 @@ +# Using the dissector + +The dissector can be used with `wireshark` and `tshark`. It requires another wireshark module [`luagcrypt`](https://github.com/Lekensteyn/luagcrypt) which is not packaged in most Linux distributions and needs building from source. Instructions here are suitable for Debian and its derivatives (tested on Debian 12 Bookworm amd64). + +## Build `luagcrypt.so` +``` +sudo apt install lua5.2 liblua5.2-dev libgcrypt20-dev libgpg-error-dev +git clone https://github.com/Lekensteyn/luagcrypt.git +cd luagcrypt +make LUA_DIR=/usr +``` +## Install `luagcrypt.so` +The shared object library should be copied to `/usr/local/lib/lua/5.2/` +``` +mkdir --parents /usr/local/lib/lua/5.2/ +cp luagcypt.so /usr/local/lib/lua/5.2/ +``` +Additionally, the system where the dissector is used needs these packages installing (if not already present): `libgcrypt20 libgpg-error0` +## Install `baichuan.lua` +Copy the dissector to the host where `wireshark` (or `tshark`) will be used to analyse the captured packets: +``` +mkdir --parents $HOME/.local/lib/wireshark/plugins/ +cp baichuan.lua $HOME/.local/lib/wireshark/plugins/ +``` + diff --git a/kubernetes/README.md b/kubernetes/README.md new file mode 100644 index 0000000..e603e55 --- /dev/null +++ b/kubernetes/README.md @@ -0,0 +1,50 @@ +### Neolink in Kubernetes + +#### Introduction + +This README provides guidance on deploying the NeoLink application on Kubernetes using the provided manifest files. The deployment is designed to set up a NeoLink application within its own namespace, with a specific configuration for node affinity, resource limits, and service exposure. + +#### Prerequisites + +- Kubernetes Cluster +- Command-line tool (kubectl) +- Basic understanding of Kubernetes concepts (Pods, Services, Deployments, ConfigMaps) + +#### Deployment Overview + +The deployment consists of four main parts: + +1. Namespace Creation: A new namespace neolink is created to isolate the resources. + +2. Deployment Configuration: The neolink-app-deployment is set up with: + - A single replica. + - Affinity to arm64 nodes (Though this is optional). + - Resource limits and requests for CPU and memory. + - A custom command and args to use a specific configuration file. + +3. Service Exposure: A LoadBalancer type service named neolink exposes the application on port 8554. + +4. ConfigMap: Contains the application configuration neolink.toml. + +#### Steps to Deploy + +```bash +kubectl apply -f manifest.yaml +``` + +### Configuration Details + +- The neolink.toml file in the ConfigMap provides the application configuration. Customize it as per your requirements. +- The deployment is set to favor arm64 architecture nodes via a `nodeAffinity`. This is a personal preference as in my cluster all my raspberrpis (except one) run 32bit raspian OS. And to try and get more bang for my buck I was to run neolink on my arm64 8Gb node. Again, this is totaly optional for you. +- Resource limits are set to ensure efficient use of cluster resources. +- The LoadBalancer service will make the application accessible externally. + +#### Troubleshooting + +- If the pod fails to start, check the pod logs and describe the pod for more details. +- Ensure that the arm64 node is available and schedulable in your cluster (if you're using nodeAffinity). +- Verify that the ConfigMap is correctly applied and mounted. + +#### Conclusion + +This guide provides a step-by-step approach to deploying the NeoLink application on a Kubernetes cluster. Modify the manifests as necessary to fit your specific requirements and environment. diff --git a/kubernetes/manifest.yaml b/kubernetes/manifest.yaml new file mode 100644 index 0000000..f6ced5d --- /dev/null +++ b/kubernetes/manifest.yaml @@ -0,0 +1,172 @@ +--- +apiVersion: v1 +kind: Namespace +metadata: + name: neolink +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: neolink-app-deployment + namespace: neolink + labels: + app: neolink +spec: + replicas: 1 + selector: + matchLabels: + app: neolink + template: + metadata: + labels: + app: neolink + spec: + containers: + - name: neolink + image: quantumentangledandy/neolink + ports: + - containerPort: 8554 + command: ["/bin/sh", "-c"] + args: ["cp /config/neolink.toml /etc/neolink.toml && /usr/local/bin/neolink rtsp --config /etc/neolink.toml"] + volumeMounts: + - name: config-volume + mountPath: /config + resources: + limits: + memory: "600Mi" + cpu: "300m" + requests: + memory: "200Mi" + cpu: "150m" + volumes: + - name: config-volume + configMap: + name: default-config +--- +apiVersion: v1 +kind: Service +metadata: + labels: + app: neolink + name: neolink + namespace: neolink +spec: + ports: + - name: tcp-interface-neolink + port: 8554 + protocol: TCP + targetPort: 8554 + selector: + app: neolink + type: LoadBalancer +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: default-config + namespace: neolink +data: + neolink.toml: | + # A bind value of 0.0.0.0 means any network this computer can access + # You can chage this to a specfic network e.g. "192.168.1.101" here + # Or to no networks e.g. this computer only "127.0.0.1" + bind = "0.0.0.0" + + # Default port is 8554 but you can change it by uncommenting the following + # bind_port = 8554 + + # Uncomment the following and supply a path to a valid PEM + # to activate TLS encryption. + # The PEM should contain the certificate and the private key + # If TLS is activated you must connect with "rtsps://" and not "rtsp://" + # certificate = "/path/to/pem/with/cert/and/key" + + # Choose if the client is required to provide a certificate signed by the server's CA. + # none|requested|required - default none + # tls_client_auth = "required" + + # You can password protect the rtsp server mount points by adding users + # like the following me and someone. If you do not add [[users]] + # then anyone can connect without a password or username + # To access such a stream try using a url such as "rtsp://me:mepass@192.168.1.101/driveway" + + # [[users]] + # name = "me" + # pass = "mepass" + # + # [[users]] + # name = "someone" + # pass = "someonepass" + + # Uncomment to enable MQTT + #[mqtt] + # mqtt.broker_addr = "192.168.1.122" + # mqtt.port = 1883 + # mqtt.credentials = ["mqtt_user", "mqtt_password"] + + + [[cameras]] + name = "driveway" + username = "admin" + password = "12345678" + address = "192.168.1.187:9000" + # MQTT Discovery: https://www.home-assistant.io/integrations/mqtt/#mqtt-discovery + # mqtt.discovery.topic = "homeassistant" # Uncomment to enable + # If using discovery, _ characters are replaced with spaces in the name and title case is applied + # mqtt.discovery.features = ["floodlight"] # Uncomment if this camera has a spotlight/floodlight + + # If you use a battery camera: **Instead** of an `address` supply the uid + # as follows + # uid = "ABCD01234567890EFG" + + # By default any of the users can connect (or anyone at all if no users are specfied) + # You can uncomment the following to permit only specfic users + # permitted_users = [ "me" ] + + # By default "both" "mainStream" and "subStream" are connected + # If your device has user connection limits try a single stream instead. + # stream = "mainStream" + + # By default neolink will use any means to connect to the camera + # from a UID + # This include relaying via reolink servers + # This variable `discovery` controls the method of UID discovery + # - Possible values + # "relay" # Any means including connecting and transmitting through reolink + # "map" # Register our local ip address with reolink and ask the camera to connect to us but don't relay data through reolink + # "remote" # Register our local ip address with reolink but only permit same network connections (useful if broadcast is not possible) + # "local" # Do not contact reolink servers at all. Rely soley on local UDP broadcast based discovery + # + # "cellular" # Cellular camera only support Relay and Map to speed up connecting to them this option will skip the local/remote + # + # discovery = "relay" + + # Certain types of camera emit status messages (such as battery levels) + # + # By default we hide these status messages from the user but you can instead requst that + # they be printed to stdout using print_format + # + # Valid values are: + # - None + # - Human + # - Xml + # + # print_format = "None" + + + [[cameras]] + name = "storage shed" + username = "admin" + password = "987654321" + address = "192.168.1.245:9000" + # If you use a battery camera: **Instead** of an `address` supply the uid + # as follows + # uid = "ABCD01234567890EFG" + + # If you use an NVR that relays several camera connections you can choose which + # camera to connect to with by setting the `channel_id` + # + # By default channel_id = 0. Eg the first connected camera on the device + # **Note**: that unlike in the offical client the numbering starts from 0 not 1. + # An 8 channel NVR would have channels 0 through 7 + # channel_id = 0 diff --git a/sample_config.toml b/sample_config.toml index 89ef291..85a7ea8 100644 --- a/sample_config.toml +++ b/sample_config.toml @@ -98,6 +98,6 @@ address = "192.168.1.245:9000" # camera to connect to with by setting the `channel_id` # # By default channel_id = 0. Eg the first connected camera on the device -# **Note**: that unlike in the offical client the numbering starts from 0 not 1. +# **Note**: that unlike in the official client the numbering starts from 0 not 1. # An 8 channel NVR would have channels 0 through 7 # channel_id = 0 diff --git a/src/common/instance.rs b/src/common/instance.rs index ea697c1..83d431f 100644 --- a/src/common/instance.rs +++ b/src/common/instance.rs @@ -125,7 +125,7 @@ impl NeoInstance { if let Err(e) = &r { log::debug!("- Task Result: {e:?}"); } - if let Err(Some(neolink_core::Error::CameraServiceUnavaliable(400))) = r.as_ref().map_err(|e| e.downcast_ref::()) { + if let Err(Some(neolink_core::Error::CameraServiceUnavailable(400))) = r.as_ref().map_err(|e| e.downcast_ref::()) { // Retryable without a reconnect // Usually occurs when camera is starting up // or the connection is initialising diff --git a/src/mqtt/mod.rs b/src/mqtt/mod.rs index 299ef93..6b11343 100644 --- a/src/mqtt/mod.rs +++ b/src/mqtt/mod.rs @@ -467,7 +467,7 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R }).await; let image = match image { Err(e) => match e.downcast::() { - Ok(neolink_core::Error::CameraServiceUnavaliable(_)) => { + Ok(neolink_core::Error::CameraServiceUnavailable(_)) => { log::debug!("Image not supported"); futures::future::pending().await }, @@ -512,7 +512,7 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R }).await; let xml = match xml { Err(e) => match e.downcast::() { - Ok(neolink_core::Error::CameraServiceUnavaliable(_)) => { + Ok(neolink_core::Error::CameraServiceUnavailable(_)) => { log::debug!("Battery not supported"); futures::future::pending().await }, diff --git a/src/rtsp/mod.rs b/src/rtsp/mod.rs index 9f45725..1d5bf43 100644 --- a/src/rtsp/mod.rs +++ b/src/rtsp/mod.rs @@ -104,7 +104,7 @@ pub(crate) async fn main(_opt: Opt, reactor: NeoReactor) -> Result<()> { loop { thread_config.changed().await?; if let Err(e) = thread_rtsp.set_up_tls(&thread_config.borrow().clone()) { - log::error!("Could not seup TLS: {e}"); + log::error!("Could not setup TLS: {e}"); } } } => v @@ -128,7 +128,7 @@ pub(crate) async fn main(_opt: Opt, reactor: NeoReactor) -> Result<()> { let config = thread_config.borrow().clone(); if let Err(e) = apply_users(&thread_rtsp, &curr_users).await { - log::error!("Could not seup TLS: {e}"); + log::error!("Could not setup TLS: {e}"); } if config.certificate.is_none() && !curr_users.is_empty() { @@ -186,7 +186,7 @@ pub(crate) async fn main(_opt: Opt, reactor: NeoReactor) -> Result<()> { for (running_name, token) in cameras.iter() { if ! config_names.contains(running_name) { - log::debug!("Rtsp::main Cancel1"); + log::debug!("Rtsp::main Cancel!"); token.cancel(); } } diff --git a/src/rtsp/stream.rs b/src/rtsp/stream.rs index 1f94164..b12c12a 100644 --- a/src/rtsp/stream.rs +++ b/src/rtsp/stream.rs @@ -323,7 +323,7 @@ async fn stream_run( log::debug!("Path: {}", path); mounts.add_factory(path, factory.clone()); } - log::info!("{}: Avaliable at {}", name, paths.join(", ")); + log::info!("{}: Available at {}", name, paths.join(", ")); let stream_cancel = CancellationToken::new(); let drop_guard = stream_cancel.clone().drop_guard();