예제 #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)
	}
}
예제 #2
0
func main() {
	conn := sssl.Client(stdio.NewStdioConn(), big.NewInt(123))
	fmt.Fprintf(os.Stderr, "***** Client's message: hi\n")
	_, err := conn.Write([]byte("hi"))
	if err != nil {
		fmt.Fprintf(os.Stderr, "***** Client failed writing message\n")
		os.Exit(1)
	}
	var p [2]byte
	_, err = io.ReadFull(conn, p[:])
	if err != nil {
		fmt.Fprintf(os.Stderr, "***** Client failed reading server's response\n")
		os.Exit(1)
	}
	if string(p[:]) != "hi" {
		fmt.Fprintf(os.Stderr, "***** Client received %#v but expected %#v\n",
			string(p[:]), "hi")
		os.Exit(1)
	}
}
예제 #3
0
파일: main.go 프로젝트: nkhuyu/htc2015
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()
}
예제 #4
0
파일: main.go 프로젝트: nkhuyu/htc2015
func main() {
	conn := sssl.Server(stdio.NewStdioConn(), dh.Private())
	io.Copy(conn, conn)
}