bk-rs / ssh-rs

https://docs.rs/async-ssh2-lite
Apache License 2.0
56 stars 21 forks source link

error[E0599]: the method `handshake` exists for struct `AsyncSession<Async<TcpStream>>`, but its trait bounds were not satisfied #39

Closed TheBlindM closed 1 year ago

TheBlindM commented 1 year ago

code:


pub async fn initConnection<R: Runtime>(initConnectDto: InitConnectDto, window: Window<R>) -> Result<()> {
    let sessionId = initConnectDto.sessionId;
    let ssh_session = ssh_session_service::find(sessionId).await?.expect("当前会话不存在");

    println!("{}", format!("{:?}:{:?}", ssh_session.ip, ssh_session.port));
    let addr = format!("{}:{}", ssh_session.ip, ssh_session.port).to_socket_addrs()?.next().unwrap();
    let stream = Async::<TcpStream>::connect(addr).await?;

    let mut session = AsyncSession::new(stream, None)?;
    session.handshake().await?;

    session.userauth_password(&*ssh_session.username, &*ssh_session.pwd.expect("密码为空")).await?;
    session.authenticated();
}

err_msg:

error[E0599]: the method `handshake` exists for struct `AsyncSession<Async<TcpStream>>`, but its trait bounds were not satisfied
   --> src\service\terminal_service.rs:39:10
    |
39  |     session.handshake().await?;
    |             ^^^^^^^^^ method cannot be called on `AsyncSession<Async<TcpStream>>` due to unsatisfied trait bounds
    |
   ::: C:\Users\10431\.cargo\registry\src\index.crates.io-6f17d22bba15001f\async-io-1.13.0\src\lib.rs:594:1
    |
594 | pub struct Async<T> {
    | ------------------- doesn't satisfy `Async<std::net::TcpStream>: AsyncSessionStream`
    |
    = note: the following trait bounds were not satisfied:
            `Async<std::net::TcpStream>: AsyncSessionStream`
vkill commented 1 year ago

Hi @TheBlindM

Please enable async-io feature then try connect

let mut session = AsyncSession::<async_ssh2_lite::AsyncIoTcpStream>::connect(addr, None).await?;
session.handshake().await?;

Or

async-ssh2-lite = "0.4.6"

Looks like the problem with async-io version.

TheBlindM commented 1 year ago

Hi @TheBlindM

Please enable async-io feature then try connect

let mut session = AsyncSession::<async_ssh2_lite::AsyncIoTcpStream>::connect(addr, None).await?;
session.handshake().await?;

Or

async-ssh2-lite = "0.4.6"

Looks like the problem with async-io version.

async-ssh2-lite = "0.4.6"
async-io = {version = "1.13.0",default-features = false, optional = true}

Unresolved reference: AsyncIoTcpStream. how enable async-io?

vkill commented 1 year ago

how enable async-io?

async-ssh2-lite = {version = "0.4.6",  features = ["async-io"] }