conn, err := cl.Listener.Accept()
select {
case <-cl.quit:
+ conn.Close()
return
default:
}
log.Print(err)
return
}
+ log.Printf("accepted connection from %s", conn.RemoteAddr())
go func() {
if err := cl.runConnection(conn, nil); err != nil {
log.Print(err)
func (me *Client) runConnection(sock net.Conn, torrent *torrent) (err error) {
conn := &connection{
+ Incoming: torrent == nil,
Socket: sock,
Choked: true,
PeerChoked: true,
// Maintains the state of a connection with a peer.
type connection struct {
- Socket net.Conn
- closed bool
- mu sync.Mutex // Only for closing.
- post chan peer_protocol.Message
- write chan []byte
+ Socket net.Conn
+ Incoming bool
+ closed bool
+ mu sync.Mutex // Only for closing.
+ post chan peer_protocol.Message
+ write chan []byte
// Stuff controlled by the local peer.
Interested bool
if !cn.Choked && !cn.PeerInterested {
c('?')
}
+ if cn.Incoming {
+ c('I')
+ }
fmt.Fprintln(w)
}