]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Ensure 64-bit alignment of ConnStats fields
authorMatt Joiner <anacrolix@gmail.com>
Sat, 23 Jun 2018 08:33:56 +0000 (18:33 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Sat, 23 Jun 2018 08:33:56 +0000 (18:33 +1000)
Fixes #262.

client.go
connection.go
torrent.go

index 705354ba7fa0153f5d257731ea9531f506556acc..bc90f0cb7f33b39800f5b2d2359741309fc40e6b 100644 (file)
--- a/client.go
+++ b/client.go
@@ -39,6 +39,9 @@ import (
 // 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
@@ -62,8 +65,6 @@ type Client struct {
        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
 }
index f58ab28835474b9a26a6aea7d086d51ed98872f4..21ebbf1b3b152e98d581ca616d71a39d12d635f2 100644 (file)
@@ -38,6 +38,9 @@ const (
 
 // 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
@@ -55,8 +58,6 @@ type connection struct {
        // other ConnStat instances as determined when the *Torrent became known.
        reconciledHandshakeStats bool
 
-       stats ConnStats
-
        lastMessageReceived     time.Time
        completedHandshake      time.Time
        lastUsefulChunkReceived time.Time
index 481d4c34ad74fada34d64ee793c89606dff37550..ccddd57368f9500105712dffc2f07297095f6bd9 100644 (file)
@@ -45,6 +45,9 @@ type peersKey struct {
 
 // 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
 
@@ -134,8 +137,6 @@ type Torrent struct {
        // 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