@ -21,7 +21,7 @@ import (
"github.com/tendermint/tendermint/crypto/secp256k1"
"github.com/tendermint/tendermint/crypto/secp256k1"
"github.com/tendermint/tendermint/libs/async"
"github.com/tendermint/tendermint/libs/async"
tmos "github.com/tendermint/tendermint/libs/os"
tmos "github.com/tendermint/tendermint/libs/os"
"github.com/tendermint/tendermint/libs/rand"
tmrand "github.com/tendermint/tendermint/libs/rand"
)
)
type kvstoreConn struct {
type kvstoreConn struct {
@ -105,7 +105,7 @@ func TestSecretConnectionHandshake(t *testing.T) {
func TestConcurrentWrite ( t * testing . T ) {
func TestConcurrentWrite ( t * testing . T ) {
fooSecConn , barSecConn := makeSecretConnPair ( t )
fooSecConn , barSecConn := makeSecretConnPair ( t )
fooWriteText := rand . Rand Str( dataMaxSize )
fooWriteText := tm rand. Str ( dataMaxSize )
// write from two routines.
// write from two routines.
// should be safe from race according to net.Conn:
// should be safe from race according to net.Conn:
@ -127,7 +127,7 @@ func TestConcurrentWrite(t *testing.T) {
func TestConcurrentRead ( t * testing . T ) {
func TestConcurrentRead ( t * testing . T ) {
fooSecConn , barSecConn := makeSecretConnPair ( t )
fooSecConn , barSecConn := makeSecretConnPair ( t )
fooWriteText := rand . Rand Str( dataMaxSize )
fooWriteText := tm rand. Str ( dataMaxSize )
n := 100
n := 100
// read from two routines.
// read from two routines.
@ -174,8 +174,8 @@ func TestSecretConnectionReadWrite(t *testing.T) {
// Pre-generate the things to write (for foo & bar)
// Pre-generate the things to write (for foo & bar)
for i := 0 ; i < 100 ; i ++ {
for i := 0 ; i < 100 ; i ++ {
fooWrites = append ( fooWrites , rand . Rand Str( ( rand . Rand Int( ) % ( dataMaxSize * 5 ) ) + 1 ) )
barWrites = append ( barWrites , rand . Rand Str( ( rand . Rand Int( ) % ( dataMaxSize * 5 ) ) + 1 ) )
fooWrites = append ( fooWrites , tm rand. Str ( ( tm rand. Int ( ) % ( dataMaxSize * 5 ) ) + 1 ) )
barWrites = append ( barWrites , tm rand. Str ( ( tm rand. Int ( ) % ( dataMaxSize * 5 ) ) + 1 ) )
}
}
// A helper that will run with (fooConn, fooWrites, fooReads) and vice versa
// A helper that will run with (fooConn, fooWrites, fooReads) and vice versa
@ -372,11 +372,11 @@ func TestNonEd25519Pubkey(t *testing.T) {
func createGoldenTestVectors ( t * testing . T ) string {
func createGoldenTestVectors ( t * testing . T ) string {
data := ""
data := ""
for i := 0 ; i < 32 ; i ++ {
for i := 0 ; i < 32 ; i ++ {
randSecretVector := rand . Rand Bytes( 32 )
randSecretVector := tm rand. Bytes ( 32 )
randSecret := new ( [ 32 ] byte )
randSecret := new ( [ 32 ] byte )
copy ( ( * randSecret ) [ : ] , randSecretVector )
copy ( ( * randSecret ) [ : ] , randSecretVector )
data += hex . EncodeToString ( ( * randSecret ) [ : ] ) + ","
data += hex . EncodeToString ( ( * randSecret ) [ : ] ) + ","
locIsLeast := rand . Rand Bool( )
locIsLeast := tm rand. Bool ( )
data += strconv . FormatBool ( locIsLeast ) + ","
data += strconv . FormatBool ( locIsLeast ) + ","
recvSecret , sendSecret := deriveSecrets ( randSecret , locIsLeast )
recvSecret , sendSecret := deriveSecrets ( randSecret , locIsLeast )
data += hex . EncodeToString ( ( * recvSecret ) [ : ] ) + ","
data += hex . EncodeToString ( ( * recvSecret ) [ : ] ) + ","
@ -400,7 +400,7 @@ func BenchmarkWriteSecretConnection(b *testing.B) {
}
}
fooWriteBytes := make ( [ ] [ ] byte , 0 , len ( randomMsgSizes ) )
fooWriteBytes := make ( [ ] [ ] byte , 0 , len ( randomMsgSizes ) )
for _ , size := range randomMsgSizes {
for _ , size := range randomMsgSizes {
fooWriteBytes = append ( fooWriteBytes , rand . Rand Bytes( size ) )
fooWriteBytes = append ( fooWriteBytes , tm rand. Bytes ( size ) )
}
}
// Consume reads from bar's reader
// Consume reads from bar's reader
go func ( ) {
go func ( ) {
@ -418,7 +418,7 @@ func BenchmarkWriteSecretConnection(b *testing.B) {
b . StartTimer ( )
b . StartTimer ( )
for i := 0 ; i < b . N ; i ++ {
for i := 0 ; i < b . N ; i ++ {
idx := rand . Rand Intn( len ( fooWriteBytes ) )
idx := tm rand. Intn ( len ( fooWriteBytes ) )
_ , err := fooSecConn . Write ( fooWriteBytes [ idx ] )
_ , err := fooSecConn . Write ( fooWriteBytes [ idx ] )
if err != nil {
if err != nil {
b . Errorf ( "failed to write to fooSecConn: %v" , err )
b . Errorf ( "failed to write to fooSecConn: %v" , err )
@ -448,11 +448,11 @@ func BenchmarkReadSecretConnection(b *testing.B) {
}
}
fooWriteBytes := make ( [ ] [ ] byte , 0 , len ( randomMsgSizes ) )
fooWriteBytes := make ( [ ] [ ] byte , 0 , len ( randomMsgSizes ) )
for _ , size := range randomMsgSizes {
for _ , size := range randomMsgSizes {
fooWriteBytes = append ( fooWriteBytes , rand . Rand Bytes( size ) )
fooWriteBytes = append ( fooWriteBytes , tm rand. Bytes ( size ) )
}
}
go func ( ) {
go func ( ) {
for i := 0 ; i < b . N ; i ++ {
for i := 0 ; i < b . N ; i ++ {
idx := rand . Rand Intn( len ( fooWriteBytes ) )
idx := tm rand. Intn ( len ( fooWriteBytes ) )
_ , err := fooSecConn . Write ( fooWriteBytes [ idx ] )
_ , err := fooSecConn . Write ( fooWriteBytes [ idx ] )
if err != nil {
if err != nil {
b . Errorf ( "failed to write to fooSecConn: %v, %v,%v" , err , i , b . N )
b . Errorf ( "failed to write to fooSecConn: %v, %v,%v" , err , i , b . N )