It now successfully sends a fortune, but the server then crashes
Change-Id: I3ad675a40fe78cbfc84d6f1e2ee7a54f02a21f97
diff --git a/runtime/internal/flow/conn/grpc/conn.go b/runtime/internal/flow/conn/grpc/conn.go
index d72bbf6..d319973 100644
--- a/runtime/internal/flow/conn/grpc/conn.go
+++ b/runtime/internal/flow/conn/grpc/conn.go
@@ -43,15 +43,15 @@
// TODO: what if bytesRead < 3? = 3?
func (c *conn) Read(b []byte) (n int, err error) {
- c.mu.Lock()
- defer c.mu.Unlock()
+ // c.mu.Lock()
+ // defer c.mu.Unlock()
if !doEncrypt {
log.Printf("Beginning to Read.\n")
frame := [3]byte{}
frameCopied, err := c.rawConn.Read(frame[:])
if frameCopied != 3 {
- return -1, errors.New("Did not copy 3 frame bytes.")
+ return frameCopied, errors.New("Did not copy 3 frame bytes.")
}
msgSize := read3ByteUint(frame)
@@ -72,7 +72,7 @@
frame := [3]byte{}
frameCopied, err := c.rawConn.Read(frame[:])
if frameCopied != 3 {
- return -1, errors.New("Did not copy 3 frame bytes.")
+ return frameCopied, errors.New("Did not copy 3 frame bytes.")
}
msgSize := read3ByteUint(frame)
@@ -107,15 +107,15 @@
// TODO: all this casting is gross
func (c *conn) Write(b []byte) (n int, err error) {
// log.Printf("Write called:\n%v\n", string(debug.Stack()))
- c.mu.Lock()
- defer c.mu.Unlock()
+ // c.mu.Lock()
+ // defer c.mu.Unlock()
if !doEncrypt {
log.Printf("Beginning to write.\n")
tmp := make([]byte, 3)
err = write3ByteUint(tmp, len(b))
if err != nil {
- return -1, err
+ return 0, err
}
bytesCopied, err := io.Copy(c.rawConn, bytes.NewReader(tmp))
if err != nil {
@@ -136,7 +136,7 @@
tmp := make([]byte, 3, 3+len(b)+box.Overhead) // TODO: is this enough? Also, why do we need both of tmp and out?
err = write3ByteUint(tmp[:3], len(b)+box.Overhead)
if err != nil {
- return -1, err
+ return 0, err
}
out := box.SealAfterPrecomputation(tmp, b, c.currentNonce(), c.sharedKey)
// log.Printf("tmp: %v", tmp)
@@ -154,7 +154,7 @@
log.Printf("Did not write entire message. Expected to write %d bytes but wrote %d.", len(out), bytesCopied)
log.Printf("Failed to write.\n")
log.Fatal(err)
- return -1, errors.New(errMsg)
+ return int(bytesCopied), errors.New(errMsg)
}
// log.Printf("cap(b): %d, len(b) %d, cap(out): %d, len(out): %d\n", cap(b), len(b), cap(out), len(out))
log.Printf("Succeeded in writing!\n\n")
@@ -184,51 +184,51 @@
// TODO: cover these up with an interface?
// TODO: remove all these useless mutex locks and unlocks
func (c *conn) Close() error {
- c.mu.Lock()
- defer c.mu.Unlock()
- debug.PrintStack()
- // log.Fatalf("DON'T CLOSE THE CONNETION\n")
+ // c.mu.Lock()
+ // defer c.mu.Unlock()
+ log.Printf("SOMEONE IS CLOSING THE CONNECTION\n")
return c.rawConn.Close()
}
func (c *conn) LocalAddr() net.Addr {
- c.mu.Lock()
- defer c.mu.Unlock()
+ // c.mu.Lock()
+ // defer c.mu.Unlock()
return c.rawConn.LocalAddr()
}
func (c *conn) RemoteAddr() net.Addr {
- c.mu.Lock()
- defer c.mu.Unlock()
+ // c.mu.Lock()
+ // defer c.mu.Unlock()
return c.rawConn.RemoteAddr()
}
func (c *conn) SetDeadline(t time.Time) error {
- c.mu.Lock()
- defer c.mu.Unlock()
+ // c.mu.Lock()
+ // defer c.mu.Unlock()
return c.rawConn.SetDeadline(t)
}
func (c *conn) SetReadDeadline(t time.Time) error {
- c.mu.Lock()
- defer c.mu.Unlock()
+ // c.mu.Lock()
+ // defer c.mu.Unlock()
return c.rawConn.SetReadDeadline(t)
}
func (c *conn) SetWriteDeadline(t time.Time) error {
- c.mu.Lock()
- defer c.mu.Unlock()
+ // c.mu.Lock()
+ // defer c.mu.Unlock()
return c.rawConn.SetWriteDeadline(t)
}
// TODO: should I just collapse current and advance?
func (c *conn) currentNonce() *[24]byte {
+ c.mu.Lock()
+ defer c.mu.Unlock()
return &c.nonce
}
// TODO: re enable.
func (c *conn) advanceNonce() {
-
// c.counter++
// binary.LittleEndian.PutUint64(c.nonce[:], c.counter)
}