~taiite/public-inbox

senpai: Implement support for socks5 proxy v1 PROPOSED

the-y: 1
 Implement support for socks5 proxy

 5 files changed, 54 insertions(+), 9 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~taiite/public-inbox/patches/29554/mbox | git am -3
Learn more about email & git

[PATCH senpai] Implement support for socks5 proxy Export this patch

Hey hey, what a cool irc client, but i was in need for some socks5 support. Here are the
changes i made. This is the first time i work on some go code and also
the first time i send a patch in over email ^^ So of course open for any
improvements on either end.

Cheers

---
 app.go           | 12 +++++++++++-
 config.go        | 31 ++++++++++++++++++++++++-------
 doc/senpai.5.scd |  7 +++++++
 go.mod           |  3 ++-
 go.sum           | 10 ++++++++++
 5 files changed, 54 insertions(+), 9 deletions(-)

diff --git a/app.go b/app.go
index 1144560..6bffc0d 100644
--- a/app.go
+++ b/app.go
@@ -14,6 +14,7 @@ import (
	"git.sr.ht/~taiite/senpai/irc"
	"git.sr.ht/~taiite/senpai/ui"
	"github.com/gdamore/tcell/v2"
	"golang.org/x/net/proxy"
)

const eventChanSize = 64
@@ -330,7 +331,16 @@ func (app *App) tryConnect() (conn net.Conn, err error) {
		}
	}

	conn, err = net.Dial("tcp", addr)
	if app.cfg.Socks5Addr != "" {
		dialer, socks5_err := proxy.SOCKS5("tcp", app.cfg.Socks5Addr, app.cfg.Socks5Auth, nil)
		if socks5_err != nil {
			return
		}
		conn, err = dialer.Dial("tcp", addr)
	} else {
		conn, err = net.Dial("tcp", addr)
	}

	if err != nil {
		return
	}
diff --git a/config.go b/config.go
index 35857ba..40dd4ee 100644
--- a/config.go
+++ b/config.go
@@ -12,6 +12,7 @@ import (
	"github.com/gdamore/tcell/v2"

	"git.sr.ht/~emersion/go-scfg"
	"golang.org/x/net/proxy"
)

type Color tcell.Color
@@ -51,13 +52,15 @@ type ConfigColors struct {
}

type Config struct {
	Addr     string
	Nick     string
	Real     string
	User     string
	Password *string
	TLS      bool
	Channels []string
	Addr       string
	Nick       string
	Real       string
	User       string
	Password   *string
	TLS        bool
	Socks5Addr string
	Socks5Auth *proxy.Auth
	Channels   []string

	Typings bool
	Mouse   bool
@@ -89,6 +92,8 @@ func Defaults() (cfg Config, err error) {
		User:            "",
		Password:        nil,
		TLS:             true,
		Socks5Addr:      "",
		Socks5Auth:      nil,
		Channels:        nil,
		Typings:         true,
		Mouse:           true,
@@ -234,6 +239,18 @@ func unmarshal(filename string, cfg *Config) (err error) {
			if cfg.TLS, err = strconv.ParseBool(tls); err != nil {
				return err
			}
		case "socks5addr":
			if err := d.ParseParams(&cfg.Socks5Addr); err != nil {
				return err
			}
		case "socks5auth":
			var socks5auth string
			if err := d.ParseParams(&socks5auth); err != nil {
				return err
			}
			splitted := strings.Split(socks5auth, ":")
			cfg.Socks5Auth = &proxy.Auth{User: splitted[0]}
			cfg.Socks5Auth.Password = splitted[1]
		case "typings":
			var typings string
			if err := d.ParseParams(&typings); err != nil {
diff --git a/doc/senpai.5.scd b/doc/senpai.5.scd
index e75513d..295105e 100644
--- a/doc/senpai.5.scd
+++ b/doc/senpai.5.scd
@@ -43,6 +43,13 @@ Some settings are required, the others are optional.
	will be ignored and the first line of the output of *password-cmd* will be
	used for login.

*socks5addr*
	The address (host:port) of your socks5 proxy. 

*socks5auth*
	The authentication (_user:password_) for your socks5 proxy specified with
	_socks5addr_. 

*channel*
	A spaced separated list of channel names that senpai will automatically join
	at startup and server reconnect. This directive can be specified multiple
diff --git a/go.mod b/go.mod
index d3c9b55..e5bfa74 100644
--- a/go.mod
+++ b/go.mod
@@ -6,7 +6,8 @@ require (
	git.sr.ht/~emersion/go-scfg v0.0.0-20201019143924-142a8aa629fc
	github.com/gdamore/tcell/v2 v2.3.11
	github.com/mattn/go-runewidth v0.0.10
	golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf
	golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
	golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
	golang.org/x/time v0.0.0-20210611083556-38a9dc6acbc6
	mvdan.cc/xurls/v2 v2.3.0
)
diff --git a/go.sum b/go.sum
index 856f865..4190b38 100644
--- a/go.sum
+++ b/go.sum
@@ -19,14 +19,24 @@ github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsK
github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk=
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf h1:MZ2shdL+ZM/XzY3ZGOnh4Nlpnxz5GSOhOmtHo3iPU6M=
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/time v0.0.0-20210611083556-38a9dc6acbc6 h1:Vv0JUPWTyeqUq42B2WJ1FeIDjjvGKoA2Ss+Ts0lAVbs=
golang.org/x/time v0.0.0-20210611083556-38a9dc6acbc6/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
mvdan.cc/xurls/v2 v2.3.0 h1:59Olnbt67UKpxF1EwVBopJvkSUBmgtb468E4GVWIZ1I=
-- 
2.35.1