dissertation-2-code/tcp/listener.go
Jake Hillion d4168fc97f
All checks were successful
continuous-integration/drone/push Build is passing
reconnecting tcp flows
2020-11-01 17:16:43 +00:00

34 lines
478 B
Go

package tcp
import (
"mpbl3p/proxy"
"net"
)
func NewListener(p *proxy.Proxy, local string, v proxy.MacVerifier) 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)
}
f := Flow{conn: conn}
p.AddConsumer(&f)
p.AddProducer(&f, v)
}
}()
return nil
}