示例#1
0
func secureEcho(conn io.ReadWriteCloser) {
	conn, err := secure.Handshake(conn)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		return
	}
	pipe(conn, conn)
}
示例#2
0
// 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
}
示例#3
0
// 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
}