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.

84 lines
3.0 KiB

  1. // Copyright 2017-2018 DERO Project. All rights reserved.
  2. // Use of this source code in any form is governed by RESEARCH license.
  3. // license can be found in the LICENSE file.
  4. // GPG: 0F39 E425 8C65 3947 702A 8234 08B2 0360 A03A 9DE8
  5. //
  6. //
  7. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
  8. // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  9. // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
  10. // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  11. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  12. // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  13. // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  14. // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  15. // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. package p2p
  17. import "encoding/binary"
  18. var FLAGS_VALUE uint32 = 0 // we donot support fluffly blocks at this point in time
  19. var support_response_bytes = [29]byte{0x01, 0x11, 0x01, 0x01, 0x01, 0x01, 0x02, 0x01, 0x01, 0x04, 0x0d, 0x73, 0x75, 0x70, 0x70,
  20. 0x6f, 0x72, 0x74, 0x5f, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x06, 0x00, 0x00, 0x00, 0x00}
  21. // handle P2P_COMMAND_REQUEST_SUPPORT_FLAGS
  22. func Handle_P2P_Support_Flags(connection *Connection,
  23. i_command_header *Levin_Header, buf []byte) {
  24. // deserialize data header
  25. var i_data_header Levin_Data_Header // incoming data header
  26. err := i_data_header.DeSerialize(buf)
  27. if err != nil {
  28. connection.logger.Debugf("We should destroy connection here, data header cnot deserialized")
  29. connection.Exit = true
  30. return
  31. }
  32. // make sure data is length 10
  33. // create a new response header
  34. var o_command_header Levin_Header
  35. //var o_data_header Levin_Data_Header
  36. binary.LittleEndian.PutUint32(support_response_bytes[25:], FLAGS_VALUE) // packed 8+8+1+4 bytes
  37. o_command_header.CB = uint64(len(support_response_bytes))
  38. o_command_header.Command = P2P_COMMAND_REQUEST_SUPPORT_FLAGS
  39. o_command_header.ReturnData = false
  40. o_command_header.Flags = LEVIN_PACKET_RESPONSE
  41. o_command_header_bytes, _ := o_command_header.Serialize()
  42. connection.Conn.Write(o_command_header_bytes)
  43. connection.Conn.Write(support_response_bytes[:])
  44. }
  45. // send the hand shake
  46. func Send_SupportFlags_Command(connection *Connection) {
  47. connection.Lock()
  48. var o_command_header Levin_Header
  49. var o_data_header Levin_Data_Header
  50. o_data_bytes, _ := o_data_header.Serialize()
  51. o_command_header.CB = uint64(len(o_data_bytes))
  52. o_command_header.Command = P2P_COMMAND_REQUEST_SUPPORT_FLAGS
  53. o_command_header.ReturnData = true
  54. o_command_header.Flags = LEVIN_PACKET_REQUEST
  55. o_command_header_bytes, _ := o_command_header.Serialize()
  56. connection.Conn.Write(o_command_header_bytes)
  57. connection.Conn.Write(o_data_bytes)
  58. connection.Command_queue.PushBack(uint32(P2P_COMMAND_REQUEST_SUPPORT_FLAGS))
  59. connection.Unlock()
  60. }