Skip to content

Commit

Permalink
xrootd: use crypto/rand instead of math/rand
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastien Binet <binet@cern.ch>
  • Loading branch information
sbinet committed Feb 14, 2023
1 parent d0b7e3e commit 89566f9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
14 changes: 7 additions & 7 deletions xrootd/file_test.go
Expand Up @@ -6,9 +6,9 @@ package xrootd // import "go-hep.org/x/hep/xrootd"

import (
"context"
"crypto/rand"
"fmt"
"log"
"math/rand"
"path"
"reflect"
"testing"
Expand Down Expand Up @@ -323,12 +323,6 @@ func TestFile_Stat(t *testing.T) {
func testFile_StatVirtualFS(t *testing.T, addr string) {
t.Parallel()

want := xrdfs.VirtualFSStat{
NumberRW: 1,
FreeRW: 444,
UtilizationRW: 6,
}

client, err := NewClient(context.Background(), addr, "gopher")
if err != nil {
t.Fatalf("could not create client: %v", err)
Expand All @@ -345,6 +339,12 @@ func testFile_StatVirtualFS(t *testing.T, addr string) {
// FIXME: Investigate whether this request is allowed by the protocol: https://github.com/xrootd/xrootd/issues/728
t.Skip("Skipping this test because XRootD server probably doesn't support such requests.")

want := xrdfs.VirtualFSStat{
NumberRW: 1,
FreeRW: 444,
UtilizationRW: 6,
}

got, err := file.StatVirtualFS(context.Background())
if err != nil {
t.Fatalf("invalid stat call: %v", err)
Expand Down
3 changes: 1 addition & 2 deletions xrootd/fshandler.go
Expand Up @@ -5,9 +5,9 @@
package xrootd // import "go-hep.org/x/hep/xrootd"

import (
"crypto/rand"
"fmt"
"io"
"math/rand"
"os"
"path"
"sync"
Expand Down Expand Up @@ -146,7 +146,6 @@ func (h *fshandler) Open(sessionID [16]byte, request *open.Request) (xrdproto.Ma
// we have appr. 0.7 probability to find a free handle by the random guess.
// Then, probability that no free handle is found by 100 tries is something near pow(0.3,100) = 1e-53.
for i := 0; i < 100; i++ {
// TODO: use crypto/rand under Windows (4 times faster than math/rand) if handle generation is on the hot path.
rand.Read(handle[:])
if _, dup := sess.handles[handle]; !dup {
resp := open.Response{FileHandle: handle}
Expand Down
2 changes: 1 addition & 1 deletion xrootd/fshandler_test.go
Expand Up @@ -6,8 +6,8 @@ package xrootd_test // import "go-hep.org/x/hep/xrootd"

import (
"context"
"crypto/rand"
"fmt"
"math/rand"
"net"
"os"
"path"
Expand Down

0 comments on commit 89566f9

Please sign in to comment.