port byte order to big endian
This commit is contained in:
parent
9c152bae79
commit
1eab73d560
5 changed files with 6 additions and 12 deletions
|
@ -167,9 +167,6 @@ func (m *Message) unmarshalPayload(r io.Reader) error {
|
|||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("incomming payload: %d bytes\n", len(pbuf))
|
||||
fmt.Println(pbuf)
|
||||
|
||||
if uint32(n) != m.Length {
|
||||
return fmt.Errorf("expected to have read exactly %d bytes got %d", m.Length, n)
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ func (p *AddrWithTime) UnmarshalBinary(b []byte) error {
|
|||
p.Timestamp = binary.LittleEndian.Uint32(b[0:4])
|
||||
p.Services = binary.LittleEndian.Uint64(b[4:12])
|
||||
binary.Read(bytes.NewReader(b[12:28]), binary.BigEndian, &p.Addr.IP)
|
||||
p.Addr.Port = binary.LittleEndian.Uint16(b[28:30])
|
||||
p.Addr.Port = binary.BigEndian.Uint16(b[28:30])
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ package payload
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
|
||||
. "github.com/anthdm/neo-go/pkg/util"
|
||||
)
|
||||
|
@ -48,8 +47,6 @@ func (p *Inventory) UnmarshalBinary(b []byte) error {
|
|||
// TODO: what byte is [1:2] ?
|
||||
// We have 1 byte for the type which is uint8 and 32 for the hash.
|
||||
// There is 1 byte left over.
|
||||
fmt.Println(b[0:1])
|
||||
fmt.Println(b[1:2])
|
||||
binary.Read(bytes.NewReader(b), binary.LittleEndian, &p.Type)
|
||||
p.Hash.UnmarshalBinary(b[2:len(b)])
|
||||
return nil
|
||||
|
|
|
@ -171,10 +171,7 @@ func (s *Server) loop() {
|
|||
// TODO: unregister peers on error.
|
||||
// processMessage processes the received message from a remote node.
|
||||
func (s *Server) processMessage(msg *Message, peer *Peer) error {
|
||||
rpcLogger.Printf("IN :: %s", msg.commandType())
|
||||
if msg.Length > 0 {
|
||||
rpcLogger.Printf("IN :: %+v", msg.Payload)
|
||||
}
|
||||
rpcLogger.Printf("IN :: %s :: %+v", msg.commandType(), msg.Payload)
|
||||
|
||||
switch msg.commandType() {
|
||||
case cmdVersion:
|
||||
|
@ -228,6 +225,9 @@ func (s *Server) handleVersionCmd(v *payload.Version, peer *Peer) error {
|
|||
}
|
||||
|
||||
func (s *Server) handleAddrCmd(addrList *payload.AddressList, peer *Peer) error {
|
||||
for _, addr := range addrList.Addrs {
|
||||
fmt.Println(addr)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -52,8 +52,8 @@ func handleConnection(s *Server, conn net.Conn, initiated bool) {
|
|||
|
||||
// Read from the connection and decode it into an RPCMessage and
|
||||
// tell the server there is message available for proccesing.
|
||||
msg := &Message{}
|
||||
for {
|
||||
msg := &Message{}
|
||||
if err := msg.decode(conn); err != nil {
|
||||
// remote connection probably closed.
|
||||
if err == io.EOF {
|
||||
|
|
Loading…
Reference in a new issue