Pieces []*piece
Data MMapSpan
MetaInfo *metainfo.MetaInfo
- Conns []*connection
+ Conns []*Connection
Peers []Peer
Priorities *list.List
}
PeerId [20]byte
DataReady chan DataSpec
- mu sync.Mutex
+ sync.Mutex
+ mu *sync.Mutex
event sync.Cond
halfOpen int
}
func (c *Client) Start() {
+ c.mu = &c.Mutex
c.torrents = make(map[InfoHash]*Torrent)
if c.HalfOpenLimit == 0 {
c.HalfOpenLimit = 10
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)