You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1007 B

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. package peer
  2. import (
  3. . "github.com/tendermint/tendermint/binary"
  4. "io"
  5. )
  6. /* Packet */
  7. type Packet struct {
  8. Channel String
  9. Bytes ByteSlice
  10. // Hash
  11. }
  12. func NewPacket(chName String, bytes ByteSlice) Packet {
  13. return Packet{
  14. Channel: chName,
  15. Bytes: bytes,
  16. }
  17. }
  18. func (p Packet) WriteTo(w io.Writer) (n int64, err error) {
  19. n, err = WriteOnto(&p.Channel, w, n, err)
  20. n, err = WriteOnto(&p.Bytes, w, n, err)
  21. return
  22. }
  23. func ReadPacketSafe(r io.Reader) (pkt Packet, err error) {
  24. chName, err := ReadStringSafe(r)
  25. if err != nil {
  26. return
  27. }
  28. // TODO: packet length sanity check.
  29. bytes, err := ReadByteSliceSafe(r)
  30. if err != nil {
  31. return
  32. }
  33. return NewPacket(chName, bytes), nil
  34. }
  35. /* InboundPacket */
  36. type InboundPacket struct {
  37. Peer *Peer
  38. Channel *Channel
  39. Time Time
  40. Packet
  41. }
  42. /* NewFilterMsg */
  43. type NewFilterMsg struct {
  44. ChName String
  45. Filter interface{} // todo
  46. }
  47. func (m *NewFilterMsg) WriteTo(w io.Writer) (int64, error) {
  48. panic("TODO: implement")
  49. return 0, nil // TODO
  50. }