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.

68 lines
2.0 KiB

  1. package p2p
  2. import "encoding/binary"
  3. var FLAGS_VALUE uint32 = 0 // we donot support fluffly blocks at this point in time
  4. var support_response_bytes = [29]byte{0x01, 0x11, 0x01, 0x01, 0x01, 0x01, 0x02, 0x01, 0x01, 0x04, 0x0d, 0x73, 0x75, 0x70, 0x70,
  5. 0x6f, 0x72, 0x74, 0x5f, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x06, 0x00, 0x00, 0x00, 0x00}
  6. // handle P2P_COMMAND_REQUEST_SUPPORT_FLAGS
  7. func Handle_P2P_Support_Flags(connection *Connection,
  8. i_command_header *Levin_Header, buf []byte) {
  9. // deserialize data header
  10. var i_data_header Levin_Data_Header // incoming data header
  11. err := i_data_header.DeSerialize(buf)
  12. if err != nil {
  13. connection.logger.Debugf("We should destroy connection here, data header cnot deserialized")
  14. connection.Exit = true
  15. return
  16. }
  17. // make sure data is length 10
  18. // create a new response header
  19. var o_command_header Levin_Header
  20. //var o_data_header Levin_Data_Header
  21. binary.LittleEndian.PutUint32(support_response_bytes[25:], FLAGS_VALUE) // packed 8+8+1+4 bytes
  22. o_command_header.CB = uint64(len(support_response_bytes))
  23. o_command_header.Command = P2P_COMMAND_REQUEST_SUPPORT_FLAGS
  24. o_command_header.ReturnData = false
  25. o_command_header.Flags = LEVIN_PACKET_RESPONSE
  26. o_command_header_bytes, _ := o_command_header.Serialize()
  27. connection.Conn.Write(o_command_header_bytes)
  28. connection.Conn.Write(support_response_bytes[:])
  29. }
  30. // send the hand shake
  31. func Send_SupportFlags_Command(connection *Connection) {
  32. connection.Lock()
  33. var o_command_header Levin_Header
  34. var o_data_header Levin_Data_Header
  35. o_data_bytes, _ := o_data_header.Serialize()
  36. o_command_header.CB = uint64(len(o_data_bytes))
  37. o_command_header.Command = P2P_COMMAND_REQUEST_SUPPORT_FLAGS
  38. o_command_header.ReturnData = true
  39. o_command_header.Flags = LEVIN_PACKET_REQUEST
  40. o_command_header_bytes, _ := o_command_header.Serialize()
  41. connection.Conn.Write(o_command_header_bytes)
  42. connection.Conn.Write(o_data_bytes)
  43. connection.Command_queue.PushBack(uint32(P2P_COMMAND_REQUEST_SUPPORT_FLAGS))
  44. connection.Unlock()
  45. }