enable/disable for listeners
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
Jake Hillion 2021-04-09 19:00:35 +01:00
parent 1cf9cc880d
commit a0654b0016
3 changed files with 16 additions and 8 deletions

View File

@ -85,7 +85,7 @@ func buildTcp(ctx context.Context, p *proxy.Proxy, peer Peer, g func() proxy.Mac
return nil
}
err := tcp.NewListener(ctx, p, laddr(), v, g)
err := tcp.NewListener(ctx, p, laddr(), v, g, !peer.DisableConsumer, !peer.DisableProducer)
if err != nil {
return err
}
@ -135,7 +135,7 @@ func buildUdp(ctx context.Context, p *proxy.Proxy, peer Peer, g func() proxy.Mac
return nil
}
err := udp.NewListener(ctx, p, laddr(), v, g, c)
err := udp.NewListener(ctx, p, laddr(), v, g, c, !peer.DisableConsumer, !peer.DisableProducer)
if err != nil {
return err
}

View File

@ -7,7 +7,7 @@ import (
"net"
)
func NewListener(ctx context.Context, p *proxy.Proxy, local string, v func() proxy.MacVerifier, g func() proxy.MacGenerator) error {
func NewListener(ctx context.Context, p *proxy.Proxy, local string, v func() proxy.MacVerifier, g func() proxy.MacGenerator, enableConsumers bool, enableProducers bool) error {
laddr, err := net.ResolveTCPAddr("tcp", local)
if err != nil {
return err
@ -33,8 +33,12 @@ func NewListener(ctx context.Context, p *proxy.Proxy, local string, v func() pro
log.Printf("received new tcp connection: %v\n", f)
p.AddConsumer(ctx, &f, g())
p.AddProducer(ctx, &f, v())
if enableConsumers {
p.AddConsumer(ctx, &f, g())
}
if enableProducers {
p.AddProducer(ctx, &f, v())
}
}
}()

View File

@ -27,7 +27,7 @@ func fromUdpAddress(address net.UDPAddr) ComparableUdpAddress {
}
}
func NewListener(ctx context.Context, p *proxy.Proxy, local string, v func() proxy.MacVerifier, g func() proxy.MacGenerator, c func() Congestion) error {
func NewListener(ctx context.Context, p *proxy.Proxy, local string, v func() proxy.MacVerifier, g func() proxy.MacGenerator, c func() Congestion, enableConsumers bool, enableProducers bool) error {
laddr, err := net.ResolveUDPAddr("udp", local)
if err != nil {
return err
@ -85,8 +85,12 @@ func NewListener(ctx context.Context, p *proxy.Proxy, local string, v func() pro
receivedConnections[raddr] = &f
p.AddConsumer(ctx, &f, g)
p.AddProducer(ctx, &f, v)
if enableConsumers {
p.AddConsumer(ctx, &f, g)
}
if enableProducers {
p.AddProducer(ctx, &f, v)
}
log.Println("handling...")
if err := f.queueDatagram(ctx, buf[:n]); err != nil {