The utp firewall callback might want to use it. I can't think of a better way to determine with an incoming connection request should be blocked.
for _, _s := range sockets {
s := _s // Go is fucking retarded.
for _, _s := range sockets {
s := _s // Go is fucking retarded.
- cl.onClose = append(cl.onClose, func() { s.Close() })
+ cl.onClose = append(cl.onClose, func() { go s.Close() })
if peerNetworkEnabled(parseNetworkString(s.Addr().Network()), cl.config) {
cl.dialers = append(cl.dialers, s)
cl.listeners = append(cl.listeners, s)
if peerNetworkEnabled(parseNetworkString(s.Addr().Network()), cl.config) {
cl.dialers = append(cl.dialers, s)
cl.listeners = append(cl.listeners, s)
func (cl *Client) outgoingConnection(t *Torrent, addr PeerRemoteAddr, ps PeerSource, trusted bool) {
cl.dialRateLimiter.Wait(context.Background())
c, err := cl.establishOutgoingConn(t, addr)
func (cl *Client) outgoingConnection(t *Torrent, addr PeerRemoteAddr, ps PeerSource, trusted bool) {
cl.dialRateLimiter.Wait(context.Background())
c, err := cl.establishOutgoingConn(t, addr)
+ if err == nil {
+ c.conn.SetWriteDeadline(time.Time{})
+ }
cl.lock()
defer cl.unlock()
// Don't release lock between here and addPeerConn, unless it's for
cl.lock()
defer cl.unlock()
// Don't release lock between here and addPeerConn, unless it's for
return
}
torrent.Add("received handshake for loaded torrent", 1)
return
}
torrent.Add("received handshake for loaded torrent", 1)
+ c.conn.SetWriteDeadline(time.Time{})
cl.lock()
defer cl.unlock()
t.runHandshookConnLoggingErr(c)
cl.lock()
defer cl.unlock()
t.runHandshookConnLoggingErr(c)
if c.PeerID == cl.peerID {
if c.outgoing {
connsToSelf.Add(1)
if c.PeerID == cl.peerID {
if c.outgoing {
connsToSelf.Add(1)
- addr := c.conn.RemoteAddr().String()
+ addr := c.RemoteAddr.String()
cl.dopplegangerAddrs[addr] = struct{}{}
} /* else {
// Because the remote address is not necessarily the same as its client's torrent listen
cl.dopplegangerAddrs[addr] = struct{}{}
} /* else {
// Because the remote address is not necessarily the same as its client's torrent listen
t.logger.WithLevel(log.Debug).Printf("local and remote peer ids are the same")
return nil
}
t.logger.WithLevel(log.Debug).Printf("local and remote peer ids are the same")
return nil
}
- c.conn.SetWriteDeadline(time.Time{})
c.r = deadlineReader{c.conn, c.r}
completedHandshakeConnectionFlags.Add(c.connectionFlags(), 1)
if connIsIpv6(c.conn) {
c.r = deadlineReader{c.conn, c.r}
completedHandshakeConnectionFlags.Add(c.connectionFlags(), 1)
if connIsIpv6(c.conn) {
PeerID PeerID
PeerExtensionBytes pp.PeerExtensionBits
PeerID PeerID
PeerExtensionBytes pp.PeerExtensionBits
- // The actual Conn, used for closing, and setting socket options.
+ // The actual Conn, used for closing, and setting socket options. Do not use methods on this
+ // while holding any mutexes.
conn net.Conn
// The Reader and Writer for this Conn, with hooks installed for stats,
// limiting, deadlines etc.
conn net.Conn
// The Reader and Writer for this Conn, with hooks installed for stats,
// limiting, deadlines etc.
}
cn.tickleWriter()
if cn.conn != nil {
}
cn.tickleWriter()
if cn.conn != nil {
}
if cb := cn.callbacks.PeerConnClosed; cb != nil {
cb(cn)
}
if cb := cn.callbacks.PeerConnClosed; cb != nil {
cb(cn)
} else {
pc.Discovery = PeerSourceIncoming
}
} else {
pc.Discovery = PeerSourceIncoming
}
+ pc.conn.SetWriteDeadline(time.Time{})
t.cl.lock()
defer t.cl.unlock()
err = t.cl.runHandshookConn(pc, t)
t.cl.lock()
defer t.cl.unlock()
err = t.cl.runHandshookConn(pc, t)