diff --git a/demo/client b/demo/client index 25de02d..430f02e 100755 Binary files a/demo/client and b/demo/client differ diff --git a/demo/client.go b/demo/client.go index 96996cc..07ce6b4 100644 --- a/demo/client.go +++ b/demo/client.go @@ -12,8 +12,6 @@ func main() { // handle error fmt.Println("Err!") } - //fmt.Printf("conn: %v\n", conn) - fmt.Fprintf(conn, "\x01\x02\x03\x04") //fmt.Fprintf(conn, "GET / HTTP/1.0\r\n\r\n") //status, err := bufio.NewReader(conn).ReadString('\n') diff --git a/demo/server b/demo/server index 74069d3..aadaa19 100755 Binary files a/demo/server and b/demo/server differ diff --git a/demo/server.go b/demo/server.go index 33dfae0..5759dd1 100644 --- a/demo/server.go +++ b/demo/server.go @@ -4,7 +4,7 @@ import ( "fmt" "log" "time" - //"net" + hkex "blitter.com/herradurakex" ) @@ -30,7 +30,7 @@ func main() { // Handle the connection in a new goroutine. // The loop then returns to accepting, so that // multiple connections may be served concurrently. - go func(c hkex.HKExConn) (e error) { + go func(c hkex.Conn) (e error) { ch := make(chan []byte) chN := 0 eCh := make(chan error) diff --git a/herradurakex.go b/herradurakex.go index b6a22f0..78cb61c 100644 --- a/herradurakex.go +++ b/herradurakex.go @@ -146,18 +146,18 @@ func (h *HerraduraKEx) String() string { /*---------------------------------------------------------------------*/ -type HKExConn struct { +type Conn struct { c net.Conn // which also implements io.Reader, io.Writer, ... h *HerraduraKEx } // Dial as net.Dial(), but with implicit HKEx PeerD read on connect -func Dial(protocol string, ipport string) (hc *HKExConn, err error) { +func Dial(protocol string, ipport string) (hc *Conn, err error) { c, err := net.Dial(protocol, ipport) if err != nil { return nil, err } - hc = &HKExConn{c, New(0, 0)} + hc = &Conn{c, New(0, 0)} // KEx fmt.Fprintf(c, "0x%s\n", hc.h.d.Text(16)) @@ -175,7 +175,7 @@ func Dial(protocol string, ipport string) (hc *HKExConn, err error) { return } -func (hc *HKExConn) Close() (err error) { +func (hc *Conn) Close() (err error) { err = hc.c.Close() fmt.Println("[Conn Closing]") return @@ -202,14 +202,14 @@ func (hl *HKExListener) Close() { fmt.Println("[Listener Closed]") } -func (hl *HKExListener) Accept() (hc HKExConn, err error) { +func (hl *HKExListener) Accept() (hc Conn, err error) { c, err := hl.l.Accept() fmt.Println("[Accepted]") if err != nil { - return HKExConn{nil, nil}, err + return Conn{nil, nil}, err } - hc = HKExConn{c, New(0, 0)} + hc = Conn{c, New(0, 0)} d := big.NewInt(0) _, err = fmt.Fscanln(c, d) @@ -230,7 +230,7 @@ func (hl *HKExListener) Accept() (hc HKExConn, err error) { } /*---------------------------------------------------------------------*/ -func (hc HKExConn) Read(b []byte) (n int, err error) { +func (hc Conn) Read(b []byte) (n int, err error) { n, err = hc.c.Read(b) fmt.Printf("[Decrypting...]\n") fmt.Printf("[ciphertext:%+v]\n", b[0:n]) @@ -244,7 +244,7 @@ func (hc HKExConn) Read(b []byte) (n int, err error) { return } -func (hc HKExConn) Write(b []byte) (n int, err error) { +func (hc Conn) Write(b []byte) (n int, err error) { fmt.Printf("[Encrypting...]\n") for i, _ := range b { // FOR TESTING ONLY!! USE REAL CRYPTO HERE @@ -256,11 +256,11 @@ func (hc HKExConn) Write(b []byte) (n int, err error) { return } -// Return c coerced into a HKExConn (which implements interface net.Conn) +// Return c coerced into a HKEx Conn (which implements interface net.Conn) // Only useful if one wants to convert an open connection later to HKEx // (Use Dial() instead to start with HKEx automatically.) -func NewHKExConn(c *net.Conn) (hc *HKExConn) { - hc = new(HKExConn) +func NewHKExConn(c *net.Conn) (hc *Conn) { + hc = new(Conn) hc.c = *c hc.h = New(0, 0)