Skip to content

Commit

Permalink
Merge pull request #10 from Terran-Stakers/master
Browse files Browse the repository at this point in the history
Small refactoring & better web server implem
  • Loading branch information
catShaark authored Nov 25, 2021
2 parents 2b00ba5 + 94bc294 commit ea781c2
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 67 deletions.
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ require (
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/gtank/merlin v0.1.1 // indirect
github.com/jessevdk/go-flags v1.4.0 // indirect
github.com/jrick/logrotate v1.0.0 // indirect
Expand All @@ -41,8 +42,11 @@ require (
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
go.opencensus.io v0.23.0 // indirect
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
golang.org/x/net v0.0.0-20211020060615-d418f374d309 // indirect
golang.org/x/sys v0.0.0-20211023085530-d6a326fbbf70 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
google.golang.org/protobuf v1.27.1 // indirect
googlemaps.github.io/maps v1.3.2 // indirect
)
15 changes: 15 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
Expand All @@ -257,6 +258,8 @@ github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hf
github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
Expand Down Expand Up @@ -333,6 +336,7 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxv
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
Expand Down Expand Up @@ -478,6 +482,7 @@ github.com/sasha-s/go-deadlock v0.3.1 h1:sqv7fDNShgjcaxkO0JNcOAlr8B9+cV5Ey/OB71e
github.com/sasha-s/go-deadlock v0.3.1/go.mod h1:F73l+cr82YSh10GxyRI6qZiCgK64VaZjwesgfQ1/iLM=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/seccomp/libseccomp-golang v0.9.1/go.mod h1:GbW5+tmTXfcxTToHLXlScSlAvWlF4P2Ca7zGrPiEpWo=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
Expand Down Expand Up @@ -513,6 +518,7 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
Expand Down Expand Up @@ -546,6 +552,8 @@ go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.23.0 h1:gqCw0LfLxScz8irSi8exQc7fyQ0fKQU/qnC/X8+V/1M=
go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E=
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
Expand Down Expand Up @@ -641,6 +649,7 @@ golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81R
golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210903162142-ad29c8ab022f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
Expand Down Expand Up @@ -738,6 +747,9 @@ golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxb
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac h1:7zkz7BUtwNFFqcowJ+RIgu2MaV/MapERkDIy+mwPyjs=
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down Expand Up @@ -863,6 +875,7 @@ google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKa
google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk=
google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
google.golang.org/grpc v1.37.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
Expand All @@ -879,6 +892,8 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
googlemaps.github.io/maps v1.3.2 h1:3YfYdVWFTFi7lVdCdrDYW3dqHvfCSUdC7/x8pbMOuKQ=
googlemaps.github.io/maps v1.3.2/go.mod h1:cCq0JKYAnnCRSdiaBi7Ex9CW15uxIAk7oPi8V/xEh6s=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
164 changes: 105 additions & 59 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,31 @@
package main

import (
"embed"
"fmt"
"github.com/mitchellh/go-homedir"
"github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/libs/log"
tmos "github.com/tendermint/tendermint/libs/os"
tmstrings "github.com/tendermint/tendermint/libs/strings"
"github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/p2p/pex"
"github.com/tendermint/tendermint/version"
"html/template"
"net/http"
"os"
"path/filepath"
"time"

"github.com/mitchellh/go-homedir"
)

var (
// https://blog.jetbrains.com/go/2021/06/09/how-to-use-go-embed-in-go-1-16/
//go:embed resources
res embed.FS
pages = map[string]string{
"/": "web/index.html",
}
configDir = ".tinyseed"
logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout))
)

// Config defines the configuration format
type Config struct {
ListenAddress string `toml:"laddr" comment:"Address to listen for incoming connections"`
HttpPort string `toml:"http_port" comment:"Port for the http server"`
ChainID string `toml:"chain_id" comment:"network identifier (todo move to cli flag argument? keeps the config network agnostic)"`
NodeKeyFile string `toml:"node_key_file" comment:"path to node_key (relative to tendermint-seed home directory or an absolute path)"`
AddrBookFile string `toml:"addr_book_file" comment:"path to address book (relative to tendermint-seed home directory or an absolute path)"`
Expand All @@ -43,48 +39,95 @@ type Config struct {
func DefaultConfig() *Config {
return &Config{
ListenAddress: "tcp://0.0.0.0:6969",
HttpPort: "3000",
ChainID: "osmosis-1",
NodeKeyFile: "config/node_key.json",
AddrBookFile: "data/addrbook.json",
NodeKeyFile: "node_key.json",
AddrBookFile: "addrbook.json",
AddrBookStrict: true,
MaxNumInboundPeers: 1000,
MaxNumInboundPeers: 3000,
MaxNumOutboundPeers: 1000,
Seeds: "[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656",
}
}

func startWebServer() {
http.Handle("/", http.FileServer(http.Dir("/tmp")))


s := &http.Server{
Addr: ":8080",
Handler: myHandler,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
}
}

func main() {
idOverride := os.Getenv("ID")
seedOverride := os.Getenv("SEEDS")
userHomeDir, err := homedir.Dir()
seedConfig := DefaultConfig()

if err != nil {
panic(err)
}
homeDir := filepath.Join(userHomeDir, ".terranseed")
configFile := "config/config.toml"
configFilePath := filepath.Join(homeDir, configFile)

// init config directory & files
homeDir := filepath.Join(userHomeDir, configDir, "config")
configFilePath := filepath.Join(homeDir, "config.toml")
nodeKeyFilePath := filepath.Join(homeDir, seedConfig.NodeKeyFile)
addrBookFilePath := filepath.Join(homeDir, seedConfig.AddrBookFile)

MkdirAllPanic(filepath.Dir(nodeKeyFilePath), os.ModePerm)
MkdirAllPanic(filepath.Dir(addrBookFilePath), os.ModePerm)
MkdirAllPanic(filepath.Dir(configFilePath), os.ModePerm)
SeedConfig := DefaultConfig()

if idOverride != "" {
SeedConfig.ChainID = idOverride
seedConfig.ChainID = idOverride
}
if seedOverride != "" {
SeedConfig.Seeds = seedOverride
seedConfig.Seeds = seedOverride
}
logger.Info("Starting Web Server...")
StartWebServer(*seedConfig)
logger.Info("Starting Seed Node...")
Start(*seedConfig)
}

func StartWebServer(seedConfig Config) {

// serve static assets
fs := http.FileServer(http.Dir("./web/assets"))
http.Handle("/assets/", http.StripPrefix("/assets/", fs))

// serve html files
http.HandleFunc("/", serveTemplate)

// start web server in non-blocking
go func() {
err := http.ListenAndServe(":"+seedConfig.HttpPort, nil)
logger.Info("HTTP Server started", "port", seedConfig.HttpPort)
if err != nil {
panic(err)
}
}()
}

func serveTemplate(w http.ResponseWriter, r *http.Request) {
index := filepath.Join("./web/templates", "index.html")
templates := filepath.Join("./web/templates", filepath.Clean(r.URL.Path))
logger.Info("index", "i", index, "t", templates)

// Return a 404 if the template doesn't exist
fileInfo, err := os.Stat(templates)

if err != nil || fileInfo.IsDir() {
http.Redirect(w, r, "/index.html", 302)
return
}

tmpl, err := template.ParseFiles(index, templates)
if err != nil {
// Log the detailed error
logger.Error(err.Error())
// Return a generic "Internal Server Error" message
http.Error(w, http.StatusText(500), 500)
return
}

err = tmpl.ExecuteTemplate(w, "index", nil)
if err != nil {
logger.Error(err.Error())
http.Error(w, http.StatusText(500), 500)
}
Start(*SeedConfig)
}

// MkdirAllPanic invokes os.MkdirAll but panics if there is an error
Expand All @@ -96,42 +139,30 @@ func MkdirAllPanic(path string, perm os.FileMode) {
}

// Start starts a Tenderseed
func Start(SeedConfig Config) {
logger := log.NewTMLogger(
log.NewSyncWriter(os.Stdout),
)

chainID := SeedConfig.ChainID
nodeKeyFilePath := SeedConfig.NodeKeyFile
addrBookFilePath := SeedConfig.AddrBookFile
func Start(seedConfig Config) {

MkdirAllPanic(filepath.Dir(nodeKeyFilePath), os.ModePerm)
MkdirAllPanic(filepath.Dir(addrBookFilePath), os.ModePerm)
chainID := seedConfig.ChainID

cfg := config.DefaultP2PConfig()
cfg.AllowDuplicateIP = true

// allow a lot of inbound peers since we disconnect from them quickly in seed mode
cfg.MaxNumInboundPeers = 3000

// keep trying to make outbound connections to exchange peering info
cfg.MaxNumOutboundPeers = 400

userHomeDir, err := homedir.Dir()
nodeKeyFilePath := filepath.Join(userHomeDir, configDir, "config", seedConfig.NodeKeyFile)
nodeKey, err := p2p.LoadOrGenNodeKey(nodeKeyFilePath)
if err != nil {
panic(err)
}

logger.Info("terranseed",
logger.Info("Configuration",
"key", nodeKey.ID(),
"listen", SeedConfig.ListenAddress,
"node listen", seedConfig.ListenAddress,
"http server port", seedConfig.HttpPort,
"chain", chainID,
"strict-routing", SeedConfig.AddrBookStrict,
"max-inbound", SeedConfig.MaxNumInboundPeers,
"max-outbound", SeedConfig.MaxNumOutboundPeers,
"strict-routing", seedConfig.AddrBookStrict,
"max-inbound", seedConfig.MaxNumInboundPeers,
"max-outbound", seedConfig.MaxNumOutboundPeers,
)

// TODO(roman) expose per-module log levels in the config
filteredLogger := log.NewFilter(logger, log.AllowInfo())

protocolVersion :=
Expand All @@ -141,11 +172,11 @@ func Start(SeedConfig Config) {
0,
)

// NodeInfo gets info on yhour node
// NodeInfo gets info on your node
nodeInfo := p2p.DefaultNodeInfo{
ProtocolVersion: protocolVersion,
DefaultNodeID: nodeKey.ID(),
ListenAddr: SeedConfig.ListenAddress,
ListenAddr: seedConfig.ListenAddress,
Network: chainID,
Version: "0.6.9",
Channels: []byte{pex.PexChannel},
Expand All @@ -162,12 +193,15 @@ func Start(SeedConfig Config) {
panic(err)
}

book := pex.NewAddrBook(addrBookFilePath, SeedConfig.AddrBookStrict)
addrBookFilePath := filepath.Join(userHomeDir, configDir, "config", seedConfig.AddrBookFile)
book := pex.NewAddrBook(addrBookFilePath, seedConfig.AddrBookStrict)
book.SetLogger(filteredLogger.With("module", "book"))

pexReactor := pex.NewReactor(book, &pex.ReactorConfig{
SeedMode: true,
Seeds: tmstrings.SplitAndTrim(SeedConfig.Seeds, ",", " "),
SeedMode: true,
Seeds: tmstrings.SplitAndTrim(seedConfig.Seeds, ",", " "),
SeedDisconnectWaitPeriod: 1 * time.Second, // default is 28 hours, we just want to harvest as many addresses as possible
PersistentPeersMaxDialPeriod: 0, // use exponential back-off
})
pexReactor.SetLogger(filteredLogger.With("module", "pex"))

Expand All @@ -194,5 +228,17 @@ func Start(SeedConfig Config) {
panic(err)
}

go func() {
// Fire periodically
ticker := time.NewTicker(5 * time.Second)

for {
select {
case <-ticker.C:
logger.Info("Peers list", "peers", sw.Peers().List())
}
}
}()

sw.Wait()
}
3 changes: 3 additions & 0 deletions web/assets/css/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
h2 {
color: grey;
}
8 changes: 0 additions & 8 deletions web/index.html

This file was deleted.

12 changes: 12 additions & 0 deletions web/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{define "index"}}

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="/assets/css/main.css" />
</head>
<body>
<h2>It works!</h2>
</body>
</html>
{{end}}

0 comments on commit ea781c2

Please sign in to comment.