Browse Source

add debora support

pull/43/merge
Ethan Buchman 10 years ago
committed by Jae Kwon
parent
commit
9ce75fe755
3 changed files with 70 additions and 2 deletions
  1. +10
    -1
      cmd/main.go
  2. +36
    -1
      daemon/daemon.go
  3. +24
    -0
      p2p/pex_reactor.go

+ 10
- 1
cmd/main.go View File

@ -29,7 +29,16 @@ Commands:
case "daemon":
config.ParseFlags(args[1:])
logger.Reset()
daemon.Daemon()
var deborable daemon.DeboraMode
if len(args) > 1 {
switch args[1] {
case "debora":
deborable = daemon.DeboraPeerMode
case "dev":
deborable = daemon.DeboraDevMode
}
}
daemon.Daemon(deborable)
case "gen_account":
gen_account()
case "gen_validator":


+ 36
- 1
daemon/daemon.go View File

@ -4,6 +4,7 @@ import (
"os"
"os/signal"
"github.com/ebuchman/debora"
bc "github.com/tendermint/tendermint2/blockchain"
. "github.com/tendermint/tendermint2/common"
"github.com/tendermint/tendermint2/config"
@ -172,7 +173,36 @@ func (n *Node) MempoolReactor() *mempl.MempoolReactor {
return n.mempoolReactor
}
func Daemon() {
// debora variables
var (
AppName = "tendermint"
SrcPath = "github.com/tendermint/tendermint2/cmd"
PublicKey = "30820122300d06092a864886f70d01010105000382010f003082010a0282010100dd861e9cd5a3f3fc27d46531aa9d87f5b63f6358fa00397482c4ab93abf4ab2e3ed75380fc714d52b5e80afc184f21d5732f2d6dacc23f0e802e585ee005347c2af0ad992ee5c11b2a96f72bcae78bef314ba4448b33c3a1df7a4d6e6a808d21dfeb67ef974c0357ba54649dbcd92ec2a8d3a510da747e70cb859a7f9b15a6eceb2179c225afd3f8fb15be38988f9b82622d855f343af5830ca30a5beff3905b618f6cc39142a60ff5840595265a1f7b9fbd504760667a1b2508097c1831fd13f54c794a08468d65db9e27aff0a889665ebd7de4a6e9a6c09b3811b6cda623be48e1214ba0f9b378441e2a02b3891bc8ec1ae7081988e15c2f53fa6512784b390203010001"
DeboraCallPort = 56565
)
type DeboraMode int
const (
DeboraPeerMode DeboraMode = iota
DeboraDevMode
)
func deboraBroadcast(n *Node) func([]byte) {
return func(payload []byte) {
msg := &p2p.PexDeboraMessage{Payload: payload}
n.sw.Broadcast(p2p.PexChannel, msg)
}
}
func Daemon(deborable DeboraMode) {
// Add to debora
if deborable == DeboraPeerMode {
if err := debora.Add(PublicKey, SrcPath, AppName); err != nil {
log.Info("Failed to add program to debora", "error", err)
}
}
// Create & start node
n := NewNode()
@ -180,6 +210,11 @@ func Daemon() {
n.AddListener(l)
n.Start()
if deborable == DeboraDevMode {
log.Info("Running debora-dev server (listen to call)")
debora.DebListenAndServe("tendermint", DeboraCallPort, deboraBroadcast(n))
}
// If seedNode is provided by config, dial out.
if config.App().GetString("SeedNode") != "" {
n.DialSeed()


+ 24
- 0
p2p/pex_reactor.go View File

@ -7,6 +7,7 @@ import (
"sync/atomic"
"time"
"github.com/ebuchman/debora"
"github.com/tendermint/tendermint2/binary"
. "github.com/tendermint/tendermint2/common"
)
@ -115,6 +116,13 @@ func (pexR *PEXReactor) Receive(chId byte, src *Peer, msgBytes []byte) {
for _, addr := range msg.(*pexAddrsMessage).Addrs {
pexR.book.AddAddress(addr, srcAddr)
}
case *PexDeboraMessage:
srcAddr := src.Connection().RemoteAddress.String()
payload := msg.(*PexDeboraMessage).Payload
log.Info(fmt.Sprintf("Received debora msg with payload %s or %x", payload, payload))
if err := debora.Call(srcAddr, payload); err != nil {
log.Info("Debora upgrade call failed.", "error", err)
}
default:
// Ignore unknown message.
}
@ -215,6 +223,7 @@ const (
msgTypeRequest = byte(0x01)
msgTypeAddrs = byte(0x02)
msgTypeHandshake = byte(0x03)
msgTypeDebora = byte(0x04)
)
// TODO: check for unnecessary extra bytes at the end.
@ -230,6 +239,8 @@ func DecodeMessage(bz []byte) (msg interface{}, err error) {
msg = &pexRequestMessage{}
case msgTypeAddrs:
msg = binary.ReadBinary(&pexAddrsMessage{}, r, n, &err)
case msgTypeDebora:
msg = binary.ReadBinary(&PexDeboraMessage{}, r, n, &err)
default:
msg = nil
}
@ -273,3 +284,16 @@ func (m *pexAddrsMessage) TypeByte() byte { return msgTypeAddrs }
func (m *pexAddrsMessage) String() string {
return fmt.Sprintf("[pexAddrs %v]", m.Addrs)
}
/*
A pexDeboraMessage requests the node to upgrade its source code
*/
type PexDeboraMessage struct {
Payload []byte
}
func (m *PexDeboraMessage) TypeByte() byte { return msgTypeDebora }
func (m *PexDeboraMessage) String() string {
return "[pexDebora]"
}

Loading…
Cancel
Save