Fixes #262.
// Clients contain zero or more Torrents. A Client manages a blocklist, the
// TCP/UDP protocol ports, and DHT as desired.
type Client struct {
+ // An aggregate of stats over all connections. First in struct to ensure
+ // 64-bit alignment of fields. See #262.
+ stats ConnStats
mu sync.RWMutex
event sync.Cond
closed missinggo.Event
dopplegangerAddrs map[string]struct{}
badPeerIPs map[string]struct{}
torrents map[metainfo.Hash]*Torrent
- // An aggregate of stats over all connections.
- stats ConnStats
acceptLimiter map[ipStr]int
}
// Maintains the state of a connection with a peer.
type connection struct {
+ // First to ensure 64-bit alignment for atomics. See #262.
+ stats ConnStats
+
t *Torrent
// The actual Conn, used for closing, and setting socket options.
conn net.Conn
// other ConnStat instances as determined when the *Torrent became known.
reconciledHandshakeStats bool
- stats ConnStats
-
lastMessageReceived time.Time
completedHandshake time.Time
lastUsefulChunkReceived time.Time
// Maintains state of torrent within a Client.
type Torrent struct {
+ // Torrent-level aggregate statistics. First in struct to ensure 64-bit
+ // alignment. See #262.
+ stats ConnStats
cl *Client
logger *log.Logger
// These "inclinations" are used to give connections preference for
// different pieces.
connPieceInclinationPool sync.Pool
- // Torrent-level statistics.
- stats ConnStats
// Count of each request across active connections.
pendingRequests map[request]int