Just some commented-out SetReadDeadline() experiments

This commit is contained in:
Russ Magee 2018-01-16 18:30:57 -08:00
parent 942b8865cf
commit e09f052f45
2 changed files with 17 additions and 5 deletions

View File

@ -35,7 +35,6 @@ func main() {
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
fmt.Println("Accepted client") fmt.Println("Accepted client")
// Handle the connection in a new goroutine. // Handle the connection in a new goroutine.

View File

@ -27,21 +27,27 @@ import (
"fmt" "fmt"
"math/big" "math/big"
"net" "net"
"time"
) )
/*---------------------------------------------------------------------*/ /*---------------------------------------------------------------------*/
// Conn is a HKex connection - a drop-in replacement for net.Conn // Conn is a HKex connection - a drop-in replacement for net.Conn
type Conn struct { type Conn struct {
//net.Conn
c net.Conn // which also implements io.Reader, io.Writer, ... c net.Conn // which also implements io.Reader, io.Writer, ...
h *HerraduraKEx h *HerraduraKEx
cipheropts uint32 // post-KEx cipher/hmac options cipheropts uint32 // post-KEx cipher/hmac options
opts uint32 // post-KEx protocol options (caller-defined) opts uint32 // post-KEx protocol options (caller-defined)
op uint8 // post-KEx 'op' (caller-defined) op uint8 // post-KEx 'op' (caller-defined)
r cipher.Stream r cipher.Stream
w cipher.Stream w cipher.Stream
} }
func (c *Conn) SetReadDeadline(t time.Time) error {
return c.SetReadDeadline(t)
}
// ConnOpts returns the cipher/hmac options value, which is sent to the // ConnOpts returns the cipher/hmac options value, which is sent to the
// peer but is not itself part of the KEx. // peer but is not itself part of the KEx.
// //
@ -141,7 +147,7 @@ func Dial(protocol string, ipport string, extensions ...string) (hc *Conn, err e
if err != nil { if err != nil {
return nil, err return nil, err
} }
hc = &Conn{c: c, h: New(0, 0), cipheropts: 0, opts: 0, op:0, r: nil, w: nil} hc = &Conn{c: c, h: New(0, 0), cipheropts: 0, opts: 0, op: 0, r: nil, w: nil}
hc.applyConnExtensions(extensions...) hc.applyConnExtensions(extensions...)
@ -218,7 +224,7 @@ func (hl *HKExListener) Accept() (hc Conn, err error) {
} }
fmt.Println("[Accepted]") fmt.Println("[Accepted]")
hc = Conn{c: c, h: New(0, 0), cipheropts: 0, opts: 0, op:0, r: nil, w: nil} hc = Conn{c: c, h: New(0, 0), cipheropts: 0, opts: 0, op: 0, r: nil, w: nil}
d := big.NewInt(0) d := big.NewInt(0)
_, err = fmt.Fscanln(c, d) _, err = fmt.Fscanln(c, d)
@ -243,6 +249,7 @@ func (hl *HKExListener) Accept() (hc Conn, err error) {
hc.w = hc.getStream(hc.h.fa) hc.w = hc.getStream(hc.h.fa)
return return
} }
/*---------------------------------------------------------------------*/ /*---------------------------------------------------------------------*/
// Read into a byte slice // Read into a byte slice
@ -250,9 +257,15 @@ func (hl *HKExListener) Accept() (hc Conn, err error) {
// See go doc io.Reader // See go doc io.Reader
func (c Conn) Read(b []byte) (n int, err error) { func (c Conn) Read(b []byte) (n int, err error) {
fmt.Printf("[Decrypting...]\n") fmt.Printf("[Decrypting...]\n")
//c.c.SetReadDeadline(time.Now().Add(1 * time.Second))
n, err = c.c.Read(b) n, err = c.c.Read(b)
if err != nil && err.Error() != "EOF" { if err != nil && err.Error() != "EOF" {
panic(err) //if neterr, ok := err.(net.Error); ok {
// fmt.Printf("[Read() timeout - %s]\n", neterr)
//} else {
// panic(err)
//}
} }
fmt.Printf(" ctext:%+v\n", b[:n]) // print only used portion fmt.Printf(" ctext:%+v\n", b[:n]) // print only used portion
db := bytes.NewBuffer(b[:n]) db := bytes.NewBuffer(b[:n])