[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taldir] branch master updated: refactor and restructure project
From: |
gnunet |
Subject: |
[taler-taldir] branch master updated: refactor and restructure project |
Date: |
Wed, 06 Jul 2022 16:46:14 +0200 |
This is an automated email from the git hooks/post-receive script.
martin-schanzenbach pushed a commit to branch master
in repository taldir.
The following commit(s) were added to refs/heads/master by this push:
new 37874b8 refactor and restructure project
37874b8 is described below
commit 37874b8c865ff295b1e125ee36c970fc8dedf7bd
Author: Martin Schanzenbach <schanzen@gnunet.org>
AuthorDate: Wed Jul 6 16:46:11 2022 +0200
refactor and restructure project
---
Makefile | 7 ++++++
cmd/taldir-cli/main.go | 42 +++++++++++++++++++++++++++++++
taldir.go => cmd/taldir-server/main.go | 45 +---------------------------------
taldir-validate-twitter.sh | 2 +-
test.sh | 2 +-
util/helper.go | 22 +++++++++++++++++
6 files changed, 74 insertions(+), 46 deletions(-)
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..ecfade3
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,7 @@
+all: server cli
+
+server:
+ go build ./cmd/taldir-server
+
+cli:
+ go build ./cmd/taldir-cli
diff --git a/cmd/taldir-cli/main.go b/cmd/taldir-cli/main.go
new file mode 100644
index 0000000..5bab284
--- /dev/null
+++ b/cmd/taldir-cli/main.go
@@ -0,0 +1,42 @@
+package main
+
+import (
+ "os"
+ "fmt"
+ "flag"
+ "taler.net/taldir/util"
+ "crypto/sha512"
+)
+
+// Generates a link from a code and address
+func generateLink(addr string, code string) string {
+ h := sha512.New()
+ h.Write([]byte(addr))
+ h_addr := util.EncodeBinaryToString(h.Sum(nil))
+ return "taler://taldir/" + h_addr + "/" + code + "-wallet"
+}
+
+func main() {
+ var solveFlag = flag.Bool("s", false, "Provide a solution for the
code/pubkey")
+ var linkFlag = flag.Bool("l", false, "Provide a link for activation")
+ var codeFlag = flag.String("c", "", "Activation code")
+ var pubkeyFlag = flag.String("p", "", "Public key")
+ var addressFlag = flag.String("a", "", "Address")
+ flag.Parse()
+ if *solveFlag {
+ if len(*codeFlag) == 0 || len(*pubkeyFlag) == 0 {
+ fmt.Println("You need to provide an activation code and a public key to
generate a solution")
+ os.Exit(1)
+ }
+ fmt.Println(util.GenerateSolution(*pubkeyFlag, *codeFlag))
+ os.Exit(0)
+ }
+ if *linkFlag {
+ if len(*codeFlag) == 0 || len(*addressFlag) == 0 {
+ fmt.Println("You need to provide an activation code and an address to
generate a link")
+ os.Exit(1)
+ }
+ fmt.Println(generateLink(*addressFlag, *codeFlag))
+ os.Exit(0)
+ }
+}
diff --git a/taldir.go b/cmd/taldir-server/main.go
similarity index 90%
rename from taldir.go
rename to cmd/taldir-server/main.go
index fda7e30..247b106 100644
--- a/taldir.go
+++ b/cmd/taldir-server/main.go
@@ -250,7 +250,7 @@ func validationRequest(w http.ResponseWriter, r
*http.Request){
w.WriteHeader(http.StatusNotFound)
return
}
- expectedSolution := generateSolution(validation.PublicKey, validation.Code)
+ expectedSolution := util.GenerateSolution(validation.PublicKey,
validation.Code)
if confirm.Solution != expectedSolution {
// FIXME how TF do we rate limit here??
w.WriteHeader(http.StatusForbidden)
@@ -433,28 +433,6 @@ func validationPage(w http.ResponseWriter, r
*http.Request) {
return
}
-// Generates a link from a code and address
-func generateLink(addr string, code string) string {
- h := sha512.New()
- h.Write([]byte(addr))
- h_addr := util.EncodeBinaryToString(h.Sum(nil))
- return "taler://taldir/" + h_addr + "/" + code + "-wallet"
-}
-
-// Generates a solution from a code and pubkey
-func generateSolution(pubkeyEncoded string, code string) string {
- pubkey, err := util.DecodeStringToBinary(pubkeyEncoded, 36)
- if err != nil {
- fmt.Println("error decoding pubkey:", err)
- return ""
- }
- h := sha512.New()
- h.Write([]byte(code))
- h.Write(pubkey)
- return util.EncodeBinaryToString(h.Sum(nil))
-}
-
-
func handleRequests() {
myRouter := mux.NewRouter().StrictSlash(true)
@@ -487,33 +465,12 @@ func main() {
if cfg.Section("taldir").Key("production").MustBool(false) {
fmt.Println("Production mode enabled")
}
- var solveFlag = flag.Bool("s", false, "Provide a solution for the
code/pubkey")
- var linkFlag = flag.Bool("l", false, "Provide a link for activation")
- var codeFlag = flag.String("c", "", "Activation code")
- var pubkeyFlag = flag.String("p", "", "Public key")
- var addressFlag = flag.String("a", "", "Address")
var dropFlag = flag.Bool("D", false, "Drop all data in table (DANGEROUS!)")
flag.Parse()
- if *solveFlag {
- if len(*codeFlag) == 0 || len(*pubkeyFlag) == 0 {
- fmt.Println("You need to provide an activation code and a public key to
generate a solution")
- os.Exit(1)
- }
- fmt.Println(generateSolution(*pubkeyFlag, *codeFlag))
- os.Exit(0)
- }
validators = make(map[string]bool)
for _, a := range
strings.Split(cfg.Section("taldir").Key("validators").String(), " ") {
validators[a] = true
}
- if *linkFlag {
- if len(*codeFlag) == 0 || len(*addressFlag) == 0 {
- fmt.Println("You need to provide an activation code and an address to
generate a link")
- os.Exit(1)
- }
- fmt.Println(generateLink(*addressFlag, *codeFlag))
- os.Exit(0)
- }
validators = make(map[string]bool)
for _, a := range
strings.Split(cfg.Section("taldir").Key("validators").String(), " ") {
validators[a] = true
diff --git a/taldir-validate-twitter.sh b/taldir-validate-twitter.sh
index e600d9f..5aec5cb 100755
--- a/taldir-validate-twitter.sh
+++ b/taldir-validate-twitter.sh
@@ -7,6 +7,6 @@
#
TWITTER_USER=$1
CODE=$2
-LINK=$(./taldir -l -a $1 -c $2)
+LINK=$(./taldir-cli -l -a $1 -c $2)
MESSAGE="Follow this link to complete your Taldir registration: $LINK"
t dm $TWITTER_USER $MESSAGE
diff --git a/test.sh b/test.sh
index 413b47c..e6aeaef 100755
--- a/test.sh
+++ b/test.sh
@@ -8,7 +8,7 @@ H_ADDRESS=`echo -n abc@test | openssl dgst -binary -sha512 |
gnunet-base32`
echo "Code: $CODE; Address: $H_ADDRESS"
# Validate
# echo localhost:11000/register/$H_ADDRESS/$CODE
-SOLUTION=$(./taldir -s -c ${CODE} -p ${PUBKEY})
+SOLUTION=$(./taldir-cli -s -c ${CODE} -p ${PUBKEY})
echo "Solution: $SOLUTION"
curl -v localhost:11000/$H_ADDRESS --data "{\"solution\": \"${SOLUTION}\"}"
# Get mapping
diff --git a/util/helper.go b/util/helper.go
new file mode 100644
index 0000000..19a72ae
--- /dev/null
+++ b/util/helper.go
@@ -0,0 +1,22 @@
+package util
+
+import (
+ "fmt"
+ "crypto/sha512"
+)
+
+
+// Generates a solution from a code and pubkey
+func GenerateSolution(pubkeyEncoded string, code string) string {
+ pubkey, err := DecodeStringToBinary(pubkeyEncoded, 36)
+ if err != nil {
+ fmt.Println("error decoding pubkey:", err)
+ return ""
+ }
+ h := sha512.New()
+ h.Write([]byte(code))
+ h.Write(pubkey)
+ return EncodeBinaryToString(h.Sum(nil))
+}
+
+
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-taldir] branch master updated: refactor and restructure project,
gnunet <=