Listen for connection on rM instead of host
This commit is contained in:
parent
87981226c5
commit
dcd3007932
21
reStream.sh
21
reStream.sh
@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
# default values for arguments
|
||||
ssh_host="root@10.11.99.1" # remarkable connected through USB
|
||||
remarkable="10.11.99.1" # remarkable connected through USB
|
||||
landscape=true # rotate 90 degrees to the right
|
||||
output_path=- # display output through ffplay
|
||||
format=- # automatic output format
|
||||
@ -19,7 +19,7 @@ while [ $# -gt 0 ]; do
|
||||
shift
|
||||
;;
|
||||
-s | --source)
|
||||
ssh_host="$2"
|
||||
remarkable="$2"
|
||||
shift
|
||||
shift
|
||||
;;
|
||||
@ -84,12 +84,12 @@ done
|
||||
|
||||
ssh_cmd() {
|
||||
echo "[SSH]" "$@" >&2
|
||||
ssh -o ConnectTimeout=1 -o PasswordAuthentication=no "$ssh_host" "$@"
|
||||
ssh -o ConnectTimeout=1 -o PasswordAuthentication=no "root@$remarkable" "$@"
|
||||
}
|
||||
|
||||
# check if we are able to reach the remarkable
|
||||
if ! ssh_cmd true; then
|
||||
echo "$ssh_host unreachable or you have not set up an ssh key."
|
||||
echo "$remarkable unreachable or you have not set up an ssh key."
|
||||
echo "If you see a 'Permission denied' error, please visit"
|
||||
echo "https://github.com/rien/reStream/#installation for instructions."
|
||||
exit 1
|
||||
@ -185,14 +185,13 @@ fi
|
||||
|
||||
set -e # stop if an error occurs
|
||||
|
||||
receive_cmd="ssh_cmd ./restream"
|
||||
#echo './restream --connect "$(echo $SSH_CLIENT | cut -d " " -f1):61819"'
|
||||
#receive_cmd="ssh_cmd 'echo ABC $(echo $SSH_CLIENT | cut -d " " -f1):61819' & ; nc -l -p 61819"
|
||||
|
||||
if $unsecure_connection; then
|
||||
echo "Spawning unsecure connection"
|
||||
ssh_cmd 'sleep 0.25 && ./restream --connect "$(echo $SSH_CLIENT | cut -d " " -f1):61819"' &
|
||||
receive_cmd="nc -l -p 61819"
|
||||
listen_port=16789
|
||||
ssh_cmd "./restream --listen $listen_port" &
|
||||
sleep 1 # give some time to restream.rs to start listening
|
||||
receive_cmd="nc 10.11.99.1 $listen_port"
|
||||
else
|
||||
receive_cmd="ssh_cmd ./restream"
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
|
36
src/main.rs
36
src/main.rs
@ -9,18 +9,22 @@ use lz_fear::CompressionSettings;
|
||||
use std::default::Default;
|
||||
use std::fs::File;
|
||||
use std::io::{BufRead, BufReader, Read, Seek, SeekFrom, Write};
|
||||
use std::net::{TcpStream, TcpListener};
|
||||
use std::process::Command;
|
||||
use std::time::Duration;
|
||||
use std::thread;
|
||||
use std::sync::mpsc::channel;
|
||||
|
||||
#[derive(Clap)]
|
||||
#[clap(version = crate_version!(), author = crate_authors!())]
|
||||
pub struct Opts {
|
||||
#[clap(
|
||||
long,
|
||||
name = "address",
|
||||
short = 'c',
|
||||
about = "Establish a new unsecure connection to send the data to which reduces some load on the reMarkable and improves fps."
|
||||
name = "port",
|
||||
short = 'l',
|
||||
about = "Listen for an (unsecure) TCP connection to send the data to which reduces some load on the reMarkable and improves fps."
|
||||
)]
|
||||
connect: Option<String>,
|
||||
listen: Option<usize>,
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
@ -49,11 +53,8 @@ fn main() -> Result<()> {
|
||||
};
|
||||
|
||||
let stdout = std::io::stdout();
|
||||
let data_target: Box<dyn Write> = if let Some(ref address) = opts.connect {
|
||||
eprintln!("[rM] Sending stream to {} (instead of stdout)", address);
|
||||
let conn = std::net::TcpStream::connect(address)?;
|
||||
conn.set_write_timeout(Some(std::time::Duration::from_secs(3)))?;
|
||||
Box::new(conn)
|
||||
let data_target: Box<dyn Write> = if let Some(port) = opts.listen {
|
||||
Box::new(listen_timeout(port, Duration::from_secs(3))?)
|
||||
} else {
|
||||
Box::new(stdout.lock())
|
||||
};
|
||||
@ -63,6 +64,23 @@ fn main() -> Result<()> {
|
||||
.context("Error while compressing framebuffer stream")
|
||||
}
|
||||
|
||||
fn listen_timeout(port: usize, timeout: Duration) -> Result<TcpStream> {
|
||||
let listen_addr = format!("0.0.0.0:{}", port);
|
||||
let listen = TcpListener::bind(&listen_addr)?;
|
||||
eprintln!("[rM] listening for a TCP connection on {}", listen_addr);
|
||||
|
||||
let (tx, rx) = channel();
|
||||
thread::spawn(move || {
|
||||
tx.send(listen.accept()).unwrap();
|
||||
});
|
||||
|
||||
let (conn, conn_addr) = rx.recv_timeout(timeout)
|
||||
.context("Timeout while waiting for host to connect to reMarkable")??;
|
||||
eprintln!("[rM] connection received from {}", conn_addr);
|
||||
conn.set_write_timeout(Some(timeout))?;
|
||||
Ok(conn)
|
||||
}
|
||||
|
||||
fn remarkable_version() -> Result<String> {
|
||||
let content = std::fs::read("/sys/devices/soc0/machine")
|
||||
.context("Failed to read /sys/devices/soc0/machine")?;
|
||||
|
Loading…
x
Reference in New Issue
Block a user