Sha256: ac8261acbcaddf273af17aeed061be827d6b191bcd7da5abe72ba8a8bb8b9e1b

Contents?: true

Size: 888 Bytes

Versions: 8

Compression:

Stored size: 888 Bytes

Contents

# -*- coding: binary -*-

require 'rex/proto/kademlia/message'

module Rex
module Proto
module Kademlia
  # Opcode for a PING response
  PONG = 0x61

  # A Kademlia pong message.
  class Pong < Message
    # @return [Integer] the source port from which the PING was received
    attr_reader :port

    def initialize(port = nil)
      super(PONG)
      @port = port
    end

    # Builds a pong from given data
    #
    # @param data [String] the data to decode
    # @return [Pong] the pong if the data is valid, nil otherwise
    def self.from_data(data)
      message = super(data)
      return if message.type != PONG
      return if message.body.size != 2
      Pong.new(message.body.unpack('v')[0])
    end

    # Get this Pong as a String
    #
    # @return [String] the string representation of this Pong
    def to_str
      super + [@port].pack('v')
    end
  end
end
end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rex-2.0.13 lib/rex/proto/kademlia/pong.rb
rex-2.0.12 lib/rex/proto/kademlia/pong.rb
rex-2.0.11 lib/rex/proto/kademlia/pong.rb
rex-2.0.10 lib/rex/proto/kademlia/pong.rb
rex-2.0.9 lib/rex/proto/kademlia/pong.rb
rex-2.0.8 lib/rex/proto/kademlia/pong.rb
rex-2.0.7 lib/rex/proto/kademlia/pong.rb
rex-2.0.5 lib/rex/proto/kademlia/pong.rb