Skip to content

Latest commit

 

History

History
109 lines (74 loc) · 3.24 KB

README.md

File metadata and controls

109 lines (74 loc) · 3.24 KB

RevDial

RevDial CI codecov Go Report Card Go Reference License: MIT

Overview

RevDial is a Go package that provides a mechanism for managing network connections through reverse dialing. It allows an accepted connection to be transformed into a dialer. This dialer can then create new network connections back to the original dialer, which in turn uses a listener to accept these connections. This functionality is particularly useful in scenarios like exposing a service that is hidden behind a NAT, where you want to proxy requests via a publicly exposed server.

This package is inspired by the Go revdial/v2 package, which focuses on reverse dialing HTTP services. Unlike that package, RevDial is not limited to the HTTP protocol and can handle any TCP-based protocols.

Installation

To install the package, use the following command:

go get github.com/ksysoev/revdial

Usage

Using a Dialer

package main

import (
	"context"
	"fmt"
	"github.com/ksysoev/revdial"
)

func main() {
	dialer := revdial.NewDialer("localhost:9090")

	if err := dialer.Start(context.Background()); err != nil {
		fmt.Printf("Failed to start dialer: %v\n", err)
		return
	}

	defer dialer.Stop()

	conn, err := dialer.DialContext(ctx)
	if err != nil {
		fmt.Printf("failed to dial: %v", err)
		return
	}

    defer conn.Close()

    // Here your logic for handling connection
}

Using a Listener

package main

import (
	"context"
	"fmt"
	"github.com/ksysoev/revdial"
)

func main() {
	listener, err := revdial.Listen(context.Background(), "localhost:9090")
	if err != nil {
		fmt.Printf("Failed to create listener: %v\n", err)
		return
	}
	defer listener.Close()

	fmt.Println("Listener created")

    for  {
        conn, err := listener.Accept()
        if err != nil {
            fmt.Printf("Failed to accept connection: %v\n", err)
		    return
        }
    
        // Here logic for handling incomming connection

        conn.Close()
    }
}

Planned Features

  • Authentication Support: Add support for various authentication mechanisms to secure connections.
  • TLS Support: Implement TLS support to encrypt the data transmitted over the connections.
  • Configuration Options: Provide more configuration options to customize the behavior of the dialer and listener.

Contributing

Contributions are welcome! Please open an issue or submit a pull request with your changes. Make sure to follow the project's coding guidelines and include tests for any new features or bug fixes.

License

This project is licensed under the MIT License. See the LICENSE file for details.