Browse Source

beginning to write pex

pull/9/head
Jae Kwon 11 years ago
parent
commit
a6f574658f
3 changed files with 69 additions and 5 deletions
  1. +0
    -3
      peer/msg.go
  2. +2
    -2
      peer/peer.go
  3. +67
    -0
      peer/pex.go

+ 0
- 3
peer/msg.go View File

@ -1,12 +1,9 @@
package peer
import (
"io"
. "github.com/tendermint/tendermint/binary"
)
type Message interface {
Binary
Type() string
}

+ 2
- 2
peer/peer.go View File

@ -201,8 +201,8 @@ func NewPacket(chName String, bytes ByteSlice) Packet {
}
func (p Packet) WriteTo(w io.Writer) (n int64, err error) {
n, err = WriteOnto(&p.Channel, w, n, err)
n, err = WriteOnto(&p.Bytes, w, n, err)
n, err = WriteOnto(p.Channel, w, n, err)
n, err = WriteOnto(p.Bytes, w, n, err)
return
}


+ 67
- 0
peer/pex.go View File

@ -0,0 +1,67 @@
package peer
import (
. "github.com/tendermint/tendermint/binary"
"io"
)
const pexCh = "PEX"
func peerExchangeHandler(c *Client) {
for {
// inPkt := c.Receive(pexCh) // {Peer, Time, Packet}
// decode message
// if message is a peer request
// if message is
}
// cleanup
}
/* Messages */
const (
pexTypeRequest = Byte(0x00)
pexTypeResponse = Byte(0x01)
)
func decodeMsg(bytes ByteSlice) (t Byte, msg Message) {
//return pexTypeRequest, nil
return pexTypeResponse, nil
}
/*
A response with peer addresses
*/
type pexResponseMsg struct {
Addrs []*NetAddress
}
func readPexResponseMsg(r io.Reader) *pexResponseMsg {
numAddrs := int(ReadUInt32(r))
addrs := []*NetAddress{}
for i := 0; i < numAddrs; i++ {
addr := ReadNetAddress(r)
addrs = append(addrs, addr)
}
return &pexResponseMsg{
Addrs: addrs,
}
}
func (m *pexResponseMsg) WriteTo(w io.Writer) (n int64, err error) {
n, err = WriteOnto(UInt32(len(m.Addrs)), w, n, err)
for _, addr := range m.Addrs {
n, err = WriteOnto(addr, w, n, err)
}
return
}
func (m *pexResponseMsg) Type() string {
return "pexTypeResponse"
}

Loading…
Cancel
Save