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"`
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
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
"testing"
"github.com/bradfitz/iter"
+ "github.com/stretchr/testify/require"
)
func TestReadUntil(t *testing.T) {
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)
}