From 95db42e64528d8a72a175d158aec395b285a5901 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Mon, 9 May 2022 16:36:54 +0200 Subject: [PATCH] Move identd to separate package --- cmd/soju/main.go | 4 +++- ident.go => identd/identd.go | 6 ++---- server.go | 7 ++++++- 3 files changed, 11 insertions(+), 6 deletions(-) rename ident.go => identd/identd.go (97%) diff --git a/cmd/soju/main.go b/cmd/soju/main.go index 1230cf1..1293cb5 100644 --- a/cmd/soju/main.go +++ b/cmd/soju/main.go @@ -25,6 +25,7 @@ import ( "git.sr.ht/~emersion/soju" "git.sr.ht/~emersion/soju/config" "git.sr.ht/~emersion/soju/database" + "git.sr.ht/~emersion/soju/identd" ) // TCP keep-alive interval for downstream TCP connections @@ -235,7 +236,7 @@ func main() { }() case "ident": if srv.Identd == nil { - srv.Identd = soju.NewIdentd() + srv.Identd = identd.New() } host := u.Host @@ -247,6 +248,7 @@ func main() { log.Fatalf("failed to start listener on %q: %v", listen, err) } ln = proxyProtoListener(ln, srv) + ln = soju.NewRetryListener(ln) go func() { if err := srv.Identd.Serve(ln); err != nil { log.Printf("serving %q: %v", listen, err) diff --git a/ident.go b/identd/identd.go similarity index 97% rename from ident.go rename to identd/identd.go index a596a86..db4b258 100644 --- a/ident.go +++ b/identd/identd.go @@ -1,4 +1,4 @@ -package soju +package identd import ( "bufio" @@ -49,7 +49,7 @@ type Identd struct { lock sync.RWMutex } -func NewIdentd() *Identd { +func New() *Identd { return &Identd{entries: make(map[identKey]string)} } @@ -74,8 +74,6 @@ func (s *Identd) Delete(remoteAddr, localAddr string) { } func (s *Identd) Serve(ln net.Listener) error { - ln = &retryListener{Listener: ln} - for { conn, err := ln.Accept() if err != nil { diff --git a/server.go b/server.go index b4ecb0b..9ca4a00 100644 --- a/server.go +++ b/server.go @@ -21,6 +21,7 @@ import ( "git.sr.ht/~emersion/soju/config" "git.sr.ht/~emersion/soju/database" + "git.sr.ht/~emersion/soju/identd" ) // TODO: make configurable @@ -101,6 +102,10 @@ type retryListener struct { delay time.Duration } +func NewRetryListener(ln net.Listener) net.Listener { + return &retryListener{Listener: ln} +} + func (ln *retryListener) Accept() (net.Conn, error) { for { conn, err := ln.Listener.Accept() @@ -138,7 +143,7 @@ type Config struct { type Server struct { Logger Logger - Identd *Identd // can be nil + Identd *identd.Identd // can be nil MetricsRegistry prometheus.Registerer // can be nil config atomic.Value // *Config