Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plumb context to handleIRC #20

Merged
merged 2 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions robustirc-bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@
}
}

func (p *bridge) handleIRC(conn net.Conn) {
func (p *bridge) handleIRC(ctx context.Context, conn net.Conn) {

Check failure on line 301 in robustirc-bridge/bridge.go

View workflow job for this annotation

GitHub Actions / CI (1.15)

undefined: context

Check failure on line 301 in robustirc-bridge/bridge.go

View workflow job for this annotation

GitHub Actions / CI (1.15)

undefined: context

Check failure on line 301 in robustirc-bridge/bridge.go

View workflow job for this annotation

GitHub Actions / CI (1.17)

undefined: context

Check failure on line 301 in robustirc-bridge/bridge.go

View workflow job for this annotation

GitHub Actions / CI (1.17)

undefined: context

Check failure on line 301 in robustirc-bridge/bridge.go

View workflow job for this annotation

GitHub Actions / CI (1.18)

undefined: context

Check failure on line 301 in robustirc-bridge/bridge.go

View workflow job for this annotation

GitHub Actions / CI (1.19)

undefined: context

Check failure on line 301 in robustirc-bridge/bridge.go

View workflow job for this annotation

GitHub Actions / CI (1.13)

undefined: context

Check failure on line 301 in robustirc-bridge/bridge.go

View workflow job for this annotation

GitHub Actions / CI (1.13)

undefined: context

Check failure on line 301 in robustirc-bridge/bridge.go

View workflow job for this annotation

GitHub Actions / CI (1.11)

undefined: context

Check failure on line 301 in robustirc-bridge/bridge.go

View workflow job for this annotation

GitHub Actions / CI (1.11)

undefined: context

Check failure on line 301 in robustirc-bridge/bridge.go

View workflow job for this annotation

GitHub Actions / CI (1.12)

undefined: context

Check failure on line 301 in robustirc-bridge/bridge.go

View workflow job for this annotation

GitHub Actions / CI (1.12)

undefined: context

Check failure on line 301 in robustirc-bridge/bridge.go

View workflow job for this annotation

GitHub Actions / CI (1.14)

undefined: context

Check failure on line 301 in robustirc-bridge/bridge.go

View workflow job for this annotation

GitHub Actions / CI (1.14)

undefined: context

Check failure on line 301 in robustirc-bridge/bridge.go

View workflow job for this annotation

GitHub Actions / CI (1.16)

undefined: context

Check failure on line 301 in robustirc-bridge/bridge.go

View workflow job for this annotation

GitHub Actions / CI (1.16)

undefined: context
var quitmsg, killmsg string
var waitingForPingReply bool

Expand Down Expand Up @@ -527,6 +527,7 @@
log.Fatal("You must specify either -network and -listen, or -socks.")
}

ctx := context.Background()

Check failure on line 530 in robustirc-bridge/bridge.go

View workflow job for this annotation

GitHub Actions / CI (1.15)

undefined: context

Check failure on line 530 in robustirc-bridge/bridge.go

View workflow job for this annotation

GitHub Actions / CI (1.15)

undefined: context

Check failure on line 530 in robustirc-bridge/bridge.go

View workflow job for this annotation

GitHub Actions / CI (1.17)

undefined: context

Check failure on line 530 in robustirc-bridge/bridge.go

View workflow job for this annotation

GitHub Actions / CI (1.17)

undefined: context

Check failure on line 530 in robustirc-bridge/bridge.go

View workflow job for this annotation

GitHub Actions / CI (1.18)

undefined: context

Check failure on line 530 in robustirc-bridge/bridge.go

View workflow job for this annotation

GitHub Actions / CI (1.19)

undefined: context

Check failure on line 530 in robustirc-bridge/bridge.go

View workflow job for this annotation

GitHub Actions / CI (1.13)

undefined: context

Check failure on line 530 in robustirc-bridge/bridge.go

View workflow job for this annotation

GitHub Actions / CI (1.13)

undefined: context

Check failure on line 530 in robustirc-bridge/bridge.go

View workflow job for this annotation

GitHub Actions / CI (1.11)

undefined: context

Check failure on line 530 in robustirc-bridge/bridge.go

View workflow job for this annotation

GitHub Actions / CI (1.11)

undefined: context

Check failure on line 530 in robustirc-bridge/bridge.go

View workflow job for this annotation

GitHub Actions / CI (1.12)

undefined: context

Check failure on line 530 in robustirc-bridge/bridge.go

View workflow job for this annotation

GitHub Actions / CI (1.12)

undefined: context

Check failure on line 530 in robustirc-bridge/bridge.go

View workflow job for this annotation

GitHub Actions / CI (1.14)

undefined: context

Check failure on line 530 in robustirc-bridge/bridge.go

View workflow job for this annotation

GitHub Actions / CI (1.14)

undefined: context

Check failure on line 530 in robustirc-bridge/bridge.go

View workflow job for this annotation

GitHub Actions / CI (1.16)

undefined: context

Check failure on line 530 in robustirc-bridge/bridge.go

View workflow job for this annotation

GitHub Actions / CI (1.16)

undefined: context
if *httpAddress != "" {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
for _, n := range robustsession.CopyNetworks() {
Expand Down Expand Up @@ -570,7 +571,7 @@
listeners = append(listeners, ln)
go func() {
log.Printf("RobustIRC IRC bridge listening on %q (SOCKS). Specify an empty -socks= to disable.\n", *socks)
if err := serveSocks(ln, &connWG); err != nil {
if err := serveSocks(ctx, ln, &connWG); err != nil {
log.Fatal(err)
}
}()
Expand All @@ -582,7 +583,7 @@
log.Printf("Not listening on %q (IRC) because -network= was not specified.\n", *listen)
ln := maybeTLSListener(*socks)
listeners = append(listeners, ln)
log.Fatal(serveSocks(ln, &connWG))
log.Fatal(serveSocks(ctx, ln, &connWG))
}

// IRC
Expand All @@ -607,13 +608,13 @@
connWG.Add(1)
go func() {
defer connWG.Done()
p.handleIRC(conn)
p.handleIRC(ctx, conn)
}()
}
}()
}
} else if n := nfds(); *network != "" && n > 0 {
if err := handleSocketActivation(n, &connWG); err != nil {
if err := handleSocketActivation(ctx, n, &connWG); err != nil {
log.Fatal(err)
}
}
Expand Down
5 changes: 3 additions & 2 deletions robustirc-bridge/socket_activation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package main

import (
"context"
"log"
"net"
"os"
Expand Down Expand Up @@ -32,7 +33,7 @@ func nfds() int {
// handleSocketActivation handles listening on the systemd-provided sockets.
// It can return an error to differentiate between this implementation and
// the no-op on Windows.
func handleSocketActivation(n int, connWG *sync.WaitGroup) error {
func handleSocketActivation(ctx context.Context, n int, connWG *sync.WaitGroup) error {
names := strings.Split(os.Getenv("LISTEN_FDNAMES"), ":")
os.Unsetenv("LISTEN_PID")
os.Unsetenv("LISTEN_FDS")
Expand Down Expand Up @@ -67,7 +68,7 @@ func handleSocketActivation(n int, connWG *sync.WaitGroup) error {
connWG.Add(1)
go func() {
defer connWG.Done()
p.handleIRC(conn)
p.handleIRC(ctx, conn)
}()
}
}()
Expand Down
9 changes: 5 additions & 4 deletions robustirc-bridge/socks.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"encoding/binary"
"errors"
"fmt"
Expand Down Expand Up @@ -55,7 +56,7 @@ type socksConnectionData struct {
Port uint16
}

func serveSocks(ln net.Listener, connWG *sync.WaitGroup) error {
func serveSocks(ctx context.Context, ln net.Listener, connWG *sync.WaitGroup) error {
for {
conn, err := ln.Accept()
if err != nil {
Expand All @@ -69,7 +70,7 @@ func serveSocks(ln net.Listener, connWG *sync.WaitGroup) error {
defer connWG.Done()
s := &socksServer{conn}

if err := s.handleConn(); err != nil {
if err := s.handleConn(ctx); err != nil {
log.Printf("Could not SOCKS: %v\n", err)
}
}()
Expand All @@ -79,7 +80,7 @@ func serveSocks(ln net.Listener, connWG *sync.WaitGroup) error {
return nil
}

func (s *socksServer) handleConn() (err error) {
func (s *socksServer) handleConn(ctx context.Context) (err error) {
defer s.conn.Close()

if err = s.greet(); err != nil {
Expand Down Expand Up @@ -122,7 +123,7 @@ func (s *socksServer) handleConn() (err error) {
return err
}

p.handleIRC(s.conn)
p.handleIRC(ctx, s.conn)
// never returns
return nil
}
Expand Down
Loading