tImplement -t flag for choosing between nodes being (in)valid initially. - tordam - A library for peer discovery inside the Tor network
 (HTM) git clone https://git.parazyd.org/tordam
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 9273ef22a622c87441f711236c2d11515da6914f
 (DIR) parent b97811cbf9b58bcf190ed3cc88aa414a04cc84e6
 (HTM) Author: parazyd <parazyd@dyne.org>
       Date:   Thu, 19 Jul 2018 16:22:53 +0200
       
       Implement -t flag for choosing between nodes being (in)valid initially.
       
       Diffstat:
         M cmd/dam-dir/main.go                 |       9 +++++++++
         M pkg/damlib/config.go                |       4 ++++
         M pkg/damlib/validate.go              |       6 +++++-
       
       3 files changed, 18 insertions(+), 1 deletion(-)
       ---
 (DIR) diff --git a/cmd/dam-dir/main.go b/cmd/dam-dir/main.go
       t@@ -22,6 +22,7 @@ package main
        
        import (
                "encoding/json"
       +        "flag"
                "log"
                "net/http"
                "os"
       t@@ -213,6 +214,14 @@ func handleElse(rw http.ResponseWriter, request *http.Request) {}
        
        func main() {
                var wg sync.WaitGroup
       +        var t bool
       +
       +        flag.BoolVar(&t, "t", false, "Mark all new nodes valid initially")
       +        flag.Parse()
       +
       +        if t {
       +                lib.Testnet = true
       +        }
        
                // Chdir to our working directory.
                if _, err := os.Stat(lib.Cwd); os.IsNotExist(err) {
 (DIR) diff --git a/pkg/damlib/config.go b/pkg/damlib/config.go
       t@@ -46,3 +46,7 @@ const TorPortMap = "80:49371,13010:13010,13011:13011,5000:5000"
        
        // DirPort is the port where dam-dir will be listening.
        const DirPort = 49371
       +
       +// Testnet is flipped with a flag in dam-dir and represents if all new
       +// nodes are initially marked valid or not.
       +var Testnet = false
 (DIR) diff --git a/pkg/damlib/validate.go b/pkg/damlib/validate.go
       t@@ -155,7 +155,11 @@ func ValidateFirstHandshake(req map[string]string) (bool, string) {
                if ex != 1 { // We did not have this node in redis.
                        info["pubkey"] = pub
                        info["firstseen"] = time.Now().Unix()
       -                info["valid"] = 1
       +                if Testnet {
       +                        info["valid"] = 1
       +                } else {
       +                        info["valid"] = 0
       +                }
                }
        
                log.Printf("%s: writing to redis\n", req["address"])