enable/disable for listeners
This commit is contained in:
parent
1cf9cc880d
commit
a0654b0016
@ -85,7 +85,7 @@ func buildTcp(ctx context.Context, p *proxy.Proxy, peer Peer, g func() proxy.Mac
|
|||||||
return nil
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -135,7 +135,7 @@ func buildUdp(ctx context.Context, p *proxy.Proxy, peer Peer, g func() proxy.Mac
|
|||||||
return nil
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"net"
|
"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)
|
laddr, err := net.ResolveTCPAddr("tcp", local)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -33,9 +33,13 @@ func NewListener(ctx context.Context, p *proxy.Proxy, local string, v func() pro
|
|||||||
|
|
||||||
log.Printf("received new tcp connection: %v\n", f)
|
log.Printf("received new tcp connection: %v\n", f)
|
||||||
|
|
||||||
|
if enableConsumers {
|
||||||
p.AddConsumer(ctx, &f, g())
|
p.AddConsumer(ctx, &f, g())
|
||||||
|
}
|
||||||
|
if enableProducers {
|
||||||
p.AddProducer(ctx, &f, v())
|
p.AddProducer(ctx, &f, v())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -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)
|
laddr, err := net.ResolveUDPAddr("udp", local)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -85,8 +85,12 @@ func NewListener(ctx context.Context, p *proxy.Proxy, local string, v func() pro
|
|||||||
|
|
||||||
receivedConnections[raddr] = &f
|
receivedConnections[raddr] = &f
|
||||||
|
|
||||||
|
if enableConsumers {
|
||||||
p.AddConsumer(ctx, &f, g)
|
p.AddConsumer(ctx, &f, g)
|
||||||
|
}
|
||||||
|
if enableProducers {
|
||||||
p.AddProducer(ctx, &f, v)
|
p.AddProducer(ctx, &f, v)
|
||||||
|
}
|
||||||
|
|
||||||
log.Println("handling...")
|
log.Println("handling...")
|
||||||
if err := f.queueDatagram(ctx, buf[:n]); err != nil {
|
if err := f.queueDatagram(ctx, buf[:n]); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user