tordam

A library for peer discovery inside the Tor network
git clone https://git.parazyd.org/tordam
Log | Files | Refs | README | LICENSE

commit b86db595deb695358fc2591453f9b1dbea1267b8
parent fef7f290c2817471b77e212ea8eb7fd0d75f3b26
Author: parazyd <parazyd@dyne.org>
Date:   Fri,  8 Dec 2017 18:40:09 +0100

Write "firstseen" and "valid" only if the node is not in redis

Diffstat:
Mcmd/dam-dir/main.go | 16++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/cmd/dam-dir/main.go b/cmd/dam-dir/main.go @@ -99,9 +99,9 @@ func handlePost(rw http.ResponseWriter, request *http.Request) { jsonVal, err := json.Marshal(ret) lib.CheckError(err) - // TODO: We probably _do_ want to allow the keyholder to - // reannounce itself, so let's not handle this yet. - //ex := RedisCli.Exists(n.Address) + // Check if we have seen this node already. + ex, err := RedisCli.Exists(n.Address).Result() + lib.CheckError(err) // Save the node into redis info := map[string]interface{}{ @@ -111,11 +111,15 @@ func handlePost(rw http.ResponseWriter, request *http.Request) { "signature": n.Signature, "secret": base64.StdEncoding.EncodeToString([]byte(randString)), "pubkey": n.Pubkey, - "firstseen": n.Firstseen, "lastseen": n.Lastseen, - "valid": 0, // This should be 1 after the node is not considered malicious } - log.Println("Writing into Redis") + + if ex != 1 { + info["firstseen"] = n.Firstseen + info["valid"] = 0 // This should be 1 after the node is not considered malicious + } + + log.Println("Writing to Redis") redRet, err := RedisCli.HMSet(n.Address, info).Result() lib.CheckError(err)