43 lines
698 B
Go
43 lines
698 B
Go
package tcp
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"mpbl3p/proxy"
|
|
"net"
|
|
)
|
|
|
|
func NewListener(ctx context.Context, p *proxy.Proxy, local string, v func() proxy.MacVerifier, g func() proxy.MacGenerator) error {
|
|
laddr, err := net.ResolveTCPAddr("tcp", local)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
listener, err := net.ListenTCP("tcp", laddr)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
go func() {
|
|
for {
|
|
conn, err := listener.AcceptTCP()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
if err := conn.SetWriteBuffer(0); err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
f := NewFlowConn(conn)
|
|
|
|
log.Printf("received new tcp connection: %v\n", f)
|
|
|
|
p.AddConsumer(ctx, &f, g())
|
|
p.AddProducer(ctx, &f, v())
|
|
}
|
|
}()
|
|
|
|
return nil
|
|
}
|