Reconnect to the torrentfs -testPeer at regular intervals if it's missing for any loaded torrents

This commit is contained in:
Matt Joiner 2013-10-22 18:01:56 +11:00
parent 8df567e822
commit fe5f8317d4
2 changed files with 17 additions and 5 deletions

View File

@ -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

View 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)