mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-22 09:21:32 +00:00
bug fixes in binary
This commit is contained in:
73
main.go
73
main.go
@ -1,33 +1,35 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/tendermint/tendermint/config"
|
||||
"github.com/tendermint/tendermint/p2p"
|
||||
)
|
||||
|
||||
func initPeer(peer *p2p.Peer) {
|
||||
//
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
// Define channels for our app
|
||||
chDescs := []ChannelDescriptor{
|
||||
ChannelDescriptor{
|
||||
chDescs := []p2p.ChannelDescriptor{
|
||||
p2p.ChannelDescriptor{
|
||||
Name: "PEX",
|
||||
SendBufferSize: 2,
|
||||
RecvBuffersize: 2,
|
||||
RecvBufferSize: 2,
|
||||
},
|
||||
ChannelDescriptor{
|
||||
p2p.ChannelDescriptor{
|
||||
Name: "block",
|
||||
SendBufferSize: 10,
|
||||
RecvBufferSize: 10,
|
||||
},
|
||||
ChannelDescriptor{
|
||||
p2p.ChannelDescriptor{
|
||||
Name: "mempool",
|
||||
SendBufferSize: 100,
|
||||
RecvBufferSize: 100,
|
||||
},
|
||||
ChannelDescriptor{
|
||||
p2p.ChannelDescriptor{
|
||||
Name: "consensus",
|
||||
SendBufferSize: 1000,
|
||||
RecvBufferSize: 1000,
|
||||
@ -35,19 +37,62 @@ func main() {
|
||||
}
|
||||
|
||||
// Create the switch
|
||||
sw := NewSwitch(chDescs)
|
||||
sw := p2p.NewSwitch(chDescs)
|
||||
|
||||
// Create a listener for incoming connections
|
||||
l := NewDefaultListener("tcp", ":8001")
|
||||
l := p2p.NewDefaultListener("tcp", ":8001")
|
||||
go func() {
|
||||
for {
|
||||
inConn, ok := <-l.Connections()
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
sw.AddPeerWithConnection(inConn, false)
|
||||
peer, err := sw.AddPeerWithConnection(inConn, false)
|
||||
if err != nil {
|
||||
log.Infof("Ignoring error from incoming connection: %v\n%v",
|
||||
peer, err)
|
||||
continue
|
||||
}
|
||||
initPeer(peer)
|
||||
}
|
||||
}()
|
||||
|
||||
// TODO
|
||||
// Open our address book
|
||||
book := p2p.NewAddrBook(config.AppDir + "/addrbook.json")
|
||||
|
||||
// Start PEX
|
||||
go p2p.PexHandler(sw, book)
|
||||
|
||||
// Sleep forever
|
||||
go _trapSignal()
|
||||
select {}
|
||||
}
|
||||
|
||||
func initPeer(peer *p2p.Peer) {
|
||||
// TODO: ask for more peers if we need them.
|
||||
}
|
||||
|
||||
func trapSignal() {
|
||||
ch := make(chan os.Signal)
|
||||
signal.Notify(ch, syscall.SIGINT)
|
||||
sig := <-ch
|
||||
fmt.Println("???", sig)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
func _trapSignal() {
|
||||
// capture ctrl+c and stop CPU profiler
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, os.Interrupt)
|
||||
//signal.Notify(c, syscall.SIGINT)
|
||||
go func() {
|
||||
fmt.Println("inside")
|
||||
for sig := range c {
|
||||
fmt.Println("signal!>>", sig)
|
||||
log.Infof("captured %v, stopping profiler and exiting..", sig)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Println("inside done")
|
||||
}()
|
||||
fmt.Println("ok")
|
||||
}
|
||||
|
Reference in New Issue
Block a user