|
@@ -7,6 +7,7 @@ import (
|
|
"fmt"
|
|
"fmt"
|
|
"io"
|
|
"io"
|
|
"log"
|
|
"log"
|
|
|
|
+ "math/rand"
|
|
"net"
|
|
"net"
|
|
"net/http"
|
|
"net/http"
|
|
"os"
|
|
"os"
|
|
@@ -50,11 +51,12 @@ var (
|
|
beQuiet = flag.Bool("quiet", true, "Be quiet")
|
|
beQuiet = flag.Bool("quiet", true, "Be quiet")
|
|
doVersion = flag.Bool("version", false, "Show version information")
|
|
doVersion = flag.Bool("version", false, "Show version information")
|
|
|
|
|
|
- natsEC *nats.EncodedConn
|
|
|
|
- count uint64
|
|
|
|
- timeout = -1 * time.Second
|
|
|
|
- ipPriv *ip.IP
|
|
|
|
- config Config
|
|
|
|
|
|
+ natsEC *nats.EncodedConn
|
|
|
|
+ natsJsonEC *nats.EncodedConn
|
|
|
|
+ count uint64
|
|
|
|
+ timeout = -1 * time.Second
|
|
|
|
+ ipPriv *ip.IP
|
|
|
|
+ config Config
|
|
|
|
|
|
// Version contains the program Version, e.g. 1.0.1
|
|
// Version contains the program Version, e.g. 1.0.1
|
|
Version string
|
|
Version string
|
|
@@ -162,6 +164,11 @@ func main() {
|
|
log.Fatalf("Encoded Connection: %v!\n", err)
|
|
log.Fatalf("Encoded Connection: %v!\n", err)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ natsJsonEC, err = nats.NewEncodedConn(natsConn, nats.JSON_ENCODER)
|
|
|
|
+ if err != nil {
|
|
|
|
+ log.Fatalf("Encoded Connection: %v!\n", err)
|
|
|
|
+ }
|
|
|
|
+
|
|
// What should I do?
|
|
// What should I do?
|
|
if config.RequestsFile != "" {
|
|
if config.RequestsFile != "" {
|
|
replayFile()
|
|
replayFile()
|
|
@@ -502,6 +509,8 @@ func replayFile() {
|
|
var startTs time.Time
|
|
var startTs time.Time
|
|
var endTs time.Time
|
|
var endTs time.Time
|
|
|
|
|
|
|
|
+ rand.Seed(time.Now().UnixNano())
|
|
|
|
+
|
|
for {
|
|
for {
|
|
fh, err := os.Open(config.RequestsFile)
|
|
fh, err := os.Open(config.RequestsFile)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -536,6 +545,25 @@ func replayFile() {
|
|
|
|
|
|
natsEC.Publish(config.NatsQueue, &req)
|
|
natsEC.Publish(config.NatsQueue, &req)
|
|
|
|
|
|
|
|
+ if strings.Index(r[1], ".") < 0 {
|
|
|
|
+ fp := data.Fingerprint{
|
|
|
|
+ ClientID: "scw",
|
|
|
|
+ Fingerprint: fmt.Sprintf("%x%x%x%x\n", rand.Int(), rand.Int(), rand.Int(), rand.Int()),
|
|
|
|
+ Remote: r[0],
|
|
|
|
+ Url: r[1],
|
|
|
|
+ Source: r[0],
|
|
|
|
+ CreatedAt: time.Now(),
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if strings.HasPrefix(r[0], "50.31.") {
|
|
|
|
+ fp.Fingerprint = "a1f2c2ee560ce6580d66d451a9c8dfbf"
|
|
|
|
+ natsJsonEC.Publish("fingerprints_scw", fp)
|
|
|
|
+ } else if rand.Intn(10) < 8 {
|
|
|
|
+ natsJsonEC.Publish("fingerprints_scw", fp)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
count++
|
|
count++
|
|
if config.SleepFor.Duration >= time.Nanosecond {
|
|
if config.SleepFor.Duration >= time.Nanosecond {
|
|
endTs = time.Now()
|
|
endTs = time.Now()
|