From fc5a7351a7beb2c89f79c1703dfba4881750410e Mon Sep 17 00:00:00 2001 From: Mario Trangoni Date: Fri, 2 Jun 2023 15:30:43 +0200 Subject: [PATCH 1/2] chore: Fix spelling issues Signed-off-by: Mario Trangoni --- server/server.go | 2 +- server/server_handler.go | 6 +++--- share/cnet/conn_ws.go | 6 +++--- share/cos/signal.go | 13 +++++++------ share/tunnel/tunnel_in_proxy_udp.go | 27 ++++++++++++++------------- 5 files changed, 28 insertions(+), 26 deletions(-) diff --git a/server/server.go b/server/server.go index b7df1282..f29dcaa3 100644 --- a/server/server.go +++ b/server/server.go @@ -32,7 +32,7 @@ type Config struct { TLS TLSConfig } -// Server respresent a chisel service +// Server represent a chisel service type Server struct { *cio.Logger config *Config diff --git a/server/server_handler.go b/server/server_handler.go index 952aa4d8..d4aeaeda 100644 --- a/server/server_handler.go +++ b/server/server_handler.go @@ -19,7 +19,7 @@ func (s *Server) handleClientHandler(w http.ResponseWriter, r *http.Request) { //websockets upgrade AND has chisel prefix upgrade := strings.ToLower(r.Header.Get("Upgrade")) protocol := r.Header.Get("Sec-WebSocket-Protocol") - if upgrade == "websocket" { + if upgrade == "websocket" { if protocol == chshare.ProtocolVersion { s.handleWebsocket(w, r) return @@ -123,7 +123,7 @@ func (s *Server) handleWebsocket(w http.ResponseWriter, req *http.Request) { //confirm reverse tunnels are allowed if r.Reverse && !s.config.Reverse { l.Debugf("Denied reverse port forwarding request, please enable --reverse") - failed(s.Errorf("Reverse port forwaring not enabled on server")) + failed(s.Errorf("Reverse port forwarding not enabled on server")) return } //confirm reverse tunnel is available @@ -132,7 +132,7 @@ func (s *Server) handleWebsocket(w http.ResponseWriter, req *http.Request) { return } } - //successfuly validated config! + //successfully validated config! r.Reply(true, nil) //tunnel per ssh connection tunnel := tunnel.New(tunnel.Config{ diff --git a/share/cnet/conn_ws.go b/share/cnet/conn_ws.go index 9639e991..9cf0c601 100644 --- a/share/cnet/conn_ws.go +++ b/share/cnet/conn_ws.go @@ -12,7 +12,7 @@ type wsConn struct { buff []byte } -//NewWebSocketConn converts a websocket.Conn into a net.Conn +// NewWebSocketConn converts a websocket.Conn into a net.Conn func NewWebSocketConn(websocketConn *websocket.Conn) net.Conn { c := wsConn{ Conn: websocketConn, @@ -20,8 +20,8 @@ func NewWebSocketConn(websocketConn *websocket.Conn) net.Conn { return &c } -//Read is not threadsafe though thats okay since there -//should never be more than one reader +// Read is not threadsafe though that's okay since there +// should never be more than one reader func (c *wsConn) Read(dst []byte) (int, error) { ldst := len(dst) //use buffer or read new message diff --git a/share/cos/signal.go b/share/cos/signal.go index f44e4487..709bb2bc 100644 --- a/share/cos/signal.go +++ b/share/cos/signal.go @@ -1,4 +1,5 @@ -//+build !windows +//go:build !windows +// +build !windows package cos @@ -13,8 +14,8 @@ import ( "github.com/jpillora/sizestr" ) -//GoStats prints statistics to -//stdout on SIGUSR2 (posix-only) +// GoStats prints statistics to +// stdout on SIGUSR2 (posix-only) func GoStats() { //silence complaints from windows const SIGUSR2 = syscall.Signal(0x1f) @@ -24,14 +25,14 @@ func GoStats() { for range c { memStats := runtime.MemStats{} runtime.ReadMemStats(&memStats) - log.Printf("recieved SIGUSR2, go-routines: %d, go-memory-usage: %s", + log.Printf("received SIGUSR2, go-routines: %d, go-memory-usage: %s", runtime.NumGoroutine(), sizestr.ToString(int64(memStats.Alloc))) } } -//AfterSignal returns a channel which will be closed -//after the given duration or until a SIGHUP is received +// AfterSignal returns a channel which will be closed +// after the given duration or until a SIGHUP is received func AfterSignal(d time.Duration) <-chan struct{} { ch := make(chan struct{}) go func() { diff --git a/share/tunnel/tunnel_in_proxy_udp.go b/share/tunnel/tunnel_in_proxy_udp.go index 3f3fa8be..46876dfb 100644 --- a/share/tunnel/tunnel_in_proxy_udp.go +++ b/share/tunnel/tunnel_in_proxy_udp.go @@ -18,18 +18,19 @@ import ( "golang.org/x/sync/errgroup" ) -//listenUDP is a special listener which forwards packets via -//the bound ssh connection. tricky part is multiplexing lots of -//udp clients through the entry node. each will listen on its -//own source-port for a response: -// (random) -// src-1 1111->... dst-1 6345->7777 -// src-2 2222->... <---> udp <---> udp <-> dst-1 7543->7777 -// src-3 3333->... listener handler dst-1 1444->7777 +// listenUDP is a special listener which forwards packets via +// the bound ssh connection. tricky part is multiplexing lots of +// udp clients through the entry node. each will listen on its +// own source-port for a response: // -//we must store these mappings (1111-6345, etc) in memory for a length -//of time, so that when the exit node receives a response on 6345, it -//knows to return it to 1111. +// (random) +// src-1 1111->... dst-1 6345->7777 +// src-2 2222->... <---> udp <---> udp <-> dst-1 7543->7777 +// src-3 3333->... listener handler dst-1 1444->7777 +// +// we must store these mappings (1111-6345, etc) in memory for a length +// of time, so that when the exit node receives a response on 6345, it +// knows to return it to 1111. func listenUDP(l *cio.Logger, sshTun sshTunnel, remote *settings.Remote) (*udpListener, error) { a, err := net.ResolveUDPAddr("udp", remote.Local()) if err != nil { @@ -64,7 +65,7 @@ type udpListener struct { func (u *udpListener) run(ctx context.Context) error { defer u.inbound.Close() - //udp doesnt accept connections, + //udp doesn't accept connections, //udp simply forwards packets //and therefore only needs to listen eg, ctx := errgroup.WithContext(ctx) @@ -178,7 +179,7 @@ func (u *udpListener) getUDPChan(ctx context.Context) (*udpChannel, error) { c: rwc, } u.outbound = o - u.Debugf("aquired channel") + u.Debugf("acquired channel") return o, nil } From 430a7a56feb9c890dced2fbbefd1c3dd2cc7d417 Mon Sep 17 00:00:00 2001 From: Mario Trangoni Date: Fri, 2 Jun 2023 15:47:42 +0200 Subject: [PATCH 2/2] Add codespell to the CI Signed-off-by: Mario Trangoni --- .github/workflows/ci.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2469f7e3..2a0d2cae 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,6 +2,18 @@ on: [push, pull_request] name: CI jobs: # ================ + # LINTER JOB + # runs on every push and PR + # ================ + linter: + name: Linter checks + steps: + - name: Spelling check + uses: codespell-project/actions-codespell@v2 + with: + check_filenames: true + check_hidden: true + # ================ # TEST JOB # runs on every push and PR # runs 2x3 times (see matrix)