Giter VIP home page Giter VIP logo

ppp-stream's Introduction

crates.io

ppp-stream

This is a simple library that adds helper functions to AsyncRead streams for HAProxy Protocol extraction. The Proxy Protocol parsing is implemented by the great ppp library, many thanks to @misalcedo and all the other contributors.

Also, big thanks to @simao for his contribution to this project.

ppp-stream's People

Contributors

conblem avatar simao avatar

Stargazers

 avatar  avatar

Watchers

 avatar

ppp-stream's Issues

Implementing AsyncWrite

Hi,

I am trying to implement AsyncWrite for PPPRefStream, so I can run the following code:

    let mut local = stream.remote_addr_unpin().await?;

    let mut remote = TcpStream::connect("myip:22").await.context("could not connect to remote")?;

    tokio::io::copy_bidirectional(&mut local, &mut remote).await.context("copying streams")?;

I have the following implementation:

impl <'a, T> AsyncWrite for PPPRefStream<'a, T> where T: AsyncWrite {
    fn poll_write(
        self: Pin<&mut Self>,
        cx: &mut std::task::Context<'_>,
        buf: &[u8],
    ) -> std::task::Poll<std::result::Result<usize, std::io::Error>> {
        let this = self.get_mut();
        this.inner.as_mut().poll_write(cx, buf)
    }

    fn poll_flush(self: Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> std::task::Poll<std::result::Result<(), std::io::Error>> {
        let this = self.get_mut();
        this.inner.as_mut().poll_flush(cx)
    }

    fn poll_shutdown(self: Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> std::task::Poll<std::result::Result<(), std::io::Error>> {
        let this = self.get_mut();
        this.inner.as_mut().poll_shutdown(cx)
    }
}

This works sometimes. It always works with http, proxying the request, but with ssh sometimes I get errors when trying to connect, like:

ssh client error:
Bad packet length 1231976033.
rust app error:
thread 'tokio-runtime-worker' panicked at 'called `Result::unwrap()` on an `Err` value: copying streams

Caused by:
    Connection reset by peer (os error 104)', src/main.rs:55:34

Am I missing something in my implementation?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.