Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 7 additions & 5 deletions robustirc-bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package main

import (
"bufio"
"context"
"crypto/tls"
"flag"
"fmt"
Expand Down Expand Up @@ -298,7 +299,7 @@ func (s *ircsession) getMessages() {
}
}

func (p *bridge) handleIRC(conn net.Conn) {
func (p *bridge) handleIRC(ctx context.Context, conn net.Conn) {
var quitmsg, killmsg string
var waitingForPingReply bool

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

ctx := context.Background()
if *httpAddress != "" {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
for _, n := range robustsession.CopyNetworks() {
Expand Down Expand Up @@ -570,7 +572,7 @@ func main() {
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 +584,7 @@ func main() {
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 +609,13 @@ func main() {
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