diff --git a/consumer.go b/consumer.go index 9a69e30..67557a0 100644 --- a/consumer.go +++ b/consumer.go @@ -2,6 +2,8 @@ package main import ( + "crypto/md5" + "crypto/sha1" "crypto/sha256" "encoding/hex" "fmt" @@ -19,7 +21,7 @@ type consumed struct { logins []string } -func hash(val []byte) string { +func hash256(val []byte) string { h := sha256.New() h.Write(val) @@ -27,6 +29,22 @@ func hash(val []byte) string { return hex.EncodeToString(h.Sum(nil)) } +func hash160(val []byte) string { + + h := sha1.New() + h.Write(val) + + return hex.EncodeToString(h.Sum(nil)) +} + +func hash128(val []byte) string { + + h := md5.New() + h.Write(val) + + return hex.EncodeToString(h.Sum(nil)) +} + func consumer() { for { @@ -46,7 +64,7 @@ func consumer() { bulk.Unordered() for p := range prod { - mlID := hash([]byte(fmt.Sprintf("%s%s", prod[p].user, start.Format("20060102T15")))) + mlID := hash128([]byte(fmt.Sprintf("%s%s", prod[p].user, start.Format("20060102T15")))) mquota := MongoQuota{ ID: mlID, User: prod[p].user, diff --git a/main.go b/main.go index 3ad1d7b..b128ed5 100644 --- a/main.go +++ b/main.go @@ -12,7 +12,7 @@ import ( ) const ( - _Version = "v2.2.2" + _Version = "v2.3.0" _Producer = 0 _Consumer = 1 ) diff --git a/options.go b/options.go index cd65620..12cd7b1 100644 --- a/options.go +++ b/options.go @@ -70,6 +70,6 @@ func init() { flag.DurationVar(&opts.Timeout, "T", 0, "Running timeout") flag.BoolVar(&opts.Debug, "D", false, "Debug") flag.BoolVar(&opts.Test, "DD", false, "Test") - flag.IntVar(&opts.MaxBulk, "M", 500, "Max Mongodb bulk") + flag.IntVar(&opts.MaxBulk, "M", 300, "Max Mongodb bulk") flag.IntVar(&opts.Queue, "q", 2, "parallel consumer") }