Exemple #1
0
func main() {
	conn := sssl.Client(stdio.NewStdioConn(), dh.Private())
	_, err := conn.Write([]byte("hello, world!"))
	if err != nil {
		os.Exit(1)
	}
	var p [13]byte
	_, err = io.ReadFull(conn, p[:])
	if err != nil {
		os.Exit(1)
	}
	if string(p[:]) != "hello, world!" {
		os.Exit(1)
	}
}
Exemple #2
0
func main() {
	if len(os.Args) < 2 {
		fmt.Fprintf(os.Stderr, "Usage: %s <address>\n", os.Args[0])
		os.Exit(1)
	}
	c, err := net.Dial("tcp", os.Args[1])
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error: %v\n", err)
		os.Exit(1)
	}
	conn := sssl.Client(c, dh.Private())
	defer conn.Close()

	go func() {
		defer conn.Close()
		io.Copy(os.Stdout, conn)
	}()
	io.Copy(conn, os.Stdin)
}
Exemple #3
0
func main() {
	if len(os.Args) < 2 {
		fmt.Fprintf(os.Stderr, "Usage: %s <address>\n", os.Args[0])
		os.Exit(1)
	}
	l, err := net.Listen("tcp", os.Args[1])
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error: %v\n", err)
		os.Exit(1)
	}
	defer l.Close()
	for {
		c, err := l.Accept()
		if err != nil {
			fmt.Fprintf(os.Stderr, "Error: %v\n", err)
			os.Exit(1)
		}
		conn := sssl.Server(c, dh.Private())
		go func() {
			defer conn.Close()
			io.Copy(conn, conn)
		}()
	}
}
Exemple #4
0
func main() {
	underlying := stdio.NewStdioConn()
	conn := sssl.Client(underlying, dh.Private())
	err := conn.Handshake()
	if err != nil {
		os.Exit(1)
	}

	r := rand.New(rand.NewSource(time.Now().Unix()))

	buf_out := &bytes.Buffer{}
	underlying.Output = WriteCloser{
		Writer: buf_out,
		Closer: ioutil.NopCloser(nil)}
	buf_in := bufio.NewReaderSize(os.Stdin, 1024*1024)
	underlying.Input = ReadCloser{
		Reader: buf_in,
		Closer: os.Stdin}

	var expected int64
	bytes_remaining := 63 * 1024 * 1024
	var buffer [65536]byte
	for bytes_remaining > 0 {
		amount := r.Intn(len(buffer))
		if amount > bytes_remaining {
			amount = bytes_remaining
		}
		bytes_remaining -= amount
		// just write out different sizes of zeros
		buf_slice := buffer[:amount]
		_, err = conn.Write(buf_slice)
		if err != nil {
			panic(err)
		}
		expected += int64(amount)
	}

	var wg sync.WaitGroup
	wg.Add(2)

	go func() {
		defer wg.Done()
		_, err := buf_out.WriteTo(os.Stdout)
		if err != nil {
			panic(err)
		}
	}()

	go func() {
		defer wg.Done()
		var total int64
		var buffer [65536]byte
		var zeros [65536]byte
		for total < expected {
			amount := int64(len(buffer))
			if expected-total < amount {
				amount = expected - total
			}
			buf_slice := buffer[:amount]
			n, err := io.ReadFull(conn, buf_slice)
			if err != nil {
				panic(err)
			}
			if !bytes.Equal(buf_slice[:n], zeros[:amount]) {
				panic("not equal")
			}
			total += amount
		}
	}()

	wg.Wait()
}
Exemple #5
0
func main() {
	conn := sssl.Server(stdio.NewStdioConn(), dh.Private())
	io.Copy(conn, conn)
}