]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Reconnect to the torrentfs -testPeer at regular intervals if it's missing for any...
authorMatt Joiner <anacrolix@gmail.com>
Tue, 22 Oct 2013 07:01:56 +0000 (18:01 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 22 Oct 2013 07:01:56 +0000 (18:01 +1100)
client.go
cmd/torrentfs/main.go

index 1914977f3e564ce2ee54877311d4f4cf41cf60a9..4a7ee817dde8cbdeeb0b21ef17323345ad278891 100644 (file)
--- a/client.go
+++ b/client.go
@@ -220,7 +220,7 @@ type Torrent struct {
        Pieces     []*piece
        Data       MMapSpan
        MetaInfo   *metainfo.MetaInfo
-       Conns      []*connection
+       Conns      []*Connection
        Peers      []Peer
        Priorities *list.List
 }
@@ -383,7 +383,8 @@ type Client struct {
        PeerId        [20]byte
        DataReady     chan DataSpec
 
-       mu    sync.Mutex
+       sync.Mutex
+       mu    *sync.Mutex
        event sync.Cond
 
        halfOpen int
@@ -435,6 +436,7 @@ func (cl *Client) TorrentReadAt(ih InfoHash, off int64, p []byte) (n int, err er
 }
 
 func (c *Client) Start() {
+       c.mu = &c.Mutex
        c.torrents = make(map[InfoHash]*Torrent)
        if c.HalfOpenLimit == 0 {
                c.HalfOpenLimit = 10
index edfd1d17690e790cc6f8680477b200f136252461..be2295fb846988ec1b0fde58e9d6e3fd6a469822 100644 (file)
@@ -323,16 +323,26 @@ func main() {
        go fs.publishData()
        go func() {
                for {
+               torrentLoop:
                        for _, t := range client.Torrents() {
+                               client.Lock()
+                               for _, c := range t.Conns {
+                                       if c.Socket.RemoteAddr().String() == testAddr.String() {
+                                               client.Unlock()
+                                               continue torrentLoop
+                                       }
+                               }
+                               client.Unlock()
                                if testAddr != nil {
-                                       client.AddPeers(t.InfoHash, []torrent.Peer{{
+                                       if err := client.AddPeers(t.InfoHash, []torrent.Peer{{
                                                IP:   testAddr.IP,
                                                Port: testAddr.Port,
-                                       }})
+                                       }}); err != nil {
+                                               log.Print(err)
+                                       }
                                }
                        }
                        time.Sleep(10 * time.Second)
-                       break
                }
        }()
        fusefs.Serve(conn, fs)