Fixed some issues connecting for interop

This commit is contained in:
obscuren 2014-05-22 17:33:46 +02:00
parent 4e1c6a8a22
commit 14787ac148

28
peer.go
View File

@ -18,7 +18,7 @@ const (
// The size of the output buffer for writing messages // The size of the output buffer for writing messages
outputBufferSize = 50 outputBufferSize = 50
// Current protocol version // Current protocol version
ProtocolVersion = 12 ProtocolVersion = 17
) )
type DiscReason byte type DiscReason byte
@ -119,7 +119,7 @@ type Peer struct {
// this to prevent receiving false peers. // this to prevent receiving false peers.
requestedPeerList bool requestedPeerList bool
host []interface{} host []byte
port uint16 port uint16
caps Caps caps Caps
@ -134,8 +134,7 @@ type Peer struct {
} }
func NewPeer(conn net.Conn, ethereum *Ethereum, inbound bool) *Peer { func NewPeer(conn net.Conn, ethereum *Ethereum, inbound bool) *Peer {
data, _ := ethutil.Config.Db.Get([]byte("KeyRing")) pubkey := ethutil.GetKeyRing().Get(0).PublicKey[1:]
pubkey := ethutil.NewValueFromBytes(data).Get(2).Bytes()
return &Peer{ return &Peer{
outputQueue: make(chan *ethwire.Msg, outputBufferSize), outputQueue: make(chan *ethwire.Msg, outputBufferSize),
@ -342,6 +341,7 @@ func (p *Peer) HandleInbound() {
if ethutil.Config.Debug { if ethutil.Config.Debug {
ethutil.Config.Log.Infof("[PEER] Block %x failed\n", block.Hash()) ethutil.Config.Log.Infof("[PEER] Block %x failed\n", block.Hash())
ethutil.Config.Log.Infof("[PEER] %v\n", err) ethutil.Config.Log.Infof("[PEER] %v\n", err)
ethutil.Config.Log.Debugln(block)
} }
break break
} else { } else {
@ -437,7 +437,7 @@ func (p *Peer) HandleInbound() {
// If a parent is found send back a reply // If a parent is found send back a reply
if parent != nil { if parent != nil {
ethutil.Config.Log.Debugf("[PEER] Found conical block, returning chain from: %x ", parent.Hash()) ethutil.Config.Log.Debugf("[PEER] Found canonical block, returning chain from: %x ", parent.Hash())
chain := p.ethereum.BlockChain().GetChainFromHash(parent.Hash(), amountOfBlocks) chain := p.ethereum.BlockChain().GetChainFromHash(parent.Hash(), amountOfBlocks)
if len(chain) > 0 { if len(chain) > 0 {
ethutil.Config.Log.Debugf("[PEER] Returning %d blocks: %x ", len(chain), parent.Hash()) ethutil.Config.Log.Debugf("[PEER] Returning %d blocks: %x ", len(chain), parent.Hash())
@ -531,11 +531,10 @@ func (p *Peer) Stop() {
} }
func (p *Peer) pushHandshake() error { func (p *Peer) pushHandshake() error {
data, _ := ethutil.Config.Db.Get([]byte("KeyRing")) pubkey := ethutil.GetKeyRing().Get(0).PublicKey
pubkey := ethutil.NewValueFromBytes(data).Get(2).Bytes()
msg := ethwire.NewMessage(ethwire.MsgHandshakeTy, []interface{}{ msg := ethwire.NewMessage(ethwire.MsgHandshakeTy, []interface{}{
uint32(ProtocolVersion), uint32(0), p.Version, byte(p.caps), p.port, pubkey, uint32(ProtocolVersion), uint32(0), p.Version, byte(p.caps), p.port, pubkey[1:],
}) })
p.QueueMessage(msg) p.QueueMessage(msg)
@ -667,23 +666,24 @@ func (p *Peer) RlpData() []interface{} {
return []interface{}{p.host, p.port, p.pubkey} return []interface{}{p.host, p.port, p.pubkey}
} }
func packAddr(address, port string) ([]interface{}, uint16) { func packAddr(address, port string) ([]byte, uint16) {
addr := strings.Split(address, ".") addr := strings.Split(address, ".")
a, _ := strconv.Atoi(addr[0]) a, _ := strconv.Atoi(addr[0])
b, _ := strconv.Atoi(addr[1]) b, _ := strconv.Atoi(addr[1])
c, _ := strconv.Atoi(addr[2]) c, _ := strconv.Atoi(addr[2])
d, _ := strconv.Atoi(addr[3]) d, _ := strconv.Atoi(addr[3])
host := []interface{}{int32(a), int32(b), int32(c), int32(d)} host := []byte{byte(a), byte(b), byte(c), byte(d)}
prt, _ := strconv.Atoi(port) prt, _ := strconv.Atoi(port)
return host, uint16(prt) return host, uint16(prt)
} }
func unpackAddr(value *ethutil.Value, p uint64) string { func unpackAddr(value *ethutil.Value, p uint64) string {
a := strconv.Itoa(int(value.Get(0).Uint())) byts := value.Bytes()
b := strconv.Itoa(int(value.Get(1).Uint())) a := strconv.Itoa(int(byts[0]))
c := strconv.Itoa(int(value.Get(2).Uint())) b := strconv.Itoa(int(byts[1]))
d := strconv.Itoa(int(value.Get(3).Uint())) c := strconv.Itoa(int(byts[2]))
d := strconv.Itoa(int(byts[3]))
host := strings.Join([]string{a, b, c, d}, ".") host := strings.Join([]string{a, b, c, d}, ".")
port := strconv.Itoa(int(p)) port := strconv.Itoa(int(p))