socks5 icon indicating copy to clipboard operation
socks5 copied to clipboard

Migrate the net.* structures to net.* interface types to allow different transports/address types

Open eyedeekay opened this issue 3 years ago • 2 comments

Not associated with an existing issue.

Changes proposed in this pull request:

  • This PR migrates txthinking/socks5 from using concrete net types(net.TCPAddr, net.TCPConn) to using interface net types(net.Addr, net.Conn, net.PacketConn).
  • It also implements the ability to add a custom Resolver and a custom Dialer which use interface types as well.
  • This allows developers to use custom dialers and resolves in order to work with alternate pseudo-TLD's directly. In my use case, this pseudo-tld is the .i2p space. Developers can now do something like this:
package main

import (
	"github.com/eyedeekay/sam3/helper"
	"github.com/eyedeekay/sam3/i2pkeys"
	"github.com/txthinking/socks5"
	"log"
)

func main() {
	// Create a SOCKS5 server
	addr := "127.0.0.1:8888"
	ip := "127.0.0.1"
	username := ""
	password := ""
	tcpTimeout := 60000
	udpTimeout := 60000
	i2pkeys.FakePort = true

	primary, err := sam.I2PPrimarySession("sam-socks", "127.0.0.1:7656", "socks5")
	if err != nil {
		panic(err)
	}

	socks5.Dial = primary
	socks5.Resolver = primary

	server, err := socks5.NewClassicServer(addr, ip, username, password, tcpTimeout, udpTimeout)
	if err != nil {
		panic(err)
	}
	log.Println("Client Created")

	// Create SOCKS5 proxy on localhost port 8000
	if err := server.ListenAndServe(nil); err != nil {
		panic(err)
	}

to transparently I2P-ify their applications.

eyedeekay avatar Mar 12 '21 23:03 eyedeekay

Also I know that this currently breaks Brook because net.UDPConn only really implements net.Conn after it's been "Dialed." I'm working on a solution to that over in my brook branch.

eyedeekay avatar Mar 13 '21 17:03 eyedeekay

It has conflicts, your interfaces-only branch is out of date. pull first before push.

txthinking avatar Mar 14 '21 02:03 txthinking

recommended that you choose the small API for transport other than TCP and UDP

txthinking avatar Feb 14 '23 08:02 txthinking