Reconnect to the torrentfs -testPeer at regular intervals if it's missing for any loaded torrents
This commit is contained in:
parent
8df567e822
commit
fe5f8317d4
|
@ -220,7 +220,7 @@ type Torrent struct {
|
||||||
Pieces []*piece
|
Pieces []*piece
|
||||||
Data MMapSpan
|
Data MMapSpan
|
||||||
MetaInfo *metainfo.MetaInfo
|
MetaInfo *metainfo.MetaInfo
|
||||||
Conns []*connection
|
Conns []*Connection
|
||||||
Peers []Peer
|
Peers []Peer
|
||||||
Priorities *list.List
|
Priorities *list.List
|
||||||
}
|
}
|
||||||
|
@ -383,7 +383,8 @@ type Client struct {
|
||||||
PeerId [20]byte
|
PeerId [20]byte
|
||||||
DataReady chan DataSpec
|
DataReady chan DataSpec
|
||||||
|
|
||||||
mu sync.Mutex
|
sync.Mutex
|
||||||
|
mu *sync.Mutex
|
||||||
event sync.Cond
|
event sync.Cond
|
||||||
|
|
||||||
halfOpen int
|
halfOpen int
|
||||||
|
@ -435,6 +436,7 @@ func (cl *Client) TorrentReadAt(ih InfoHash, off int64, p []byte) (n int, err er
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Start() {
|
func (c *Client) Start() {
|
||||||
|
c.mu = &c.Mutex
|
||||||
c.torrents = make(map[InfoHash]*Torrent)
|
c.torrents = make(map[InfoHash]*Torrent)
|
||||||
if c.HalfOpenLimit == 0 {
|
if c.HalfOpenLimit == 0 {
|
||||||
c.HalfOpenLimit = 10
|
c.HalfOpenLimit = 10
|
||||||
|
|
|
@ -323,16 +323,26 @@ func main() {
|
||||||
go fs.publishData()
|
go fs.publishData()
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
|
torrentLoop:
|
||||||
for _, t := range client.Torrents() {
|
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 {
|
if testAddr != nil {
|
||||||
client.AddPeers(t.InfoHash, []torrent.Peer{{
|
if err := client.AddPeers(t.InfoHash, []torrent.Peer{{
|
||||||
IP: testAddr.IP,
|
IP: testAddr.IP,
|
||||||
Port: testAddr.Port,
|
Port: testAddr.Port,
|
||||||
}})
|
}}); err != nil {
|
||||||
|
log.Print(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
time.Sleep(10 * time.Second)
|
time.Sleep(10 * time.Second)
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
fusefs.Serve(conn, fs)
|
fusefs.Serve(conn, fs)
|
||||||
|
|
Loading…
Reference in New Issue