Giter Site home page Giter Site logo

sumup-oss / gocat Goto Github PK

View Code? Open in Web Editor NEW
143.0 11.0 14.0 163 KB

21st century, multi-purpose relay from source to destination

Home Page: https://medium.com/@syndbg/gocat-a-21st-century-multi-purpose-relay-from-source-to-destination-5d9026f6cdb

License: Apache License 2.0

Go 100.00%

gocat's Introduction

gocat

Faster Golang alternative of socat.

Multi-purpose relay from source to destination.

A relay is a tool for bidirectional data transfer between two independent data channels.

Supported source-to-destination relays:

  • TCP to Unix,
  • Unix to TCP.
  • Need something else? Feel free to open an issue to discuss it or shoot a Pull Request.

Why?

  • Significantly faster than socat with medium and larger message payloads.
  • Static binary, it just works. TM
  • Actively health checks the source to prevent hanging/zombified source connections. (initial reason why socat didn't work for us)

Why not?

  • socat performs slightly better with small message payloads.

Where it's used?

At SumUp we use it as a backbone for infrastructure and deployment system(s) that:

  • need to relay SSH protocol,
  • proxy to TCP -> Unix or vice-versa where speed
  • have reliability as an important concern.

As a now open-source project of SumUp, we hope that we find more use-cases together.

Benchmarks

How the benchmarks work

Benchmarks are sending a message from the destination, relaying via gocat/socat to the source, which is an echo server that relays back to the destination via gocat/socat.

Reading the benchmarks

X axis is the message payload size.

Y axis is throughput as per golang test's -count argument, which benchmarks only the sending and receiving of a message sync or async.

TCP to UNIX

tcp-to-unix

Unix to TCP

unix-to-tcp

Benchmarking mistakes?

Think we can improve them or got something wrong? Feel free to open an issue to discuss it.

We want the best possible benchmark and opportunity to improve the software!

Configuration

Check out config.go

Usage

Unix Domain Socket to TCP

Example SSH agent forwarding

gocat

> gocat unix-to-tcp --src /run/ssh-agent.socket --dst 0.0.0.0:56789

socat

# NOTE: `-d -d -d` is to reach at least some level of verbosity
> socat -d -d -d TCP-LISTEN:56789,reuseaddr,fork UNIX-CLIENT:/run/ssh-agent.socket

TCP to Unix Domain Socket

Example TCP to ssh-agent socket forwarding

gocat

> gocat tcp-to-unix --src 0.0.0.0:56789 --dst /tmp/sshagent.sock

socat

# NOTE: `-d -d -d` is to reach at least some level of verbosity
> socat -t 100000 -v UNIX-LISTEN:/tmp/sshagent.sock,unlink-early,mode=777,fork TCP:0.0.0.0:56789

Contributing

Check out CONTRIBUTING.md

Code of conduct (CoC)

We want to foster an inclusive and friendly community around our Open Source efforts. Like all SumUp Open Source projects, this project follows the Contributor Covenant Code of Conduct. Please, read it and follow it.

If you feel another member of the community violated our CoC or you are experiencing problems participating in our community because of another individual's behavior, please get in touch with our maintainers. We will enforce the CoC.

About SumUp

SumUp logo

It is our mission to make easy and fast card payments a reality across the entire world. You can pay with SumUp in more than 30 countries, already. Our engineers work in Berlin, Cologne, Sofia and Sāo Paulo. They write code in JavaScript, Swift, Ruby, Go, Java, Erlang, Elixir and more. Want to come work with us? Head to our careers page to find out more.

gocat's People

Contributors

mtsvyatkovski avatar syndbg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gocat's Issues

TCP to TCP support

A port forwarding capability would be useful. Especially if it can be between IPv4<->IPv6.

Named pipes support on Windows

Scope:

  • npipe-to-tcp
  • tcp-to-npipe
  • npipe-to-unix
  • unix-to-npipe

It is possible to implement only unix or tcp parts and then chain it through another gocat process for tcp<->unix.

Afterthoughts.
Probably also npipe-to-npipe. But again, this could be achieved by chaining multiple processes.

How to link a couple of fake ttys in Linux/macOS

Could you confirm support for something like below?

socat -d -d \
    pty,raw,nonblock,echo=0,iexten=0,link=/tmp/tty.fake.slave \
    pty,raw,nonblock,echo=0,iexten=0,link=/tmp/tty.fake.master &

This is currently used to test serial communication protocols on macOS but I am moving to M1 silicone where brew/ports are not fully supported yet making socat not readily available.

Hang with high CPU usage when source not available

go version: go1.16.7 linux/amd64
os: linux 5.11.0-31-generic

In tcp-to-unix mode, trying to connect to a missing source causes 100% CPU usage. If the source later becomes available nothing changes.

Example: If no process is listening on port 8999, running..

gocat --tcp-to-unix --src 127.0.0.1:8999 --dst /tmp/foo.sock

Causes 100% CPU load. Starting a server on 8999 afterwards, say..

python3 -m http.server 8999

does not cause relaying to connect. On the other hand, if the server is started before gocat, everything works fine.

This is because healthCheckSource in abstract_duplex_relay.go closes the passed listener when it gets an error dialing the source connection. In the Relay function, errors on listener.Accept are ignored (except a context error), so execution spins forever in a loop getting errors on the closed listener.

Will post a PR fix that's been working for me, if that's acceptable.

Multiple source support for tcp-to-unix connection.

As of now we can provide single tcp source and single unix connection for example tcp-to-unix --src localhost:8100 --dst /var/run/usbmuxd
So it is feasible that we can have multiple tcp sources and they can relay the data to a unix connection.
for example tcp-to-unix --src localhost:8100,localhost:8200,localhost:8300 --dst /var/run/usbmuxd?

Or is there a way to achieve the same?

Error on socket file not existing in advance

I tried the following:

$ ./gocat unix-to-tcp --src /tmp/foo.sock --dst buildeventservice.googleapis.com:443
couldn't create relay from unix socket to TCP
 --- at /usr/local/home/fangism/gocat/cmd/unix_to_tcp.go:60 (NewUnixToTCPCmd.func1) ---
Caused by: could not stat /tmp/sponge.sock
 --- at /usr/local/home/fangism/gocat/internal/relay/unix_socket_tcp.go:59 (NewUnixSocketTCP) ---
Caused by: stat /tmp/foo.sock: no such file or directory

/tmp/foo.sock did not exist ahead of running gocat.
Should gocat create that socket file when opening it? Other proxy-like tools I've used didn't require the socket file to exist in advance.
Or am I simply using it incorrectly?

gocat release 0.2.0 replies with wrong version number 0.1.0

Hello,

In automating some of our build process, we noticed that the current latest release reports the wrong (older) version number:

joshz@joshz-laptop ~/Downloads $ ./gocat-v0.2.0-linux-amd64 version
0.1.0

The 0.2.0 release also doesn't include recent patches submitted by Dave, and others: v0.2.0...master

Could you please bump the version (maybe to 0.2.1) and release that?

Thank you for your help and the great code!
Josh

tcp <> vsock support

Hello,

Is there a plan to support AF_VSOCK sockets? I am currently using socat for TCP <> VSOCK but performance is not great so I'm looking for a replacement. Apologies if this is already supported.

BTW congrats for the project,

Matias.

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.