Move identd to separate package
This commit is contained in:
parent
620a8789b0
commit
95db42e645
@ -25,6 +25,7 @@ import (
|
|||||||
"git.sr.ht/~emersion/soju"
|
"git.sr.ht/~emersion/soju"
|
||||||
"git.sr.ht/~emersion/soju/config"
|
"git.sr.ht/~emersion/soju/config"
|
||||||
"git.sr.ht/~emersion/soju/database"
|
"git.sr.ht/~emersion/soju/database"
|
||||||
|
"git.sr.ht/~emersion/soju/identd"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TCP keep-alive interval for downstream TCP connections
|
// TCP keep-alive interval for downstream TCP connections
|
||||||
@ -235,7 +236,7 @@ func main() {
|
|||||||
}()
|
}()
|
||||||
case "ident":
|
case "ident":
|
||||||
if srv.Identd == nil {
|
if srv.Identd == nil {
|
||||||
srv.Identd = soju.NewIdentd()
|
srv.Identd = identd.New()
|
||||||
}
|
}
|
||||||
|
|
||||||
host := u.Host
|
host := u.Host
|
||||||
@ -247,6 +248,7 @@ func main() {
|
|||||||
log.Fatalf("failed to start listener on %q: %v", listen, err)
|
log.Fatalf("failed to start listener on %q: %v", listen, err)
|
||||||
}
|
}
|
||||||
ln = proxyProtoListener(ln, srv)
|
ln = proxyProtoListener(ln, srv)
|
||||||
|
ln = soju.NewRetryListener(ln)
|
||||||
go func() {
|
go func() {
|
||||||
if err := srv.Identd.Serve(ln); err != nil {
|
if err := srv.Identd.Serve(ln); err != nil {
|
||||||
log.Printf("serving %q: %v", listen, err)
|
log.Printf("serving %q: %v", listen, err)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package soju
|
package identd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
@ -49,7 +49,7 @@ type Identd struct {
|
|||||||
lock sync.RWMutex
|
lock sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewIdentd() *Identd {
|
func New() *Identd {
|
||||||
return &Identd{entries: make(map[identKey]string)}
|
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 {
|
func (s *Identd) Serve(ln net.Listener) error {
|
||||||
ln = &retryListener{Listener: ln}
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
conn, err := ln.Accept()
|
conn, err := ln.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
@ -21,6 +21,7 @@ import (
|
|||||||
|
|
||||||
"git.sr.ht/~emersion/soju/config"
|
"git.sr.ht/~emersion/soju/config"
|
||||||
"git.sr.ht/~emersion/soju/database"
|
"git.sr.ht/~emersion/soju/database"
|
||||||
|
"git.sr.ht/~emersion/soju/identd"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: make configurable
|
// TODO: make configurable
|
||||||
@ -101,6 +102,10 @@ type retryListener struct {
|
|||||||
delay time.Duration
|
delay time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewRetryListener(ln net.Listener) net.Listener {
|
||||||
|
return &retryListener{Listener: ln}
|
||||||
|
}
|
||||||
|
|
||||||
func (ln *retryListener) Accept() (net.Conn, error) {
|
func (ln *retryListener) Accept() (net.Conn, error) {
|
||||||
for {
|
for {
|
||||||
conn, err := ln.Listener.Accept()
|
conn, err := ln.Listener.Accept()
|
||||||
@ -138,7 +143,7 @@ type Config struct {
|
|||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
Logger Logger
|
Logger Logger
|
||||||
Identd *Identd // can be nil
|
Identd *identd.Identd // can be nil
|
||||||
MetricsRegistry prometheus.Registerer // can be nil
|
MetricsRegistry prometheus.Registerer // can be nil
|
||||||
|
|
||||||
config atomic.Value // *Config
|
config atomic.Value // *Config
|
||||||
|
Loading…
Reference in New Issue
Block a user