2022-09-25 19:01:39 +00:00
|
|
|
/*
|
|
|
|
Copyright 2022 Erigon-Lightclient contributors
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-09-23 23:53:27 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-09-24 14:44:34 +00:00
|
|
|
"context"
|
|
|
|
"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/log/v3"
|
2022-09-23 23:53:27 +00:00
|
|
|
)
|
|
|
|
|
2022-09-25 18:39:09 +00:00
|
|
|
var (
|
|
|
|
defaultIpAddr = "127.0.0.1" // Localhost
|
|
|
|
defaultPort = 8080
|
|
|
|
defaultTcpPort = uint(9000)
|
|
|
|
)
|
2022-09-24 14:44:34 +00:00
|
|
|
|
2022-09-23 23:53:27 +00:00
|
|
|
func main() {
|
2022-09-25 00:14:10 +00:00
|
|
|
log.Root().SetHandler(log.LvlFilterHandler(log.LvlInfo, log.StderrHandler))
|
2022-09-25 20:41:51 +00:00
|
|
|
discCfg, genesisCfg, networkCfg, err := clparams.GetConfigsByNetwork(clparams.MainnetNetwork)
|
2022-09-24 14:44:34 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Error("error", "err", err)
|
|
|
|
return
|
|
|
|
}
|
2022-09-24 18:48:56 +00:00
|
|
|
sent, err := sentinel.New(context.Background(), sentinel.SentinelConfig{
|
2022-09-25 18:39:09 +00:00
|
|
|
IpAddr: defaultIpAddr,
|
|
|
|
Port: defaultPort,
|
|
|
|
TCPPort: defaultTcpPort,
|
2022-09-24 14:44:34 +00:00
|
|
|
DiscoverConfig: *discCfg,
|
2022-09-25 20:41:51 +00:00
|
|
|
GenesisConfig: genesisCfg,
|
|
|
|
NetworkConfig: networkCfg,
|
2022-09-24 14:44:34 +00:00
|
|
|
})
|
2022-09-24 18:48:56 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Error("error", "err", err)
|
|
|
|
return
|
|
|
|
}
|
2022-09-24 14:44:34 +00:00
|
|
|
if err := sent.Start(); err != nil {
|
2022-09-25 18:39:09 +00:00
|
|
|
log.Error("failed to start sentinel", "err", err)
|
2022-09-24 14:44:34 +00:00
|
|
|
return
|
|
|
|
}
|
2022-09-25 00:14:10 +00:00
|
|
|
log.Info("Sentinel started", "enr", sent.String())
|
2022-09-24 14:44:34 +00:00
|
|
|
logInterval := time.NewTicker(5 * time.Second)
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-logInterval.C:
|
2022-09-25 18:39:09 +00:00
|
|
|
log.Info("[Lighclient] Networking Report", "peers", sent.GetPeersCount())
|
2022-09-24 14:44:34 +00:00
|
|
|
default:
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
}
|
|
|
|
}
|
2022-09-23 23:53:27 +00:00
|
|
|
}
|