added dep, makefile
This commit is contained in:
parent
0aee55d249
commit
d989d42ad3
7 changed files with 298 additions and 10 deletions
cmd
|
@ -1,6 +1,7 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
crand "crypto/rand"
|
||||
"math/rand"
|
||||
"os"
|
||||
"os/signal"
|
||||
|
@ -9,11 +10,12 @@ import (
|
|||
"sync"
|
||||
"syscall"
|
||||
|
||||
"github.com/hashicorp/serf/serf"
|
||||
"github.com/lbryio/internal-apis/app/crypto"
|
||||
"github.com/lbryio/lbry.go/errors"
|
||||
"github.com/lbryio/reflector.go/cluster"
|
||||
|
||||
"github.com/btcsuite/btcutil/base58"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/hashicorp/serf/serf"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
@ -41,7 +43,7 @@ func clusterCmd(cmd *cobra.Command, args []string) {
|
|||
var eventCh <-chan serf.Event
|
||||
var err error
|
||||
|
||||
nodeName := crypto.RandString(12)
|
||||
nodeName := randString(12)
|
||||
clusterAddr := "127.0.0.1:" + strconv.Itoa(clusterPort)
|
||||
if args[0] == clusterStart {
|
||||
c, eventCh, err = cluster.Connect(nodeName, clusterAddr, clusterPort)
|
||||
|
@ -121,3 +123,19 @@ func getAliveMembers(members []serf.Member) []serf.Member {
|
|||
}
|
||||
return alive
|
||||
}
|
||||
|
||||
// RandString returns a random alphanumeric string of a given length
|
||||
func randString(length int) string {
|
||||
buf := make([]byte, length)
|
||||
_, err := crand.Reader.Read(buf)
|
||||
if err != nil {
|
||||
panic(errors.Err(err))
|
||||
}
|
||||
|
||||
randStr := base58.Encode(buf)[:length]
|
||||
if len(randStr) < length {
|
||||
panic(errors.Err("Could not create random string that is long enough"))
|
||||
}
|
||||
|
||||
return randStr
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue