dissertation-2-code/tcp/listener.go
Jake Hillion 3291eb4a6c
All checks were successful
continuous-integration/drone/push Build is passing
reset write buffer
2021-01-23 20:46:06 +00:00

42 lines
663 B
Go

package tcp
import (
"log"
"mpbl3p/proxy"
"net"
)
func NewListener(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(20); err != nil {
// panic(err)
//}
f := NewFlowConn(conn)
log.Printf("received new tcp connection: %v\n", f)
p.AddConsumer(&f, g())
p.AddProducer(&f, v())
}
}()
return nil
}