Record if a connection was incoming

This commit is contained in:
Matt Joiner 2014-07-01 00:04:28 +10:00
parent 147ad31135
commit 23cfe49ea4
2 changed files with 12 additions and 5 deletions

View File

@ -224,6 +224,7 @@ func (cl *Client) acceptConnections() {
conn, err := cl.Listener.Accept()
select {
case <-cl.quit:
conn.Close()
return
default:
}
@ -231,6 +232,7 @@ func (cl *Client) acceptConnections() {
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)
@ -309,6 +311,7 @@ func (cl *Client) incomingPeerPort() int {
func (me *Client) runConnection(sock net.Conn, torrent *torrent) (err error) {
conn := &connection{
Incoming: torrent == nil,
Socket: sock,
Choked: true,
PeerChoked: true,

View File

@ -15,11 +15,12 @@ import (
// 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
@ -76,6 +77,9 @@ func (cn *connection) WriteStatus(w io.Writer) {
if !cn.Choked && !cn.PeerInterested {
c('?')
}
if cn.Incoming {
c('I')
}
fmt.Fprintln(w)
}