commit 9147bc58a4b1708622c4a466902136930e9db07f
parent 475f06264c63ca48384bbc8c0f1492fd7d4512c8
Author: parazyd <parazyd@dyne.org>
Date: Sat, 27 Oct 2018 13:02:21 +0200
Implement deletion in damlib's PublishToRedis function.
The function now requires an additional argument, which will tell it
whether the event is deletion or not.
Diffstat:
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/cmd/dam-dir/main.go b/cmd/dam-dir/main.go
@@ -192,7 +192,7 @@ func handlePost(rw http.ResponseWriter, request *http.Request) {
lib.CheckError(err)
}
- lib.PublishToRedis(n.Address)
+ lib.PublishToRedis("am", n.Address)
return
}
@@ -200,7 +200,7 @@ func handlePost(rw http.ResponseWriter, request *http.Request) {
// If we have't returned so far, the handshake is invalid.
log.Printf("%s: 2/2 handshake invalid.\n", n.Address)
// Delete it all from redis.
- // TODO: Also pubsub here.
+ lib.PublishToRedis("d", n.Address)
_, err := lib.RedisCli.Del(n.Address).Result()
lib.CheckError(err)
if err := postback(rw, ret, 400); err != nil {
@@ -226,7 +226,7 @@ func pollNodeTTL(interval int64) {
diff := int64((now - int64(lastseen)) / 60)
if diff > interval {
log.Printf("Deleting %s from redis because of expiration\n", i)
- // TODO: Redis pubsub
+ lib.PublishToRedis("d", i)
lib.RedisCli.Del(i)
}
}
diff --git a/pkg/damlib/redis.go b/pkg/damlib/redis.go
@@ -38,7 +38,7 @@ var RedisCli = redis.NewClient(&redis.Options{
// PublishToRedis is a function that publishes a node's status to Redis.
// This is used for Gource visualization.
-func PublishToRedis(address string) {
+func PublishToRedis(mt, address string) {
var timestamp, username, modtype, onion, pubstr string
nodedata, err := RedisCli.HGetAll(address).Result()
@@ -47,6 +47,8 @@ func PublishToRedis(address string) {
timestamp = nodedata["lastseen"]
if timestamp == nodedata["firstseen"] {
modtype = "A"
+ } else if mt == "d" {
+ modtype = "D"
} else {
modtype = "M"
}