2022-09-23 23:53:27 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-09-24 14:44:34 +00:00
|
|
|
"context"
|
|
|
|
"crypto/ecdsa"
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/ledgerwatch/erigon/cmd/lightclient/clparams"
|
2022-09-23 23:53:27 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cmd/lightclient/sentinel"
|
2022-09-24 14:44:34 +00:00
|
|
|
"github.com/ledgerwatch/erigon/crypto"
|
|
|
|
"github.com/ledgerwatch/log/v3"
|
2022-09-23 23:53:27 +00:00
|
|
|
)
|
|
|
|
|
2022-09-24 14:44:34 +00:00
|
|
|
func generateKey() (*ecdsa.PrivateKey, error) {
|
|
|
|
key, err := crypto.GenerateKey()
|
|
|
|
if err != nil {
|
|
|
|
err = fmt.Errorf("failed to generate node key: %w", err)
|
|
|
|
}
|
|
|
|
return key, err
|
|
|
|
}
|
|
|
|
|
2022-09-23 23:53:27 +00:00
|
|
|
func main() {
|
2022-09-24 14:44:34 +00:00
|
|
|
log.Root().SetHandler(log.LvlFilterHandler(log.LvlInfo, log.StderrHandler))
|
|
|
|
discCfg, err := clparams.GetDefaultDiscoveryConfig(clparams.Mainnet)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("error", "err", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
sent := sentinel.New(context.Background(), sentinel.SentinelConfig{
|
|
|
|
IpAddr: "127.0.0.1",
|
|
|
|
Port: 8080,
|
|
|
|
DiscoverConfig: *discCfg,
|
|
|
|
})
|
|
|
|
if err := sent.Start(); err != nil {
|
|
|
|
log.Error("error", "err", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
logInterval := time.NewTicker(5 * time.Second)
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-logInterval.C:
|
|
|
|
log.Info("DEBUG", "peers", len(sent.GetListener().AllNodes()))
|
|
|
|
default:
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
}
|
|
|
|
}
|
2022-09-23 23:53:27 +00:00
|
|
|
}
|