Skip to content

Commit

Permalink
cleaned changes
Browse files Browse the repository at this point in the history
  • Loading branch information
randomlogin committed Feb 28, 2024
1 parent b3cdf51 commit 6a0af05
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 105 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
github.com/getlantern/systray v1.1.0
github.com/miekg/dns v1.1.43
github.com/pkg/browser v0.0.0-20210706143420-7d21f8c997e2
github.com/randomlogin/sane v0.0.2
github.com/spf13/viper v1.8.1
github.com/sqweek/dialog v0.0.0-20210702151303-c326b49d3f01
golang.org/x/crypto v0.16.0
Expand Down Expand Up @@ -276,6 +275,7 @@ require (
github.com/prometheus/common v0.6.0 // indirect
github.com/prometheus/procfs v0.0.2 // indirect
github.com/prometheus/tsdb v0.7.1 // indirect
github.com/randomlogin/sane v0.0.3-0.20240214015449-25817feea1bb // indirect
github.com/retailnext/hllpp v1.0.1-0.20180308014038-101a6d2f8b52 // indirect
github.com/rjeczalik/notify v0.9.1 // indirect
github.com/rogpeppe/fastuuid v1.2.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,8 @@ github.com/prometheus/tsdb v0.7.1 h1:YZcsG11NqnK4czYLrWd9mpEuAJIHVQLwdrleYfszMAA
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/randomlogin/sane v0.0.2 h1:rWnVhAOJt8h4dyyCNI4AQdEUPrl7JWoo0dsg82/IFgk=
github.com/randomlogin/sane v0.0.2/go.mod h1:HPQHPiYP6lIs+7yjaJVnohnv5kHHif7lrsWp/JVUFcc=
github.com/randomlogin/sane v0.0.3-0.20240214015449-25817feea1bb h1:PJTU2XOK9mpJeckmYYctf9AKqp4gfmljmfgmJgdfVe8=
github.com/randomlogin/sane v0.0.3-0.20240214015449-25817feea1bb/go.mod h1:HPQHPiYP6lIs+7yjaJVnohnv5kHHif7lrsWp/JVUFcc=
github.com/retailnext/hllpp v1.0.1-0.20180308014038-101a6d2f8b52/go.mod h1:RDpi1RftBQPUCDRw6SmxeaREsAaRKnOclghuzp/WRzc=
github.com/rjeczalik/notify v0.9.1 h1:CLCKso/QK1snAlnhNR/CNvNiFU2saUtjV0bx3EwNeCE=
github.com/rjeczalik/notify v0.9.1/go.mod h1:rKwnCoCGeuQnwBtTSPL9Dad03Vh2n40ePRrjvIXnJho=
Expand Down
3 changes: 1 addition & 2 deletions internal/config/auto/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"io/fs"
"io/ioutil"
"os"
"path"
"strings"
Expand Down Expand Up @@ -134,7 +133,7 @@ func getProfilePaths() ([]string, error) {
}

func readPEM(certPath string) ([]byte, error) {
cert, err := ioutil.ReadFile(certPath)
cert, err := os.ReadFile(certPath)
if err != nil {
return nil, fmt.Errorf("failed reading root certificate: %v", err)
}
Expand Down
25 changes: 12 additions & 13 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
"encoding/json"
"encoding/pem"
"fmt"
"github.com/randomlogin/sane"
"io/ioutil"
"net/http"
"os"
"path"
"strings"
"time"

"github.com/randomlogin/sane"
)

const AppName = "Fingertip"
Expand All @@ -23,13 +23,12 @@ const CertKeyFileName = "private.key"
const CertName = "DNSSEC"

type App struct {
Path string
CertPath string
keyPath string
// DNSProcPath string
Proxy sane.Config
ProxyAddr string
Version string
Path string
CertPath string
keyPath string
Proxy sane.Config
ProxyAddr string
Version string

Store *Store
Debug Debugger
Expand Down Expand Up @@ -93,12 +92,12 @@ func (c *App) getOrCreateCA() (string, string, error) {
}

func loadX509KeyPair(certFile, keyFile string) (tls.Certificate, error) {
certPEMBlock, err := ioutil.ReadFile(certFile)
certPEMBlock, err := os.ReadFile(certFile)
if err != nil {
return tls.Certificate{}, err
}

keyPEMBlock, err := ioutil.ReadFile(keyFile)
keyPEMBlock, err := os.ReadFile(keyFile)
if err != nil {
return tls.Certificate{}, err
}
Expand Down Expand Up @@ -175,10 +174,10 @@ func NewConfig() (*App, error) {

c.Proxy.Constraints = nameConstraints
c.Proxy.SkipNameChecks = false
c.Proxy.Verbose = false
c.Proxy.Validity = time.Hour
c.Proxy.ContentHandler = &contentHandler{c}
c.Proxy.Verbose = true
c.Proxy.Verbose = false
c.Proxy.ExternalService = DefaultExternalService
c.Proxy.RootsPath = path.Join(c.Path, "roots.json")
if c.Proxy.Certificate, c.Proxy.PrivateKey, err = c.loadCA(); err != nil {
return nil, fmt.Errorf("failed creating config: %v", err)
Expand Down
12 changes: 7 additions & 5 deletions internal/config/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/spf13/viper"
"io/ioutil"
"os"

"github.com/spf13/viper"
)

const (
DefaultProxyAddr = "127.0.0.1:9590"
DefaultRootAddr = "127.0.0.1:9591"
DefaultRecursiveAddr = "127.0.0.1:9592"
DefaultRecursiveAddr = "https://hnsdoh.com/dns-query"
DefaultEthereumEndpoint = "https://mainnet.infura.io/v3/b0933ce6026a4e1e80e89e96a5d095bc"
DefaultExternalService = "https://sdaneproofs.htools.work/proofs/"
)

// User Represents user facing configuration
Expand Down Expand Up @@ -47,7 +48,7 @@ func readStore(path, version string, old *Store) (*Store, error) {
return zero, nil
}

b, err := ioutil.ReadFile(path)
b, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("failed reading app config: %v", err)
}
Expand All @@ -71,7 +72,7 @@ func (i *Store) Save() error {
return fmt.Errorf("failed encoding app config: %v", err)
}

if err := ioutil.WriteFile(i.path, b, 0664); err != nil {
if err := os.WriteFile(i.path, b, 0664); err != nil {
return fmt.Errorf("faild writing app config: %v", err)
}
return err
Expand All @@ -91,6 +92,7 @@ func ReadUserConfig(path string) (config User, err error) {
viper.SetDefault("PROXY_ADDRESS", DefaultProxyAddr)
viper.SetDefault("ROOT_ADDRESS", DefaultRootAddr)
viper.SetDefault("RECURSIVE_ADDRESS", DefaultRecursiveAddr)
viper.SetDefault("EXTERNAL_SERVICE", DefaultExternalService)
viper.SetDefault("ETHEREUM_ENDPOINT", DefaultEthereumEndpoint)

err = viper.ReadInConfig()
Expand Down
6 changes: 3 additions & 3 deletions internal/resolvers/dnssec/dnssec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package dnssec
import (
"bufio"
"errors"
"github.com/miekg/dns"
"io/ioutil"
"os"
"path"
"sort"
"strconv"
"strings"
"testing"
"time"

"github.com/miekg/dns"
)

type testHDR struct {
Expand All @@ -36,7 +36,7 @@ func TestVerify(t *testing.T) {
wd, _ := os.Getwd()

dir := path.Join(wd, "testdata")
files, err := ioutil.ReadDir(dir)
files, err := os.ReadDir(dir)
if err != nil {
t.Fatal(err)
}
Expand Down
95 changes: 14 additions & 81 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@ import (
"fingertip/internal/config"
"fingertip/internal/config/auto"
"fingertip/internal/resolvers"

// "fingertip/internal/resolvers/proc"
"fingertip/internal/ui"
"fmt"
"github.com/randomlogin/sane"
"github.com/randomlogin/sane/resolver"
"github.com/randomlogin/sane/sync"
"github.com/emersion/go-autostart"
"github.com/pkg/browser"
"log"
"net/http"
"os"
"path"
"path/filepath"
"time"

"github.com/emersion/go-autostart"
"github.com/pkg/browser"
"github.com/randomlogin/sane"
"github.com/randomlogin/sane/resolver"
"github.com/randomlogin/sane/sync"
)

const Version = "0.0.3"
Expand Down Expand Up @@ -47,11 +49,6 @@ func setupApp() *App {

c.Version = Version

// c.DNSProcPath, err = getProcPath()
// if err != nil {
// log.Fatal(err)
// }
// c.DNSProcPath = path.Join(c.DNSProcPath, "hnsd")
app, err := NewApp(c)
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -149,14 +146,16 @@ func main() {
app.autostartEnabled = true
}

// hnsErrCh := make(chan error)
serverErrCh := make(chan error)
onBoardingFilename := path.Join(app.config.Path, "init")
onBoarded := onBoardingSeen(onBoardingFilename)

hnsdPath, err := getProcPath()
if err != nil {
log.Fatal(err)
}
hnsdPath = path.Join(hnsdPath, "/hnsd")

// TODO: this should probably move into start() below?
hnsdPath := "/media/data/Projects/handshake/hnsd/hnsd"
hnsdCheckpointPath := ""
if hnsdPath == "" {
log.Fatal("path to hnsd is not provided")
Expand All @@ -169,7 +168,6 @@ func main() {
sync.GetRoots(hnsdPath, app.config.Path, hnsdCheckpointPath)

start := func() {
// app.proc.Start(hnsErrCh)
ui.Data.SetOptionsEnabled(true)
ui.Data.SetStarted(true)

Expand Down Expand Up @@ -222,62 +220,6 @@ func main() {
return true
}

// ticker := time.NewTicker(150 * time.Millisecond)

// go func() {
// for {
// select {
// case err := <-serverErrCh:
// if errors.Is(err, http.ErrServerClosed) {
// continue
// }

// ui.ShowErrorDlg(err.Error())
// log.Printf("[ERR] app: proxy server failed: %v", err)

// app.stop()
// ui.Data.SetStarted(false)
// case err := <-hnsErrCh:
// if !app.proc.Started() {
// continue
// }

// // hns process crashed attempt to restart
// // TODO: check if port is already in use

// attempts := app.proc.Retries()
// if attempts > 9 {
// err := fmt.Errorf("[ERR] app: fatal error hnsd process keeps crashing err: %v", err)
// ui.ShowErrorDlg(err.Error())
// app.stop()
// log.Fatal(err)
// }

// // log to a file could be useful for debugging
// line := fmt.Sprintf("[ERR] app: hnsd process crashed restart attempt #%d err: %v", attempts, err)
// log.Printf(line)
// fileLogger.Printf(line)

// // increment retries and restart process
// app.proc.IncrementRetries()
// app.proc.Stop()
// app.proc.Start(hnsErrCh)

// case <-ticker.C:
// if !app.proc.Started() {
// ui.Data.SetBlockHeight("--")
// app.config.Debug.SetBlockHeight(0)
// continue
// }

// height := app.proc.GetHeight()
// ui.Data.SetBlockHeight(fmt.Sprintf("#%d", height))
// app.config.Debug.SetBlockHeight(height)
// }

// }
// }()

ui.OnStop = func() {
app.stop()
ui.Data.SetOptionsEnabled(false)
Expand Down Expand Up @@ -314,7 +256,6 @@ func main() {

func NewApp(appConfig *config.App) (*App, error) {
var err error
// var hnsProc *proc.HNSProc
app := &App{
autostart: &autostart.App{
Name: config.AppId,
Expand All @@ -332,13 +273,6 @@ func NewApp(appConfig *config.App) (*App, error) {
app.proxyURL = config.GetProxyURL(usrConfig.ProxyAddr)
app.usrConfig = &usrConfig

// if hnsProc, err = proc.NewHNSProc(appConfig.DNSProcPath, usrConfig.RootAddr, usrConfig.RecursiveAddr); err != nil {
// return nil, err
// }
// hnsProc.SetUserAgent("fingertip:" + Version)

// app.proc = hnsProc

app.server, err = app.newProxyServer()
if err != nil {
return nil, err
Expand All @@ -348,13 +282,12 @@ func NewApp(appConfig *config.App) (*App, error) {
}

func (a *App) NewResolver() (resolver.Resolver, error) {
// rs, err := resolver.NewStub(a.usrConfig.RecursiveAddr)
rs, err := resolver.NewStub("https://hnsdoh.com/dns-query")
rs, err := resolver.NewStub(a.usrConfig.RecursiveAddr)
if err != nil {
return nil, err
}

hip5 := resolvers.NewHIP5Resolver(rs, a.usrConfig.RootAddr, func() bool {return true})
hip5 := resolvers.NewHIP5Resolver(rs, a.usrConfig.RootAddr, func() bool { return true })
ethExt, err := resolvers.NewEthereum(a.usrConfig.EthereumEndpoint)
if err != nil {
return nil, err
Expand Down

0 comments on commit 6a0af05

Please sign in to comment.