]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fix a few data races
authorMatt Joiner <anacrolix@gmail.com>
Tue, 2 Jun 2015 14:00:25 +0000 (00:00 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 2 Jun 2015 14:00:25 +0000 (00:00 +1000)
dht/dht.go
file.go

index 01d2835209a7c0221bbe421087042be1acce1c72..3f4377307f99dd17fa7d35c45039b1c64229b21d 100644 (file)
@@ -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 2efbaeaaf8d0149e1e0b865492d1f1470a763a8f..688fc2faa92ae6af221d706a94fe4d27461f5eb2 100644 (file)
--- 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