func (srv *Server) loop(l *blend.Listener) { for { session := l.AcceptSession() go func() { for { outConn := session.Accept() // Read the first empty chunk from the connection if _, err := outConn.Read(); err != nil { srv.frame.Printf("first read (%s)", err) outConn.Close() continue } // Dial user server inConn, err := net.Dial("tcp", srv.inAddr) if err != nil { outConn.Close() srv.frame.Printf("server dial tcp address %s (%s)", srv.inAddr, err) time.Sleep(time.Second) // Prevents DoS when local TCP server is down temporarily continue } Proxy(inConn, outConn) } }() } }
func newListener(workerID n.WorkerID, pid int, listener *blend.Listener) *Listener { l := &Listener{ addr: NewNetAddr(workerID, pid, listener.Addr()), // Compute what our address looks like on the outside. listener: listener, ach: make(chan n.Conn), } go l.loop() return l }