func secureEcho(conn io.ReadWriteCloser) { conn, err := secure.Handshake(conn) if err != nil { fmt.Fprintln(os.Stderr, err) return } pipe(conn, conn) }
// Dial generates a private/public key pair, // connects to the server, perform the handshake // and return a reader/writer. func Dial(addr string) (io.ReadWriteCloser, error) { conn, err := net.Dial("tcp", addr) if err != nil { return nil, err } if sec { return secure.Handshake(conn) } return conn, err }
// Serve starts a secured echo server on the given listener. func Serve(l net.Listener) error { for { conn, err := l.Accept() if err != nil { return err } if sec { secure.Handshake(conn) continue } go pipe(conn, conn) } return nil }