erigon-pulse/cmd/lightclient/main.go
Enrique Jose Avila Asapche abfa374165
LightClient P2P refactoring (#5507)
* separated convertions into utils.go

* added log to bad peers

* more verbose errors and names

* warn when banning bad peer

* has and get in function name

* space

* lint

* ops

* little rename

* deleted unused func

* revert
2022-09-25 20:39:09 +02:00

50 lines
1.1 KiB
Go

package main
import (
"context"
"time"
"github.com/ledgerwatch/erigon/cmd/lightclient/clparams"
"github.com/ledgerwatch/erigon/cmd/lightclient/sentinel"
"github.com/ledgerwatch/log/v3"
)
var (
defaultIpAddr = "127.0.0.1" // Localhost
defaultPort = 8080
defaultTcpPort = uint(9000)
)
func main() {
log.Root().SetHandler(log.LvlFilterHandler(log.LvlInfo, log.StderrHandler))
discCfg, err := clparams.GetDefaultDiscoveryConfig(clparams.MainnetNetwork)
if err != nil {
log.Error("error", "err", err)
return
}
sent, err := sentinel.New(context.Background(), sentinel.SentinelConfig{
IpAddr: defaultIpAddr,
Port: defaultPort,
TCPPort: defaultTcpPort,
DiscoverConfig: *discCfg,
})
if err != nil {
log.Error("error", "err", err)
return
}
if err := sent.Start(); err != nil {
log.Error("failed to start sentinel", "err", err)
return
}
log.Info("Sentinel started", "enr", sent.String())
logInterval := time.NewTicker(5 * time.Second)
for {
select {
case <-logInterval.C:
log.Info("[Lighclient] Networking Report", "peers", sent.GetPeersCount())
default:
time.Sleep(100 * time.Millisecond)
}
}
}