Skip to content

Commit

Permalink
Fixed default port in icy_net.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrueger committed Jan 27, 2025
1 parent 7ea6c13 commit 65c8fe7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
11 changes: 0 additions & 11 deletions crates/icy_net/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,6 @@ pub enum ConnectionType {
SecureWebsocket,
}

impl ConnectionType {
pub fn get_default_port(self) -> u16 {
match self {
ConnectionType::Telnet => 23,
ConnectionType::SSH => 22,
ConnectionType::Websocket | ConnectionType::SecureWebsocket => 443,
_ => 0,
}
}
}

#[async_trait]
pub trait Connection: Send + Unpin {
fn get_connection_type(&self) -> ConnectionType;
Expand Down
6 changes: 5 additions & 1 deletion crates/icy_net/src/connection/ssh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ pub struct Credentials {
}

impl SSHConnection {
pub async fn open<A: ToSocketAddrs>(addr: &A, caps: TermCaps, credentials: Credentials) -> crate::Result<Self> {
pub async fn open(addr: impl Into<String>, caps: TermCaps, credentials: Credentials) -> crate::Result<Self> {
let mut addr:String = addr.into();
if !addr.contains(':') {
addr.push_str(":22");
}
let ssh = SshClient::connect(addr, &credentials.user_name, credentials.password).await?;
println!("SSH connection established");
let channel = ssh.session.channel_open_session().await?;
Expand Down
9 changes: 7 additions & 2 deletions crates/icy_net/src/connection/telnet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
use async_trait::async_trait;
use tokio::{
io::{AsyncReadExt, AsyncWriteExt},
net::{TcpStream, ToSocketAddrs},
net::TcpStream,
};

use super::{Connection, ConnectionType};
Expand Down Expand Up @@ -61,7 +61,12 @@ pub struct TelnetConnection {
}

impl TelnetConnection {
pub async fn open<A: ToSocketAddrs>(addr: &A, caps: TermCaps, timeout: Duration) -> crate::Result<Self> {
pub async fn open(addr: impl Into<String>, caps: TermCaps, timeout: Duration) -> crate::Result<Self> {
let mut addr:String = addr.into();
if !addr.contains(':') {
addr.push_str(":23");
}

let result = tokio::time::timeout(timeout, TcpStream::connect(addr)).await;
match result {
Ok(tcp_stream) => match tcp_stream {
Expand Down
2 changes: 2 additions & 0 deletions crates/icy_net/src/terminal/virtual_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ pub struct VirtualScreen {
impl VirtualScreen {
pub fn new<T: BufferParser + 'static>(parser: T) -> Self {
let mut buffer = Buffer::new((80, 25));
buffer.is_terminal_buffer = true;
buffer.terminal_state.fixed_size = true;
buffer.buffer_type = icy_engine::BufferType::Unicode;
let caret = Caret::default();
Self {
Expand Down

0 comments on commit 65c8fe7

Please sign in to comment.