]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Minor comments and test improvement
authorMatt Joiner <anacrolix@gmail.com>
Fri, 16 Sep 2016 02:13:06 +0000 (12:13 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Fri, 16 Sep 2016 02:13:06 +0000 (12:13 +1000)
config.go
mse/mse.go
mse/mse_test.go

index 9ea764161736b77816e8cc98e3d3958da2e756ba..8b180fdc933bd582f0caf0d8f0e618dda3c93abc 100644 (file)
--- a/config.go
+++ b/config.go
@@ -33,8 +33,9 @@ type Config struct {
        DisableUTP bool
        // For the bittorrent protocol.
        DisableTCP bool `long:"disable-tcp"`
-       // Called to instantiate storage for each added torrent. Provided backends
-       // are in $REPO/data. If not set, the "file" implementation is used.
+       // Called to instantiate storage for each added torrent. Builtin backends
+       // are in the storage package. If not set, the "file" implementation is
+       // used.
        DefaultStorage    storage.ClientImpl
        DisableEncryption bool `long:"disable-encryption"`
 
index 46b59a4838862d387137519ff3030fb5504aac57..d366aa75b9d86def62c8a64c89ee5eb0a0c657ca 100644 (file)
@@ -183,13 +183,14 @@ func newPadLen() int64 {
        return ret
 }
 
+// Manages state for both initiating and receiving handshakes.
 type handshake struct {
        conn   io.ReadWriter
        s      [96]byte
-       initer bool
-       skeys  [][]byte
-       skey   []byte
-       ia     []byte // Initial payload. Only used by the initiator.
+       initer bool     // Whether we're initiating or receiving.
+       skeys  [][]byte // Skeys we'll accept if receiving.
+       skey   []byte   // Skey we're initiating with.
+       ia     []byte   // Initial payload. Only used by the initiator.
 
        writeMu    sync.Mutex
        writes     [][]byte
@@ -311,6 +312,8 @@ func suffixMatchLen(a, b []byte) int {
        return 0
 }
 
+// Reads from r until b has been seen. Keeps the minimum amount of data in
+// memory.
 func readUntil(r io.Reader, b []byte) error {
        b1 := make([]byte, len(b))
        i := 0
index d74dec97bbcedd9cb7d5b66b6700ea79951fa54e..6c2799542e79f02966e9d353940beaca1bf115b3 100644 (file)
@@ -10,6 +10,7 @@ import (
        "testing"
 
        "github.com/bradfitz/iter"
+       "github.com/stretchr/testify/require"
 )
 
 func TestReadUntil(t *testing.T) {
@@ -117,5 +118,10 @@ func (tr *trackReader) Read(b []byte) (n int, err error) {
 
 func TestReceiveRandomData(t *testing.T) {
        tr := trackReader{rand.Reader, 0}
-       ReceiveHandshake(readWriter{&tr, ioutil.Discard}, nil)
+       _, err := ReceiveHandshake(readWriter{&tr, ioutil.Discard}, nil)
+       // No skey matches
+       require.Error(t, err)
+       // Establishing S, and then reading the maximum padding for giving up on
+       // synchronizing.
+       require.EqualValues(t, 96+532, tr.n)
 }