Browse Source

Close on version mismatch

Jakob Borg 12 years ago
parent
commit
8d3aa97047
2 changed files with 26 additions and 0 deletions
  1. 4 0
      protocol/protocol.go
  2. 22 0
      protocol/protocol_test.go

+ 4 - 0
protocol/protocol.go

@@ -192,6 +192,10 @@ func (c *Connection) readerLoop() {
 			c.close()
 			break
 		}
+		if hdr.version != 0 {
+			c.close()
+			break
+		}
 
 		c.wLock.Lock()
 		c.lastReceive = time.Now()

+ 22 - 0
protocol/protocol_test.go

@@ -135,3 +135,25 @@ func TestRequestResponseErr(t *testing.T) {
 		t.Error("Never passed")
 	}
 }
+
+func TestVersionErr(t *testing.T) {
+	m0 := &TestModel{}
+	m1 := &TestModel{}
+
+	ar, aw := io.Pipe()
+	br, bw := io.Pipe()
+
+	c0 := NewConnection("c0", ar, bw, m0)
+	NewConnection("c1", br, aw, m1)
+
+	c0.mwriter.writeHeader(header{
+		version: 2,
+		msgID:   0,
+		msgType: 0,
+	})
+	c0.flush()
+
+	if !m1.closed {
+		t.Error("Connection should close due to unknown version")
+	}
+}