From: Matt Joiner <anacrolix@gmail.com>
Date: Tue, 2 Jun 2015 14:00:25 +0000 (+1000)
Subject: Fix a few data races
X-Git-Tag: v1.0.0~1168
X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=71f5a1882ad14fcef7e8af8d398da1396f64e97b;p=btrtrc.git

Fix a few data races
---

diff --git a/dht/dht.go b/dht/dht.go
index 01d28352..3f437730 100644
--- a/dht/dht.go
+++ b/dht/dht.go
@@ -629,7 +629,10 @@ func (s *Server) serve() error {
 			logonce.Stderr.Printf("received dht packet exceeds buffer size")
 			continue
 		}
-		if s.ipBlocked(util.AddrIP(addr)) {
+		s.mu.Lock()
+		blocked := s.ipBlocked(util.AddrIP(addr))
+		s.mu.Unlock()
+		if blocked {
 			continue
 		}
 		s.processPacket(b[:n], newDHTAddr(addr))
diff --git a/file.go b/file.go
index 2efbaeaa..688fc2fa 100644
--- a/file.go
+++ b/file.go
@@ -35,6 +35,8 @@ type FilePieceState struct {
 
 // Returns the state of pieces in this file.
 func (f *File) State() (ret []FilePieceState) {
+	f.t.cl.mu.Lock()
+	defer f.t.cl.mu.Unlock()
 	pieceSize := int64(f.t.usualPieceSize())
 	off := f.offset % pieceSize
 	remaining := f.length