tImplement deletion in damlib's PublishToRedis function. - tordam - A library for peer discovery inside the Tor network
HTML git clone https://git.parazyd.org/tordam
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
DIR commit 9147bc58a4b1708622c4a466902136930e9db07f
DIR parent 475f06264c63ca48384bbc8c0f1492fd7d4512c8
HTML 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:
M cmd/dam-dir/main.go | 6 +++---
M pkg/damlib/redis.go | 4 +++-
2 files changed, 6 insertions(+), 4 deletions(-)
---
DIR diff --git a/cmd/dam-dir/main.go b/cmd/dam-dir/main.go
t@@ -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
}
t@@ -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 {
t@@ -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)
}
}
DIR diff --git a/pkg/damlib/redis.go b/pkg/damlib/redis.go
t@@ -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()
t@@ -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"
}